def moveTo(self, source, destination): """Orders a fleet to move to a destination source - ID of the fleet to move destination - ID of the destination object """ object = self.objects[source] if object.subtype is FLEET: target = self.objects[destination] descs = OrderDescs() order_types = objectutils.getOrderTypes(self.getCache(), source) for order_type in order_types.popitem()[1]: if not descs.has_key(order_type): continue descclass = descs[order_type] if descclass._name in ['Move', 'Move To', 'Intercept']: orderargs = [0, source, -1, descclass.subtype, 0, []] for prop in descclass.properties: if isinstance(prop, parameters.OrderParamAbsSpaceCoords): pos = [x for x in tp_helpers.getAbsPosition(target)] orderargs.append([pos]) if isinstance(prop, parameters.OrderParamObject): orderargs.append(destination) order = objects.Order(*orderargs) order._dirty = True self.sendOrder(source, order) self.starmap.connectObjects(source, destination) break
def moveTo(self, source, destination): """Orders a fleet to move to a destination source - ID of the fleet to move destination - ID of the destination object """ object = self.objects[source] if object.subtype is FLEET: target = self.objects[destination] descs = OrderDescs() order_types = objectutils.getOrderTypes(self.getCache(), source) for order_type in order_types.popitem()[1]: if not descs.has_key(order_type): continue descclass = descs[order_type] if descclass._name in ['Move', 'Move To', 'Intercept']: orderargs = [0, source, -1, descclass.subtype, 0, []] for prop in descclass.properties: if isinstance(prop, parameters.OrderParamAbsSpaceCoords): pos = [ x for x in tp_helpers.getAbsPosition(target) ] orderargs.append([pos]) if isinstance(prop, parameters.OrderParamObject): orderargs.append(destination) order = objects.Order(*orderargs) order._dirty = True self.sendOrder(source, order) self.starmap.connectObjects(source, destination) break
def updateOrdersWindow(self, id, cache): """Update the order queue and available orders in the orders window Returns True if the window is updated successfully. """ wm = cegui.WindowManager.getSingleton() order_queue = wm.getWindow("Orders/OrderQueue") order_list = wm.getWindow("Orders/OrderList") order_queue.resetList() order_list.resetList() order_list.setText("") self.order_queue_items = [] self.order_queue_list = [] order_types = objectutils.getOrderTypes(cache, id) if len(order_types) <= 0: return False object = cache.objects[id] queuelist = cache.orders[objectutils.getOrderQueueList(cache, id)[0][1]] for o_node in queuelist: index = order_queue.addRow() order = o_node.CurrentOrder self.order_queue_list.append(o_node) item = cegui.ListboxTextItem(order._name) item.setAutoDeleted(False) item.setSelectionBrushImage("SleekSpace", "MultiListSelectionBrush") self.order_queue_items.append(item) order_queue.setItem(item, 0, index) # col id, row id item = cegui.ListboxTextItem(str(order.turns)) item.setAutoDeleted(False) order_queue.setItem(item, 1, index) self.order_queue_items.append(item) if len(order_types) > 0: self.orders = {} descs = OrderDescs() for order_type in order_types.popitem()[1]: if not descs.has_key(order_type): continue description = descs[order_type] item = cegui.ListboxTextItem(description._name) item.setAutoDeleted(False) self.orders[order_type] = item order_list.addItem(item) return True
def FindPath(cache, obj): """ Figure out the path this object will take. Returns a list of tuples (node, order destination) """ if not isinstance(obj, Object): raise TypeError("Object must be an object not %r" % obj) locations = [(-1, obj.pos)] for listpos, node in enumerate(cache.orders[obj.id]): order = node.CurrentOrder # FIXME: Needs to be a better way to do this... orderdesc = OrderDescs()[order._subtype] if len(orderdesc.names) != 1: continue argument_name, subtype = orderdesc.names[0] if subtype == constants.ARG_ABS_COORD: locations.append((node, getattr(order, argument_name))) elif subtype == constants.ARG_OBJECT: locations.append( (node, cache.objects[getattr(order, argument_name)].pos)) if len(locations) == 1: return None return locations
def OnKeyUp(self, evt): if evt.GetKeyCode() in (77, ): if self.oid is None: return # FIXME: Duplicate code!!!! canmove = False for orderid in self.application.cache.objects[ self.oid].order_types: order = OrderDescs()[orderid] # FIXME: Needs to be a better way to do this... if order._name in ("Move", "Move To", "Intercept"): canmove = True break if canmove: if evt.ShiftDown(): def n(mode=self.mode): self.SetMode(mode) self.GUIWaypoint.SetCallNext(n) self.SetMode(self.GUIWaypoint) else: TrackerObjectOrder.OnKeyUp(self, evt) if sys.platform == "win32": self.Canvas.ProcessEvent(evt)
def setValues(self, order_node): """Update argument widgets with values from an order node""" wm = cegui.WindowManager.getSingleton() self.order_node = order_node order = order_node.CurrentOrder order_description = OrderDescs()[order._subtype] widgets = self.arguments[:] # assume that argument widgets are created in the same order as order_description for name, argument in order_description.names: widget = widgets[0] del widgets[0] prefix = widget.name.c_str() base_name = ARG_GUI_MAP[argument] print base_name, name value = getattr(order, name) print value if base_name == "Position": i = 0 for elem in ['X', 'Y', 'Z']: wm.getWindow("%s/%s" % (prefix, elem)).setText(str(value[i])) i += 1 elif base_name == "Turns": elem_widget = wm.getWindow("%s/Editbox" % prefix) elem_widget.setText(str(value)) elif base_name == "List": elem_widget = wm.getWindow("%s/Listbox" % prefix) index = elem_widget.addRow() for tuple in value[1]: selection_name = None selection_id = tuple[0] for selection in value[0]: if selection[0] == selection_id: selection_name = selection[1] if not selection_name: break queue = [] self.listbox_queue[selection_name] = queue item = cegui.ListboxTextItem(str(tuple[1])) item.setAutoDeleted(False) item.setSelectionBrushImage("SleekSpace", "MultiListSelectionBrush") elem_widget.setItem(item, 0, index) queue.append(item) item = cegui.ListboxTextItem(selection_name) item.setAutoDeleted(False) item.setSelectionBrushImage("SleekSpace", "MultiListSelectionBrush") elem_widget.setItem(item, 1, index) queue.append(item) elif base_name == "String": elem_widget = wm.getWindow("%s/String" % prefix) elem_widget.setText(str(value[1])) elif base_name == "Objects": elem_widget = wm.getWindow("%s/Object" % prefix) else: self.hide() return None
def showOrder(self, evt=None, index=None): """Show the arguments for a selected order evt is used if the method is a callback from CEGUI index is used to indicate which of the available orders to show Either evt or index will be used only, the other parameter can be None """ if evt: index = int(evt.window.name.c_str()[17:]) if index == None: print "no valid index" return None id = self.parent.getIDFromMovable(self.parent.current_object) cache = self.parent.getCache() object = cache.objects[id] descs = OrderDescs() orders = [] for order_type in objectutils.getOrderTypes(cache, id).popitem()[1]: if not descs.has_key(order_type): continue orders.append(descs[order_type]) order_description = orders[index] self.arguments = [] orderargs = [0, id, -1, order_description.subtype, 0, []] for prop in order_description.properties: orderargs += self.defaults[type(prop)] order = order_description(*orderargs) # need to send an empty order to get allowable choices e.g. production self.parent.sendOrder(id, order) for prop in order_description.properties: print "adding argument", prop self.arguments_window.addArgument(prop.name, ARG_PARAM_MAP[type(prop)]) self.arguments_window.show(order_description._name) self.arguments_window.setCurrentOrder(id, order_description.subtype) self.update_order = order self.update_id = id
def openOrdersMenu(self): """Open the radial menu which shows available orders""" if not self.current_object: return id = self.getIDFromMovable(self.current_object) object = self.objects[id] order_types = objectutils.getOrderTypes(self.getCache(), id) if len(order_types) > 0: self.orders_menu.entity = self.current_object if self.orders_menu.toggle(): descs = OrderDescs() for order_type in order_types.popitem()[1]: if not descs.has_key(order_type): continue description = descs[order_type] #print description self.orders_menu.add(description._name, self.orders_window, "showOrder") else: self.orders_window.hideArguments()
def confirm(self, evt): """Fill an order with arguments and send to the server""" print "Sending Order" wm = cegui.WindowManager.getSingleton() order_description = OrderDescs()[self.order_subtype] print order_description orderargs = [0, self.id, -1, order_description.subtype, 0, []] orderargs += self.getArguments() order = order_description(*orderargs) if self.order_node: self.parent.sendOrder(self.id, order, "change", self.order_node) self.order_node = None else: self.parent.sendOrder(self.id, order) self.hide()
def ObjectLeftClick(self, icon, obj, samesystem=False): """ Move the red arrow to the current object. """ # FIXME: This really is a horrible hack :( if self.parent.mode is self.parent.GUISelect: self.ArrowTo(self['selected-arrow'], icon, obj) self.canvas.Draw() return True elif self.parent.mode is self.parent.GUIWaypointEdit: # FIXME: Hack from windows.main.panelOrder import panelOrder order = self.parent.application.gui.main.panels[panelOrder.title] if hasattr(order, "OnSelectPosition"): order.OnSelectPosition(self.Selected.current.pos) return False elif self.parent.mode is self.parent.GUIWaypoint: orderdesc = None for orderdesc in OrderDescs().values(): if orderdesc._name in ("Move",) : break assert not orderdesc is None if samesystem: assert len(self.nodes) > 0 # Modify the last move order updatedorder = orderdesc(0, self.oid, -1, orderdesc.subtype, 0, [], self.Selected.current.pos) self.ChangeOrder(updatedorder,self.nodes[-1]) self.ObjectHoverEnter(self.Selected, self.canvas.WorldToPixel(self.Selected.XY)) else: # Insert new move order neworder = orderdesc(0, self.oid, -1, orderdesc.subtype, 0, [], self.Selected.current.pos) self.InsertAfterOrder(neworder) return False
def ObjectSelect(self, id): """\ Called when an object is selected. """ self.SetMode(self.GUISelect) # Check if this object can move so we can enable waypoint mode canmove = False for orderid in self.application.cache.objects[id].order_types: order = OrderDescs()[orderid] # FIXME: Needs to be a better way to do this... if order._name in ("Move", "Move To", "Intercept"): canmove = True break if canmove: self.WaypointButton.Enable() else: self.WaypointButton.Disable()
def ObjectRightClick(self, icon, hover): """ Popup a selection menu. """ self.menumap = {} orders = [] if not self.oid is None: obj = self.cache.objects[self.oid] for id in obj.order_types: orderdesc = OrderDescs()[id] if len(orderdesc.names) != 1: continue argument_name, subtype = orderdesc.names[0] if subtype == constants.ARG_ABS_COORD: def s(to, what=obj, how=orderdesc): print "order what: %r to: %r (%r) how: %r" % (what, to, to.pos, how) neworder = how(0, what.id, -1, how.subtype, 0, [], to.pos) neworder._dirty = True self.InsertAfterOrder(neworder) moveorder = s elif subtype == constants.ARG_OBJECT: def s(to, what=obj, how=orderdesc): print "order what: %r to: %r how: %r" % (what, to, how) neworder = how(0, what.id, -1, how.subtype, 0, [], to.id) neworder._dirty = True self.InsertAfterOrder(neworder) moveorder = s else: continue orders.append((orderdesc._name, moveorder)) menu = wx.Menu() for obj in icon: id = wx.NewId() def s(evt, obj=obj): self.SelectObject(obj.id) self.menumap[id] = s if obj == hover: menu.AppendCheckItem(id, obj.name) menu.Check(id, True) else: menu.Append(id, obj.name) if len(orders) > 0: for name, order in orders: submenu = wx.Menu() for obj in icon: id = wx.NewId() def s(evt, obj=obj, order=order): order(obj) self.menumap[id] = s submenu.Append(id, "to %s" % obj.name) menu.AppendSeparator() menu.AppendMenu(wx.NewId(), "%s %s" % (name ,self.Selected.current.name), submenu) self.parent.Bind(wx.EVT_MENU, self.OnContextMenu) self.parent.Bind(wx.EVT_MENU_CLOSE, self.OnContextMenuClose) #pos = self.canvas.WorldToPixel(icon.XY) self.parent.PopupMenu(menu) self.menumap = None