def _createScene(self): """Setup CEGUI and create the various scenes""" # Initialise CEGUI Renderer self.guiRenderer = cegui.OgreCEGUIRenderer(self.renderWindow, ogre.RENDER_QUEUE_OVERLAY, True, 0, self.sceneManager) self.guiSystem = cegui.System(self.guiRenderer) cegui.Logger.getSingleton().loggingLevel = cegui.Insane # Load Cegui Scheme cegui.ImagesetManager.getSingleton().createImageset("thousandparsec.imageset") cegui.SchemeManager.getSingleton().loadScheme("SleekSpace.scheme") self.guiSystem.setDefaultMouseCursor("SleekSpace", "MouseArrow") wmgr = cegui.WindowManager.getSingleton() root = wmgr.createWindow("DefaultWindow", "root") self.guiSystem.setGUISheet(root) self.starmap = scene.StarmapScene(self, self.sceneManager) self.changeScene(self.starmap) self.starmap.create(self.application.cache) wmgr.getWindow("Windows").hide() self.guiSystem.injectMousePosition(0, 0) # Check shader syntax gpu = ogre.GpuProgramManager.getSingleton() syntaxi = gpu.getSupportedSyntax() for syntax in syntaxi: print "Supported shader syntax: ", syntax
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 setupCEGUI(self): sceneManager = self.sceneManager # CEGUI self.renderer = CEGUI.OgreCEGUIRenderer(self.renderWindow, ogre.RENDER_QUEUE_OVERLAY, False, 3000, sceneManager) self.system = CEGUI.System(self.renderer)
def __init__(self, parent): Window.__init__(self, parent) self.clear() # store as [ListboxTextItem : design_id] pairs helpers.bindEvent("Designs/DesignList", self, "selectDesign", cegui.Listbox.EventSelectionChanged) current_design = cegui.WindowManager.getSingleton().getWindow("Designs/CurrentDesign") current_design.addColumn("#", 0, cegui.UDim(0.3, 0)) current_design.addColumn("Component", 1, cegui.UDim(0.5, 0)) current_design.setSelectionMode(cegui.MultiColumnList.RowSingle)
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 setupCEGUI(self): sceneManager = self.sceneManager # CEGUI self.renderer = CEGUI.OgreCEGUIRenderer(self.renderWindow, ogre.RENDER_QUEUE_OVERLAY, False, 3000, sceneManager) self.system = CEGUI.System(self.renderer) CEGUI.SchemeManager.getSingleton().loadScheme("TaharezLookSkin.scheme") self.system.setDefaultMouseCursor("TaharezLook", "MouseArrow") self.system.setDefaultFont("BlueHighway-12")
def __init__(self): self.text = [] self.target = None wm = cegui.WindowManager.getSingleton() self.overlay = wm.createWindow("SleekSpace/FrameWindow", self.name) self.overlay.size = cegui.UVector2(cegui.UDim(0.2, 0), cegui.UDim(0.2, 0)) self.overlay.setProperty("TitlebarEnabled", "False") self.overlay.setProperty("CloseButtonEnabled", "False") self.overlay.setProperty("FrameEnabled", "True") self.overlay.setProperty("Alpha", "0.5") self.overlay.hide()
def add(self, caption, parent, handler): wm = cegui.WindowManager.getSingleton() index = len(self.buttons) button = wm.createWindow("SleekSpace/Button", "%s/Button%i" % (self.window_name, index)) button.size = cegui.UVector2(cegui.UDim(0.5, 0), cegui.UDim(0.2, 0)) button.text = caption button.setProperty("ClippedByParent", "False") self.menu.addChildWindow(button) self.buttons.append(button) self.arrange() helpers.bindEvent("%s/Button%i" % (self.window_name, index), parent, handler, cegui.PushButton.EventClicked)
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 arrange(self): i = 1 spacing = 360 / len(self.buttons) for button in self.buttons: position = [0.5, 0.5] interval = spacing * i interval = math.radians(interval) x = 0.5 * math.cos(interval) y = 0.5 * math.sin(interval) position[0] += x position[1] += y i += 1 button.position = cegui.UVector2(cegui.UDim(position[0] - 0.25, 0), cegui.UDim(position[1] - 0.05, 0))
def _createScene(self): """Setup CEGUI and create the various scenes""" # Initialise CEGUI Renderer self.guiRenderer = cegui.OgreCEGUIRenderer(self.renderWindow, ogre.RENDER_QUEUE_OVERLAY, True, 0, self.sceneManager) self.guiSystem = cegui.System(self.guiRenderer) cegui.Logger.getSingleton().loggingLevel = cegui.Insane # Load Cegui Scheme cegui.ImagesetManager.getSingleton().createImageset( "controls.imageset") cegui.SchemeManager.getSingleton().loadScheme("SleekSpace.scheme") self.guiSystem.setDefaultMouseCursor("SleekSpace", "MouseArrow") wmgr = cegui.WindowManager.getSingleton() root = helpers.loadWindowLayout("battleviewer.layout") self.guiSystem.setGUISheet(root) # Bind events to their respective buttons and set up other misc GUI stuff self.gfl = GUIFadeListener() ogre_root = ogre.Root.getSingleton() ogre_root.addFrameListener(self.gfl) helpers.bindEvent("Controls/Next", self, "next_round", cegui.Window.EventMouseButtonDown) helpers.bindEvent("Controls/Prev", self, "prev_round", cegui.Window.EventMouseButtonDown) helpers.bindEvent("Controls/Beginning", self, "beginning_round", cegui.Window.EventMouseButtonDown) helpers.bindEvent("Controls/End", self, "end_round", cegui.Window.EventMouseButtonDown) helpers.bindEvent("Controls/Stop", self, "stop_prog", cegui.Window.EventMouseButtonDown) helpers.bindEvent("Controls/Play", self, "start_prog", cegui.Window.EventMouseButtonDown) self.gfl.registerElement("Controls") self.gfl.registerElement("Logs", 0.01, 3) self.battlescene = BattleScene(self, self.sceneManager).initial( self.battle.sides) self.rounds = self.battle.rounds self.queue_round() self.roundtimer = ogre.Timer() self.changeScene(self.battlescene) self.guiSystem.injectMousePosition(0, 0)
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 __init__(self, parent): Window.__init__(self, parent) self.clear() helpers.bindEvent("Messages/Next", self, "nextMessage", cegui.PushButton.EventClicked) helpers.bindEvent("Messages/Prev", self, "prevMessage", cegui.PushButton.EventClicked) helpers.bindEvent("Messages/Goto", self, "gotoMessageSubject", cegui.PushButton.EventClicked) helpers.bindEvent("Messages/Delete", self, "deleteMessage", cegui.PushButton.EventClicked) helpers.bindEvent("Messages/MessageList", self, "selectMessage", cegui.MultiColumnList.EventSelectionChanged) wm = cegui.WindowManager.getSingleton() message_list = wm.getWindow("Messages/MessageList") message_list.addColumn("Subject", 0, cegui.UDim(0.7, 0)) message_list.addColumn("Turn", 1, cegui.UDim(0.1, 0)) message_list.setSelectionMode(cegui.MultiColumnList.RowSingle) self.message_list = message_list
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 __init__(self, parent): Window.__init__(self, parent) self.clear() helpers.bindEvent("Orders/Delete", self, "deleteOrder", cegui.PushButton.EventClicked) helpers.bindEvent("Orders/NewOrder", self, "newOrder", cegui.PushButton.EventClicked) helpers.bindEvent("Orders/Edit", self, "editOrder", cegui.PushButton.EventClicked) wm = cegui.WindowManager.getSingleton() order_queue = wm.getWindow("Orders/OrderQueue") order_queue.addColumn("Type", 0, cegui.UDim(0.4, 0)) order_queue.addColumn("Turns left", 1, cegui.UDim(0.4, 0)) order_queue.setSelectionMode(cegui.MultiColumnList.RowSingle) self.arguments_window = ArgumentsWindow(parent) self.update_order = None self.update_id = None
def handleColourChanged( self, e): self.Preview.setProperty("ImageColours", CEGUI.PropertyHelper.colourToString(CEGUI.colour( self.Red.getScrollPosition() / 255.0, self.Green.getScrollPosition() / 255.0, self.Blue.getScrollPosition() / 255.0))) return True
def __init__(self, camera): self.camera = camera self.entity = None self.buttons = [] im = cegui.ImagesetManager.getSingleton() if im.isImagesetPresent(self.imageset): image = im.getImageset(self.imageset) else: image = im.createImagesetFromImageFile(self.imageset, "halo2.png") # TODO: Import into ThousandParsec imageset wm = cegui.WindowManager.getSingleton() self.menu = wm.createWindow("SleekSpace/StaticImage", self.window_name) self.menu.size = cegui.UVector2(cegui.UDim(0.23, 0), cegui.UDim(0.3, 0)) self.menu.setProperty("Image", "set:Radial image:full_image") self.menu.hide()
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 handleCheckStateChanged(self, e): ## activate controller if set if (self.mItemSelectorController): checkbox = e.window self.mItemSelectorController.itemStateChanged(checkbox.getID(), checkbox.isSelected()) if checkbox.isSelected(): selectColour = 0.0 else: selectColour = 1.0 checkbox.setProperty("NormalTextColour", CEGUI.PropertyHelper.colourToString(CEGUI.colour(selectColour, 1.0, selectColour))) return True
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 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 updateDebugRTTWindow(self): return ## Clear listbox self.mDebugRTTListbox.resetList() ## Clear imagesets self.mDebugRTTStaticImage.setProperty("Image", "") isIt = self.mDebugRTTImageSets.begin() while isIt != self.mDebugRTTImageSets.self.end(): CEGUI.ImagesetManager.getSingleton().destroyImageset(isIt) isIt+= 1 self.mDebugRTTImageSets.clear() ## Add an entry for each rself.ender texture for all active compositors vp = self.mMain.getRenderWindow().getViewport(0) chain = Ogre.CompositorManager.getSingleton().getCompositorChain(vp) it = chain.getCompositors() while (it.hasMoreElements()): inst = it.getNext() if (inst.getEnabled()): texIt = inst.getTechnique().getTextureDefinitionIterator() while (texIt.hasMoreElements()): texDef = texIt.getNext() ## Get instance name of texture instName = inst.getTextureInstanceName(texDef.name) ## Create CEGUI texture from name of OGRE texture tex = self.mMain.getGuiRself.enderer().createTexture(instName) ## Create imageset imgSet = CEGUI.ImagesetManager.getSingleton().createImageset( instName, tex) self.mDebugRTTImageSets.push_back(imgSet) imgSet.defineImage("RttImage", CEGUI.Point(0.0, 0.0), CEGUI.Size(tex.getWidth(), tex.getHeight()), CEGUI.Point(0.0,0.0)) item = CEGUI.ListboxTextItem(texDef.name, 0, imgSet) ## new item.setSelectionBrushImage("TaharezLook", "ListboxSelectionBrush") item.setSelectionColours(CEGUI.colour(0,0,1)) self.mDebugRTTListbox.addItem(item)
def addItemSelector(self, displayText): ## add a new item selector ## determine new index for item idx = len(self.mItemSelectorContainer) item = ItemSelector() self.mItemSelectorContainer.append(item) ## create new checkbox item.CheckBoxWidget = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Checkbox", "ItemCheckbox" + str(idx)) checkbox=item.CheckBoxWidget ## set checkbox ID to selector ID checkbox.setID(idx) checkbox.setSize(CEGUI.UVector2(CEGUI.UDim(0, 140), CEGUI.UDim(0, ITEM_YSIZE))) checkbox.setText(displayText) checkbox.setProperty("HoverTextColour", CEGUI.PropertyHelper.colourToString(CEGUI.colour(1.0, 1.0, 0.0))) ## add event handler for when checkbox state changes checkbox.subscribeEvent(CEGUI.Checkbox.EventCheckStateChanged, self,"handleCheckStateChanged" ) checkbox.setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 12 + (ITEM_YSIZE + ITEM_YSPACING)* (idx)))) ## add checkbox to the scroll pane self.mScrollablePane.addChildWindow(checkbox)
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 __init__(self, application, renderWindow, camera): ois.MouseListener.__init__(self) ois.KeyListener.__init__(self) FrameListener.__init__(self, renderWindow, camera) self.application = application self.keepRendering = True # whether to continue rendering or not self.sceneDetailIndex = 0 self.ceguiTimer = ogre.Timer() root = self.application.root self.console = console.Console(root) self.console.addLocals({'root': root}) self.console.addLocals({'app': application}) wm = cegui.WindowManager.getSingleton() self.fps = wm.createWindow("SleekSpace/StaticText", "fps_counter") self.fps.position = cegui.UVector2(cegui.UDim(0.9, 0), cegui.UDim(0.0, 0)) self.fps.size = cegui.UVector2(cegui.UDim(0.1, 0), cegui.UDim(0.1, 0)) self.application.guiSystem.getGUISheet().addChildWindow(self.fps) self.fps.setVisible(settings.show_fps)
def makeUVector2Scale(x=0, y=0): return cegui.UVector2(cegui.UDim(x, 0), cegui.UDim(y, 0))
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()
def updateMessageList(self): reference = cegui.MCLGridRef(self.message_index, 0) self.message_list.setItemSelectState(reference, True)
def update(self, x, y): self.menu.position = cegui.UVector2(cegui.UDim(-0.10, x), cegui.UDim(-0.12, y))
def makeUVector2(pair1=(0, 0), pair2=(0, 0)): return cegui.UVector2(cegui.UDim(pair1[0], pair1[1]), cegui.UDim(pair2[0], pair2[1]))
def _createGUI(self): # initiaslise CEGUI Renderer if CEGUI.Version__.startswith ("0.6"): self.guiRenderer = cegui.OgreCEGUIRenderer(self.renderWindow,ogre.RenderQueueGroupID.RENDER_QUEUE_OVERLAY, False, 3000, self.sceneManager) self.system = cegui.System(self.guiRenderer) else: self.guiRenderer = CEGUI.OgreRenderer.bootstrapSystem() self.system = CEGUI.System.getSingleton() cegui.Logger.getSingleton().loggingLevel = cegui.Insane # load TaharezLook scheme if CEGUI.Version__.startswith ("0.6"): CEGUI.SchemeManager.getSingleton().loadScheme("TaharezLookSkin.scheme") else: CEGUI.SchemeManager.getSingleton().create("TaharezLookSkin.scheme") self.system.setDefaultMouseCursor("TaharezLook", "MouseArrow") # default layout sheet = cegui.WindowManager.getSingleton().createWindow("DefaultWindow", "root_wnd") self.system.setGUISheet (sheet) # control colours blue = cegui.colour(0.0, 0.0, 1.0, 0.5) red = cegui.colour(1.0, 0.0, 0.0, 0.5) green = cegui.colour(0.0, 1.0, 0.0, 1.0) blue_back = cegui.colour(0.0, 0.0, 1.0, 1.0) red_back = cegui.colour(1.0, 0.0, 0.0, 1.0) # setup tooltip self.system.setDefaultTooltip("TaharezLook/Tooltip" ) tip = self.system.getDefaultTooltip() # displayTime # the number of seconds the tooltip should be displayed for before it automatically # de-activates itself. # 0 indicates that the tooltip should never timesout and auto-deactivate. # hoverTime # the number of seconds the mouse should hover stationary over the target window # before the tooltip gets activated. # fadeTime # number of seconds that should be taken to fade the tooltip into and out of # visibility. #tip.displayTime=0.80 tip.hoverTime = 0.10 tip.fadeTime=1.0 # an edit box editBox = CreateControl("TaharezLook/MultiLineEditbox", "an edit control",sheet,[0.10,0.80],[0.80,0.80],'') editBox.text="The above static text control was created using UDIM" editBox.text+="UDIM is the new 'unified' co-ord system replacement for relative/absolute coords" editBox.text+=" The basic concept is UDIM(scale,offset) where:" editBox.text+=" scale is the relative component usually 0.0 to 1.0" editBox.text+=" offset is the absolute component in pixels " editBox.readOnly=True # create static text box UDIM stat =cegui.WindowManager.getSingleton().createWindow("TaharezLook/StaticText", "Label") stat.windowHeight=cegui.UDim(0.05,0) # %window parents height,offset pixels parent stat.windowWidth=cegui.UDim(0.80,0) # %window parents width, offset pixels parent stat.windowXPosition = cegui.UDim(0.10,0) # %position parent window width,offset pixels parent stat.windowYPosition = cegui.UDim(0.05,0) # %position parent window height,offset pixels parent stat.text = "Drag Above Icon to different cells in frame window" if CEGUI.Version__.startswith ("0.6"): img = cegui.ImagesetManager.getSingleton().getImageset("TaharezLook").getImage("ListboxSelectionBrush") else: img = cegui.ImagesetManager.getSingleton().get("TaharezLook").getImage("ListboxSelectionBrush") stat.backgroundImage = img stat.backgroundColours = cegui.ColourRect(red,red,red,red) #colrect stat.textColours = (1.0,1.0,1.0) # white stat.frameColours = blue if CEGUI.Version__.startswith ("0.6"): stat.horizontalFormatting=cegui.Centred # LeftAligned else: stat.horizontalFormatting=cegui.CentredRenderedString #sheet.addChildWindow(stat) # creates first frame window frs=cegui.WindowManager.getSingleton().createWindow("TaharezLook/FrameWindow", "Rucksack") frs.setPosition (CEGUI.UVector2(cegui_reldim (0.03), cegui_reldim (0.05))) frs.setSize(CEGUI.UVector2(cegui_reldim(0.45), cegui_reldim(0.6))) frs.text = "Test Frame" sheet.addChildWindow(frs) # creates second frame window feq=cegui.WindowManager.getSingleton().createWindow("TaharezLook/FrameWindow", "Equipped Items") feq.setPosition (CEGUI.UVector2(cegui_reldim (0.5), cegui_reldim (0.05))) feq.setSize(CEGUI.UVector2(cegui_reldim(0.45), cegui_reldim(0.6))) feq.text = "Test Frame 2" sheet.addChildWindow(feq) # add a number of 'slots' to each frame window # the slots will act as targets for drag/drop # the slots ust normal StaticText widgets with the relevant event handlers attached # create 4x4 staic image grid for each frame cols = 4 rows = 4 deltax=1.0/cols deltay=1.0/rows for x in [frs,feq]: for xp in range(cols): for yp in range(rows): name = "Slot" + str(xp) + str(yp) + x.name.c_str() self.keep.append(name) c = CreateControl("TaharezLook/StaticImage",name,x,[xp*deltax,yp*deltay],[deltax,deltay],'Image1',1) c.setUserData (name) print "UserData:",c.getUserData() self.img.append(c) # create events for each slot for slot in self.img: self.ec.append(slot.subscribeEvent(slot.EventDragDropItemEnters, handleDragEnter,"")) self.ec.append(slot.subscribeEvent(slot.EventDragDropItemLeaves, handleDragLeave,"")) self.ec.append(slot.subscribeEvent(slot.EventDragDropItemDropped, handleDragDropped,"")) # create a drag/drop container item=cegui.WindowManager.getSingleton().createWindow("DragContainer", "theItem") item.position = CEGUI.UVector2(cegui_reldim (CONTAINER_POS), cegui_reldim (CONTAINER_POS)) item.setSize(CEGUI.UVector2(cegui_reldim(CONTAINER_SIZE), cegui_reldim(CONTAINER_SIZE))) # create a static iamge as drag container's contents and parent to drag container itemIcon=cegui.WindowManager.getSingleton().createWindow("TaharezLook/StaticImage", "theContainer") itemIcon.setPosition (CEGUI.UVector2(cegui_reldim (0.0), cegui_reldim (0.0)) ) itemIcon.setSize(CEGUI.UVector2(cegui_reldim(1.0), cegui_reldim(1.0))) # set image itemIcon.setProperty("Image", "set:TaharezLook image:CloseButtonNormal") # disable to allow inputs to pass through. itemIcon.disable itemIcon.tooltipText ="Drag Me" # add itemIcon to drag drop container item.addChildWindow(itemIcon) # events to change mouse cursor self.ec1= item.subscribeEvent(item.EventMouseEnters,onMouseEnters, "") self.ec2= item.subscribeEvent(item.EventMouseLeaves,onMouseLeaves, "") # set starting slot for the item startslot=self.img[0] startslot.addChildWindow(item)
def _createGUI(self): CEGUI.Imageset.setDefaultResourceGroup("imagesets") CEGUI.Font.setDefaultResourceGroup("fonts") CEGUI.Scheme.setDefaultResourceGroup("schemes") CEGUI.WidgetLookManager.setDefaultResourceGroup("looknfeels") CEGUI.WindowManager.setDefaultResourceGroup("layouts") CEGUI.ScriptModule.setDefaultResourceGroup("lua_scripts") # initiaslise CEGUI Renderer self.guiRenderer = cegui.OgreCEGUIRenderer(self.renderWindow,ogre.RENDER_QUEUE_OVERLAY, False, 4000, self.sceneManager) self.system = cegui.System(self.guiRenderer) cegui.Logger.getSingleton().loggingLevel = cegui.Insane # load WindowsLook Cegui Scheme cegui.SchemeManager.getSingleton().loadScheme("WindowsLookSkin.scheme") self.system.setDefaultMouseCursor("WindowsLook", "MouseArrow") cegui.FontManager.getSingleton().createFont("Iconified-12.font") # load layout sheet = cegui.WindowManager.getSingleton().createWindow("DefaultWindow", "root_wnd") self.system.guiSheet = sheet # control colours blue = cegui.colour(0.0, 0.0, 1.0, 0.5) red = cegui.colour(1.0, 0.0, 0.0, 0.5) green = cegui.colour(0.0, 1.0, 0.0, 1.0) blue_back = cegui.colour(0.0, 0.0, 1.0, 1.0) red_back = cegui.colour(1.0, 0.0, 0.0, 1.0) # Menu Bar Events Test # ================================================= # MenuBar # menuItem1 - EventPopupOpened/Closed/EventListContentsChanged # p1 - EventListContentsChanged # popupmenuitem1 - EventClicked # popupmenuitem2 # popupmenuitem3 # # menuItem2 # p2 - EventPopupOpened/Closed # popupmenuitem4 # popupmenuitem5 # p3 - EventListContentsChanged # popupmenuitem6 - EventClicked # popupmenuitem7 # menuItem3 # ================================================= # create menu bar menubar = CreateControl("WindowsLook/Menubar" , "MenuBar" ,sheet ,[0.0,0.0],[1.0,0.05],[0.01,0.01],[1.0,1.0],"Test") # create menu items menuitem1= CreateControl("WindowsLook/MenuItem" , "MenuItem1" ,menubar ,[0.15,0.05],[0.5,0.5],[0.01,0.01],[1.0,1.0],"Menu1") menuitem2= CreateControl("WindowsLook/MenuItem" , "MenuItem2" ,menubar ,[0.15,0.05],[0.5,0.5],[0.01,0.01],[1.0,1.0],"Menu2") menuitem3= CreateControl("WindowsLook/MenuItem" , "MenuItem3" ,menubar ,[0.15,0.05],[0.5,0.5],[0.01,0.01],[1.0,1.0],"Menu3") # doesn't work though we have a PopupMenuItem ???? #mi1= CreateControl("WindowsLook/MenuItem" , "Item1" ,menuitem1 ,[0.15,0.15],[0.2,0.25],[0.01,0.01],[1.0,1.0],"File") # create popup menu 1 p1= CreateControl("WindowsLook/PopupMenu" , "PopupMenu1" ,sheet ,[0.15,0.15],[0.2,0.25],[0.01,0.01],[1.0,1.0],"File") popupmenuitem1= CreateControl("WindowsLook/MenuItem" , "Popup1" ,p1 ,[0.15,0.06],[0.2,0.05],[0.01,0.01],[1.0,1.0],"PopItem1") popupmenuitem2= CreateControl("WindowsLook/MenuItem" , "Popup2" ,p1 ,[0.15,0.11],[0.2,0.05],[0.01,0.01],[1.0,1.0],"PopItem2") poupmenuitem3= CreateControl("WindowsLook/MenuItem" , "Popup3" ,p1 ,[0.15,0.16],[0.2,0.05],[0.01,0.01],[1.0,1.0],"PopItem3") # create popup menu 2 p2= CreateControl("WindowsLook/PopupMenu" , "PopupMenu2" ,sheet ,[0.15,0.15],[0.2,0.25],[0.01,0.01],[1.0,1.0],"File") popupmenuitem4= CreateControl("WindowsLook/MenuItem" , "Popup4" ,p2 ,[0.15,0.06],[0.2,0.05],[0.01,0.01],[1.0,1.0],"PopItem4") popupmenuitem5= CreateControl("WindowsLook/MenuItem" , "Popup5" ,p2 ,[0.15,0.11],[0.2,0.05],[0.01,0.01],[1.0,1.0],"PopItem5") # create popup menu 3 p3= CreateControl("WindowsLook/PopupMenu" , "PopupMenu3" ,sheet ,[0.15,0.15],[0.2,0.25],[0.01,0.01],[1.0,1.0],"File") popupmenuitem6= CreateControl("WindowsLook/MenuItem" , "Popup6" ,p3 ,[0.15,0.06],[0.2,0.05],[0.01,0.01],[1.0,1.0],"PopItem6") popupmenuitem7= CreateControl("WindowsLook/MenuItem" , "Popup7" ,p3 ,[0.15,0.11],[0.2,0.05],[0.01,0.01],[1.0,1.0],"PopItem7") # attach popup menus to menu bar items menuitem1.popupMenu=p1 menuitem2.popupMenu=p2 # attach popup menu to popuitem popupmenuitem5.popupMenu=p3 # print event member names print menubar.EventPopupOpened print menubar.EventPopupClosed print menubar.EventListContentsChanged print p1.EventPopupOpened print p1.EventPopupClosed print p1.EventListContentsChanged # events menuitem self.ec1= menubar.subscribeEvent(menubar.EventPopupOpened, onMenuOpened,"") self.ec2= menubar.subscribeEvent(menubar.EventPopupClosed, onMenuClosed,"") self.ec3= menubar.subscribeEvent(menubar.EventListContentsChanged, onMenuChanged,"") # A MenuItem attached to this menu opened a PopupMenu. # An item in popup2 opens popup3 self.ec4= p2.subscribeEvent(p2.EventPopupOpened, onMenuOpened) self.ec5= p2.subscribeEvent(p2.EventPopupClosed, onMenuClosed) # events change item in a popup self.ec6= p1.subscribeEvent(p1.EventListContentsChanged, onMenuChanged) self.ec7= p3.subscribeEvent(p3.EventListContentsChanged, onMenuChanged) # events individual popup items self.ec8= popupmenuitem1.subscribeEvent(popupmenuitem1.EventClicked, onMenuSelection) self.ec9= popupmenuitem6.subscribeEvent(popupmenuitem6.EventClicked, onMenuSelection) # test list contents changed popup/menu popupmenuitem1.text = "Event Clicked 1" popupmenuitem6.text = "Event Clicked 2" menuitem3.text="Change 3"