Preferred district

This commit is contained in:
John 2015-08-07 17:36:58 +03:00
parent e31d7fae8e
commit 4a0ac70835
3 changed files with 32 additions and 16 deletions

View file

@ -813,7 +813,7 @@ class OTPClientRepository(ClientRepositoryBase):
district = None district = None
if not district: if not district:
self.distributedDistrict = self.getStartingDistrict() self.distributedDistrict = self.getStartingDistrict()
if self.distributedDistrict is None: if not self.distributedDistrict:
self.loginFSM.request('noShards') self.loginFSM.request('noShards')
return return
shardId = self.distributedDistrict.doId shardId = self.distributedDistrict.doId
@ -1030,26 +1030,26 @@ class OTPClientRepository(ClientRepositoryBase):
pass pass
def getStartingDistrict(self): def getStartingDistrict(self):
district = None if not self.activeDistrictMap:
if len(self.activeDistrictMap.keys()) == 0:
self.notify.info('no shards') self.notify.info('no shards')
return return
maxPop = config.GetInt('shard-mid-pop', 300) maxPop = config.GetInt('shard-mid-pop', 300)
preferred = settings.get('preferredShard', None)
if preferred:
for shard in self.activeDistrictMap.values():
if shard.available and shard.name == preferred and shard.avatarCount < maxPop:
return shard
# Join the least populated district.
for shard in self.activeDistrictMap.values(): for shard in self.activeDistrictMap.values():
if district: if shard.available and shard.avatarCount < maxPop:
if shard.avatarCount < district.avatarCount and shard.available: district = shard
if shard.avatarCount < maxPop: maxPop = district.avatarCount
district = shard
else:
if shard.available:
if shard.avatarCount < maxPop:
district = shard
if district is not None: if district:
self.notify.debug('chose %s: pop %s' % (district.name, district.avatarCount)) self.notify.debug('chose %s: pop %s' % (district.name, district.avatarCount))
return district return district
def getShardName(self, shardId): def getShardName(self, shardId):

View file

