def display(self, fleetDlg): self.fleetDlg = fleetDlg self.fleet = fleet = client.get(self.fleetDlg.fleetID, noUpdate = 1) self.win.vStarMap.currX = fleet.x self.win.vStarMap.currY = fleet.y self.win.vStarMap.alwaysShowRangeFor = fleet.oid self.win.vStarMap.setPosition = 0 self.win.vStarMap.lockObj = fleet.orbiting self.win.vStarMap.precompute() self.sendShipIndex = 0 self.sendShipType = ["Move","Deploy"] self.sendShipTypeIndex = 0 self.targets = [] if self.targetID: target = client.get(self.targetID, noUpdate = 1) self.win.vStarMap.highlightPos = (target.x, target.y) # ships self.sendShips = [] # collect buildings for designID, a, b, c in self.fleet.ships: #fixed bug in reference of designID...added a, b, c to do it; breaks list lookup otherwise (not sure why) with hash error --RC if designID not in self.sendShips: self.sendShips.append(designID) self.showCommands() self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def onSelectMapObj(self, widget, action, data): target = client.get(data, noUpdate = 1) if not self.sendShips: self.win.setStatus(_("No ships found.")) return if target.type == T_PLANET: self.targetID = target.oid self.win.vStarMap.highlightPos = (target.x, target.y) elif target.type in (T_SYSTEM, T_WORMHOLE): if self.sendShipTypeIndex == 1: self.win.setStatus(_("You must select a planet")) return self.targetID = target.oid self.win.vStarMap.highlightPos = (target.x, target.y) else: self.win.vStarMap.hightlightPos = None return self.targetID = target.oid #prevent spam abuse if self.targetID not in self.targets: #split single ship off fleet newfleet = self.splitShip() if newfleet: #move the ship if self.sendShipTypeIndex == 0: self.moveShip(newfleet) elif self.sendShipTypeIndex == 1: self.deployShip(newfleet) #add fleet to starmap without recomputing the whole starmap client.db[newfleet.oid] = client.get(newfleet.oid, forceUpdate = 1) self.win.vStarMap.precomputeFleet(newfleet) self.win.vStarMap.requestRepaint() else: self.win.setStatus(_("You cannot order a ship to the same system twice in one Scout Wave command")) self.showCommands()
def update(self,configUpdated=False): self.galaxyRestart(None, None, False) player = client.getPlayer() turn = client.getTurn() self.win.vTurn.text = res.formatTime(turn) if configUpdated: self.win.vStarMap.updateConfigModes() self.win.vStarMap.precompute() # center of 1st player star if not self.centered: player = client.getPlayer() if player.planets: planet = client.get(player.planets[0]) self.win.vStarMap.setPos(planet.x, planet.y) elif player.fleets: fleet = client.get(player.fleets[0]) self.win.vStarMap.setPos(fleet.x, fleet.y) self.centered = 1 self.refocus() #only fire off when dialog first updated # enable/disable construction self.win.vConstruction.enabled = Utils.enableConstruction(client) # enable/disable diplomacy #if player.diplomacyRels: self.win.vDiplomacy.enabled = 1 #else: # self.win.vDiplomacy.enabled = 0 # highlight messages button? self.messagesDlg.update() if self.messagesDlg.newMsgs > 0: self.win.vMessages.foreground = gdata.sevColors[gdata.MAJ] else: self.win.vMessages.foreground = None
def showDesigns(self): player = client.getPlayer() # check if highlighted ship design exists if self.highlightedDesignID not in player.shipDesigns: self.highlightedDesignID = None # designs highlighted = 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 != Const.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 # plus ships in global queue for queue in player.prodQueues: for task in queue: 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.highlightedDesignID: highlighted = item items.append(item) self.win.vDesigns.items = items self.win.vDesigns.itemsChanged() self.win.vDesigns.highlightItem(highlighted, 0)
def showCommands(self): if self.targetID == OID_NONE: info = _('No target selected') else: target = client.get(self.targetID, noUpdate = 1) info = getattr(target, 'name', res.getUnknownName()) # correct buildingIndex if self.sendShipIndex >= len(self.sendShips): self.sendShipIndex = 0 if self.sendShipTypeIndex >= 2: self.sendShipTypeIndex = 0 # get target data self.win.vTarget.text = info fleet = self.fleet if self.targetID != OID_NONE: curTarget = client.get(self.targetID, noUpdate = 1) target = OID_NONE if fleet.orbiting != OID_NONE and target == OID_NONE: target = fleet.orbiting elif target == OID_NONE: target = fleet.oid if target != OID_NONE: lastTarget = client.get(target, noUpdate = 1) curX = curTarget.x curY = curTarget.y lstX = lastTarget.x lstY = lastTarget.y dx = curX - lstX dy = curY - lstY lnght = math.sqrt(dx*dx + dy*dy) speedBoost = getattr(fleet, "speedBoost", 1) fleetSpeed = getattr(fleet, "speed", 0) maxDelta = fleetSpeed / Rules.turnsPerDay * speedBoost if maxDelta != 0: eta = lnght / maxDelta self.win.vEta.text = res.formatTime(eta) else: self.win.vEta.text = _("N/A") else: self.win.vEta.text = _("N/A") if self.sendShips: self.win.vSendShip.enabled = 1 techID = self.sendShips[self.sendShipIndex] self.win.vSendShip.text = client.getPlayer().shipDesigns[techID].name self.win.vSendShip.data = techID self.win.vSendShipType.text = self.sendShipType[self.sendShipTypeIndex] else: self.win.setStatus(_("No ships found."))
def onConstruct(self, widget, action, data): if not data: self.win.setStatus(_('Select technology to construct.')) return if not self.sourceID: self.sourceID = self.planetID try: self.quantity = int(self.win.vQuantity.text) except ValueError: self.win.setStatus(_('Specify quantity (1, 2, 3, ...).')) return try: self.win.setStatus(_('Executing START CONSTRUCTION command...')) planet = client.get(self.sourceID, noUpdate = 1) if self.extraSlot: for i in range(1, self.quantity + 1): client.cmdProxy.startConstruction(self.sourceID, Rules.Tech.ADDSLOT3, 1, self.planetID, False, self.win.vReportFin.checked, OID_NONE) player = client.getPlayer() planet.prodQueue, player.stratRes = client.cmdProxy.startConstruction(self.sourceID, data.techID, 1, self.planetID, data.techID < 1000, self.win.vReportFin.checked, self.structToDemolish) else: player = client.getPlayer() planet.prodQueue, player.stratRes = client.cmdProxy.startConstruction(self.sourceID, data.techID, self.quantity, self.planetID, data.techID < 1000, self.win.vReportFin.checked, self.structToDemolish) self.win.setStatus(_('Command has been executed.')) except GameException, e: self.win.setStatus(e.args[0]) return
def alterMenu(self, widget, action, data): """ Update menu according to current situation, being different in singleplayer or when player is imperator of competitive galaxy, or player has no rights to finish galaxy at all. """ if client.db != None: player = client.getPlayer() galaxy = client.get(player.galaxy) # player can restart (finish) it's own singleplayer galaxy anytime if galaxy.scenario == Const.SCENARIO_SINGLE: # depends on state of galaxy if not galaxy.timeEnabled: self.systemMenu.items[7].text = _("Resume galaxy") else: self.systemMenu.items[7].text = _("Pause galaxy") self.systemMenu.items[7].action = "onToggleTime" self.systemMenu.items[6].enabled = True self.systemMenu.items[7].enabled = True elif galaxy.scenario == Const.SCENARIO_OUTERSPACE: # standard behavior if player.imperator > 2: # player is imperator for more than two weeks - has right to finish galaxy self.systemMenu.items[6].enabled = True else: # no right to finish galaxy self.systemMenu.items[6].enabled = False # you cannot resign when time is stopped if galaxy.timeEnabled: self.systemMenu.items[7].enabled = True else: self.systemMenu.items[7].enabled = False
def display(self, fleetDlg): self.fleetDlg = fleetDlg fleet = client.get(self.fleetDlg.fleetID, noUpdate = 1) self.origShips = fleet.ships[:] self.storEn = self.origEn = fleet.storEn self.origEnMax = fleet.maxEn self.newShips = [] self.newBio = 0 self.newMin = 0 self.newEn = 0 self.newEnMax = 0 self.checks = 0 self.Nchecks = 0 self.win.vDesign.checked = 0 self.win.vClass.checked = 0 self.win.vDmg.checked = 0 self.win.vExpr.checked = 0 self.win.vLevel.checked = 0 self.win.vSpeed.checked = 0 self.win.vNDesign.checked = 0 self.win.vNClass.checked = 0 self.win.vNDmg.checked = 0 self.win.vNExpr.checked = 0 self.win.vNLevel.checked = 0 self.win.vNSpeed.checked = 0 self.show() self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def onConstruct(self, widget, action, data): planet = client.get(self.planetID, noUpdate = 1) player = client.getPlayer() if not self.techID: self.win.setStatus(_('Select technology to construct.')) return if not self.targetID: self.win.setStatus(_('Select planet to construct on.')) return try: self.quantity = int(self.win.vQuantity.text) except ValueError: self.win.setStatus(_('Specify quantity (1, 2, 3, ...).')) return # government centers have additional query and if confirmed, another round of this function is called if self.techID < 1000: tech = player.shipDesigns[self.techID] else: tech = client.getTechInfo(self.techID) if not getattr(tech, 'govPwr', 0) == 0 and not self.govTransferConfirm: # confirm dialog doesn't send through parameters, so we have to save them self.govTransferData = (widget, action, data) self.confirmDlg.display(_("Do you want to issue relocation of your government?"), _("Yes"), _("No"), self.onGovTransferConfirmed) else: try: self.win.setStatus(_('Executing START CONSTRUCTION command...')) planet.prodQueue, player.stratRes = client.cmdProxy.startConstruction(self.planetID, self.techID, self.quantity, self.targetID, self.techID < 1000, self.win.vReportFin.checked, self.structToDemolish) self.win.setStatus(_('Command has been executed.')) except GameException, e: self.win.setStatus(e.args[0]) return
def display(self, systemID, caller): system = client.get(systemID, noUpdate = 1) self.caller = caller self.systemID = systemID self.win.vStarMap.currX = system.x self.win.vStarMap.currY = system.y self.win.vStarMap.setPosition = 0 self.win.vStarMap.precompute() if self.targetID: target = client.get(self.targetID, noUpdate = 1) self.win.vStarMap.highlightPos = (target.x, target.y) self.show() self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def onAllReaded(self, widget, action, data): obj = client.get(self.selectedObjID) for messageID in obj._messages: message = obj._messages[messageID] if message["forum"] == self.selectedForum: message["readed"] = 1 self.update()
def display(self, caller, objID, objType, forum, msgID = None): self.caller = caller self.msgSpec = gdata.mailboxSpec[objType, forum] messages = client.get(objID)._messages if self.msgSpec[1] == None: # cannot reply return elif self.msgSpec[1] == "forum": self.recipientObjID = [objID] self.recipientForum = forum if msgID != None: self.topic = messages[msgID]["topic"] else: self.topic = "" elif self.msgSpec[1] == "sender" and msgID != None: message = messages[msgID] self.recipientObjID = [message["senderID"]] self.recipientForum = "INBOX" self.topic = message["topic"] if self.topic[:4] != "Re: ": self.topic = "Re: %s" % self.topic elif self.msgSpec[1]: self.recipientObjID = [] self.recipientForum = "INBOX" self.topic = "" self.show() self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def onDelete(self, widget, action, data): selItem = self.win.vMessages.selection[0] i = 0 # magic 14 is the amount of message topics shown at a time sliderMaxPos = len(self.win.vMessages.items) - 14 sliderPos = int(self.win.vMessages.bar.slider.position) for candidate in self.win.vMessages.items: if candidate == selItem: break i += 1 del client.get(selItem.tObjID)._messages[selItem.tMsgID] self.update() if i >= len(self.win.vMessages.items): i -= 1 if sliderPos >= sliderMaxPos and sliderMaxPos > 0: # deleting when scrolled the list down all the way sliderPos = sliderMaxPos - 1 if i - abs(sliderPos) > 14 - 1 or i < sliderPos: # center vMessages on selected message sliderPos = i - 7 if sliderPos < 0: sliderPos = 0 if sliderPos >= sliderMaxPos: sliderPos = sliderMaxPos - 1 if i < 0: # no more messages to be shown return self.win.vMessages.selectItem(self.win.vMessages.items[i]) self.onMessageSelected(None, None, None) self.win.vMessages.bar.slider.position = sliderPos self.win.vMessages.itemsChanged()
def doSearch(self): found = False for objID in client.db.keys(): obj = client.get(objID, noUpdate=1) if hasattr(obj, "type") and obj.type in (T_SYSTEM, T_WORMHOLE): name = string.lower(getattr(obj, "name", "")) if len(name) > 0 and not name in self.founded and fnmatch.fnmatch(name, self.pattern): if hasattr(obj, "x") and hasattr(obj, "y") and self.mapWidget: self.mapWidget.highlightPos = (obj.x, obj.y) self.mapWidget.setPos(obj.x, obj.y) self.update() found = True self.founded.append(name) break name = str(objID) if not name in self.founded and fnmatch.fnmatch(name, self.pattern): if hasattr(obj, "x") and hasattr(obj, "y") and self.mapWidget: self.mapWidget.highlightPos = (obj.x, obj.y) self.mapWidget.setPos(obj.x, obj.y) self.update() found = True self.founded.append(name) break if not found and self.mapWidget: self.mapWidget.highlightPos = None self.win.setStatus(_("No system found"))
def show(self): player = client.getPlayer() self.buildingsCount = {} self.buildingsPos = {} for planetID in player.planets: planet = client.get(planetID) if hasattr(planet, "slots"): for struct in planet.slots: techID = struct[STRUCT_IDX_TECHID] if not techID in self.buildingsCount: self.buildingsCount[techID] = 1 else: self.buildingsCount[techID] = self.buildingsCount[techID] + 1 if not techID in self.buildingsPos: self.buildingsPos[techID] = {planetID: 1} else: planetList = self.buildingsPos[techID] if not planetID in planetList: planetList[planetID] = 1 else: planetList[planetID] = planetList[planetID] + 1 items = [] for techID in self.buildingsCount: tech = client.getTechInfo(techID) items.append(ui.Item(tech.name, tStructCount = self.buildingsCount[techID], techID = techID)) self.win.vStructures.items = items self.win.vStructures.itemsChanged()
def onShowLocation(self, widget, action, data): planet = client.get(data.planetID, noUpdate = 1) # center on map if hasattr(planet, "x"): gdata.mainGameDlg.win.vStarMap.highlightPos = (planet.x, planet.y) gdata.mainGameDlg.win.vStarMap.setPos(planet.x, planet.y) return self.win.setStatus(_("Cannot show location"))
def show(self): player = client.getPlayer() items = [] index = 0 # copy msgs = player.messages[:] msgs.reverse() currTurn = client.getTurn() for sourceID, msgID, locationID, turn, data in msgs: item = ui.Item(None, index = index) item.tTime = res.formatTime(turn - currTurn) item.message = (sourceID, msgID, locationID, turn, data) item.tSourceID = sourceID if sourceID != OID_NONE and sourceID != player.oid: obj = client.get(sourceID, noUpdate = 1) if obj: item.tSource = getattr(obj, 'name', res.getUnknownName()) else: item.tSource = _('N/A') else: item.tSource = _('-') item.tLocationID = locationID if locationID != OID_NONE: obj = client.get(locationID, noUpdate = 1) item.tLocation = getattr(obj, 'name', res.getUnknownName()) else: item.tLocation = _('-') item.tMessage = messages.getMsgText(msgID, data) sev = messages.getMsgSeverity(msgID) if sev == messages.CRI: item.foreground = (0xd0, 0x20, 0x20) elif sev == messages.MAJ: item.foreground = (0xff, 0xff, 0x00) elif sev == messages.MIN: item.foreground = None if not self.showMIN: continue elif sev == messages.INFO: item.foreground = (0xc0, 0xc0, 0xc0) if not self.showInfo: continue index += 1 items.append(item) self.win.vMessages.items = items self.win.vMessages.itemsChanged() self.win.vDelete.enabled = 0
def display(self, systemID, caller): system = client.get(systemID, noUpdate = 1) self.caller = caller self.systemID = systemID self.win.vStarMap.setPosition = 0 self.win.vStarMap.control_modes['minimap'] = 0 self.win.vStarMap.control_modes['hotbuttons'] = 0 self.win.vStarMap.setPos(system.x, system.y) self.win.vStarMap.precompute() if self.targetID: target = client.get(self.targetID, noUpdate = 1) self.win.vStarMap.highlightPos = (target.x, target.y) self.show() self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def onDeleteAllConfirmed(self): obj = client.get(self.selectedObjID) # must make list (changing directory) for messageID in obj._messages.keys(): message = obj._messages[messageID] if message["forum"] == self.selectedForum: del obj._messages[messageID] self.update()
def onAutoDelete(self, widget, action, data): self.win.setStatus(_('Executing CLEAR PROCESSED ACTIONS command...')) fleet = client.get(self.fleetID, noUpdate = 1) fleet.actions, fleet.actionIndex = client.cmdProxy.clearProcessedActions(fleet.oid) self.win.setStatus(_('Command has been executed.')) self.win.vCommands.selection = [] self.update() gdata.mainGameDlg.update()
def onContactSelected(self, widget, action, data): self.recipientObjID = [] text = "" for item in self.cwin.vContacts.selection: self.recipientObjID.append(item.tRecipientID) recipient = client.get(item.tRecipientID) text = u"%s, %s" % (text, _("%s / %s") % (recipient.name, _(self.msgSpec[0]))) self.win.vRecipient.text = text[2:] self.cwin.hide()
def onDeleteAllCommands(self, widget, action, data): index = 0 while len(self.win.vCommands.items) > index: self.win.vCommands.selection = [self.win.vCommands.items[index]] index += self.onDeleteCommand(widget, action, data, all=1) self.win.setStatus(_('Command has been executed.')) fleet = client.get(self.fleetID,forceUpdate=1) self.update() gdata.mainGameDlg.update()
def onShowLocation(self, widget, action, data): item = self.win.vPlanets.selection[0] system = client.get(item.tSysID, noUpdate=1) if hasattr(system, "x"): gdata.mainGameDlg.win.vStarMap.highlightPos = (system.x, system.y) gdata.mainGameDlg.win.vStarMap.setPos(system.x, system.y) self.hide() return self.win.setStatus(_("Cannot show location"))
def onDeleteAllCommands(self, widget, action, data): # vCommands does not update in this cycle, so we have to use index for i in range(len(self.win.vCommands.items), 0, -1): self.win.vCommands.selection = [self.win.vCommands.items[i - 1]] self.onDeleteCommand(widget, action, data, update=False) self.win.setStatus(_('Command has been executed.')) fleet = client.get(self.fleetID,forceUpdate=1) self.update() gdata.mainGameDlg.update()
def galaxyFinishButton(self, widget, action, data): player = client.getPlayer() galaxy = client.get(player.galaxy) if galaxy.scenario == Const.SCENARIO_OUTERSPACE and player.imperator > 2: localTime = time.time() gdata.config.game.lastGalaxyFinishShown = str(localTime) self.galaxyFinishDlg.display(finishAction = self.onFinishConfirmedOuterspace) elif galaxy.scenario == Const.SCENARIO_SINGLE: self.confirmDlg.display(_('Are you really really sure you want to finish this single player galaxy of yours? You won\'t be able to get back.'), _('Finish'), _('No'), confirmAction = self.onFinishConfirmedSingle)
def precompute(self): system = client.get(self.systemID, noUpdate = 1) self._mines = {} if hasattr(system, "minefield"): for mine in system.minefield: if mine in self._mines: self._mines[mine] += 1 else: self._mines[mine] = 1
def onSelectMapObj(self, widget, action, data): self.win.vStarMap.highlightPos = None obj = client.get(data, noUpdate = 1) if obj == None: self.app.setStatus(_('Cannot select object on map')) return if obj.type in (T_PLANET, T_SYSTEM, T_WORMHOLE): self.starSystemDlg.display(data) elif obj.type == T_FLEET: self.fleetDlg.display(data)
def onShowLoc(self, widget, action, data): item = self.win.vMessages.selection[0] if item.tLocationID != OID_NONE: obj = client.get(item.tLocationID, noUpdate = 1) if hasattr(obj, "x"): gdata.mainGameDlg.win.vStarMap.highlightPos = (obj.x, obj.y) gdata.mainGameDlg.win.vStarMap.setPos(obj.x, obj.y) self.hide() return self.win.setStatus(_("Cannot show location"))
def onSelectMapObj(self, widget, action, data): target = client.get(data, noUpdate = 1) if target.type == Const.T_PLANET: self.win.setStatus(_("Select system, please.")) elif target.type in (Const.T_SYSTEM, Const.T_WORMHOLE): self.targetID = target.oid self.win.vStarMap.highlightPos = (target.x, target.y) else: self.win.vStarMap.hightlightPos = None self.show()
def onScrap(self, widget, action, data): # count number of ships using this design count = 0 for fleetID in client.getPlayer().fleets: fleet = client.get(fleetID) for designID, hp, shieldHP, exp in fleet.ships: if designID == self.selectedDesignID: count += 1 self.confirmDlg.display(_('Deletion of this design dismantle %d ship(s). Are you sure to scrap it?') % count, _('Yes'), _('No'), confirmAction = self.onScrapConfirmed)
def onSelectContact(self, widget, action, data): player = client.getPlayer() items = [] for contactID in player.diplomacyRels: contact = client.get(contactID) item = ui.Item(contact.name, tRecipientID=contactID) items.append(item) self.cwin.vContacts.items = items self.cwin.vContacts.itemsChanged() self.cwin.show()
def display(self, fleetDlg, cmdIndex): self.fleetDlg = fleetDlg self.cmdIndex = cmdIndex fleet = client.get(self.fleetDlg.fleetID, noUpdate=1) self.win.vStarMap.alwaysShowRangeFor = fleet.oid self.win.vStarMap.setPosition = 0 self.win.vStarMap.control_modes['minimap'] = 0 self.win.vStarMap.control_modes['hotbuttons'] = 0 self.win.vStarMap.setPos(fleet.x, fleet.y) self.win.vStarMap.precompute() self.command = Const.FLACTION_MOVE self.deplShipIndex = 0 if self.targetID: target = client.get(self.targetID, noUpdate=1) self.win.vStarMap.highlightPos = (target.x, target.y) self.showCommands() self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def onShowLocation(self, widget, action, data): item = self.win.vProblems.selection[0] if item.tType in (T_SYSTEM, T_PLANET, T_FLEET): object = client.get(item.tOID, noUpdate = 1) # center on map if hasattr(object, "x"): gdata.mainGameDlg.win.vStarMap.highlightPos = (object.x, object.y) gdata.mainGameDlg.win.vStarMap.setPos(object.x, object.y) self.hide() return self.win.setStatus(_("Cannot show location."))
def onSelectStruct(self, widget, action, data): planetList = self.buildingsPos[data.techID] tech = client.getTechInfo(data.techID) self.win.vPlanetsTitle.text = _("Planets with structure %s") % tech.name if planetList: items = [] for planetID in planetList: planet = client.get(planetID) items.append(ui.Item(planet.name, tStructCount = planetList[planetID], planetID = planetID)) self.win.vPlanets.items = items self.win.vPlanets.itemsChanged()
def show(self): system = client.get(self.systemID, noUpdate=1) self.win.vName.text = getattr(system, 'name', res.getUnknownName()) items = [ ui.Item(_('Alpha, Beta, ...'), tIndex=1), ui.Item(_('I, II, III, ...'), tIndex=2), ui.Item(_('Prime, Secundus, ...'), tIndex=3), ui.Item(_('A, B, C, D, E, ...'), tIndex=4), ui.Item(_('1, 2, 3, 4, 5, ...'), tIndex=5), ] self.win.vNumbers.items = items self.win.vNumbers.itemsChanged()
def _populatePopup(self, playerID, fleet): if hasattr(fleet, 'owner') and playerID != fleet.owner: owner = getattr(client.get(fleet.owner, noUpdate=1), "name", res.getUnknownName()) ownerName = " (%s)" % owner ownerNameTip = owner ownerTipTitle = _("Owner") else: ownerName = "" ownerNameTip = "" ownerTipTitle = "" return ownerName, ownerNameTip, ownerTipTitle
def onSelectMapObj(self, widget, action, data): target = client.get(data, noUpdate = 1) if target.type == Const.T_PLANET: self.targetID = target.oid self.win.vStarMap.highlightPos = (target.x, target.y) elif target.type in (Const.T_SYSTEM, Const.T_WORMHOLE): self.targetID = target.oid self.win.vStarMap.highlightPos = (target.x, target.y) else: self.win.vStarMap.hightlightPos = None self.targetPlayerID = getattr(target, "owner", Const.OID_NONE) self.showCommands()
def display(self, objID): fleet = client.get(objID) if not hasattr(fleet, "ships"): return self.fleetID = objID self.showFleet() # show window if not self.win.visible: self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def onDeleteCommand(self, widget, action, data, all=0): sel = self.win.vCommands.selection if not sel: self.win.setStatus(_('Select command to delete.')) return item = sel[0] try: self.win.setStatus(_('Executing DELETE COMMAND command...')) fleet = client.get(self.fleetID, noUpdate=1) fleet.actions, fleet.actionIndex = client.cmdProxy.deleteAction( self.fleetID, item.tIndex - 1) self.win.vCommands.selection = [] if not all: # 0 from UI; 1 from "DeleteAll" function self.win.setStatus(_('Command has been executed.')) if item.text == gdata.fleetActions[FLACTION_WAIT]: fleet = client.get(self.fleetID, forceUpdate=1) self.update() gdata.mainGameDlg.update() return 0 except ige.GameException, e: self.win.setStatus(_(e.args[0])) return 1
def onScrap(self, widget, action, data): # count number of ships using this design count = 0 for fleetID in client.getPlayer().fleets: fleet = client.get(fleetID) for designID, hp, shieldHP, exp in fleet.ships: if designID == self.selectedDesignID: count += 1 self.confirmDlg.display(_('Deletion of this design dismantle %d ship(s). Are you sure to scrap it?') % count, _('Yes'), _('No'), confirmAction=self.onScrapConfirmed, agreementNeeded=count != 0)
def onShowLoc(self, widget, action, data): item = self.win.vMessages.selection[0] if item.tLocationID != Const.OID_NONE: obj = client.get(item.tLocationID, noUpdate=1) if hasattr(obj, "x"): gdata.mainGameDlg.win.vStarMap.highlightPos = (obj.x, obj.y) gdata.mainGameDlg.win.vStarMap.setPos(obj.x, obj.y) self.hide() return if item.tForum == "EVENTS" and re.match(('^%s(.*)')%(_('Research completed:')),item.text): gdata.mainGameDlg.researchDlg.display() return self.win.setStatus(_("Cannot show location"))
def onSend(self, widget, action, data): if not self.recipientObjID: self.win.setStatus(_("Select a recipient, please.")) return if not self.win.vTopic.text: self.win.setStatus(_("Specify a topic, please.")) return if self.win.vText.text == [""]: self.win.setStatus(_("Type a message, please.")) return try: self.win.setStatus(_("Executing SEND MESSAGE command...")) message = { "forum": self.recipientForum, "topic": self.win.vTopic.text, "text": string.join(self.win.vText.text, "\n"), } # send message to all recipients for objID in self.recipientObjID: client.cmdProxy.sendMsg(objID, message) # put message into outbox if forum is INBOX if self.recipientForum == "INBOX": recipients = "" for objID in self.recipientObjID: recipient = client.get(objID) recipients = u"%s, %s" % (recipients, recipient.name) message = { "forum": "OUTBOX", "topic": "To %s - %s" % ( recipients[2:], self.win.vTopic.text, ), "text": _("To %s / %s:\n\n%s") % ( recipients[2:], _(self.msgSpec[0]), "\n".join(self.win.vText.text), ) } client.cmdProxy.sendMsg(client.getPlayerID(), message) self.win.setStatus(_("Command has been executed.")) except ige.GameException as e: self.win.setStatus(e.args[0]) return client.getMessages() self.hide() self.caller.update()
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 display(self, objID, caller): obj = client.get(objID, noUpdate=1) self.caller = caller self.win.vStarMap.setPosition = 0 self.win.vStarMap.control_modes['minimap'] = 0 self.win.vStarMap.control_modes['hotbuttons'] = 0 self.win.vStarMap.setPos(obj.x, obj.y) self.win.vStarMap.precompute() self.win.vStarMap.highlightPos = (obj.x, obj.y) self.show() self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def onSelectPlanet(self, widget, action, data): item = self.win.vPlanets.selection[0] planet = client.get(item.tPlanetID, noUpdate=1) if hasattr(planet, "owner") and planet.owner == client.getPlayerID(): # show dialog gdata.mainGameDlg.onSelectMapObj(None, None, item.tPlanetID) else: # center on map if hasattr(planet, "x"): gdata.mainGameDlg.win.vStarMap.highlightPos = (planet.x, planet.y) gdata.mainGameDlg.win.vStarMap.setPos(planet.x, planet.y) self.hide() return self.win.setStatus(_("Cannot show location"))
def onDelete(self, widget, action, data): try: self.win.setStatus(_('Executing DELETE CUSTOM FLEET NAME command...')) fleet = client.get(self.fleetID, noUpdate = 1) name = client.cmdProxy.removeFleetName(self.fleetID) state = client.cmdProxy.setMergeState(self.fleetID, 1) #reset to normal joins fleet.customname = None fleet.allowmerge = state self.win.setStatus(_('Command has been executed.')) self.hide() for dialog in gdata.updateDlgs: dialog.update() except ige.GameException, e: self.win.setStatus(_(e.args[0]))
def galaxyFinishButton(self, widget, action, data): player = client.getPlayer() galaxy = client.get(player.galaxy) if galaxy.scenario == Const.SCENARIO_OUTERSPACE and player.imperator > 2: localTime = time.time() gdata.config.game.lastGalaxyFinishShown = str(localTime) self.galaxyFinishDlg.display( finishAction=self.onFinishConfirmedOuterspace) elif galaxy.scenario == Const.SCENARIO_SINGLE: self.confirmDlg.display(_( 'Are you really really sure you want to finish this single player galaxy of yours? You won\'t be able to get back.' ), _('Finish'), _('No'), confirmAction=self.onFinishConfirmedSingle)
def onClose(self, widget, action, data): if not self.win.vNumbers.selection: self.win.setStatus(_('Select planet numbering type, please.')) return item = self.win.vNumbers.selection[0] # rename try: self.win.setStatus(_('Executing RENAME SYSTEM command...')) system = client.get(self.systemID, noUpdate=1) names = client.cmdProxy.rename(self.systemID, self.win.vName.text, item.tIndex) system.name = names[0] # update planets if hasattr(system, "planets"): index = 1 for planetID in system.planets: client.get(planetID, noUpdate=1).name = names[index] index += 1 self.win.setStatus(_('Command has been executed.')) self.hide() for dialog in gdata.updateDlgs: dialog.update() except ige.GameException as e: self.win.setStatus(_(e.args[0]))
def onRename(self, widget, action, data): # rename try: self.win.setStatus(_('Executing RENAME FLEET command...')) fleet = client.get(self.fleetID, noUpdate = 1) name = client.cmdProxy.renameFleet(self.fleetID, self.win.vName.text) state = client.cmdProxy.setMergeState(self.fleetID, self.state) fleet.customname = name fleet.allowmerge = state self.win.setStatus(_('Command has been executed.')) self.hide() for dialog in gdata.updateDlgs: dialog.update() except ige.GameException, e: self.win.setStatus(_(e.args[0]))
def _getNumberInBuild(self, designID): count = 0 # planet queues for planetID in client.db.keys(): planet = client.get(planetID, noUpdate=1) # skip non-planets try: count += sum((task.quantity for task in planet.prodQueue if (task.isShip and task.techID == designID))) except AttributeError: # this is either not a planet, or it's not planet with prodqueue useful for us continue # global queues for globalQueue in client.getPlayer().prodQueues: count += sum((task.quantity for task in globalQueue if (task.isShip and task.techID == designID))) return count
def onSelectSystem(self, widget, action, data): item = self.win.vPlanets.selection[0] player = client.getPlayer() system = client.get(item.tSysID, noUpdate=1) if item.tSyPYnum > 0: # you own # show dialog gdata.mainGameDlg.onSelectMapObj(None, None, item.tSysID) else: # center on map if hasattr(system, "x"): gdata.mainGameDlg.win.vStarMap.highlightPos = (system.x, system.y) gdata.mainGameDlg.win.vStarMap.setPos(system.x, system.y) self.hide() return self.win.setStatus(_("Cannot show location"))
def _populateOrder(self, fleet): # get fleet current action and target of action order = "-" targetName = "-" if hasattr(fleet, 'actions') and fleet.actionIndex < len(fleet.actions): action, target, data = fleet.actions[fleet.actionIndex] if action == Const.FLACTION_REDIRECT and not self.win.vRedirects.checked: # ok, not interested then return None order = gdata.fleetActions[action] if target != Const.OID_NONE: targetName = getattr(client.get(target, noUpdate=1), 'name', res.getUnknownName()) order = "%s %s" % (order, targetName) return order
def onForumSelected(self, widget, action, data): selItem = self.win.vForums.selection[0] if selItem.tObjID == Const.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() items = [] for messageID in ids: message = objMessages[messageID] if message["forum"] == selItem.tForum: # ignore by universe, local (private messages), or galaxy if ((selItem.tObjID == Const.OID_UNIVERSE and message["sender"] in self.uignore) or (selItem.tObjID == playerid and message["sender"] in self.lignore) or (message["sender"] in self.gignore)): continue item = self._processMessage(message) item.tMsgID = messageID item.tObjID = selItem.tObjID item.tForum = selItem.tForum 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, gdata.mailboxStripLang(selItem.tForum)][1] != None self.win.vDelete.enabled = len(self.win.vMessages.selection) > 0
def displayFleet(self, fleetID): self.setDefaults() self.designID = OID_NONE self.fleetID = fleetID self.fleet = client.get(fleetID, noUpdate=1) self.win.title = _('Fleet Details: %s') % getattr( self.fleet, 'name', res.getUnknownName()) if not hasattr(self.fleet, "ships"): return self.calcFleet(self.fleet) self.show() # show window if not self.win.visible: self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def _getContactEntry(self, contactID): contact = client.get(contactID, publicOnly=1) dipl = client.getDiplomacyWith(contactID) if dipl.relChng > 0: suffix = _(" +") elif dipl.relChng < 0: suffix = _(" -") else: suffix = _("") relation = _("%s%s") % (_(gdata.relationNames[int( dipl.relation / 125)]), suffix) contactName = _("%s [elect]") % contact.name if client.getPlayer( ).voteFor == contactID else contact.name if getattr(dipl, "stats", None): return 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=res.getPlayerColor(contactID), tooltipTitle=_("Relation"), tooltip=_("Relation %d, change %+d") % (dipl.relation, dipl.relChng), statustip=_("Relation %d, change %+d") % (dipl.relation, dipl.relChng)) else: return ui.Item(contactName, tContactID=contactID, tRelation=relation, tRelation_raw=dipl.relation, tPopulation="-", tPlanets="-", tStructures="-", tProduction="-", tScience="-", tFleetPwr="-", tContact=(_("None"), _("Mobile"), _("Static"))[dipl.contactType], foreground=res.getPlayerColor(contactID))
def onShowSource(self, widget, action, data): item = self.win.vProblems.selection[0] if item.tType == T_FLEET: object = client.get(item.tOID, noUpdate = 1) # center on map if hasattr(object, "x"): gdata.mainGameDlg.win.vStarMap.highlightPos = (object.x, object.y) gdata.mainGameDlg.win.vStarMap.setPos(object.x, object.y) self.hide() return elif item.tType in (T_SYSTEM, T_PLANET): if item.tOID != OID_NONE: gdata.mainGameDlg.onSelectMapObj(None, None, item.tOID) return elif item.tType == T_TECHNOLOGY: gdata.mainGameDlg.researchDlg.display() return self.win.setStatus(_("Cannot show location."))
def onSelectMapObj(self, widget, action, data): target = client.get(data, noUpdate=1) if target.type == Const.T_PLANET: self.win.setStatus(_("Select systems, please.")) elif target.type in (Const.T_SYSTEM, Const.T_WORMHOLE): self.targetID = target.oid self.win.vStarMap.highlightPos = (target.x, target.y) self.win.setStatus(_('Executing REDIRECT FLEETS command...')) player = client.getPlayer() if self.targetID == self.systemID: self.systemID = Const.OID_NONE try: player.shipRedirections = client.cmdProxy.redirectShips( player.oid, self.targetID, self.systemID) self.win.setStatus(_('Command has been executed.')) self.win.vStarMap.precompute() except GameException, e: self.win.setStatus(e.args[0])
def onCommandMove(self, widget, action, data): try: self.win.setStatus(_('Executing MOVE ACTION command...')) fleet = client.get(self.fleetID, noUpdate=1) index = self.win.vCommands.items.index( self.win.vCommands.selection[0]) # execute command fleet.actions = client.cmdProxy.moveAction(fleet.oid, index, widget.data) self.update() index += widget.data self.win.vCommands.selectItem(self.win.vCommands.items[index]) self.win.setStatus(_('Command has been executed.')) self.onSelectCommand(widget, action, None) gdata.mainGameDlg.update() except ige.GameException, e: self.win.setStatus(_(e.args[0])) return 1
def _processTarget(self, planet): ownerName = res.getUnknownName() ownerID = Const.OID_NONE if hasattr(planet, 'owner'): ownerID = planet.owner if planet.owner != Const.OID_NONE: ownerName = client.get(planet.owner, noUpdate=1).name if planet.plType in ("A", "G"): color = gdata.sevColors[gdata.DISABLED] else: color = res.getPlayerColor(ownerID) plname = getattr(planet, 'name', res.getUnknownName()) item = ui.Item(plname, text_raw=getattr(planet, 'plEn', plname), planetID=planet.oid, plOwner=ownerName, foreground=color) return item
def getMsgsNumber(self, objID, forum, forumtype='none'): try: messages = client.get(objID)._messages except AttributeError: log.debug("Suplying default messages for object", objID, forum) messages = {} new = 0 msgs = 0 for messageID in messages: message = messages[messageID] if ((forumtype == 'universe' and message["sender"] in self.uignore) or (forumtype == 'galaxy' and message["sender"] in self.gignore) or (forumtype == 'local' and message["sender"] in self.lignore)): continue if message["forum"] == forum: if message["readed"] == 0: new += 1 msgs += 1 return msgs, new