def display(self, caller, planetID, extraSlot=False, structToDemolish=Const.OID_NONE): if gdata.config.defaults.reportfinalization != None: val = gdata.config.defaults.reportfinalization self.win.vReportFin.checked = val == 'yes' self.caller = caller self.systemID = caller.systemID self.planetID = caller.planetID self.playerID = client.getPlayerID() self.sourceID = caller.planetID self.extraSlot = extraSlot self.maxTechLevel = 0 self.quantity = 1 self.govTransferConfirm = False self.govTransferData = None self.structToDemolish = structToDemolish self.win.vPlanets.selectItem(None) self.showPlanets() self.showTechs() self.win.show() gdata.updateDlgs.append(self)
def display(self, faultID, text): self.win.title = _('Unhandled exception: %s') % faultID self.faultID = faultID # add more informations more = [""] more.append("--- ADDITIONAL DATA ---") more.append( "GMT date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) more.append("OS: %s" % os.name) more.append("Platform: %s" % sys.platform) more.append("OSCI version %s" % versionString) more.append("Pygame version %s" % pygame.version.ver) more.append("Python %s" % sys.version) try: more.append("turn: %d" % client.getTurn()) more.append("player: %s [%d]" % (client.getPlayer().name, client.getPlayerID())) except AttributeError: pass text = text + "\n".join(more) # self.excText = text # dialog self.win.vText.text = text.split("\n") self.win.vSend.enabled = 1 self.win.show()
def display(self): self.playerID = client.getPlayerID() self.show() self.win.show() # register for updates if self not in gdata.updateDlgs: gdata.updateDlgs.append(self)
def onContactSelected(self, widget, action, data): if self.win.vContacts.selection: self.selectedPartyID = self.win.vContacts.selection[0].tContactID else: self.selectedPartyID = None self.partyDipl = client.cmdProxy.getPartyDiplomacyRels( client.getPlayerID(), self.selectedPartyID)[1] self.update() self.onPactSelected(None, None, None)
def display(self, caller, queue, structToDemolish=Const.OID_NONE): if gdata.config.defaults.reportfinalization != None: val = gdata.config.defaults.reportfinalization self.win.vReportFin.checked = val == 'yes' self.caller = caller self.playerID = client.getPlayerID() self.maxTechLevel = 0 self.quantity = 1 self.queue = queue self.showTechs() self.win.show() gdata.updateDlgs.append(self)
def display(self, caller, queue, structToDemolish = OID_NONE): if gdata.config.defaults.reportfinalization != None: val = gdata.config.defaults.reportfinalization self.win.vReportFin.checked = val == 'yes' self.caller = caller self.playerID = client.getPlayerID() self.maxTechLevel = 0 self.quantity = 1 self.queue = queue self.showTechs() self.win.show() gdata.updateDlgs.append(self)
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 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 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 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, e: self.win.setStatus(e.args[0]) return
def display(self, caller, prodProd, structToDemolish = OID_NONE): if gdata.config.defaults.reportfinalization != None: val = gdata.config.defaults.reportfinalization self.win.vReportFin.checked = val == 'yes' self.caller = caller self.systemID = caller.systemID self.planetID = caller.planetID self.playerID = client.getPlayerID() self.targetID = caller.planetID self.maxTechLevel = 0 self.quantity = 1 self.prodProd = prodProd self.structToDemolish = structToDemolish self.showTechs() self.showSlots() self.win.show() gdata.updateDlgs.append(self)
def display(self, caller, prodProd, structToDemolish=OID_NONE): if gdata.config.defaults.reportfinalization != None: val = gdata.config.defaults.reportfinalization self.win.vReportFin.checked = val == 'yes' self.caller = caller self.systemID = caller.systemID self.planetID = caller.planetID self.playerID = client.getPlayerID() self.targetID = caller.planetID self.maxTechLevel = 0 self.quantity = 1 self.prodProd = prodProd self.structToDemolish = structToDemolish self.showTechs() self.showSlots() self.win.show() gdata.updateDlgs.append(self)
def display(self, caller, planetID, extraSlot = False, structToDemolish = OID_NONE): if gdata.config.defaults.reportfinalization != None: val = gdata.config.defaults.reportfinalization self.win.vReportFin.checked = val == 'yes' self.caller = caller self.systemID = caller.systemID self.planetID = caller.planetID self.playerID = client.getPlayerID() self.sourceID = caller.planetID self.extraSlot = extraSlot self.maxTechLevel = 0 self.quantity = 1 self.structToDemolish = structToDemolish self.win.vPlanets.selectItem(None) self.showPlanets() self.showTechs() self.win.show() gdata.updateDlgs.append(self)
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, faultID, text): self.win.title = _('Unhandled exception: %s') % faultID self.faultID = faultID # add more informations more = [""] more.append("--- ADDITIONAL DATA ---") more.append("GMT date: %s" % time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime())) more.append("OS: %s" % os.name) more.append("Platform: %s" % sys.platform) more.append("OSCI version %s" % versionString) more.append("Pygame version %s" % pygame.version.ver) more.append("Python %s" % sys.version) try: more.append("turn: %d" % client.getTurn()) more.append("player: %s [%d]" % (client.getPlayer().name, client.getPlayerID())) except AttributeError: pass text = text + "\n".join(more) # self.excText = text # dialog self.win.vText.text = text.split("\n") self.win.vSend.enabled = 1 self.win.show()
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 showCommands(self): self.win.vMoveBtn.pressed = self.command == Const.FLACTION_MOVE self.win.vAttackBtn.pressed = self.command == Const.FLACTION_DECLAREWAR self.win.vDeplShipBtn.pressed = self.command == Const.FLACTION_DEPLOY self.win.vWaitBtn.pressed = self.command == Const.FLACTION_WAIT self.win.vRefuelBtn.pressed = self.command == Const.FLACTION_REFUEL self.win.vRepeatBtn.pressed = self.command == Const.FLACTION_REPEATFROM self.win.vWormholeBtn.pressed = self.command == Const.FLACTION_ENTERWORMHOLE # hide/show widgets for widget in self.win.widgets: if widget.tags and self.command in widget.tags: widget.visible = 1 elif widget.tags: widget.visible = 0 # target if self.targetID == Const.OID_NONE: info = _('No target selected') elif self.command in (Const.FLACTION_MOVE, Const.FLACTION_REFUEL, Const.FLACTION_ENTERWORMHOLE): target = client.get(self.targetID, noUpdate = 1) info = getattr(target, 'name', res.getUnknownName()) elif self.command == Const.FLACTION_DEPLOY: target = client.get(self.targetID, noUpdate = 1) if target.type == Const.T_PLANET: info = getattr(target, 'name', res.getUnknownName()) else: info = _('No planet selected') elif self.command == Const.FLACTION_DECLAREWAR: if self.targetPlayerID not in (Const.OID_NONE, client.getPlayerID()): target = client.get(self.targetPlayerID, noUpdate = 1) info = getattr(target, 'name', res.getUnknownName()) else: info = _("No commander specified.") else: info = _('?') self.win.vTarget.text = info curTarget = client.get(self.targetID, noUpdate = 1) fleet = client.get(self.fleetDlg.fleetID, noUpdate = 1) target = Const.OID_NONE oldTarget = fleet # we can hack it - only coordinates are necessary waitTurns = sum([x[2] for x in fleet.actions[fleet.actionIndex:] if x[0] == Const.FLACTION_WAIT]) eta = waitTurns # baseline targetIDs = [x[1] for x in fleet.actions[fleet.actionIndex:]] if self.targetID != Const.OID_NONE: targetIDs.append(self.targetID) for newTargetID in targetIDs: if newTargetID != Const.OID_NONE: newTarget = client.get(newTargetID) newEta = self._evalEta(fleet, oldTarget, newTarget) if newEta is not None: eta += newEta else: eta = None break oldTarget = newTarget if eta is None or not targetIDs: self.win.vEta.text = _("N/A") else: self.win.vEta.text = res.formatTime(eta) # ships fleet = client.get(self.fleetDlg.fleetID, noUpdate = 1) self.deplShips = [] # collect buildings for designID, a, b, c in 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 tech = client.getPlayer().shipDesigns[designID] if tech.deployStructs: self.deplShips.append(designID) log.debug('Adding design with structure',designID) elif tech.deployHandlers: hasHandler = False for handler in tech.deployHandlers: if handler != '': #why are blank handlers getting added in ship construction? catch here for now hasHandler = True break if hasHandler: self.deplShips.append(designID) log.debug('Adding design with project',designID) # correct buildingIndex if self.deplShipIndex >= len(self.deplShips): self.deplShipIndex = 0 if self.deplShips: self.win.vDeplShipBtn.enabled = 1 techID = self.deplShips[self.deplShipIndex] self.win.vDeplShip.text = client.getPlayer().shipDesigns[techID].name self.win.vDeplShip.data = techID else: self.win.vDeplShipBtn.enabled = 0 if self.command == Const.FLACTION_DEPLOY: self.command == Const.FLACTION_MOVE self.showCommands()
def onResignConfirmed(self): client.cmdProxy.resign(client.getPlayerID()) client.db.clear() self.app.exitLocal()
def onResignConfirmed(self): client.cmdProxy.resign(client.getPlayerID()) client.db.clear() self.app.exit()
def showCommands(self): self.win.vMoveBtn.pressed = self.command == FLACTION_MOVE self.win.vAttackBtn.pressed = self.command == FLACTION_DECLAREWAR self.win.vDeplShipBtn.pressed = self.command == FLACTION_DEPLOY self.win.vWaitBtn.pressed = self.command == FLACTION_WAIT self.win.vRefuelBtn.pressed = self.command == FLACTION_REFUEL self.win.vRepeatBtn.pressed = self.command == FLACTION_REPEATFROM self.win.vWormholeBtn.pressed = self.command == FLACTION_ENTERWORMHOLE # hide/show widgets for widget in self.win.widgets: if widget.tags and self.command in widget.tags: widget.visible = 1 elif widget.tags: widget.visible = 0 # target if self.targetID == OID_NONE: info = _('No target selected') elif self.command in (FLACTION_MOVE, FLACTION_REFUEL, FLACTION_ENTERWORMHOLE): target = client.get(self.targetID, noUpdate = 1) info = getattr(target, 'name', res.getUnknownName()) elif self.command == FLACTION_DEPLOY: target = client.get(self.targetID, noUpdate = 1) if target.type == T_PLANET: info = getattr(target, 'name', res.getUnknownName()) else: info = _('No planet selected') elif self.command == FLACTION_DECLAREWAR: if self.targetPlayerID not in (OID_NONE, client.getPlayerID()): target = client.get(self.targetPlayerID, noUpdate = 1) info = getattr(target, 'name', res.getUnknownName()) else: info = _("No commander specified.") else: info = _('?') self.win.vTarget.text = info if self.targetID != OID_NONE: curTarget = client.get(self.targetID, noUpdate = 1) fleet = client.get(self.fleetDlg.fleetID, noUpdate = 1) target = OID_NONE if len(fleet.actions) > 1: if self.cmdIndex != 0 and self.cmdIndex < len(fleet.actions): idx = self.cmdIndex else: idx = len(fleet.actions) while True: idx -= 1 if idx < 0: break #print "idx", idx, fleet.actions[idx] action, target, actionData = fleet.actions[idx] if target != OID_NONE: break 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") # ships fleet = client.get(self.fleetDlg.fleetID, noUpdate = 1) self.deplShips = [] # collect buildings for designID, a, b, c in 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 tech = client.getPlayer().shipDesigns[designID] if tech.deployStructs: self.deplShips.append(designID) log.debug('Adding design with structure',designID) elif tech.deployHandlers: hasHandler = False for handler in tech.deployHandlers: if handler != '': #why are blank handlers getting added in ship construction? catch here for now hasHandler = True break if hasHandler: self.deplShips.append(designID) log.debug('Adding design with project',designID) # correct buildingIndex if self.deplShipIndex >= len(self.deplShips): self.deplShipIndex = 0 if self.deplShips: self.win.vDeplShipBtn.enabled = 1 techID = self.deplShips[self.deplShipIndex] self.win.vDeplShip.text = client.getPlayer().shipDesigns[techID].name self.win.vDeplShip.data = techID else: self.win.vDeplShipBtn.enabled = 0 if self.command == FLACTION_DEPLOY: self.command == FLACTION_MOVE self.showCommands()