@ -87,6 +87,7 @@ class ShardPage(ShtikerPage.ShtikerPage):
self.groupDialog = None self.groupDialog = None
def load(self): def load(self):
matchGui = loader.loadModel('phase_3.5/models/gui/matching_game_gui')
main_text_scale = 0.06 main_text_scale = 0.06
title_text_scale = 0.12 title_text_scale = 0.12
self.title = DirectLabel(parent=self, relief=None, text=TTLocalizer.ShardPageTitle, text_scale=title_text_scale, textMayChange=0, pos=(0, 0, 0.6)) self.title = DirectLabel(parent=self, relief=None, text=TTLocalizer.ShardPageTitle, text_scale=title_text_scale, textMayChange=0, pos=(0, 0, 0.6))
@ -96,6 +97,7 @@ class ShardPage(ShtikerPage.ShtikerPage):
totalPop_ycoord = shardPop_ycoord - 0.44 totalPop_ycoord = shardPop_ycoord - 0.44
self.districtInfo = NodePath('Selected-Shard-Info') self.districtInfo = NodePath('Selected-Shard-Info')
self.districtInfo.reparentTo(self) self.districtInfo.reparentTo(self)
self.preferredButton = DirectButton(parent=self, relief=None, image=matchGui.find('**/minnieCircle'), pos=(0.1, 0, -0.575), scale=0.35, text=TTLocalizer.ShardPagePreferred, text_scale=0.11, text_pos=(0, -0.2), command=self.setPreferredShard)
self.totalPopulationText = DirectLabel(parent=self.districtInfo, relief=None, text=TTLocalizer.ShardPagePopulationTotal % 1, text_scale=main_text_scale, text_wordwrap=8, textMayChange=1, text_align=TextNode.ACenter, pos=(0.4247, 0, totalPop_ycoord)) self.totalPopulationText = DirectLabel(parent=self.districtInfo, relief=None, text=TTLocalizer.ShardPagePopulationTotal % 1, text_scale=main_text_scale, text_wordwrap=8, textMayChange=1, text_align=TextNode.ACenter, pos=(0.4247, 0, totalPop_ycoord))
if self.showTotalPop: if self.showTotalPop:
self.totalPopulationText.show() self.totalPopulationText.show()
@ -112,6 +114,7 @@ class ShardPage(ShtikerPage.ShtikerPage):
self.buttonXstart = self.itemFrameXorigin + 0.293 self.buttonXstart = self.itemFrameXorigin + 0.293
self.regenerateScrollList() self.regenerateScrollList()
scrollTitle = DirectFrame(parent=self.scrollList, text=TTLocalizer.ShardPageScrollTitle, text_scale=main_text_scale, text_align=TextNode.ACenter, relief=None, pos=(self.buttonXstart, 0, self.itemFrameZorigin + 0.127)) scrollTitle = DirectFrame(parent=self.scrollList, text=TTLocalizer.ShardPageScrollTitle, text_scale=main_text_scale, text_align=TextNode.ACenter, relief=None, pos=(self.buttonXstart, 0, self.itemFrameZorigin + 0.127))
matchGui.removeNode()
def firstLoadShard(self, buttonTuple): def firstLoadShard(self, buttonTuple):
curShardTuples = base.cr.listActiveShards() curShardTuples = base.cr.listActiveShards()
@ -258,9 +261,9 @@ class ShardPage(ShtikerPage.ShtikerPage):
popText = self.getPopText(shardPop) popText = self.getPopText(shardPop)
districtInfoNode = self.districtInfo.attachNewNode('district-info') districtInfoNode = self.districtInfo.attachNewNode('district-info')
self.districtStatusLabel = DirectLabel(parent=districtInfoNode, relief=None, pos=(0.4247, 0, 0.45), text=popText, text_scale=0.09, text_fg=Vec4(0, 0, 0, 1), textMayChange=1) self.districtStatusLabel = DirectLabel(parent=districtInfoNode, relief=None, pos=(0.4247, 0, 0.45), text=popText, text_scale=0.09, text_fg=Vec4(0, 0, 0, 1), textMayChange=1)
pText = '%s Population: %s' % (shardName, str(shardPop)) pText = TTLocalizer.ShardPageShardTitle % (shardName, str(shardPop))
self.populationStatusLabel = DirectLabel(parent=districtInfoNode, relief=None, pos=(0.4247, 0, 0.38), text=pText, text_scale=0.04, text_fg=Vec4(0, 0, 0, 1), textMayChange=1) self.populationStatusLabel = DirectLabel(parent=districtInfoNode, relief=None, pos=(0.4247, 0, 0.38), text=pText, text_scale=0.04, text_fg=Vec4(0, 0, 0, 1), textMayChange=1)
tText = 'Teleport to\n%s' % shardName tText = TTLocalizer.ShardPageTeleport % shardName
tImage = loader.loadModel('phase_4/models/gui/purchase_gui') tImage = loader.loadModel('phase_4/models/gui/purchase_gui')
tImage.setSz(1.35) tImage.setSz(1.35)
self.shardTeleportButton = DirectButton(parent=districtInfoNode, relief=None, pos=(0.4247, 0, 0.25), image=(tImage.find('**/PurchScrn_BTN_UP'), tImage.find('**/PurchScrn_BTN_DN'), tImage.find('**/PurchScrn_BTN_RLVR')), text=tText, text_scale=0.065, text_pos=(0.0, 0.015), text_fg=Vec4(0, 0, 0, 1), textMayChange=1, command=self.choseShard, extraArgs=[shardId]) self.shardTeleportButton = DirectButton(parent=districtInfoNode, relief=None, pos=(0.4247, 0, 0.25), image=(tImage.find('**/PurchScrn_BTN_UP'), tImage.find('**/PurchScrn_BTN_DN'), tImage.find('**/PurchScrn_BTN_RLVR')), text=tText, text_scale=0.065, text_pos=(0.0, 0.015), text_fg=Vec4(0, 0, 0, 1), textMayChange=1, command=self.choseShard, extraArgs=[shardId])
@ -272,6 +275,7 @@ class ShardPage(ShtikerPage.ShtikerPage):
self.currentO = [shardPop, shardName, shardId] self.currentO = [shardPop, shardName, shardId]
self.currentBTL['state'] = DGG.DISABLED self.currentBTL['state'] = DGG.DISABLED
self.currentBTR['state'] = DGG.DISABLED self.currentBTR['state'] = DGG.DISABLED
self.preferredButton.setColor((0, 1, 0, 1) if settings.get('preferredShard') == shardName else (1, 0, 0, 1))
if shardId == base.localAvatar.defaultShard: if shardId == base.localAvatar.defaultShard:
self.shardTeleportButton['state'] = DGG.DISABLED self.shardTeleportButton['state'] = DGG.DISABLED
@ -486,4 +490,12 @@ class ShardPage(ShtikerPage.ShtikerPage):
except: except:
place = base.cr.playGame.hood.place place = base.cr.playGame.hood.place
place.requestTeleport(canonicalHoodId, canonicalHoodId, shardId, -1) place.requestTeleport(canonicalHoodId, canonicalHoodId, shardId, -1)
def setPreferredShard(self):
if settings.get('preferredShard', '') == self.currentO[1]:
self.preferredButton.setColor(1, 0, 0, 1)
del settings['preferredShard']
else:
self.preferredButton.setColor(0, 1, 0, 1)
settings['preferredShard'] = self.currentO[1]

View file

@ -8719,6 +8719,10 @@ ColorAdvanced = 'Advanced'
ColorBasic = 'Basic' ColorBasic = 'Basic'
ColorAll = 'All' ColorAll = 'All'
ShardPagePreferred = 'Preferred'
ShardPageShardTitle = '%s Population: %s'
ShardPageTeleport = 'Teleport to\n%s'
Blacklist = [ Blacklist = [
"$1ut", "$1ut",
"$h1t", "$h1t",