def onSelectDesign(self, widget, action, data): player = client.getPlayer() fleets = self.fleetsByDesign[data.tDesignID] fleetCounts = self.fleetCountsByDesign[data.tDesignID] spec = player.shipDesigns[data.tDesignID] self.win.vFleetsTitle.text = _("Fleets contains design %s") % spec.name items = [] if fleets: for fleet in fleets: if hasattr(fleet, 'customname') and fleet.customname: fleetname = fleet.customname else: fleetname = fleet.name items.append( ui.Item(fleetname, tShipsCount=len(fleet.ships), fleet=fleet, tClassCount=fleetCounts[fleet.oid], tFleetID=fleet.oid)) self.win.vFleets.items = items self.win.vFleets.itemsChanged()
def show(self): self.precompute() keys = self._mines.keys() keys.sort() items = [] for minetech in keys: num = self._mines[minetech] tech = client.getFullTechInfo(minetech) if tech.weaponIgnoreShield: igsh = _('Yes') else: igsh = _('No') items.append( ui.Item(tech.name, tNum=num, tMinDmg=tech.weaponDmgMin, tMaxDmg=tech.weaponDmgMax, tAtt=tech.weaponAtt, tIS=igsh)) self.win.vMines.items = items self.win.vMines.itemsChanged()
def _processResearchQueueTask(self, task): player = client.getPlayer() tech = client.getTechInfo(task.techID) fulltech = client.getFullTechInfo(task.techID) researchSci = Utils.getTechRCost(player, task.techID, task.improvement) item = ui.Item(tech.name, techID=task.techID) item.tooltipTitle = _("Details") item.tooltip = _("Research points %d/%d, change %d pts/turn.") % ( task.currSci, researchSci, task.changeSci) item.statustip = item.tooltip item.tImpToMax = "*" if task.improveToMax else "" item.tImproveToMax = task.improveToMax item.tProgress = _("%d %%") % int( task.currSci * 100 / researchSci) if task.currSci > 0 else _("-") totalSci = 0 if task.changeSci > 0: etc = float(researchSci - task.currSci) / max( task.changeSci, player.effSciPoints) totalSci += researchSci - task.currSci if player.effSciPoints > 0: item.tETC = res.formatTime(etc) else: item.tETC = res.getNA() elif task.changeSci < 0: etc = -float(task.currSci) / min(task.changeSci, player.effSciPoints) item.tETC = _("[%s]") % res.formatTime(etc) elif player.effSciPoints > 0: etc = float(researchSci) / player.effSciPoints totalSci += researchSci item.tETC = res.formatTime(etc) else: item.tETC = res.getNA() if task.improveToMax: for impr in range(task.improvement + 1, fulltech.maxImprovement + 1): totalSci += Utils.getTechRCost(player, task.techID, impr) item.tLevel = _("%d-%d") % (tech.level, task.improvement) return item, totalSci
def show(self): positions = client.cmdProxy.getStartingPositions() if not positions: # there are no positions -- pop up a dialog self.confirmDlg.display( _("We are sorry, but there are no starting positions available at this moment. Please, try again later." ), _("Refresh"), _("Exit"), self.display, self.app.exit) return False items = [] for objID, name, posType in positions: item = ui.Item(name, tObjID=objID, tPosType=posType) if posType == STARTPOS_NEWPLAYER: item.tPos = _('Independent player') elif posType == STARTPOS_AIPLAYER: item.tPos = _("Rebel faction") elif posType == STARTPOS_PIRATE: item.tPos = _("Pirate faction [VIP password needed]") else: item.tPos = _('Unknown. You cannot use this.') items.append(item) self.win.vPos.setItems(items) return True
def show(self): items = [] player = client.getPlayer() origSpec = player.shipDesigns[self.designID] # count ships count = 0 for fleetID in player.fleets: fleet = client.get(fleetID) for tmpDesignID, hp, shieldHP, exp in fleet.ships: if tmpDesignID == self.designID: count += 1 # construct list selected = None for designID in player.shipDesigns: spec = player.shipDesigns[designID] if origSpec.combatClass != spec.combatClass: continue if spec.upgradeTo: continue if designID == self.designID: continue diff = max( Rules.shipMinUpgrade, int((spec.buildProd - origSpec.buildProd) * Rules.shipUpgradeMod), ) item = ui.Item( spec.name, tDiff=diff, tTotal=diff * count, tDesignID=designID, ) if designID == self.selected: selected = item items.append(item) self.win.vList.items = items self.win.vList.itemsChanged() self.win.vList.selectItem(selected)
def showPlanets(self): info = [] system = client.get(self.systemID, noUpdate=1) select = None playerID = client.getPlayerID() firstEnabled = None if hasattr(system, 'planets'): for planetID in system.planets: # get planet planet = client.get(planetID, noUpdate=1) # only player owned planets can be source planets enabled = getattr(planet, "owner") == playerID buttonText = "%s / %s" % (getattr(planet, 'name', res.getUnknownName()), getattr(planet, "effProdProd", "?")) item = ui.Item( buttonText, planetID=planetID, enabled=enabled, align=ui.ALIGN_NONE, ) info.append(item) # remember first players planet if enabled and firstEnabled == None: firstEnabled = item # select actual planet as source only if player owns it if planetID == self.sourceID and enabled: select = item # set as selected source first players planet if select == None: select = firstEnabled self.sourceID = firstEnabled.planetID self.win.vPlanets.items = info self.win.vPlanets.itemsChanged() self.win.vPlanets.selectItem(select)
def _showMenu(self): itemsPublic = [] itemsPrivate = [] for bookID in self.bookingInfo: if bookID < Const.BID_FREESTART: continue book = self.bookingInfo[bookID] tPos = book.capacity tCur = book.bookings rawTime = book.last_creation tScenario = gdata.gameScenarios[self.offering[ book.gal_type].scenario] isSelected = book.is_booked if rawTime: tTime = time.strftime(_("%m-%d-%y %H:%M"), time.localtime(rawTime)) else: tTime = _('N/A') if isSelected: tChoice = '*' else: tChoice = '' item = ui.Item(book.gal_type, tPos=tPos, tCur=tCur, tTime=tTime, tChoice=tChoice, tScenario=tScenario, tOwner=book.owner_nick, tID=bookID) if book.owner_nick: itemsPrivate.append(item) else: itemsPublic.append(item) self.win.vBookingPublic.items = itemsPublic self.win.vBookingPublic.itemsChanged() self.win.vBookingPrivate.items = itemsPrivate self.win.vBookingPrivate.itemsChanged()
def _showShips(self): items = [] player = client.getPlayer() for designID in player.shipDesigns.keys(): tech = player.shipDesigns[designID] if not self._filterShipSize(tech) or not self._filterShipMilitary(tech): continue if tech.upgradeTo != Const.OID_NONE: # skip ships that are set to upgrade continue if self.prodProd > 0: etc = res.formatTime(math.ceil(float(tech.buildProd) / self.prodProd)) else: etc = _("N/A") item = ui.Item(tech.name, tLevel=tech.level, tProd=tech.buildProd, techID=designID, tIsShip=1, tETC=etc) items.append(item) return items
def createUI(self): w, h = gdata.scrnSize self.win = ui.Window(self.app, modal = 1, escKeyClose = 1, titleOnly = w == 800 and h == 600, movable = 0, title = _('Split Fleet'), rect = ui.Rect((w - 800 - 4 * (w != 800)) / 2, (h - 600 - 4 * (h != 600)) / 2, 800 + 4 * (w != 800), 580 + 4 * (h != 600)), layoutManager = ui.SimpleGridLM(), tabChange = True, ) self.win.subscribeAction('*', self) # original fleet ui.Title(self.win, layout = (0, 0, 20, 1), text = _('Original fleet'), align = ui.ALIGN_W, font = 'normal-bold') ui.Listbox(self.win, id = 'vOShips', layout = (0, 1, 20, 21), columns = ( (_('#'), 'tCount', 1.5, ui.ALIGN_NONE), (_('Name'), 'text', 5, ui.ALIGN_W), (_('Lvl'), 'tLevel', 1.5, ui.ALIGN_NONE), (_('Class'), 'tClass', 3, ui.ALIGN_E), (_('HP'), 'tHP', 4, ui.ALIGN_E), (_('Exp'), 'tExp', 2, ui.ALIGN_E), (_('Spd'), 'tSpeed', 2, ui.ALIGN_E), ), columnLabels = 1, action = 'onOShipSelected', rmbAction = 'onMoveMenu' ) # grouping options ui.Title(self.win, layout = (0, 22, 20, 1), text = _('Group by'), align = ui.ALIGN_W, font = 'normal-bold') ui.Check(self.win, layout = (0, 23, 5, 1), id = "vDesign", text = _("design"), action = "onGroup", data = DESIGN) ui.Check(self.win, layout = (5, 23, 5, 1), id = "vClass", text = _("class"), action = "onGroup", data = CLASS) ui.Check(self.win, layout = (10, 23, 5, 1), id = "vDmg", text = _("damage"), action = "onGroup", data = DAMAGE) ui.Check(self.win, layout = (15, 23, 5, 1), id = "vExpr", text = _("experience"), action = "onGroup", data = EXPERIENCE) ui.Check(self.win, layout = (0, 24, 5, 1), id = "vLevel", text = _("level"), action = "onGroup", data = LEVEL) ui.Check(self.win, layout = (5, 24, 5, 1), id = "vSpeed", text = _("speed"), action = "onGroup", data = SPEED) # tanks ui.Title(self.win, layout = (0, 25, 20, 1), text = _('Tanks'), align = ui.ALIGN_W, font = 'normal-bold') ui.Label(self.win, layout = (0, 26, 5, 1), text = _('Fuel'), align = ui.ALIGN_W) ui.Entry(self.win, layout = (5, 26, 5, 1), id = 'vOEn', action = 'onStorChng', align = ui.ALIGN_E, data ='origEn', orderNo = 15) ui.Label(self.win, layout = (10, 26, 5, 1), id = 'vOEnMax', align = ui.ALIGN_W) # new fleet ui.Title(self.win, layout = (20, 0, 20, 1), text = _('New fleet'), align = ui.ALIGN_W, font = 'normal-bold') ui.Listbox(self.win, id = 'vNShips', layout = (20, 1, 20, 21), columns = ( (_('#'), 'tCount', 1.5, ui.ALIGN_NONE), (_('Name'), 'text', 5, ui.ALIGN_W), (_('Lvl'), 'tLevel', 1.5, ui.ALIGN_NONE), (_('Class'), 'tClass', 3, ui.ALIGN_E), (_('HP'), 'tHP', 4, ui.ALIGN_E), (_('Exp'), 'tExp', 2, ui.ALIGN_E), (_('Spd'), 'tSpeed', 2, ui.ALIGN_E), ), columnLabels = 1, action = 'onNShipSelected', rmbAction = 'onNMoveMenu') # grouping ui.Title(self.win, layout = (20, 22, 16, 1), text = _('Group by'), align = ui.ALIGN_W, font = 'normal-bold') ui.Button(self.win, layout = (36, 22, 4, 1), text = _("Clear"), action = 'onClear') ui.Check(self.win, layout = (20, 23, 5, 1), id = "vNDesign", text = _("design"), action = "onNGroup", data = DESIGN) ui.Check(self.win, layout = (25, 23, 5, 1), id = "vNClass", text = _("class"), action = "onNGroup", data = CLASS) ui.Check(self.win, layout = (30, 23, 5, 1), id = "vNDmg", text = _("damage"), action = "onNGroup", data = DAMAGE) ui.Check(self.win, layout = (35, 23, 5, 1), id = "vNExpr", text = _("experience"), action = "onNGroup", data = EXPERIENCE) ui.Check(self.win, layout = (20, 24, 5, 1), id = "vNLevel", text = _("level"), action = "onNGroup", data = LEVEL) ui.Check(self.win, layout = (25, 24, 5, 1), id = "vNSpeed", text = _("speed"), action = "onNGroup", data = SPEED) # tanks ui.Title(self.win, layout = (20, 25, 20, 1), text = _('Tanks'), align = ui.ALIGN_W, font = 'normal-bold') ui.Label(self.win, layout = (20, 26, 5, 1), text = _('Fuel'), align = ui.ALIGN_W) ui.Entry(self.win, layout = (25, 26, 5, 1), id = 'vNEn', action = 'onStorChng', align = ui.ALIGN_E, data ='newEn', orderNo = 16) ui.Label(self.win, layout = (30, 26, 5, 1), id = 'vNEnMax', align = ui.ALIGN_W) # status bar + submit/cancel ui.Title(self.win, id = 'vStatusBar', layout = (0, 27, 30, 1), align = ui.ALIGN_W) ui.TitleButton(self.win, layout = (35, 27, 5, 1), text = _('Split'), action = 'onSplit') ui.TitleButton(self.win, layout = (30, 27, 5, 1), text = _('Cancel'), action = 'onCancel') self.moveRightPopup = ui.Menu(self.app, title = _("Move right"), width = 10, columns = 2, items = [ ui.Item(_("1 ship"), action = "onMoveAction", data = 1), ui.Item(_("5 ships"), action = "onMoveAction", data = 5), ui.Item(_("10 ships"), action = "onMoveAction", data = 10), ui.Item(_("50 ships"), action = "onMoveAction", data = 50), ui.Item(_("100 ships"), action = "onMoveAction", data = 100), ui.Item(_("1/2 of ships"), action = "onMoveAction", data = 0.5), ui.Item(_("1/3 of ships"), action = "onMoveAction", data = 0.34), ui.Item(_("1/4 of ships"), action = "onMoveAction", data = 0.25), ui.Item(_("All ships"), action = "onMoveAction", data = -1), ] ) self.moveRightPopup.subscribeAction("*", self) self.moveLeftPopup = ui.Menu(self.app, title = _("Move left"), width = 10, columns = 2, items = [ ui.Item(_("1 ship"), action = "onNMoveAction", data = 1), ui.Item(_("5 ships"), action = "onNMoveAction", data = 5), ui.Item(_("10 ships"), action = "onNMoveAction", data = 10), ui.Item(_("50 ships"), action = "onNMoveAction", data = 50), ui.Item(_("100 ships"), action = "onNMoveAction", data = 100), ui.Item(_("1/2 of ships"), action = "onNMoveAction", data = 0.5), ui.Item(_("1/3 of ships"), action = "onNMoveAction", data = 0.34), ui.Item(_("1/4 of ships"), action = "onNMoveAction", data = 0.25), ui.Item(_("All ships"), action = "onNMoveAction", data = -1), ] ) self.moveLeftPopup.subscribeAction("*", self)
self.win.vHull.text = tech.name # TODO _(tech.name) else: self.win.vHull.text = _("[Click to select]") if self.ctrlID: tech = client.getTechInfo(self.ctrlID) self.win.vCtrl.text = tech.name # TODO _(tech.name) else: self.win.vCtrl.text = _("[Click to select]") # equipments items = [] selected = None for eqID in self.eqIDs: tech = client.getTechInfo(eqID) short = sequip.getShortDescr(eqID) long = sequip.getLongDescr(eqID) item = ui.Item(tech.name, techID = eqID, tNumber = self.eqIDs[eqID], tData = short, tooltip = long, statustip = long) if eqID == self.selectedEqID: selected = item items.append(item) self.win.vEquipment.items = items self.win.vEquipment.itemsChanged() self.win.vEquipment.selectItem(selected) # display computed attrs if result: hull = client.getTechInfo(result.hullID) self.win.vAClass.text = _(gdata.shipClasses[result.combatClass]) self.win.vASignature.text = _("%d") % result.signature self.win.vASpeed.text = _("%.2f") % result.speed if result.shieldHP > 0: self.win.vAHP.text = _("%d - %d") % (result.maxHP, result.shieldHP) else:
def show(self): player = client.getPlayer() # check if selected ship design exists if self.selectedDesignID not in player.shipDesigns: self.selectedDesignID = None # designs items = [] selected = None items = [] for designID in player.shipDesigns: spec = player.shipDesigns[designID] # number of ships with this design in fleet countInService = 0 for fleetID in player.fleets: fleet = client.get(fleetID) for tmpDesignID, hp, shieldHP, exp in fleet.ships: if tmpDesignID == designID: countInService += 1 hullTech = client.getFullTechInfo(spec.hullID) # number of ships in build queue countInBuild = 0 for planetID in client.db.keys(): planet = client.get(planetID, noUpdate = 1) # skip non-planets if not hasattr(planet, "type") or planet.type != T_PLANET \ or not hasattr(planet, 'owner') or not planet.owner == player.oid \ or not planet.prodQueue: continue for task in planet.prodQueue: if task.isShip and task.techID == designID: countInBuild += task.quantity # ui list item item = ui.Item(spec.name, tDesignID = designID, tClass = "%s/%s%d" % ( _(gdata.shipClasses[spec.combatClass][:1].upper()),_("TL"), hullTech.level, ), tNumber = countInService, tInBuild = countInBuild ) if spec.upgradeTo: item.foreground = gdata.sevColors[gdata.NONE] if designID == self.selectedDesignID: selected = item items.append(item) self.win.vDesigns.items = items self.win.vDesigns.itemsChanged() self.win.vDesigns.selectItem(selected) # compute if self.selectedDesignID == None: if self.ctrlID: eqIDs = {self.ctrlID : 1} else: eqIDs = {} for eqID in self.eqIDs: eqIDs[eqID] = self.eqIDs[eqID] improvements = [] self.win.vUpgrade.enabled = 0 self.win.vUpgrade.text = _("Upgrade") self.win.vScrap.enabled = 0 self.win.vConstruct.enabled = 1 else: spec = player.shipDesigns[self.selectedDesignID] self.hullID = spec.hullID eqIDs = spec.eqIDs improvements = spec.improvements self.win.vName.text = spec.name self.win.vHull.text = client.getTechInfo(self.hullID).name self.eqIDs = {} for eqID in eqIDs: tech = client.getTechInfo(eqID) if tech.subtype == "seq_ctrl": self.ctrlID = eqID self.win.vCtrl.text = tech.name else: self.eqIDs[eqID] = eqIDs[eqID] if player.shipDesigns[self.selectedDesignID].upgradeTo == 0: self.win.vUpgrade.enabled = 1 self.win.vUpgrade.text = _("Upgrade") else: self.win.vUpgrade.enabled = 1 self.win.vUpgrade.text = _("Cancel Upgrd") self.win.vScrap.enabled = 1 self.win.vConstruct.enabled = 0 try: result = ShipUtils.makeShipFullSpec(player, None, self.hullID, eqIDs, improvements) except GameException, e: self.win.setStatus(e.args[0]) try: result = ShipUtils.makeShipFullSpec(player, None, self.hullID, eqIDs, improvements, raiseExs = False) except GameException: result = None
def show(self): critical = self.win.vCritical.checked major = self.win.vMajor.checked minor = self.win.vMinor.checked info = self.win.vInfo.checked disp = 1 player = client.getPlayer() items = [] # object list (all player's objects + systems) objects = player.fleets[:] objects += player.planets[:] systems = {} for planetID in player.planets: planet = client.get(planetID) if planet.compOf not in systems: systems[planet.compOf] = None objects += systems.keys() # counting construction points value of each global production queue # holder for (number , eff production) of planets set to each queue globalQueueStats = [(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)] prodQueueProblems = [] # go through all objects for objID in objects: if objID < Const.OID_FREESTART: continue obj = client.get(objID, noUpdate=1) if not hasattr(obj, "type"): continue if obj.type == Const.T_SYSTEM: if not hasattr(obj, 'planets'): continue bio = 0 totalBio = 0 en = 0 totalEn = 0 buildingQuantity = {} buildingInfo = {} # holds modified planets planetCopies = {} for planetID in obj.planets: planet = client.get(planetID, noUpdate=1) # copy of planet to change plSlots count if not planetID in planetCopies: cPlanet = copy.deepcopy(planet) planetCopies[planetID] = cPlanet else: cPlanet = planetCopies[planetID] if hasattr(planet, 'owner') and planet.owner == player.oid: queuePlanetNumber, queueEffProd = globalQueueStats[ planet.globalQueue] queuePlanetNumber += 1 queueEffProd += planet.effProdProd globalQueueStats[planet.globalQueue] = ( queuePlanetNumber, queueEffProd) # compute bio and en for system bio += planet.changeBio totalBio += max(0, planet.storBio - planet.minBio) en += planet.changeEn totalEn += max(0, planet.storEn - planet.minEn) # the planet needs to have global queue 0 - the default one - to have its queue reported if hasattr( planet, 'prodQueue' ) and self.win.vPlanets.checked and not planet.globalQueue: totalEtc = 0 # compute length of production queue if cPlanet.prodQueue and cPlanet.effProdProd > 0: for task in cPlanet.prodQueue: if task.isShip: tech = client.getPlayer().shipDesigns[ task.techID] else: tech = client.getFullTechInfo( task.techID) if tech.isStructure and hasattr( task, "demolishStruct" ) and task.demolishStruct == 0: # total count of constructing buildings on target if buildingQuantity.has_key( task.targetID): buildingQuantity[ task. targetID] += task.quantity else: buildingQuantity[ task. targetID] = task.quantity # information about source and target of constructing if buildingInfo.has_key( (planetID, task.targetID)): buildingInfo[( planetID, task.targetID )] += task.quantity else: buildingInfo[( planetID, task.targetID )] = task.quantity elif tech.isProject and tech.id == 3802: # we are constructing Habitable Surface Expansion # so after construction we got some new slots on planet if not task.targetID in planetCopies: targetPlanet = client.get( task.targetID, noUpdate=1) cPlanet = copy.deepcopy( targetPlanet) planetCopies[ task.targetID] = cPlanet planetCopies[ task. targetID].plSlots += task.quantity if task.targetID != planetID: totalEtc += math.ceil( float(tech.buildProd * Rules.buildOnAnotherPlanetMod - task.currProd) / planet.effProdProd) totalEtc += math.ceil( (task.quantity - 1) * float( tech.buildProd * Rules.buildOnAnotherPlanetMod) / planet.effProdProd) else: totalEtc += math.ceil( task.quantity * float(tech.buildProd - task.currProd) / planet.effProdProd) totalEtc += math.ceil( (task.quantity - 1) * float(tech.buildProd) / planet.effProdProd) else: totalEtc = 99999 prodQueueProblems.append( (planetID, totalEtc, len(planet.prodQueue))) # check for structures status if hasattr(planet, 'slots') and self.win.vPlanets.checked: for struct in planet.slots: status = struct[Const.STRUCT_IDX_STATUS] problem = None tech = client.getFullTechInfo( struct[Const.STRUCT_IDX_TECHID]) if hasattr(player, 'techs'): techEff = Rules.techImprEff[ player.techs.get( struct[Const.STRUCT_IDX_TECHID], Rules.techBaseImprovement)] else: techEff = Rules.techImprEff[ Rules.techBaseImprovement] HPturn = max(1, int(0.02 * tech.maxHP * techEff)) turnsToDestroy = math.ceil( struct[Const.STRUCT_IDX_HP] / HPturn) if turnsToDestroy < 48: dispDestr = major fgColorDestr = gdata.sevColors[gdata.MAJ] if turnsToDestroy < 24: dispDestr = critical fgColorDestr = gdata.sevColors[ gdata.CRI] else: dispDestr = minor fgColorDestr = None if not status & Const.STRUCT_STATUS_ON: # structure is off if dispDestr: items.append( ui.Item( planet.name, tOID=planetID, tType=Const.T_PLANET, foreground=fgColorDestr, vDescription= _('Structure (%s) is off and will be destroyed in %s turns.' ) % (tech.name, res.formatTime(turnsToDestroy) ))) elif status & Const.STRUCT_STATUS_DETER: problem = _('is deteriorating') disp = major fgColor = gdata.sevColors[gdata.MAJ] elif status & Const.STRUCT_STATUS_NOBIO: problem = _( 'has insufficient supply of biomatter') disp = info fgColor = gdata.sevColors[gdata.INFO] elif status & Const.STRUCT_STATUS_NOEN: problem = _( 'has insufficient supply of energy') disp = info fgColor = gdata.sevColors[gdata.INFO] elif status & Const.STRUCT_STATUS_NOPOP: problem = _( 'has insufficient supply of workers') disp = info fgColor = gdata.sevColors[gdata.INFO] elif status & Const.STRUCT_STATUS_REPAIRING: problem = _('is repairing') disp = info fgColor = gdata.sevColors[gdata.INFO] if problem and disp: items.append( ui.Item(planet.name, tOID=planetID, tType=Const.T_PLANET, foreground=fgColor, vDescription=_( 'Structure (%s) %s.') % (tech.name, problem))) for planetID, quantity in buildingQuantity.items(): planet = planetCopies[planetID] # test, if there is total quantity of building as target for this planet if planet.plSlots < len(planet.slots) + quantity and major: # walk infos and search for all planets, that are building # on planet founded above for (sourceID, targetID), quantity in buildingInfo.items(): if planetID == targetID: source = client.get(sourceID, noUpdate=1) items.append( ui.Item( source.name, tOID=sourceID, tType=Const.T_PLANET, foreground=gdata.sevColors[gdata.MAJ], vDescription= _('There is no space for all constructed buildings on %s.' ) % (planet.name))) # check bio for system if bio < 0 and self.win.vSystems.checked: disp = minor fgColor = None surplusTurns = totalBio / (-bio) if surplusTurns < 168: disp = major fgColor = gdata.sevColors[gdata.MAJ] if surplusTurns < 48: disp = critical fgColor = gdata.sevColors[gdata.CRI] if disp: if totalBio > 0: items.append( ui.Item( obj.name, tOID=obj.oid, tType=Const.T_SYSTEM, foreground=fgColor, vDescription= _('Bio decreasing - last turn change %d, surplus %d (%s).' ) % (bio, totalBio, res.formatTime(surplusTurns)))) else: items.append( ui.Item( obj.name, tOID=obj.oid, tType=Const.T_SYSTEM, foreground=fgColor, vDescription= _('Bio decreasing - last turn change %d, surplus %d.' ) % (bio, totalBio))) #check en for system if en < 0 and self.win.vSystems.checked: disp = minor fgColor = None surplusTurns = totalEn / (-en) if surplusTurns < 168: disp = major fgColor = gdata.sevColors[gdata.MAJ] if surplusTurns < 48: disp = critical fgColor = gdata.sevColors[gdata.CRI] if disp: if totalEn > 0: items.append( ui.Item( obj.name, tOID=obj.oid, tType=Const.T_SYSTEM, foreground=fgColor, vDescription= _('Energy decreasing - last turn change %d, surplus %d (%s).' ) % (en, totalEn, res.formatTime(surplusTurns)))) else: items.append( ui.Item( obj.name, tOID=obj.oid, tType=Const.T_SYSTEM, foreground=fgColor, vDescription= _('Energy decreasing - last turn change %d, surplus %d.' ) % (en, totalEn))) # check fleets elif obj.type == Const.T_FLEET and self.win.vFleets.checked: if hasattr(obj, 'owner') and obj.owner == player.oid: energyReserve = obj.storEn * 100 / obj.maxEn system = None disp = major fgColor = gdata.sevColors[gdata.MAJ] note = _(' and IS NOT refueling') maxRefuelMax = 0 if hasattr(obj, 'orbiting') and obj.orbiting: system = client.get(obj.orbiting, noUpdate=1) if hasattr(system, 'planets'): for planetID in system.planets: planet = client.get(planetID, noUpdate=1) if hasattr(planet, 'owner') and hasattr( planet, 'refuelMax'): if player.diplomacyRels.has_key( planet.owner): dipl = client.getDiplomacyWith( planet.owner) if dipl.pacts.has_key( Const.PACT_ALLOW_TANKING ) and dipl.pacts[ Const.PACT_ALLOW_TANKING][ 0] == Const.PACT_ACTIVE: maxRefuelMax = max( maxRefuelMax, planet.refuelMax) else: if planet.owner == player.oid: maxRefuelMax = max( maxRefuelMax, planet.refuelMax) if maxRefuelMax > 0: disp = info fgColor = gdata.sevColors[gdata.INFO] note = _(' and IS refueling') if maxRefuelMax <= energyReserve: note = _( ' and CAN refuel, but reach planet maximum refuel amount' ) else: continue systemName = res.getUnknownName() if system and hasattr(system, "name"): systemName = system.name # check fleets energy reserve if energyReserve < 50 and maxRefuelMax == 0: disp = major fgColor = gdata.sevColors[gdata.MAJ] if energyReserve < 25 and maxRefuelMax == 0: disp = critical fgColor = gdata.sevColors[gdata.CRI] else: fgColor = gdata.sevColors[gdata.INFO] disp = info # is fleet named? if hasattr(obj, 'customname') and obj.customname: name = obj.customname else: name = getattr(obj, "name", None) if energyReserve == 100 and info and disp: items.append( ui.Item(systemName, tOID=obj.oid, tType=Const.T_FLEET, foreground=gdata.sevColors[gdata.INFO], vDescription=_( 'Fleet "%s" has full fuel tanks.') % (name))) elif disp: items.append( ui.Item( systemName, tOID=obj.oid, tType=Const.T_FLEET, foreground=fgColor, vDescription=_( 'Fleet "%s" is low on fuel [%d %%]%s.') % (name, energyReserve, note))) queConstValues = [0, 0, 0, 0, 0] queEtc = [0, 0, 0, 0, 0] for queue in xrange(5): quePlanets, queEffProd = globalQueueStats[queue] for task in player.prodQueues[queue]: if task.isShip: tech = client.getPlayer().shipDesigns[task.techID] else: tech = client.getFullTechInfo(task.techID) queConstValues[queue] += task.quantity * tech.buildProd if queEffProd > 0: queEtc[queue] = math.ceil( float(queConstValues[queue]) / queEffProd) else: queEtc[queue] = 99999 # creation of items with production queue [default one] problems for planetID, totalEtc, queueLen in prodQueueProblems: planet = client.get(planetID, noUpdate=1) # check empty production queue if queueLen == 0 and planet.effProdProd > 0 and queConstValues[ 0] == 0 and critical: items.append( ui.Item(planet.name, tOID=planetID, tType=Const.T_PLANET, foreground=gdata.sevColors[gdata.CRI], vDescription=_('Production queue is empty.'))) # check end of production queue if totalEtc + queEtc[0] < 48: fgColor = None disp = minor if totalEtc + queEtc[0] < 24: disp = major fgColor = gdata.sevColors[gdata.MAJ] if disp: items.append( ui.Item( planet.name, tOID=planetID, tType=Const.T_PLANET, foreground=fgColor, vDescription=_( 'Production queue may end in {0} turns ({1} directly in planet queue), {2} item(s) on list.' .format( res.formatTime(totalEtc + queEtc[0]), res.formatTime(totalEtc), queueLen)))) # creation of items with global queue problems for queue in xrange(1, 5): queName = res.globalQueueName(queue) quePlanets = globalQueueStats[queue][0] # check empty global production queue with at least one planet [so its relevant] if queConstValues[queue] == 0 and quePlanets > 0 and critical: items.append( ui.Item( _('Global queue ' + queName), tType=Const.T_QUEUE, foreground=gdata.sevColors[gdata.CRI], vDescription=_( 'Global production queue {0} used by {1} planet(s) is empty.' .format(queName, quePlanets)))) # check end of global production queue elif queEtc[queue] < 48: fgColor = None disp = minor if queEtc[queue] < 24: disp = major fgColor = gdata.sevColors[gdata.MAJ] if disp: items.append( ui.Item( _('Global queue ' + queName), tType=Const.T_QUEUE, foreground=fgColor, vDescription=_( 'Global production queue {0} used by {1} planet(s) runs out in {2} turns.' .format(queName, quePlanets, res.formatTime(queEtc[queue]))))) # check research queue if self.win.vResearch.checked: totalEtc = 0 # compute length of research queue for task in player.rsrchQueue: tech = client.getTechInfo(task.techID) fulltech = client.getFullTechInfo(task.techID) researchSci = Utils.getTechRCost(player, task.techID, task.improvement) maxImprovement = min(Rules.techMaxImprovement, fulltech.maxImprovement) maxImpTotalSci = 0 if task.improveToMax and task.improvement < maxImprovement: for impr in range(task.improvement + 1, maxImprovement + 1): maxImpTotalSci += Utils.getTechRCost( player, task.techID, impr) if task.changeSci > 0: value = float(researchSci - task.currSci) / max( task.changeSci, player.effSciPoints) totalEtc += int(value + 1) if player.effSciPoints != 0: totalEtc += float(maxImpTotalSci) / player.effSciPoints elif task.changeSci < 0: totalEtc -= float(task.currSci) / min( task.changeSci, player.effSciPoints) elif player.effSciPoints > 0: value = float(researchSci) / player.effSciPoints totalEtc += int(value + 1) totalEtc += float(maxImpTotalSci) / player.effSciPoints else: totalEtc = 99999 break # check empty research queue if totalEtc == 0 and len( player.rsrchQueue ) == 0 and player.effSciPoints > 0 and major: items.append( ui.Item(_('Research'), tType=Const.T_TECHNOLOGY, foreground=gdata.sevColors[gdata.MAJ], vDescription=_('Research queue is empty.'))) # check short reseach queue elif totalEtc < 48: disp = minor fgColor = None if totalEtc < 24: disp = major fgColor = gdata.sevColors[gdata.MAJ] if disp: items.append( ui.Item( _('Research'), tType=Const.T_TECHNOLOGY, foreground=fgColor, vDescription= _('Research queue ends in %s turns, %d item(s) on list.' ) % (res.formatTime(totalEtc), len(player.rsrchQueue)))) self.win.vProblems.items = items self.win.vProblems.itemsChanged()
def _detailEquipmentLists(self): # design info if self.hullID: tech = client.getTechInfo(self.hullID) self.win.vHull.text = tech.name # TODO _(tech.name) elif self.editMode: self.win.vHull.text = _("[Click to select]") else: self.win.vHull.text = "" if self.ctrlID: tech = client.getTechInfo(self.ctrlID) self.win.vCtrl.text = tech.name # TODO _(tech.name) elif self.editMode: self.win.vCtrl.text = _("[Click to select]") else: self.win.vCtrl.text = "" # equipments engines = [] weapons = [] equipment = [] selected = None selected_type = None for eqID in self.eqIDs: tech = client.getTechInfo(eqID) short = sequip.getShortDescr(eqID) _long = sequip.getLongDescr(eqID) # cache has been introduced to let items preserve highlight information if eqID in self.itemCache: item = self.itemCache[eqID] item.tNumber = self.eqIDs[eqID] else: item = ui.Item(tech.name, techID=eqID, tNumber=self.eqIDs[eqID], tData=short, tooltipTitle=_("Details"), tooltip=_long, statustip=_long) self.itemCache[eqID] = item if eqID == self.selectedEqID: selected = item selected_type = tech.subtype if tech.subtype == "seq_eng": engines.append(item) elif tech.subtype == "seq_wpn": weapons.append(item) elif tech.subtype in ["seq_mod", "seq_struct"]: equipment.append(item) self.win.vEngines.items = engines self.win.vEngines.itemsChanged() if selected_type == "seq_eng": self.win.vEngines.selectItem(selected) else: self.win.vEngines.selectItem(None) self.win.vWeapons.items = weapons self.win.vWeapons.itemsChanged() if selected_type == "seq_wpn": self.win.vWeapons.selectItem(selected) else: self.win.vWeapons.selectItem(None) self.win.vEquipment.items = equipment self.win.vEquipment.itemsChanged() if selected_type == "seq_mod": self.win.vEquipment.selectItem(selected) else: self.win.vEquipment.selectItem(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): player = client.getPlayer() # title self.win.vRQueueTitle.text = _('Research queue [%d pts/turn]') % ( player.effSciPoints, ) self.win.title = _("Research [TL%d]") % player.techLevel # Known techs items = [] #~researchable = {} disabled = [] taskIDs = {} for task in player.rsrchQueue: taskIDs[task.techID] = None for techID in player.techs.keys(): tech = client.getTechInfo(techID) improvement = player.techs[techID] item = ui.Item(tech.name, techID = techID, tLevel = '%d-%d' % (tech.level, improvement), tStruct = (' ', '*')[tech.isStructure], tShip = (' ', '*')[tech.isShipEquip], ) if improvement < Rules.techMaxImprovement and improvement < tech.maxImprovement: neededSci = Utils.getTechRCost(player, techID) if player.effSciPoints > 0: item.tETC = res.formatTime(float(neededSci) / player.effSciPoints) else: item.tETC = _("N/A") found = 0 if taskIDs.has_key(techID): item.foreground = (0xd0, 0xd0, 0xd0) else: item.foreground = None else: item.tETC = res.getNA() item.foreground = (0x80, 0x80, 0x80) if not self.showCompleted: # skip this item continue items.append(item) disabled.extend(tech.researchDisables) #~for improvement in range(1, improvement + 1): #~ for techID in tech.researchEnables[improvement]: #~ researchable[techID] = 1 self.win.vKTechs.items = items self.win.vKTechs.itemsChanged() # Research queue items = [] index = 0 queueTechs = [] total = 0 for task in player.rsrchQueue: tech = client.getTechInfo(task.techID) fulltech = client.getFullTechInfo(task.techID) queueTechs.append(task.techID) item = ui.Item(tech.name, techID = task.techID, index = index) researchSci = Utils.getTechRCost(player, task.techID, task.improvement) maxImprovement = min(Rules.techMaxImprovement,fulltech.maxImprovement) maxImpTotalSci = 0 if task.improveToMax and task.improvement < maxImprovement: for impr in range(task.improvement+1,maxImprovement+1): maxImpTotalSci += Utils.getTechRCost(player, task.techID, impr) item.tooltip = _("Research points %d/%d, change %d pts/turn.") % (task.currSci, researchSci, task.changeSci) item.statustip = item.tooltip item.tImpToMax = ["", "*"][task.improveToMax] item.tImproveToMax = task.improveToMax if task.currSci > 0: item.tProgress = _("%d %%") % int(task.currSci * 100 / researchSci) else: item.tProgress = _("-") if task.changeSci > 0: value = float(researchSci - task.currSci) / max(task.changeSci, player.effSciPoints) total += int(value + 1) if player.effSciPoints > 0: total += float(maxImpTotalSci) / player.effSciPoints item.tETC = res.formatTime(value) else: total = 0 item.tETC = res.getNA() elif task.changeSci < 0: value = - float(task.currSci) / min(task.changeSci, player.effSciPoints) item.tETC = _("[%s]") % res.formatTime(value) elif player.effSciPoints > 0: value = float(researchSci) / player.effSciPoints total += int(value + 1) total += float(maxImpTotalSci) / player.effSciPoints item.tETC = res.formatTime(value) else: item.tETC = res.getNA() item.tLevel = _("%d-%d") % (tech.level, task.improvement) items.append(item) index += 1 self.win.vRQueue.items = items self.win.vRQueue.itemsChanged() self.win.vRQueueTop.enabled = 0 self.win.vRQueueUp.enabled = 0 self.win.vRQueueDown.enabled = 0 self.win.vRQueueAbort.enabled = 0 self.win.vRQueueRepat.enabled = 0 self.win.vRQueueRepat.pressed = 0 self.win.vRQueueInfo.enabled = 0 if total == 0: self.win.vRTotal.text = _("N/A") else: self.win.vRTotal.text = res.formatTime(total) # Researchable techs items = [] for techID in client.getAllTechIDs(): if player.techs.has_key(techID) or techID in queueTechs \ or techID in disabled: continue # can check requirements tech = client.getTechInfo(techID) if not hasattr(tech, "partialData"): continue item = ui.Item(tech.name, tLevel = tech.level, techID = techID) if hasattr(tech, 'isStructure'): item.tStruct = ('', '*')[tech.isStructure] else: item.tStruct = '' if hasattr(tech, 'isShipEquip'): item.tShip = ('', '*')[tech.isShipEquip] else: item.tShip = '' if hasattr(tech, 'researchMod'): neededSci = Utils.getTechRCost(player, techID) if player.effSciPoints > 0: item.tETC = res.formatTime(float(neededSci) / player.effSciPoints) else: item.tETC = _("N/A") item.foreground = None else: item.tSci = res.getNA() item.foreground = (0xc0, 0xc0, 0xc0) # skip this item continue if hasattr(tech, "researchDisables") and tech.researchDisables: item.foreground = (0xff, 0xff, 0x00) if client.getFullTechInfo(techID).finishResearchHandler == TechHandlers.finishResTLAdvance: item.foreground = gdata.sevColors[gdata.CRI] items.append(item) self.win.vRTechs.items = items self.win.vRTechs.itemsChanged()
def show(self): items = [] if self.showInheritance: items.append( ui.Item(_("Dmg vs Small (min)"), tSm=self.sm_min[0], tMed=self.med_min[0], tLg=self.lg_min[0])) items.append( ui.Item(_("Dmg vs Small (max)"), tSm=self.sm_max[0], tMed=self.med_max[0], tLg=self.lg_max[0])) items.append(ui.Item(_(" "), tSm='', tMed='', tLg='')) items.append( ui.Item(_("Dmg vs Medium (min)"), tSm=int(self.sm_min[1] + self.sm_min[0] * Rules.weaponDmgDegrade[1]), tMed=int(self.med_min[1] + self.med_min[0] * Rules.weaponDmgDegrade[1]), tLg=int(self.lg_min[1] + self.lg_min[0] * Rules.weaponDmgDegrade[1]))) items.append( ui.Item(_("Dmg vs Medium (max)"), tSm=int(self.sm_max[1] + self.sm_max[0] * Rules.weaponDmgDegrade[1]), tMed=int(self.med_max[1] + self.med_max[0] * Rules.weaponDmgDegrade[1]), tLg=int(self.lg_max[1] + self.lg_max[0] * Rules.weaponDmgDegrade[1]))) items.append(ui.Item(_(" "), tSm='', tMed='', tLg='')) items.append( ui.Item(_("Dmg vs Large (min)"), tSm=int(self.sm_min[2] + self.sm_min[1] * Rules.weaponDmgDegrade[1] + self.sm_min[0] * Rules.weaponDmgDegrade[2]), tMed=int(self.med_min[2] + self.med_min[1] * Rules.weaponDmgDegrade[1] + self.med_min[0] * Rules.weaponDmgDegrade[2]), tLg=int(self.lg_min[2] + self.lg_min[1] * Rules.weaponDmgDegrade[1] + self.lg_min[0] * Rules.weaponDmgDegrade[2]))) items.append( ui.Item(_("Dmg vs Large (max)"), tSm=int(self.sm_max[2] + self.sm_max[1] * Rules.weaponDmgDegrade[1] + self.sm_max[0] * Rules.weaponDmgDegrade[2]), tMed=int(self.med_max[2] + self.med_max[1] * Rules.weaponDmgDegrade[1] + self.med_max[0] * Rules.weaponDmgDegrade[2]), tLg=int(self.lg_max[2] + self.lg_max[1] * Rules.weaponDmgDegrade[1] + self.lg_max[0] * Rules.weaponDmgDegrade[2]))) items.append(ui.Item(_(" "), tSm='', tMed='', tLg='')) items.append( ui.Item(_("Dmg vs Planet (min)"), tSm=int(self.sm_min[3] + self.sm_min[2] * Rules.weaponDmgDegrade[1] + self.sm_min[1] * Rules.weaponDmgDegrade[2] + self.sm_min[0] * Rules.weaponDmgDegrade[3]), tMed=int(self.med_min[3] + self.med_min[2] * Rules.weaponDmgDegrade[1] + self.med_min[1] * Rules.weaponDmgDegrade[2] + self.med_min[0] * Rules.weaponDmgDegrade[3]), tLg=int(self.lg_min[3] + self.lg_min[2] * Rules.weaponDmgDegrade[1] + self.lg_min[1] * Rules.weaponDmgDegrade[2] + self.lg_min[0] * Rules.weaponDmgDegrade[3]))) items.append( ui.Item(_("Dmg vs Planet (max)"), tSm=int(self.sm_max[3] + self.sm_max[2] * Rules.weaponDmgDegrade[1] + self.sm_max[1] * Rules.weaponDmgDegrade[2] + self.sm_max[0] * Rules.weaponDmgDegrade[3]), tMed=int(self.med_max[3] + self.med_max[2] * Rules.weaponDmgDegrade[1] + self.med_max[1] * Rules.weaponDmgDegrade[2] + self.med_max[0] * Rules.weaponDmgDegrade[3]), tLg=int(self.lg_max[3] + self.lg_max[2] * Rules.weaponDmgDegrade[1] + self.lg_max[1] * Rules.weaponDmgDegrade[2] + self.lg_max[0] * Rules.weaponDmgDegrade[3]))) else: items.append( ui.Item(_("Dmg vs Small (min)"), tSm=self.sm_min[0], tMed=self.med_min[0], tLg=self.lg_min[0])) items.append( ui.Item(_("Dmg vs Small (max)"), tSm=self.sm_max[0], tMed=self.med_max[0], tLg=self.lg_max[0])) items.append(ui.Item(_(" "), tSm='', tMed='', tLg='')) items.append( ui.Item(_("Dmg vs Medium (min)"), tSm=self.sm_min[1], tMed=self.med_min[1], tLg=self.lg_min[1])) items.append( ui.Item(_("Dmg vs Medium (max)"), tSm=self.sm_max[1], tMed=self.med_max[1], tLg=self.lg_max[1])) items.append(ui.Item(_(" "), tSm='', tMed='', tLg='')) items.append( ui.Item(_("Dmg vs Large (min)"), tSm=self.sm_min[2], tMed=self.med_min[2], tLg=self.lg_min[2])) items.append( ui.Item(_("Dmg vs Large (max)"), tSm=self.sm_max[2], tMed=self.med_max[2], tLg=self.lg_max[2])) items.append(ui.Item(_(" "), tSm='', tMed='', tLg='')) items.append( ui.Item(_("Dmg vs Planet (min)"), tSm=self.sm_min[3], tMed=self.med_min[3], tLg=self.lg_min[3])) items.append( ui.Item(_("Dmg vs Planet (max)"), tSm=self.sm_max[3], tMed=self.med_max[3], tLg=self.lg_max[3])) items.append(ui.Item(_(" "), tSm='', tMed='', tLg='')) items.append( ui.Item(_("Total Ships"), tSm=self.sm['num'], tMed=self.med['num'], tLg=self.lg['num'])) items.append( ui.Item(_("Total HPs"), tSm=self.sm['hp'], tMed=self.med['hp'], tLg=self.lg['hp'])) items.append( ui.Item(_("Total Shields"), tSm=self.sm['sh'], tMed=self.med['sh'], tLg=self.lg['sh'])) items.append(ui.Item(_(" "), tSm='', tMed='', tLg='')) smnum = max(self.sm['num'], 1) mednum = max(self.med['num'], 1) lgnum = max(self.lg['num'], 1) items.append( ui.Item(_("Average ATT"), tSm=round(1.0 * self.sm['catt'] / smnum, 1), tMed=round(1.0 * self.med['catt'] / mednum, 1), tLg=round(1.0 * self.lg['catt'] / lgnum, 1))) items.append( ui.Item(_("Average DEF"), tSm=round(1.0 * self.sm['cdef'] / smnum, 1), tMed=round(1.0 * self.med['cdef'] / mednum, 1), tLg=round(1.0 * self.lg['cdef'] / lgnum, 1))) items.append( ui.Item(_("Average Missile DEF"), tSm=round(1.0 * self.sm['mdef'] / smnum, 1), tMed=round(1.0 * self.med['mdef'] / mednum, 1), tLg=round(1.0 * self.lg['mdef'] / lgnum, 1))) self.win.vClassData.items = items self.win.vClassData.itemsChanged()
def onForumSelected(self, widget, action, data): selItem = self.win.vForums.selection[0] if selItem.tObjID == OID_NONE: # select last valid for item in self.win.vForums.items: if item.tObjID == self.selectedObjID and \ item.tForum == self.selectedForum: self.win.vForums.selectItem(item) break return self.selectedObjID = selItem.tObjID self.selectedForum = selItem.tForum self.selectedType = selItem.tType self.win.vNewTopic.enabled = 1 self.win.vAllReaded.enabled = 1 self.win.vDeleteAll.enabled = 1 player = client.getPlayer() playerid = player.oid objMessages = client.get(selItem.tObjID)._messages ids = objMessages.keys() ids.sort() ids.reverse() topics = [] items = [] for messageID in ids: message = objMessages[messageID] if message["forum"] == selItem.tForum: # ignore by universe, local (private messages), or galaxy if selItem.tObjID == OID_UNIVERSE: if message["sender"] in self.uignore: continue elif selItem.tObjID == playerid: if message["sender"] in self.lignore: continue else: if message["sender"] in self.gignore: continue # regenerate topics for messages with data if message.has_key("data") and message["topic"] == "EVENT": sourceID, msgID, locationID, turn, data = message["data"] message["topic"] = messages.getMsgText(msgID, data).split("\n")[0] topic = message["topic"] item = ui.Item(topic) if topic not in topics: topics.append(topic) #item = ui.Item(topic, tObjID = selItem.tObjID, tForum = selItem.tForum, # tMgsId = -1, font = "normal-bold") #items.append(item) if message.has_key("data"): sourceID, msgID, locationID, turn, data = message["data"] item.tLocationID = locationID item.tSourceID = sourceID obj = client.get(sourceID, noUpdate=1, publicOnly=1) #Custom name in "sender" if hasattr(obj, 'customname') and obj.customname: item.tSender = _('"%s"') % obj.customname else: item.tSender = message["sender"] foreground = gdata.sevColors[messages.getMsgSeverity( msgID)] if message["readed"]: state = _(" ") else: state = _("N") else: item.tSender = message["sender"] if message["readed"]: foreground = gdata.sevColors[gdata.NONE] if message["replied"]: state = _("R") else: state = _(" ") else: foreground = gdata.sevColors[gdata.MIN] state = _("N") date = time.strftime(_("%m-%d %H:%M"), time.localtime(message["time"])) #if date == time.strftime(_("%Y-%m-%d"), time.localtime()): # date = time.strftime(_("%H:%M"), time.localtime(message["time"])) item.tObjID = selItem.tObjID item.tForum = selItem.tForum item.tMsgID = messageID item.foreground = foreground item.tState = state item.tDate = date item.tDate_raw = message["time"] item.tType = selItem.tType items.append(item) self.win.vMessages.items = items self.win.vMessages.itemsChanged() if self.selectedForum != "EVENTS": # reset messages scrollbar position self.win.vMessages.bar.slider.position = 0 self.win.vMessages.itemsChanged() self.win.vMessage.text = [""] self.win.vReply.enabled = 0 self.win.vNewTopic.enabled = gdata.mailboxSpec[ selItem.tType, selItem.tForum][1] != None self.win.vDelete.enabled = len(self.win.vMessages.selection) > 0
def createUI(self): w, h = gdata.scrnSize self.win = ui.Window( self.app, modal=1, escKeyClose=1, titleOnly=w == 800 and h == 600, movable=0, title=_("Messages and events"), rect=ui.Rect((w - 800 - 4 * (w != 800)) / 2, (h - 600 - 4 * (h != 600)) / 2, 800 + 4 * (w != 800), 580 + 4 * (h != 600)), layoutManager=ui.SimpleGridLM(), ) self.win.subscribeAction('*', self) # forums ui.Listbox(self.win, layout=(0, 0, 10, 27), id="vForums", columns=((_("Channel"), "text", 5.5, ui.ALIGN_W), (_("#"), "tMsgs", 4.5, ui.ALIGN_E)), columnLabels=1, action="onForumSelected", sortable=0) # topics ui.Listbox(self.win, layout=(10, 0, 30, 15), id="vMessages", columns=( (_(" "), "tState", 1, ui.ALIGN_NONE), (_("Date"), "tDate", 4, ui.ALIGN_W), (_("Sender"), "tSender", 7, ui.ALIGN_W), (_("Subject"), "text", 0, ui.ALIGN_W), ), columnLabels=1, action="onMessageSelected", rmbAction="onPostMenu") # messages ui.Button(self.win, layout=(10, 15, 5, 1), text=_("To clipboard"), action="onToClipboard", id="vToClipboard", enabled=0) ui.Button(self.win, layout=(15, 15, 5, 1), text=_("New subject"), action="onNewTopic", id="vNewTopic", enabled=0) ui.Button(self.win, layout=(20, 15, 5, 1), text=_("Reply"), action="onReply", id="vReply", enabled=0) ui.Button(self.win, layout=(25, 15, 5, 1), text=_("Read all"), action="onAllReaded", id="vAllReaded", enabled=0) ui.Button(self.win, layout=(30, 15, 5, 1), text=_("Delete"), action="onDelete", id="vDelete", enabled=0) ui.Button(self.win, layout=(35, 15, 5, 1), text=_("Delete all"), action="onDeleteAll", id="vDeleteAll", enabled=0) s = ui.Scrollbar(self.win, layout=(39, 16, 1, 11)) t = ui.Text(self.win, layout=(10, 16, 29, 11), id="vMessage", editable=0) t.attachVScrollbar(s) # status bar ui.TitleButton(self.win, layout=(30, 27, 5, 1), text=_('Refresh'), action='onRefresh') ui.TitleButton(self.win, layout=(35, 27, 5, 1), text=_('Close'), action='onClose') ui.Title(self.win, id='vStatusBar', layout=(0, 27, 30, 1), align=ui.ALIGN_W) #@self.win.statusBar = self.win.vStatusBar # event menu self.eventPopup = ui.Menu(self.app, title=_("Message actions"), items=[ ui.Item(_("Show location"), action="onShowLoc"), ui.Item(_("Show source"), action="onShowSource"), ui.Item( _("Show location and delete msg"), action="onShowLocDel"), ui.Item(_("Show source and delete msg"), action="onShowSourceDel"), ui.Item(_("Delete"), action="onDelete"), ]) self.eventPopup.subscribeAction("*", self)
def createUI(self): w, h = gdata.scrnSize lw, lh = w / 20, h / 20 self.win = ui.Window( self.app, modal=1, decorated=0, alwaysInBackground=1, movable=0, rect=ui.Rect(0, 0, w, h), layoutManager=ui.SimpleGridLM(), ) self.win.subscribeAction('*', self) # map self.mapWidget = StarMapWidget(self.win, id='vStarMap', action='onSelectMapObj', layout=(0, 1, lw, lh - 2)) self.searchDlg.mapWidget = self.mapWidget self.win.callEventHandler = self.mapWidget self.mapWidget.callEventHandler = self # bottom ui.Label( self.win, id='vStatus', align=ui.ALIGN_W, layout=(0, lh - 1, lw - 16, 1), ) ui.Label( self.win, id='vTurn', align=ui.ALIGN_E, text='????.??', font='normal-bold', layout=(lw - 4, lh - 1, 4, 1), ) # top ui.Button(self.win, layout=(0, 0, 4, 1), text=_('Messages'), action='onMessages', id="vMessages") ui.Button(self.win, layout=(4, 0, 4, 1), text=_('Research'), action='onResearch') ui.Button(self.win, layout=(8, 0, 4, 1), text=_('Diplomacy'), id="vDiplomacy", action='onDiplomacy', enabled=0) ui.Button(self.win, layout=(12, 0, 4, 1), text=_('Constr'), id="vConstruction", action='onConstruction', enabled=0) ui.Button(self.win, layout=(16, 0, 4, 1), text=_('Planets'), id="vPlanetsMenu", action='onPlanetsMenu', enabled=1) ui.Button(self.win, layout=(20, 0, 4, 1), text=_('Fleets'), id="vFleetsMenu", action='onFleetsMenu', enabled=1) ui.Button(self.win, layout=(24, 0, 4, 1), text=_('Overview'), id="vOverview", action='onOverview', enabled=1) ui.Title(self.win, layout=(28, 0, lw - 37, 1)) ui.Button(self.win, layout=(lw - 9, 0, 4, 1), text=_('Problems'), action='onProblems') ui.Button(self.win, layout=(lw - 5, 0, 5, 1), text=_('Menu'), action='onMenu') self.app.statusBar = self.win.vStatus self.app.setStatus(_('Ready.')) # system menu self.systemMenu = ui.Menu( self.app, title=_("Menu"), width=5, items=[ ui.Item(_("Find system"), action="onSearch", hotkey=u'\x66'), # F ui.Item(_("Statistics"), action="onStats", hotkey=u'\x73'), # S ui.Item(_("Save View"), action="onSaveView", hotkey=u'\x76'), # V ui.Item(_("Save Starmap"), action="onSaveStarmap"), ui.Item(_("Options"), action="onOptions", hotkey=u'\x6F'), # O ui.Item(_("--------"), enabled=False), ui.Item( _("Finish galaxy"), action="galaxyFinishButton", enabled=False, data=True ), # no hotkey; if this position moved, you need to update finishGalaxy's "self.systemMenu.items" lines to reference new index position ui.Item(_("Resign"), action="onResign"), # no hotkey ui.Item(_("--------"), enabled=False), ui.Item(_("Exit"), action="onExit", hotkey=u'\x71'), # Q (also directly CTRL+F12) ]) self.systemMenu.subscribeAction("*", self) self.systemFleetMenu = ui.Menu( self.app, title=_("Fleets"), width=4, items=[ ui.Item(_("Fleet List"), action="onFleets", hotkey=u'\x66'), # F ui.Item(_("Analysis"), action="onFleetAnalysis", hotkey=u'\x61'), # A ]) self.systemFleetMenu.subscribeAction("*", self) self.systemPlanetMenu = ui.Menu( self.app, title=_("Planets"), width=5, items=[ ui.Item(_("Planet List"), action="onPlanets", hotkey=u'\x70'), # P ui.Item(_("System List"), action="onSystems", hotkey=u'\x73'), # S ui.Item(_("Global queues"), action="onGlobalQueues"), ui.Item(_("Analysis"), action="onPlanetAnalysis", hotkey=u'\x61'), #A ]) self.systemPlanetMenu.subscribeAction("*", self)
def showFleet(self): fleet = client.get(self.fleetID, noUpdate=1) if hasattr(fleet, 'customname') and fleet.customname: self.win.title = _('Fleet: %s') % fleet.customname else: self.win.title = _('Fleet: %s') % getattr(fleet, 'name', res.getUnknownName()) # fill listbox items = [] # serial ships if hasattr(fleet, 'ships'): for designID, hp, shield, exp in fleet.ships: tech = client.getPlayer().shipDesigns[designID] if shield > 0: hpInfo = _("%d + %d") % (hp, shield) hpSort = hp + 1000 * shield else: hpInfo = _("%d") % hp hpSort = hp item = ui.Item(tech.name, tHP=hpInfo, tHP_raw=hpSort, tExp=exp, tClass=_(gdata.shipClasses[tech.combatClass]), designID=designID, tLevel=Rules.shipExpToLevel.get( int(exp / tech.baseExp), Rules.shipDefLevel), tSpec=[designID, hp, shield, exp], tSpeed=_("%.2f") % tech.speed) items.append(item) self.win.vShips.items = items self.win.vShips.itemsChanged() self.win.vShips.selectItem(self.win.vShips.items[0]) self.showShip(self.win.vShips.items[0].designID, self.win.vShips.items[0].tExp) # fleet info self.win.vFCoordinates.text = '[%.1f, %.1f]' % (fleet.x, fleet.y) if fleet.orbiting != OID_NONE: self.win.vFOrbiting.text = getattr( client.get(fleet.orbiting, noUpdate=1), 'name', res.getUnknownName()) else: self.win.vFOrbiting.text = _('N/A') if hasattr(fleet, "speedBoost") and hasattr(fleet, "maxSpeed"): text = _("%.2f") % (fleet.maxSpeed * fleet.speedBoost) info = _("Base speed %.2f, speed boost %.2f") % (fleet.maxSpeed, fleet.speedBoost) else: text = _("?") info = None self.win.vFMaxSpeed.text = text self.win.vFMaxSpeed.tooltip = info self.win.vFMaxSpeed.statustip = info self.win.vFSignature.text = getattr(fleet, 'signature', '?') # commands items = [] index = 0 if hasattr(fleet, 'actions'): for action, target, data in fleet.actions: info = "-" if target != OID_NONE: targetName = getattr(client.get(target, noUpdate=1), 'name', res.getUnknownName()) else: targetName = '-' if index == fleet.actionIndex: current = '>' else: current = '' # additional info if action == FLACTION_DECLAREWAR: info = getattr(client.get(data, noUpdate=1), 'name', res.getUnknownName()) elif action == FLACTION_DEPLOY: info = client.getPlayer().shipDesigns[data].name elif action == FLACTION_REPEATFROM: info = _("Command #%d") % (data + 1) elif action == FLACTION_WAIT: info = _("%d / %d") % (fleet.actionWaitCounter, data) # create item item = ui.Item(gdata.fleetActions[action], targetName=targetName, data=info, tIndex=index + 1, current=current) items.append(item) index += 1 self.win.vCommands.items = items self.win.vCommands.selection = [] self.win.vCommands.itemsChanged() self.win.vCommandUp.enabled = 0 self.win.vCommandDown.enabled = 0 self.win.vCommandDel.enabled = 0 self.win.vCommandSetActive.enabled = 0
def showTechs(self): # techs items = [] select = None showSmall = self.win.vSmall.checked showMed = self.win.vMedium.checked showLarge = self.win.vLarge.checked showCivShip = self.win.vCivShip.checked showMilShip = self.win.vMilShip.checked for techID in client.getPlayer().techs.keys(): tech = client.getTechInfo(techID) # hide pirate techs if tech.level == 99: continue if tech.isStructure or tech.globalDisabled: continue etc = _("N/A") item = ui.Item( tech.name, tLevel=tech.level, tProd=tech.buildProd, techID=techID, tIsShip=0, ) if item.tLevel > self.maxTechLevel: self.maxTechLevel = item.tLevel if item.tLevel in self.showLevels and \ (self.showOther and (tech.isProject)): items.append(item) if techID == self.techID: select = item # special handling for ships player = client.getPlayer() if self.showShips: for designID in player.shipDesigns.keys(): tech = player.shipDesigns[designID] if not ((tech.combatClass == 0 and showSmall) or (tech.combatClass == 1 and showMed) or (tech.combatClass == 2 and showLarge)): continue if not ((tech.isMilitary and showMilShip) or (not tech.isMilitary and showCivShip)): continue if tech.upgradeTo != Const.OID_NONE: # skip ships that are set to upgrade continue etc = _("N/A") item = ui.Item( tech.name, tLevel=tech.level, tProd=tech.buildProd, techID=designID, tIsShip=1, ) items.append(item) if designID == self.techID: select = item # sort it by level and then by name items.sort(key=lambda a: (100 - a.tLevel, a.text)) self.win.vTechs.items = items self.win.vTechs.itemsChanged() self.win.vTechs.selectItem(select) # filter for i in xrange(1, 10): widget = getattr(self.win, 'vLevel%d' % i) if i in self.showLevels and i <= self.maxTechLevel: widget.visible = 1 widget.pressed = 1 elif i not in self.showLevels and i <= self.maxTechLevel: widget.visible = 1 widget.pressed = 0 else: widget.visible = 0 self.win.vShipsToggle.pressed = self.showShips self.win.vOtherToggle.pressed = self.showOther # quantity self.win.vQuantity.text = str(self.quantity)
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()
def show(self): tech = client.getTechInfo(self.techID) player = client.getPlayer() techEff = Rules.techImprEff[player.techs.get( self.techID, Rules.techBaseImprovement)] self.win.title = _('Technology: %s (TL%d)') % (tech.name, tech.level) # fill data # fill description descr = [] improvement = player.techs.get(self.techID, 0) if hasattr(tech, 'researchMod'): if improvement == 0: descr.append( _('Research costs: %d') % Utils.getTechRCost(player, self.techID)) descr.append('') elif improvement < Rules.techMaxImprovement: descr.append( _('Improvement costs: %d') % Utils.getTechRCost(player, self.techID)) descr.append('') # requires if tech.researchRequires and improvement == 0: descr.append(_('Research requires:')) for tmpTechID, improvement in tech.researchRequires: tmpTech = client.getTechInfo(tmpTechID) descr.append( _(' - %s improvement %d (TL%d)') % (tmpTech.name, improvement, tmpTech.level)) if hasattr(tech, "researchReqSRes"): for stratRes in tech.researchReqSRes: descr.append( _(" - %s (strategic resource)") % (gdata.stratRes[stratRes])) descr.append('') if hasattr(tech, "researchDisables") and tech.researchDisables: descr.append(_("Research disables:")) for tmpTechID in tech.researchDisables: tmpTech = client.getTechInfo(tmpTechID) descr.append(_(" - %s (TL%d)") % (tmpTech.name, tmpTech.level)) descr.append('') if hasattr(tech, 'partialData') and hasattr(tech, 'textPreRsrch'): # preresearch info descr.append(_('Estimated use:')) descr.extend(tech.textPreRsrch.split('\n')) descr.append('') elif not hasattr(tech, 'partialData'): tmp = [] for improvement in range(1, 6): for tmpTechID in tech.researchEnables[improvement]: tmpTech = client.getTechInfo(tmpTechID) racesDispl = "" raceChoosen = None if player.techLevel == 1: for techID in player.techs.keys(): if techID in (1990, 1991, 1992): raceChoosen = client.getTechInfo(techID).data else: raceChoosen = player.race if len(tmpTech.researchRaces) > 0 and len( tmpTech.researchRaces) < 3 and not raceChoosen: racesDispl = _(", only for %s") % tmpTech.researchRaces if not raceChoosen or len( tmpTech.researchRaces ) == 0 or raceChoosen in tmpTech.researchRaces: tmp.append( _(' - %s (with improvement %d, on TL%d%s)') % (tmpTech.name, improvement, tmpTech.level, racesDispl)) if tmp: descr.append(_('Research/Improvement enables:')) descr.extend(tmp) descr.append('') # production dependency if tech.prodBioMod != [0, 0, 0, 0 ] and tech.prodBioMod != [0, 0, 0, 1]: descr.append(_("Bio production depends:")) if tech.prodBioMod[0]: descr.append( _(" - %d %% on planet's environment") % (tech.prodBioMod[0] * 100)) if tech.prodBioMod[1]: descr.append( _(" - %d %% on planet's min. abundance") % (tech.prodBioMod[1] * 100)) if tech.prodBioMod[2]: descr.append( _(" - %d %% on planet's en. abundance") % (tech.prodBioMod[2] * 100)) if tech.prodBioMod[3]: descr.append( _(" - %d %% is not dependent on any planet's attribute" ) % (tech.prodBioMod[3] * 100)) descr.append("") if tech.prodEnMod != [0, 0, 0, 0 ] and tech.prodEnMod != [0, 0, 0, 1]: descr.append(_("Energy production depends:")) if tech.prodEnMod[0]: descr.append( _(" - %d %% on planet's environment") % (tech.prodEnMod[0] * 100)) if tech.prodEnMod[1]: descr.append( _(" - %d %% on planet's min. abundance") % (tech.prodEnMod[1] * 100)) if tech.prodEnMod[2]: descr.append( _(" - %d %% on planet's en. abundance") % (tech.prodEnMod[2] * 100)) if tech.prodEnMod[3]: descr.append( _(" - %d %% is not dependent on any planet's attribute" ) % (tech.prodEnMod[3] * 100)) descr.append("") if tech.prodProdMod != [0, 0, 0, 0 ] and tech.prodProdMod != [0, 0, 0, 1]: descr.append(_("Constr. points production depends:")) if tech.prodProdMod[0]: descr.append( _(" - %d %% on planet's environment") % (tech.prodProdMod[0] * 100)) if tech.prodProdMod[1]: descr.append( _(" - %d %% on planet's min. abundance") % (tech.prodProdMod[1] * 100)) if tech.prodProdMod[2]: descr.append( _(" - %d %% on planet's en. abundance") % (tech.prodProdMod[2] * 100)) if tech.prodProdMod[3]: descr.append( _(" - %d %% is not dependent on any planet's attribute" ) % (tech.prodProdMod[3] * 100)) descr.append("") if tech.prodSciMod != [0, 0, 0, 0 ] and tech.prodSciMod != [0, 0, 0, 1]: descr.append(_("Research points production depends:")) if tech.prodSciMod[0]: descr.append( _(" - %d %% on planet's environment") % (tech.prodSciMod[0] * 100)) if tech.prodSciMod[1]: descr.append( _(" - %d %% on planet's min. abundance") % (tech.prodSciMod[1] * 100)) if tech.prodSciMod[2]: descr.append( _(" - %d %% on planet's en. abundance") % (tech.prodSciMod[2] * 100)) if tech.prodSciMod[3]: descr.append( _(" - %d %% is not dependent on any planet's attribute" ) % (tech.prodSciMod[3] * 100)) descr.append("") requiredStrategicResourcesForBuilding = self.getStrategicResourcesText( tech, "buildSRes") requiredStrategicResourcesForResearch = self.getStrategicResourcesText( tech, "researchReqSRes") if len(requiredStrategicResourcesForBuilding) > 0 or len( requiredStrategicResourcesForResearch) > 0: descr.append(_("Required strategic resources:")) if len(requiredStrategicResourcesForBuilding) > 0: descr.append( _(" - for building: %s") % requiredStrategicResourcesForBuilding) if len(requiredStrategicResourcesForResearch) > 0: descr.append( _(" - for research: %s") % requiredStrategicResourcesForResearch) descr.append("") # decription descr.append(_('Description:')) if tech.textDescr != u'Not specified': descr.extend(tech.textDescr.split('\n')) else: descr.extend(tech.textPreRsrch.split('\n')) descr.append('') # flavor descr.append(_('Rumours:')) descr.extend(tech.textFlavor.split('\n')) descr.append('') if not len(descr): descr.append(_('No information available')) # self.win.vDescr.text = descr # re-set techType if neccessary self.techType = self.techType & ( getattr(tech, 'isStructure', 0) * V_STRUCT | getattr(tech, 'isShipHull', 0) * V_HULL | getattr(tech, 'isShipEquip', 0) * V_SEQUIP | getattr(tech, 'isProject', 0) * V_PROJECT) if self.techType == V_NONE: if getattr(tech, 'isStructure', 0): self.techType = V_STRUCT elif getattr(tech, 'isShipHull', 0): self.techType = V_HULL elif getattr(tech, 'isShipEquip', 0): self.techType = V_SEQUIP elif getattr(tech, 'isProject', 0): self.techType = V_PROJECT # set type buttons self.win.vStruct.pressed = self.techType == V_STRUCT self.win.vStruct.enabled = getattr(tech, 'isStructure', 0) self.win.vHull.pressed = self.techType == V_HULL self.win.vHull.enabled = getattr(tech, 'isShipHull', 0) self.win.vSEquip.pressed = self.techType == V_SEQUIP self.win.vSEquip.enabled = getattr(tech, 'isShipEquip', 0) self.win.vProject.pressed = self.techType == V_PROJECT self.win.vProject.enabled = getattr(tech, 'isProject', 0) # fill data items = [] for attr in dir(tech): value = getattr(tech, attr) descr, props, showIfDef, default, convertor = techAttrs.get( attr, defaultAttr) if self.techType & props and (value != default or showIfDef): item = ui.Item(descr, tValue=convertor(value)) if V_EFF & props: item.font = 'normal-bold' item.tValue = convertor(value * techEff) if V_EFF_REV & props: item.font = 'normal-bold' item.tValue = convertor(value / techEff) items.append(item) self.win.vData.items = items self.win.vData.itemsChanged()
def showTechs(self): # techs items = [] select = None showMilitary = self.win.vMilitary.checked showBio = self.win.vBioProduction.checked showEn = self.win.vEnProduction.checked showCP = self.win.vCPProduction.checked showRP = self.win.vRPProduction.checked showMorale = self.win.vMorale.checked for techID in client.getPlayer().techs.keys(): tech = client.getTechInfo(techID) if not ((tech.isMilitary and showMilitary) or \ ((getattr(tech, "prodBio", 0) > 0 or getattr(tech, "prodEnv", 0) > 0) and showBio) or \ (getattr(tech, "prodEn", 0) > 0 and showEn) or \ (getattr(tech, "prodProd", 0) > 0 and showCP) or \ (getattr(tech, "prodSci", 0) > 0 and showRP) or \ (getattr(tech, "moraleTrgt", 0) > 0 and showMorale)): continue sourcePlanet = client.get(self.sourceID, noUpdate=1) prodProd = getattr(sourcePlanet, "effProdProd", 0) if prodProd > 0: etc = math.ceil(float(tech.buildProd) / prodProd) if self.sourceID != self.planetID: etc *= Rules.buildOnAnotherPlanetMod etc = res.formatTime(etc) else: etc = _("N/A") item = ui.Item( etc, techID=techID, tIsShip=0, name=tech.name, tl=tech.level, subtype=tech.subtype, icons=((res.getTechImg(techID), ui.ALIGN_N), ), font="small-bold", align=ui.ALIGN_S, tooltipTitle=_("Details"), tooltip="%s, %d %s, %s %d" % (tech.name, tech.buildProd, _("CP"), _("TL"), tech.level), statustip="%s, %d %s, %s %d" % (tech.name, tech.buildProd, _("CP"), _("TL"), tech.level), ) if tech.level > self.maxTechLevel: self.maxTechLevel = tech.level # TODO FIX ME if tech.level in self.showLevels and \ ((self.showStructures and tech.isStructure) or \ (self.showOther and (tech.isProject))) or tech.level == 99: items.append(item) if techID == self.techID: select = item # sort methods if self.sort == 'none': # sort by name items.sort(key=lambda a: a.name) elif self.sort == 'tl': # sort by TL, subsort by name items.sort(key=lambda a: a.name) items.sort(key=lambda a: a.tl) elif self.sort == 'type': #sort by subtype, subsort by tl items.sort(key=lambda a: a.tl) items.sort(key=lambda a: a.subtype) self.win.vTechs.items = items self.win.vTechs.itemsChanged() if select: self.win.vTechs.selectItem(select) # filter for i in xrange(1, 10): widget = getattr(self.win, 'vLevel%d' % i) if i in self.showLevels and i <= self.maxTechLevel: widget.visible = 1 widget.pressed = 1 elif i not in self.showLevels and i <= self.maxTechLevel: widget.visible = 1 widget.pressed = 0 else: widget.visible = 0 # quantity self.win.vQuantity.text = str(self.quantity)
def show(self, updateForum = 1): self.newMsgs = 0 # player = client.getPlayer() objList = [player.oid] objList.append(player.galaxy) objList.append(Const.OID_UNIVERSE) # show forums items = [] colors = [gdata.sevColors[gdata.INFO], gdata.sevColors[gdata.MIN]] ## Inbox msgs, new = self.getMsgsNumber(player.oid, "INBOX",'local') self.newMsgs += new spec = gdata.mailboxSpec[Const.T_PLAYER, "INBOX"] item = ui.Item(_(spec[0]), tObjID=player.oid, tForum="INBOX", tType=Const.T_PLAYER, tMsgs=_("%d / %d") % (new, msgs), foreground=colors[new > 0]) items.append(item) # Events msgs, new = self.getMsgsNumber(player.oid, "EVENTS") self.newMsgs += new spec = gdata.mailboxSpec[Const.T_PLAYER, "EVENTS"] eventsItem = ui.Item(_(spec[0]), tObjID=player.oid, tForum="EVENTS", tType=Const.T_PLAYER, tMsgs=_("%d / %d") % (new, msgs), foreground=colors[new > 0]) items.append(eventsItem) # Outbox msgs, new = self.getMsgsNumber(player.oid, "OUTBOX") self.newMsgs += new spec = gdata.mailboxSpec[Const.T_PLAYER, "OUTBOX"] item = ui.Item(_(spec[0]), tObjID=player.oid, tForum="OUTBOX", tType=Const.T_PLAYER, tMsgs=_("%d / %d") % (new, msgs), foreground=colors[new > 0]) items.append(item) ## galaxy galaxyID = player.galaxy galaxy = client.get(galaxyID) # folder item = ui.Item(_("Galaxy %s") % galaxy.name, tObjID=Const.OID_NONE, tForum="", tMsgs="", foreground=colors[0]) items.append(item) # news msgs, new = self.getMsgsNumber(galaxyID, "NEWS") self.newMsgs += new spec = gdata.mailboxSpec[Const.T_GALAXY, "NEWS"] item = ui.Item(" %s" % _(spec[0]), tObjID=galaxyID, tForum="NEWS", tType=Const.T_GALAXY, tMsgs=_("%d / %d") % (new, msgs), foreground=colors[new > 0]) items.append(item) # public msgs, new = self.getMsgsNumber(galaxyID, "PUBLIC",'galaxy') self.newMsgs += new spec = gdata.mailboxSpec[Const.T_GALAXY, "PUBLIC"] item = ui.Item(" %s" % _(spec[0]), tObjID=galaxyID, tForum="PUBLIC", tType=Const.T_GALAXY, tMsgs=_("%d / %d") % (new, msgs), foreground=colors[new > 0]) items.append(item) ## universe item = ui.Item(_("Outer Space"), tObjID=Const.OID_NONE, tForum="", tMsgs="", foreground=colors[0]) items.append(item) # news msgs, new = self.getMsgsNumber(Const.OID_UNIVERSE, "NEWS") self.newMsgs += new spec = gdata.mailboxSpec[Const.T_UNIVERSE, "NEWS"] item = ui.Item(" %s" % _(spec[0]), tObjID=Const.OID_UNIVERSE, tForum="NEWS", tType=Const.T_UNIVERSE, tMsgs=_("%d / %d") % (new, msgs), foreground=colors[new > 0]) items.append(item) # public msgs, new = self.getMsgsNumber(Const.OID_UNIVERSE, "PUBLIC",'universe') self.newMsgs += new spec = gdata.mailboxSpec[Const.T_UNIVERSE, "PUBLIC"] item = ui.Item(" %s" % _(spec[0]), tObjID=Const.OID_UNIVERSE, tForum="PUBLIC", tType=Const.T_UNIVERSE, tMsgs=_("%d / %d") % (new, msgs), foreground=colors[new > 0]) items.append(item) # self.win.vForums.items = items self.win.vForums.itemsChanged() # find item to select found = 0 for item in items: if item.tObjID == self.selectedObjID and item.tForum == self.selectedForum: self.win.vForums.selectItem(item) found = 1 break if not found: self.win.vForums.selectItem(eventsItem) # display forum if updateForum: self.onForumSelected(None, None, None) # update mgs button gdata.mainGameDlg.updateMsgButton()
import pygameui as ui ui.SkinableTheme.setSkin("../OSSkin") app = ui.Application(update, theme=ui.SkinableTheme) app.windowSurfaceFlags = SWSURFACE def echoHandler(widget, action, data): print 'ACTION', widget, action, data popUpMenu = ui.Menu( app, title="Test Menu", items=[ ui.Item("Test 1", action="MENU TEST", data=1), ui.Item("Test 2", action="MENU TEST", data=2), ], ) popUpMenu.subscribeAction("*", echoHandler) def menuHandler(widget, action, data): print "MENU" popUpMenu.show() # create status window progBars = [] for i in xrange(0, 2):
def show(self): items = [] player = client.getPlayer() # for systemID in client.db.keys(): if systemID == player.oid: continue system = client.get(systemID, noUpdate=1) if not hasattr(system, 'planets'): continue planetsMine = 0 planetsOwned = 0 planetsUnowned = 0 planetsGA = 0 planetsNotMine = 0 en = 0 bio = 0 enres = 0 biores = 0 stratRes = Const.SR_NONE refuelMax = 0 refuelInc = 0 upgradeShip = 0 repairShip = 0 speedBoost = 0 useOwner = Const.OID_NONE for planetID in system.planets: planet = client.get(planetID, noUpdate=1) owner = getattr(planet, 'owner', Const.OID_NONE) if owner != Const.OID_NONE: useOwner = owner if owner == player.oid: planetsMine += 1 else: planetsOwned += 1 if self.showOtherPlayers: planetsNotMine += 1 en += getattr(planet, 'changeEn', 0) bio += getattr(planet, 'changeBio', 0) enres += getattr(planet, 'storEn', 0) biores += getattr(planet, 'storBio', 0) stratRes = getattr(planet, 'plStratRes', Const.SR_NONE) if stratRes == Const.SR_NONE else stratRes refuelMax = max(getattr(planet, 'refuelMax', 0), refuelMax) refuelInc = max(getattr(planet, 'refuelInc', 0), refuelInc) upgradeShip += getattr(planet, 'upgradeShip', 0) repairShip = max(getattr(planet, 'repairShip', 0), repairShip) speedBoost = max(getattr(planet, 'fleetSpeedBoost', 0), speedBoost) else: if hasattr(planet, "plType") and planet.plType in ("A", "G"): planetsGA += 1 if self.showUncolonizable: planetsNotMine += 1 else: planetsUnowned += 1 if self.showColonizable: planetsNotMine += 1 if planetsMine == 0: # fix no-data systems en = '?' bio = '?' enres = '?' biores = '?' if ((planetsMine and self.showMine) or (planetsOwned and self.showOtherPlayers) or (planetsUnowned and self.showColonizable) or (planetsGA and self.showUncolonizable)): if stratRes == Const.SR_NONE: stratResText = ' ' else: stratResText = gdata.stratRes[stratRes] problem = (bio < 0 or en < 0) if planetsMine > 0: # make sure you own it useOwner = player.oid if speedBoost > 1: speedBoost = int((speedBoost - 1) * 100) else: speedBoost = '' if self.showProblems: color = res.getSystemOverviewProblemColor(useOwner, problem) else: color = res.getPlayerColor(useOwner) item = ui.Item( getattr(system, 'name', res.getUnknownName()), tSyPnum=planetsMine + planetsOwned + planetsUnowned + planetsGA, tSyPTnum=planetsNotMine, tSyPYnum=planetsMine, tSyBioRes=biores, tSyEnRes=enres, tSyBio=bio, tSyEn=en, tSyRefuel=refuelInc, tSyRefuelMax=refuelMax, tSyRepair=(repairShip * 100), tSyUpgrade=int(upgradeShip), tSyGate=speedBoost, tStRes=_(stratResText), tSysID=systemID, foreground=color, ) items.append(item) self.win.vPlanets.items = items self.win.vPlanets.itemsChanged() # buttons self.win.vMine.pressed = self.showMine self.win.vOtherPlayers = self.showOtherPlayers self.win.vColonizable = self.showColonizable self.win.vUncolonizable = self.showUncolonizable self.win.vProblems = self.showProblems
def showTechs(self): # techs items = [] select = None showMilitary = self.win.vMilitary.checked showBio = self.win.vBioProduction.checked showEn = self.win.vEnProduction.checked showCP = self.win.vCPProduction.checked showRP = self.win.vRPProduction.checked showMorale = self.win.vMorale.checked showSmall = self.win.vSmall.checked showMed = self.win.vMedium.checked showLarge = self.win.vLarge.checked showCivShip = self.win.vCivShip.checked showMilShip = self.win.vMilShip.checked for techID in client.getPlayer().techs.keys(): tech = client.getTechInfo(techID) # hide pirate techs from ships and miscs view if not self.showStructures and tech.level == 99: continue if tech.isStructure: if (tech.isMilitary or getattr(tech, "prodBio", 0) > 0 or getattr(tech, "prodEnv", 0) > 0 or \ getattr(tech, "prodEn", 0) > 0 or getattr(tech, "prodProd", 0) > 0 or \ getattr(tech, "prodSci", 0) > 0 or getattr(tech, "moraleTrgt", 0) > 0): if not ((tech.isMilitary and showMilitary) or \ ((getattr(tech, "prodBio", 0) > 0 or getattr(tech, "prodEnv", 0) > 0) and showBio) or \ (getattr(tech, "prodEn", 0) > 0 and showEn) or \ (getattr(tech, "prodProd", 0) > 0 and showCP) or \ (getattr(tech, "prodSci", 0) > 0 and showRP) or \ (getattr(tech, "moraleTrgt", 0) > 0 and showMorale)): continue if self.prodProd > 0: etc = math.ceil(float(tech.buildProd) / self.prodProd) if self.targetID != self.planetID: etc *= Rules.buildOnAnotherPlanetMod etc = res.formatTime(etc) else: etc = _("N/A") item = ui.Item( tech.name, tLevel=tech.level, tProd=tech.buildProd, techID=techID, tIsShip=0, tETC=etc, ) if item.tLevel > self.maxTechLevel: self.maxTechLevel = item.tLevel if item.tLevel in self.showLevels and \ ((self.showStructures and tech.isStructure) or \ (self.showOther and (tech.isProject))): items.append(item) if techID == self.techID: select = item # special handling for ships player = client.getPlayer() if self.showShips: for designID in player.shipDesigns.keys(): tech = player.shipDesigns[designID] if not ((tech.combatClass == 0 and showSmall) or (tech.combatClass == 1 and showMed) or (tech.combatClass == 2 and showLarge)): continue if not ((tech.isMilitary and showMilShip) or (not tech.isMilitary and showCivShip)): continue if tech.upgradeTo != Const.OID_NONE: # skip ships that are set to upgrade continue if self.prodProd > 0: etc = res.formatTime( math.ceil(float(tech.buildProd) / self.prodProd)) else: etc = _("N/A") item = ui.Item( tech.name, tLevel=tech.level, tProd=tech.buildProd, techID=designID, tIsShip=1, tETC=etc, ) items.append(item) if designID == self.techID: select = item # sort it by level and then by name items.sort(key=lambda a: (100 - a.tLevel, a.text)) self.win.vTechs.items = items self.win.vTechs.itemsChanged() self.win.vTechs.selectItem(select) # filter for i in xrange(1, 10): widget = getattr(self.win, 'vLevel%d' % i) if i in self.showLevels and i <= self.maxTechLevel: widget.visible = 1 widget.pressed = 1 elif i not in self.showLevels and i <= self.maxTechLevel: widget.visible = 1 widget.pressed = 0 else: widget.visible = 0 self.win.vStructuresToggle.pressed = self.showStructures self.win.vShipsToggle.pressed = self.showShips self.win.vOtherToggle.pressed = self.showOther # targets info = [] system = client.get(self.systemID, noUpdate=1) select = None if hasattr(system, 'planets'): for planetID in system.planets: planet = client.get(planetID, noUpdate=1) owner = res.getUnknownName() #rel = Const.REL_UNDEF ownerID = Const.OID_NONE if hasattr(planet, 'owner'): ownerID = planet.owner if planet.owner != Const.OID_NONE: owner = client.get(planet.owner, noUpdate=1).name #rel = client.getRelationTo(planet.owner) else: owner = _('[Nobody]') if planet.plType in ("A", "G"): color = gdata.sevColors[gdata.DISABLED] else: #color = res.getFFColorCode(rel) color = res.getPlayerColor(ownerID) plname = getattr(planet, 'name', res.getUnknownName()) item = ui.Item( plname, text_raw=getattr(planet, 'plEn', plname), planetID=planetID, plOwner=owner, foreground=color, ) info.append(item) if planetID == self.targetID: select = item self.win.vTargets.items = info self.win.vTargets.itemsChanged() self.win.vTargets.selectItem(select) # quantity self.win.vQuantity.text = str(self.quantity)
def createUI(self): w, h = gdata.scrnSize self.win = ui.Window(self.app, modal=1, escKeyClose=1, titleOnly=(w == 800 and h == 600), movable=0, title=_('Diplomacy'), rect=ui.Rect((w - 800 - 4 * (w != 800)) / 2, (h - 600 - 4 * (h != 600)) / 2, 800 + 4 * (w != 800), 580 + 4 * (h != 600)), layoutManager=ui.SimpleGridLM()) self.win.subscribeAction('*', self) # player listing ui.Listbox( self.win, layout=(0, 0, 40, 14), id='vContacts', columns=((_('Name'), 'text', 8, ui.ALIGN_W), (_('Relation'), 'tRelation', 4, ui.ALIGN_E), (_('Population'), 'tPopulation', 4, ui.ALIGN_E), (_('Planets'), 'tPlanets', 4, ui.ALIGN_E), (_('Structures'), 'tStructures', 4, ui.ALIGN_E), (_('Production'), 'tProduction', 4, ui.ALIGN_E), (_('Research'), 'tScience', 4, ui.ALIGN_E), (_('Military pwr'), 'tFleetPwr', 4, ui.ALIGN_E), (_("Contact"), "tContact", 4, ui.ALIGN_E)), columnLabels=1, action="onContactSelected", rmbAction="onHighlightMenu") # Voting ui.Button(self.win, layout=(0, 14, 5, 1), text=_("Elect"), id="vVoteFor", action="onVoteFor") ui.Button(self.win, layout=(5, 14, 5, 1), text=_("Abstain"), id="vAbstain", action="onAbstain") # Highlights ui.Button(self.win, layout=(24, 14, 8, 1), text=_("Highlights On"), id="vHighlight", action="onHighlight") ui.Button(self.win, layout=(32, 14, 8, 1), text=_("Highligh Off"), id="vUHighlight", action="onUHighlight") # pacts ui.Title(self.win, layout=(0, 15, 20, 1), text=_('Pacts'), font='normal-bold', align=ui.ALIGN_W) ui.Listbox(self.win, layout=(0, 16, 20, 10), id='vPacts', columns=((_('I'), 'tState1', 3, ui.ALIGN_W), (_('Partner'), 'tState2', 3, ui.ALIGN_W), (_('Pact'), 'text', 13, ui.ALIGN_W)), columnLabels=1, action="onPactSelected") ui.Button(self.win, layout=(0, 26, 20, 1), text=_("On"), id="vChangePactState", action="onPactChange", enabled=0) # conditions ui.Title(self.win, layout=(20, 15, 20, 1), text=_('Conditions'), id="vCondTitle", font='normal-bold', align=ui.ALIGN_W) ui.Listbox(self.win, layout=(20, 16, 20, 10), id='vConditions', columns=((_('I'), 'tState1', 3, ui.ALIGN_W), (_('Partner'), 'tState2', 3, ui.ALIGN_W), (_('Pact'), 'text', 13, ui.ALIGN_W)), columnLabels=1, multiselection=1) ui.Button(self.win, layout=(20, 26, 15, 1), text=_("Change"), id="vPactConditions", action="onPactChange", enabled=0, data="CONDS") ui.Button(self.win, layout=(35, 26, 5, 1), text=_("Reset"), id="vPactCondReset", action="onPactChange", enabled=0, data="CONDSRESET") # status bar + submit/cancel ui.TitleButton(self.win, layout=(35, 27, 5, 1), text=_('Close'), action='onClose') ui.Title(self.win, id='vStatusBar', layout=(0, 27, 35, 1), align=ui.ALIGN_W) # highlight menu self.eventPopup = ui.Menu(self.app, title=_("Highligh actions"), items=[ ui.Item(_("Define color"), action="onColorDefinition"), ui.Item(_("Disable highlight"), action="onDeleteHighlight") ]) self.eventPopup.subscribeAction("*", self)
def show(self): player = client.getPlayer() # items = [] for planetID in client.db.keys(): planet = client.get(planetID, noUpdate=1) # skip non-planets if not hasattr(planet, "type") or planet.type != Const.T_PLANET: continue # shall be shown? ok = 0 if hasattr(planet, 'owner'): if self.showMine and planet.owner == player.oid: ok = 1 if self.showOtherPlayers and planet.owner != Const.OID_NONE and \ planet.owner != player.oid: ok = 1 if self.showColonizable and planet.owner == Const.OID_NONE and \ planet.plType not in ('G', 'A'): ok = 1 if self.showUncolonizable and planet.plType in ('G', 'A'): ok = 1 elif hasattr(planet, 'plType'): if self.showColonizable and planet.plType not in ('G', 'A'): ok = 1 if self.showUncolonizable and planet.plType in ('G', 'A'): ok = 1 if not ok: continue # fill in data #rel = Const.REL_UNDEF maxNA = 999999 maxNone = 99999 ownerID = Const.OID_NONE if hasattr(planet, 'owner'): ownerID = planet.owner #if planet.owner != Const.OID_NONE: # rel = client.getRelationTo(planet.owner) if planet.owner == Const.OID_NONE: #else: owner = _('[Nobody]') if hasattr(planet, 'owner') and planet.owner == player.oid: if planet.prodQueue and planet.effProdProd > 0: index = 0 totalEtc = 0 for task in planet.prodQueue: if task.isShip: tech = client.getPlayer().shipDesigns[task.techID] else: tech = client.getFullTechInfo(task.techID) if index == 0: constrInfo = tech.name # etc if task.targetID != planetID: if index == 0: etc = math.ceil( float(tech.buildProd * Rules.buildOnAnotherPlanetMod - task.currProd) / planet.effProdProd) totalEtc += etc totalEtc += math.ceil( (task.quantity - 1) * float(tech.buildProd * Rules.buildOnAnotherPlanetMod) / planet.effProdProd) else: totalEtc += math.ceil( float(tech.buildProd * Rules.buildOnAnotherPlanetMod - task.currProd) / planet.effProdProd) totalEtc += math.ceil( (task.quantity - 1) * float(tech.buildProd * Rules.buildOnAnotherPlanetMod) / planet.effProdProd) else: if index == 0: etc = math.ceil( float(tech.buildProd - task.currProd) / planet.effProdProd) totalEtc += etc totalEtc += math.ceil( (task.quantity - 1) * float(tech.buildProd) / planet.effProdProd) else: totalEtc += math.ceil( task.quantity * float(tech.buildProd - task.currProd) / planet.effProdProd) totalEtc += math.ceil( (task.quantity - 1) * float(tech.buildProd) / planet.effProdProd) index += 1 etc_raw = etc etc = res.formatTime(etc) totalEtc_raw = totalEtc totalEtc = res.formatTime(totalEtc) elif planet.prodQueue: task = planet.prodQueue[0] if task.isShip: tech = client.getPlayer().shipDesigns[task.techID] else: tech = client.getTechInfo(task.techID) constrInfo = tech.name etc = _('N/A') etc_raw = maxNA totalEtc = _("N/A") totalEtc_raw = maxNA elif planet.effProdProd > 0: constrInfo = _("-") etc = "-" etc_raw = 0 totalEtc = _("-") totalEtc_raw = 0 else: constrInfo = _("-") etc = "-" etc_raw = maxNone totalEtc = _("-") totalEtc_raw = maxNone else: constrInfo = '?' etc = '?' etc_raw = maxNA totalEtc = '?' totalEtc_raw = maxNA # used slots if hasattr(planet, 'slots'): freeSlots = planet.plSlots - len(planet.slots) else: freeSlots = '?' # morale if hasattr(planet, "morale"): morale = int(planet.morale) else: morale = "?" # plType = gdata.planetTypes[getattr(planet, 'plType', None)] # list item item = ui.Item( getattr(planet, 'name', res.getUnknownName()), tPlType=_(plType), tPlBio=getattr(planet, 'plBio', '?'), tPlMin=getattr(planet, 'plMin', '?'), tPlEn=getattr(planet, 'plEn', '?'), tChangeBio=getattr(planet, 'changeBio', '?'), tChangeEn=getattr(planet, 'changeEn', '?'), tETC=etc, tETC_raw=etc_raw, tTotalETC=totalEtc, tTotalETC_raw=totalEtc_raw, tConstrInfo=constrInfo, tFree=freeSlots, tMorale=morale, tSpace=getattr(planet, 'plSlots', '?'), tDiam=getattr(planet, 'plDiameter', 0) / 1000, tProd=getattr(planet, 'effProdProd', '?'), tSci=getattr(planet, 'effProdSci', '?'), tPlanetID=planetID, #foreground = res.getFFColorCode(rel), foreground=res.getPlayerColor(ownerID), ) items.append(item) self.win.vPlanets.items = items self.win.vPlanets.itemsChanged() # buttons self.win.vMine.pressed = self.showMine self.win.vOtherPlayers = self.showOtherPlayers self.win.vColonizable = self.showColonizable self.win.vUncolonizable = self.showUncolonizable