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 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 selectDesign(self, evt): """Select a design from the design list""" wm = cegui.WindowManager.getSingleton() designlistbox = wm.getWindow("Designs/DesignList") selected = designlistbox.getFirstSelectedItem() cache = self.parent.getCache() if selected: current_design = wm.getWindow("Designs/CurrentDesign") current_design.resetList() self.current_design_items = [] design_id = self.design_list_items[selected] design = cache.designs[design_id] owner = cache.players[design.owner].name helpers.setWidgetText("Designs", "Ship Designs - %s's %s" % (owner, design.name)) components = cache.components for component in design.components: id = component[0] total = component[1] component_info = components[id] index = current_design.addRow() # The number of components item = cegui.ListboxTextItem(str(total)) item.setAutoDeleted(False) item.setSelectionBrushImage("SleekSpace", "MultiListSelectionBrush") current_design.setItem(item, 0, index) self.current_design_items.append(item) # The name of the component item = cegui.ListboxTextItem(component_info.name) item.setAutoDeleted(False) item.setSelectionBrushImage("SleekSpace", "MultiListSelectionBrush") current_design.setItem(item, 1, index) self.current_design_items.append(item) information_string = "" properties = cache.properties for property in design.properties: id = property[0] value = property[1] new_line = properties[id].display_name # TODO: Align values to the right-hand side #new_line = new_line.ljust(100 - len(new_line)) new_line += " - " new_line += "%s\n" % value information_string += new_line helpers.setWidgetText("Designs/Information", information_string)
def addItemToList(self, evt): """Append or add a new item to an existing list argument widget""" #print "addItemToList", evt.window.name, evt.window.parent.name prefix = evt.window.parent.name.c_str() wm = cegui.WindowManager.getSingleton() listbox = wm.getWindow("%s/Listbox" % prefix) selection_widget = wm.getWindow("%s/Selection" % prefix) current_selection = selection_widget.text.c_str() if self.update_list.has_key(prefix) and self.selection_list.has_key(current_selection): selection_list = self.update_list[prefix] for triplet in selection_list: selection_id = triplet[0] selection_name = triplet[1] if selection_name == current_selection: print selection_id, selection_name, "selected" if self.listbox_queue.has_key(current_selection): queue = self.listbox_queue[current_selection] for item in queue: if item.text.c_str() == selection_name and listbox.isListboxItemInList(item): #print "Existing queue item found" grid = listbox.getItemGridReference(item) grid.column = 0 value_item = listbox.getItemAtGridReference(grid) value = int(value_item.text.c_str()) value_item.text = str(value + 1) #print "Value set:", value, grid listbox.handleUpdatedItemData() return else: queue = [] self.listbox_queue[current_selection] = queue index = listbox.addRow() item = cegui.ListboxTextItem(str(1)) item.setAutoDeleted(False) item.setSelectionBrushImage("SleekSpace", "MultiListSelectionBrush") listbox.setItem(item, 0, index) queue.append(item) item = cegui.ListboxTextItem(selection_name) item.setAutoDeleted(False) item.setSelectionBrushImage("SleekSpace", "MultiListSelectionBrush") listbox.setItem(item, 1, index) queue.append(item)
def createMessageList(self): self.message_list.resetList() self.message_list_items = [] for message_object in self.messages: message = message_object.CurrentOrder index = self.message_list.addRow() item = cegui.ListboxTextItem(str(message.subject)) item.setAutoDeleted(False) item.setSelectionBrushImage("SleekSpace", "MultiListSelectionBrush") self.message_list.setItem(item, 0, index) self.message_list_items.append(item) item = cegui.ListboxTextItem(str(message.turn)) item.setAutoDeleted(False) self.message_list.setItem(item, 1, index) self.message_list_items.append(item)
def onFoundRemoteGame(self, evt): """Called when a remote game is found from the metaserver""" print "found remote game" location = evt.game.locations["tp"][0][0] print location wm = cegui.WindowManager.getSingleton() combobox = wm.getWindow("Login/Server") item = cegui.ListboxTextItem(location) self.servers.append(item) combobox.addItem(item)
def create(self, cache): wm = cegui.WindowManager.getSingleton() listbox = wm.getWindow("System/SystemList") for object in cache.objects.values(): if object._subtype is scene.STAR: item = cegui.ListboxTextItem(object.name) item.setSelectionBrushImage("SleekSpace", "ClientBrush") item.setSelectionColours(cegui.colour(0.9, 0.9, 0.9)) item.setAutoDeleted(False) self.system_list.append(item) listbox.addItem(item)
def addArgument(self, caption, argument): """Add an argument widget to the argument window argument parameter is one of the predefined TP arguments e.g. list, string, etc """ wm = cegui.WindowManager.getSingleton() index = len(self.arguments) parent = wm.getWindow("Arguments/Pane") try: base_name = ARG_GUI_MAP[argument] except KeyError: print "Unsupported argument" return None base = wm.getWindow("Arguments/%s" % base_name) widget = helpers.copyWindow(base, "Argument%i" % index) prefix = (index, base_name) caption_widget = wm.getWindow("Argument%i/%s/Caption" % prefix) caption_widget.text = caption.capitalize() parent.addChildWindow(widget) if argument is ARG_LIST: self.arguments_pending_update.append((ARG_LIST, widget, caption)) list_widget = wm.getWindow("Argument%i/%s/Listbox" % prefix) list_widget.addColumn("#", 0, cegui.UDim(0.3, 0)) list_widget.addColumn("Type", 1, cegui.UDim(0.5, 0)) list_widget.setSelectionMode(cegui.MultiColumnList.RowSingle) helpers.bindEvent("Argument%i/%s/Add" % prefix, self, "addItemToList", cegui.PushButton.EventClicked) if argument is ARG_OBJECT: # populate the listbox with universe items list_widget = wm.getWindow("Argument%i/%s/Object" % prefix) for id, obj in self.parent.objects.items(): item = cegui.ListboxTextItem("%s (%i)" % (obj.name, id)) #print item.text item.setAutoDeleted(False) if prefix in self.object_list: self.object_list[prefix].append(item) else: self.object_list[prefix] = [item] list_widget.addItem(item) # push the new widget down so it doesn't overlap offset_x = cegui.UDim(0, 0) offset_y = cegui.UDim(0, 0) for arg_widget in self.arguments: offset_y += arg_widget.position.d_y + arg_widget.height widget.position += cegui.UVector2(offset_x, offset_y) self.arguments.append(widget) return widget
def onSound(self, evt): self.sound_items = [] dev_win = helpers.setWidgetText("Sound/Driver", settings.current_sound_device) for i in range(len(settings.sound_devices)): item = cegui.ListboxTextItem(settings.sound_devices[i]) item.setAutoDeleted(False) self.sound_items.append(item) dev_win.addItem(item) wm = cegui.WindowManager.getSingleton() wm.getWindow("Sound/Sound").setSelected(settings.sound_effects) wm.getWindow("Sound/Music").setSelected(settings.music) helpers.toggleWindow("Sound", True).activate()
def populateDesignsWindow(self, designs): """Fill the design window with designs""" wm = cegui.WindowManager.getSingleton() designlistbox = wm.getWindow("Designs/DesignList") r = random.random for design in designs.values(): item = cegui.ListboxTextItem(design.name) item.setSelectionBrushImage("SleekSpace", "ClientBrush") item.setSelectionColours(cegui.colour(0.9, 0.9, 0.9)) item.setAutoDeleted(False) random.seed(design.owner) item.setTextColours(cegui.colour(r(), r(), r())) self.design_list_items[item] = design.id designlistbox.addItem(item)
def filterSystems(self, evt): """Filters the systems based on prefix""" system_prefix = evt.window.getText().c_str() wm = cegui.WindowManager.getSingleton() listbox = wm.getWindow("System/SystemList") listbox.resetList() cache = self.parent.getCache() for object in cache.objects.values(): if object._subtype is scene.STAR: if (object.name.lower().startswith(system_prefix.lower())): item = cegui.ListboxTextItem(object.name) item.setSelectionBrushImage("SleekSpace", "ClientBrush") item.setSelectionColours(cegui.colour(0.9, 0.9, 0.9)) item.setAutoDeleted(False) self.system_list.append(item) listbox.addItem(item)
def update(self): """Updates any lists in the arguments window upon receiving from the server""" #print "Updating list items" if self.id != None and self.order_subtype != None: cache = self.parent.getCache() queue_id = objectutils.getOrderQueueList(cache, self.id)[0][1] order = cache.orders[queue_id].last.CurrentOrder for triplet in self.arguments_pending_update: #print triplet arg_type = triplet[0] argument = triplet[1] attribute = triplet[2] if arg_type is ARG_LIST: if order is None: print "order is none" break update_list = getattr(order, attribute)[0] selection = argument.getChild("%s/Selection" % argument.name.c_str()) print selection, selection.name, update_list self.update_list[argument.name.c_str()] = update_list selection.resetList() self.selection_list = {} for element in update_list: #print element[1] item = cegui.ListboxTextItem(element[1]) item.setAutoDeleted(False) selection.addItem(item) if self.selection_list.has_key(element[1]): self.selection_list[element[1]].append(item) else: self.selection_list[element[1]] = [item] self.arguments_pending_update = []
def onGraphics(self, evt): wm = cegui.WindowManager.getSingleton() if wm.getWindow("Graphics").isVisible(): return self.graphics_items = [] config = ogre.ConfigFile() config.loadDirect("ogre.cfg") self.current_system = settings.render_system.getName() config_map = settings.render_system.getConfigOptions() for c in config_map: if c.key == "Video Mode": video_modes = c.value.possibleValues elif c.key == "Anti aliasing": aa = c.value.possibleValues elif c.key == "FSAA": fsaa = c.value.possibleValues full_screen = config.getSetting("Full Screen", self.current_system) if full_screen == "Yes": self.full_screen = True wm.getWindow("Graphics/Fullscreen").setSelected(True) else: self.full_screen = False wm.getWindow("Graphics/Fullscreen").setSelected(False) self.video_mode = config.getSetting("Video Mode", self.current_system) res_win = helpers.setWidgetText("Graphics/Resolution", self.video_mode) for i in range(len(video_modes)): item = cegui.ListboxTextItem(video_modes[i]) item.setAutoDeleted(False) self.graphics_items.append(item) res_win.addItem(item) driver_win = helpers.setWidgetText("Graphics/Driver", self.current_system) for value in settings.renderers: item = cegui.ListboxTextItem(value.getName()) item.setAutoDeleted(False) self.graphics_items.append(item) driver_win.addItem(item) # Anti-aliasing comes under different names for opengl and direct3d self.fsaa = config.getSetting("FSAA", self.current_system) if len(self.fsaa) > 0: fsaa_win = helpers.setWidgetText("Graphics/AA", self.fsaa) for i in range(len(fsaa)): item = cegui.ListboxTextItem(fsaa[i]) item.setAutoDeleted(False) self.graphics_items.append(item) fsaa_win.addItem(item) self.anti_aliasing = config.getSetting("Anti aliasing", self.current_system) if len(self.anti_aliasing) > 0: aa_win = helpers.setWidgetText("Graphics/AA", self.anti_aliasing) for i in range(len(aa)): item = cegui.ListboxTextItem(aa[i]) item.setAutoDeleted(False) self.graphics_items.append(item) aa_win.addItem(item) helpers.toggleWindow("Graphics", True).activate()