def _getPlayerEntry(self): player = client.getPlayer() contactName = _( "%s [elect]" ) % player.name if player.voteFor == player.oid else player.name return ui.Item(contactName, tContactID=player.oid, tRelation="-", tRelation_raw=10000, tPopulation=getattr(player.stats, "storPop", "?"), tPlanets=getattr(player.stats, "planets", "?"), tStructures=getattr(player.stats, "structs", "?"), tProduction=getattr(player.stats, "prodProd", "?"), tScience=getattr(player.stats, "prodSci", "?"), tFleetPwr=getattr(player.stats, "fleetPwr", "?"), tContact="-", foreground=res.getFFColorCode(Const.REL_UNITY))
def _analyzeRelations(self, playerID, fleet): # this evaluates color, and if it should be shown at all # get check box selections checkBoxes = [ self.win.vEnemy.checked, self.win.vUnfriendy.checked, self.win.vNeutral.checked, self.win.vFriendly.checked, self.win.vAllied.checked ] # check fleet color and decide if display the fleet if hasattr(fleet, 'owner'): plRelation = client.getRelationTo(fleet.owner) fgColor = res.getPlayerColor(fleet.owner) if fleet.owner == playerID and self.win.vMine.checked: return fgColor return fgColor if checkBoxes[bisect.bisect(Const.REL_BOUNDARIES, plRelation)] else None else: # with no owner assume enemy return res.getFFColorCode( Const.REL_ENEMY_LO) if checkBoxes[0] else None
def show(self): player_highlight = -1 if gdata.config.game.highlight != None: player_highlight = gdata.config.game.highlight player = client.getPlayer() # build contact list items = [] if self.win.vContacts.selection: self.selectedPartyID = self.win.vContacts.selection[0].tContactID else: self.selectedPartyID = None selected = None for contactID in player.diplomacyRels: contact = client.get(contactID, publicOnly=1) dipl = client.getDiplomacyWith(contactID) if dipl.relChng > 0: relation = _("%s +") % _(gdata.relationNames[int( dipl.relation / 125)]) elif dipl.relChng < 0: relation = _("%s -") % _(gdata.relationNames[int( dipl.relation / 125)]) else: relation = _("%s") % _(gdata.relationNames[int( dipl.relation / 125)]) if player.voteFor == contactID: contactName = _("%s [elect]") % contact.name else: contactName = contact.name #f int(player_highlight) == (contactID): # colortemp = gdata.playerHighlightColor #lse: # colortemp = res.getFFColorCode(dipl.relation) colortemp = res.getPlayerColor(contactID) if hasattr(dipl, "stats") and dipl.stats: item = ui.Item( contactName, tContactID=contactID, tRelation=relation, tRelation_raw=dipl.relation, tPopulation=dipl.stats.storPop, tPlanets=dipl.stats.planets, tStructures=dipl.stats.structs, tProduction=dipl.stats.prodProd, tScience=dipl.stats.prodSci, tFleetPwr=dipl.stats.fleetPwr, tContact=(_("-"), _("Mobile"), _("Static"))[dipl.contactType], foreground=colortemp, tooltipTitle=_("Relation"), tooltip=_("Relation %d, change %+d") % (dipl.relation, dipl.relChng), statustip=_("Relation %d, change %+d") % (dipl.relation, dipl.relChng), ) else: item = ui.Item( contactName, tContactID=contactID, tRelation=relation, tRelation_raw=dipl.relation, tPopulation="-", tPlanets="-", tStructures="-", tProduction="-", tScience="-", tFleetPwr="-", tContact=(_("None"), _("Mobile"), _("Static"))[dipl.contactType], foreground=colortemp, ) items.append(item) if self.selectedPartyID == contactID: selected = item # player if player.voteFor == player.oid: contactName = _("%s [elect]") % player.name else: contactName = player.name item = ui.Item( contactName, tContactID=player.oid, tRelation="-", tRelation_raw=10000, tPopulation=getattr(player.stats, "storPop", "?"), tPlanets=getattr(player.stats, "planets", "?"), tStructures=getattr(player.stats, "structs", "?"), tProduction=getattr(player.stats, "prodProd", "?"), tScience=getattr(player.stats, "prodSci", "?"), tFleetPwr=getattr(player.stats, "fleetPwr", "?"), tContact="-", foreground=res.getFFColorCode(Const.REL_UNITY), ) items.append(item) if self.selectedPartyID == player.oid: selected = item self.win.vContacts.items = items self.win.vContacts.selectItem(selected) self.win.vContacts.itemsChanged() # voting if self.galaxyScenario == Const.SCENARIO_OUTERSPACE: # this is just in case we reloged self.win.vAbstain.visible = 1 self.win.vVoteFor.visible = 1 self.win.vAbstain.enabled = player.voteFor != Const.OID_NONE if selected: self.win.vVoteFor.enabled = selected.tContactID != player.voteFor else: self.win.vVoteFor.enabled = 0 else: self.win.vAbstain.visible = 0 self.win.vVoteFor.visible = 0 # pacts items = [] selected = None if self.selectedPartyID and self.selectedPartyID != player.oid: dipl, self.partyDipl = client.cmdProxy.getPartyDiplomacyRels( player.oid, self.selectedPartyID) if not dipl: dipl = client.getDiplomacyWith(self.selectedPartyID) for pactID in gdata.pacts: pactSpec = Rules.pactDescrs[pactID] if dipl.relation < pactSpec.validityInterval[0] or \ dipl.relation > pactSpec.validityInterval[1]: continue if pactID in dipl.pacts: pactState1 = dipl.pacts[pactID][0] if self.partyDipl: pactState2 = self.partyDipl.pacts.get( pactID, [Const.PACT_OFF])[0] pactState2Text = _(gdata.pactStates[pactState2]) else: pactState2 = Const.PACT_OFF pactState2Text = _("N/A") item = ui.Item( _(gdata.pactNames[pactID]), tState1=_(gdata.pactStates[pactState1]), tState2=pactState2Text, tPactState=pactState1, foreground=gdata.sevColors[(gdata.DISABLED, gdata.INFO, gdata.MIN)[min( pactState1, pactState2)]]) else: if self.partyDipl: pactState2 = self.partyDipl.pacts.get( pactID, [Const.PACT_OFF])[0] pactState2Text = _(gdata.pactStates[pactState2]) else: pactState2 = Const.PACT_OFF pactState2Text = _("N/A") item = ui.Item(_(gdata.pactNames[pactID]), tState1=_(gdata.pactStates[Const.PACT_OFF]), tState2=pactState2Text, tPactState=Const.PACT_OFF, foreground=gdata.sevColors[gdata.DISABLED]) item.tPactID = pactID if pactID == self.selectedPactID: selected = item items.append(item) self.win.vPacts.items = items self.win.vPacts.selectItem(selected) self.win.vPacts.itemsChanged() # Higlight buttons if gdata.config.defaults.highlights == 'yes': self.win.vHighlight.enabled = 0 self.win.vUHighlight.enabled = 1 else: self.win.vHighlight.enabled = 1 self.win.vUHighlight.enabled = 0 self.onPactSelected(None, None, None)
def show(self): # get check box selections mine = self.win.vMine.checked enemy = self.win.vEnemy.checked unfriendly = self.win.vUnfriendy.checked neutral = self.win.vNeutral.checked friendly = self.win.vFriendly.checked allied = self.win.vAllied.checked redirects = self.win.vRedirects.checked player = client.getPlayer() # items = [] for fleetID in client.db.keys(): fleet = client.get(fleetID, noUpdate = 1) # skip non-fleets if not hasattr(fleet, "type") or (fleet.type != T_FLEET and fleet.type != T_ASTEROID): continue # shall be shown? fgColor = None ownerName = "" ownerNameTip = "" # check fleet color and if display fleet if hasattr(fleet, 'owner'): plRelation = client.getRelationTo(fleet.owner) fgColor = res.getPlayerColor(fleet.owner) ok = 0 if mine and fleet.owner == player.oid: ok = 1 elif enemy and plRelation >= REL_ENEMY_LO and plRelation < REL_ENEMY_HI: ok = 1 elif unfriendly and plRelation >= REL_UNFRIENDLY_LO and plRelation < REL_UNFRIENDLY_HI: ok = 1 elif neutral and plRelation >= REL_NEUTRAL_LO and plRelation < REL_NEUTRAL_HI: ok = 1 elif friendly and plRelation >= REL_FRIENDLY_LO and plRelation < REL_FRIENDLY_HI: ok = 1 elif allied and plRelation >= REL_ALLY_LO and plRelation < REL_ALLY_HI: ok = 1 if not ok: continue if fleet.owner != player.oid: owner = getattr(client.get(fleet.owner, noUpdate = 1), "name", res.getUnknownName()) ownerName = " (%s)" % owner ownerNameTip = owner else: # asteroids has no owner fgColor = res.getFFColorCode(0) #enemy if not enemy: continue # check position of fleet system = None systemName = "-" if hasattr(fleet, 'orbiting') and fleet.orbiting: system = client.get(fleet.orbiting, noUpdate = 1) systemName = getattr(system, "name", res.getUnknownName()) elif hasattr(fleet, 'closeSystem'): system = client.get(fleet.closeSystem, noUpdate = 1) systemName = _("%s (dst)") % getattr(system, "name", res.getUnknownName()) # get fleet current action and target of action order = "-" targetName = "-" if hasattr(fleet, 'actions'): if fleet.actionIndex < len(fleet.actions): action, target, data = fleet.actions[fleet.actionIndex] if action == FLACTION_REDIRECT and not redirects: continue order = gdata.fleetActions[action] if target != OID_NONE: targetName = getattr(client.get(target, noUpdate = 1), 'name', res.getUnknownName()) order = "%s %s" % (order, targetName) # eta if hasattr(fleet, "eta"): eta = res.formatTime(fleet.eta) else: eta = "?" # fuel if hasattr(fleet, "storEn"): if fleet.maxEn > 0: fuel = 100 * fleet.storEn / fleet.maxEn else: fuel = 0 else: fuel = "?" # operational time if hasattr(fleet, 'storEn') and hasattr(fleet, 'operEn'): turns = 100000 if fleet.operEn > 0: turns = fleet.storEn / fleet.operEn rawRange = turns * fleet.speed / Rules.turnsPerDay range = "%.2f" % rawRange opTime = res.formatTime(turns) else: rawRange = 0 range = "?" opTime = "?" # last upgrade if hasattr(fleet, "lastUpgrade"): lastUpgrade = res.formatTime(fleet.lastUpgrade) else: lastUpgrade = "?" if hasattr(fleet,'customname') and fleet.customname: fleetname = fleet.customname else: fleetname = getattr(fleet, 'name', res.getUnknownName()) # create ListBox Item for fleet item = ui.Item( "%s %s" % (fleetname, ownerName), tooltip = ownerNameTip, tLocation = systemName, tOrder = order, tMP = getattr(fleet, "combatPwr", "?"), tETA = eta, tETA_raw = getattr(fleet, "eta", 0), tSignature = getattr(fleet, "signature", "?"), tFuel = fuel, tOpTime = opTime, tRange = range, tRange_raw = rawRange, tLastUpgrade = lastUpgrade, tFleetID = fleetID, foreground = fgColor) items.append(item) self.win.vFleets.items = items self.win.vFleets.itemsChanged()
def show(self): player_highlight = -1 if gdata.config.game.highlight != None: player_highlight = gdata.config.game.highlight player = client.getPlayer() # build contact list items = [] if self.win.vContacts.selection: self.selectedPartyID = self.win.vContacts.selection[0].tContactID else: self.selectedPartyID = None selected = None for contactID in player.diplomacyRels: contact = client.get(contactID,publicOnly = 1) dipl = client.getDiplomacyWith(contactID) if dipl.relChng > 0: relation = _("%s +") % _(gdata.relationNames[int(dipl.relation / 125)]) elif dipl.relChng < 0: relation = _("%s -") % _(gdata.relationNames[int(dipl.relation / 125)]) else: relation = _("%s") % _(gdata.relationNames[int(dipl.relation / 125)]) if player.voteFor == contactID: contactName = _("%s [elect]") % contact.name else: contactName = contact.name #f int(player_highlight) == (contactID): # colortemp = gdata.playerHighlightColor #lse: # colortemp = res.getFFColorCode(dipl.relation) colortemp = res.getPlayerColor(contactID) if hasattr(dipl, "stats") and dipl.stats: item = ui.Item(contactName, tContactID = contactID, tRelation = relation, tRelation_raw = dipl.relation, tPopulation = dipl.stats.storPop, tPlanets = dipl.stats.planets, tStructures = dipl.stats.structs, tProduction = dipl.stats.prodProd, tScience = dipl.stats.prodSci, tFleetPwr = dipl.stats.fleetPwr, tContact = (_("-"), _("Mobile"), _("Static"))[dipl.contactType], foreground = colortemp, tooltipTitle = _("Relation"), tooltip = _("Relation %d, change %+d") % (dipl.relation, dipl.relChng), statustip = _("Relation %d, change %+d") % (dipl.relation, dipl.relChng), ) else: item = ui.Item(contactName, tContactID = contactID, tRelation = relation, tRelation_raw = dipl.relation, tPopulation = "-", tPlanets = "-", tStructures = "-", tProduction = "-", tScience = "-", tFleetPwr = "-", tContact = (_("None"), _("Mobile"), _("Static"))[dipl.contactType], foreground = colortemp, ) items.append(item) if self.selectedPartyID == contactID: selected = item # player if player.voteFor == player.oid: contactName = _("%s [elect]") % player.name else: contactName = player.name item = ui.Item(contactName, tContactID = player.oid, tRelation = "-", tRelation_raw = 10000, tPopulation = getattr(player.stats, "storPop", "?"), tPlanets = getattr(player.stats, "planets", "?"), tStructures = getattr(player.stats, "structs", "?"), tProduction = getattr(player.stats, "prodProd", "?"), tScience = getattr(player.stats, "prodSci", "?"), tFleetPwr = getattr(player.stats, "fleetPwr", "?"), tContact = "-", foreground = res.getFFColorCode(Const.REL_UNITY), ) items.append(item) if self.selectedPartyID == player.oid: selected = item self.win.vContacts.items = items self.win.vContacts.selectItem(selected) self.win.vContacts.itemsChanged() # voting if self.galaxyScenario == Const.SCENARIO_OUTERSPACE: # this is just in case we reloged self.win.vAbstain.visible = 1 self.win.vVoteFor.visible = 1 self.win.vAbstain.enabled = player.voteFor != Const.OID_NONE if selected: self.win.vVoteFor.enabled = selected.tContactID != player.voteFor else: self.win.vVoteFor.enabled = 0 else: self.win.vAbstain.visible = 0 self.win.vVoteFor.visible = 0 # pacts items = [] selected = None if self.selectedPartyID and self.selectedPartyID != player.oid: dipl, self.partyDipl = client.cmdProxy.getPartyDiplomacyRels(player.oid, self.selectedPartyID) if not dipl: dipl = client.getDiplomacyWith(self.selectedPartyID) for pactID in gdata.pacts: pactSpec = Rules.pactDescrs[pactID] if dipl.relation < pactSpec.validityInterval[0] or \ dipl.relation > pactSpec.validityInterval[1]: continue if pactID in dipl.pacts: pactState1 = dipl.pacts[pactID][0] if self.partyDipl: pactState2 = self.partyDipl.pacts.get(pactID, [Const.PACT_OFF])[0] pactState2Text = _(gdata.pactStates[pactState2]) else: pactState2 = Const.PACT_OFF pactState2Text = _("N/A") item = ui.Item( _(gdata.pactNames[pactID]), tState1 = _(gdata.pactStates[pactState1]), tState2 = pactState2Text, tPactState = pactState1, foreground = gdata.sevColors[(gdata.DISABLED, gdata.INFO, gdata.MIN)[min(pactState1, pactState2)]] ) else: if self.partyDipl: pactState2 = self.partyDipl.pacts.get(pactID, [Const.PACT_OFF])[0] pactState2Text = _(gdata.pactStates[pactState2]) else: pactState2 = Const.PACT_OFF pactState2Text = _("N/A") item = ui.Item( _(gdata.pactNames[pactID]), tState1 = _(gdata.pactStates[Const.PACT_OFF]), tState2 = pactState2Text, tPactState = Const.PACT_OFF, foreground = gdata.sevColors[gdata.DISABLED] ) item.tPactID = pactID if pactID == self.selectedPactID: selected = item items.append(item) self.win.vPacts.items = items self.win.vPacts.selectItem(selected) self.win.vPacts.itemsChanged() # Higlight buttons if gdata.config.defaults.highlights == 'yes': self.win.vHighlight.enabled = 0 self.win.vUHighlight.enabled = 1 else: self.win.vHighlight.enabled = 1 self.win.vUHighlight.enabled = 0 self.onPactSelected(None, None, None)
def show(self): # get check box selections mine = self.win.vMine.checked enemy = self.win.vEnemy.checked unfriendly = self.win.vUnfriendy.checked neutral = self.win.vNeutral.checked friendly = self.win.vFriendly.checked allied = self.win.vAllied.checked redirects = self.win.vRedirects.checked player = client.getPlayer() # items = [] for fleetID in client.db.keys(): fleet = client.get(fleetID, noUpdate=1) # skip non-fleets if not hasattr(fleet, "type") or (fleet.type != Const.T_FLEET and fleet.type != Const.T_ASTEROID): continue # shall be shown? fgColor = None ownerTipTitle = "" ownerName = "" ownerNameTip = "" # check fleet color and if display fleet if hasattr(fleet, 'owner'): plRelation = client.getRelationTo(fleet.owner) fgColor = res.getPlayerColor(fleet.owner) ok = 0 if mine and fleet.owner == player.oid: ok = 1 elif enemy and plRelation >= Const.REL_ENEMY_LO and plRelation < Const.REL_ENEMY_HI: ok = 1 elif unfriendly and plRelation >= Const.REL_UNFRIENDLY_LO and plRelation < Const.REL_UNFRIENDLY_HI: ok = 1 elif neutral and plRelation >= Const.REL_NEUTRAL_LO and plRelation < Const.REL_NEUTRAL_HI: ok = 1 elif friendly and plRelation >= Const.REL_FRIENDLY_LO and plRelation < Const.REL_FRIENDLY_HI: ok = 1 elif allied and plRelation >= Const.REL_ALLY_LO and plRelation < Const.REL_ALLY_HI: ok = 1 if not ok: continue if fleet.owner != player.oid: owner = getattr(client.get(fleet.owner, noUpdate=1), "name", res.getUnknownName()) ownerName = " (%s)" % owner ownerNameTip = owner ownerTipTitle = _("Owner") else: # asteroids has no owner fgColor = res.getFFColorCode(0) #enemy if not enemy: continue # check position of fleet system = None systemName = "-" if hasattr(fleet, 'orbiting') and fleet.orbiting: system = client.get(fleet.orbiting, noUpdate=1) systemName = getattr(system, "name", res.getUnknownName()) elif hasattr(fleet, 'closeSystem'): system = client.get(fleet.closeSystem, noUpdate=1) systemName = _("%s (dst)") % getattr(system, "name", res.getUnknownName()) # get fleet current action and target of action order = "-" targetName = "-" if hasattr(fleet, 'actions'): if fleet.actionIndex < len(fleet.actions): action, target, data = fleet.actions[fleet.actionIndex] if action == Const.FLACTION_REDIRECT and not redirects: continue order = gdata.fleetActions[action] if target != Const.OID_NONE: targetName = getattr(client.get(target, noUpdate=1), 'name', res.getUnknownName()) order = "%s %s" % (order, targetName) # eta if hasattr(fleet, "eta"): eta = res.formatTime(fleet.eta) else: eta = "?" # fuel if hasattr(fleet, "storEn"): if fleet.maxEn > 0: fuel = 100 * fleet.storEn / fleet.maxEn else: fuel = 0 else: fuel = "?" # operational time if hasattr(fleet, 'storEn') and hasattr(fleet, 'operEn'): turns = 100000 if fleet.operEn > 0: turns = fleet.storEn / fleet.operEn rawRange = turns * fleet.speed / Rules.turnsPerDay range = "%.2f" % rawRange opTime = res.formatTime(turns) else: rawRange = 0 range = "?" opTime = "?" # last upgrade if hasattr(fleet, "lastUpgrade"): lastUpgrade = res.formatTime(fleet.lastUpgrade) else: lastUpgrade = "?" if hasattr(fleet, 'customname') and fleet.customname: fleetname = fleet.customname else: fleetname = getattr(fleet, 'name', res.getUnknownName()) # create ListBox Item for fleet item = ui.Item("%s %s" % (fleetname, ownerName), tooltipTitle=ownerTipTitle, tooltip=ownerNameTip, tLocation=systemName, tOrder=order, tMP=getattr(fleet, "combatPwr", "?"), tETA=eta, tETA_raw=getattr(fleet, "eta", 0), tSignature=getattr(fleet, "signature", "?"), tFuel=fuel, tOpTime=opTime, tRange=range, tRange_raw=rawRange, tLastUpgrade=lastUpgrade, tFleetID=fleetID, foreground=fgColor) items.append(item) self.win.vFleets.items = items self.win.vFleets.itemsChanged()