def __init__(self, parent, window): self.parent = parent self.menu = helpers.loadWindowLayout("menu.layout") window.addChildWindow(self.menu) helpers.bindButtonEvent("Menu/Main", self, "onQuitToMain") helpers.bindButtonEvent("Menu/Desktop", self, "onQuitToDesktop") helpers.bindButtonEvent("Menu/Back", self, "onBack") helpers.bindButtonEvent("Menu/Config", self, "onConfig") helpers.toggleWindow("Menu", True).activate()
def hide(self, evt=None): """Hide the argument window""" helpers.toggleWindow("Arguments", False) print self.arguments for arg in self.arguments: cegui.WindowManager.getSingleton().destroyWindow(arg) self.arguments = [] self.arguments_pending_update = [] self.order_subtype = None self.id = None self.order_node = None
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 keyPressed(self, evt): if evt.key == ois.KC_A: self.starmap.autofit() elif evt.key == ois.KC_C: if self.current_object: self.starmap.center(self.getIDFromMovable(self.current_object)) elif evt.key == ois.KC_M: helpers.toggleWindow("Messages") elif evt.key == ois.KC_O: helpers.toggleWindow("Orders") elif evt.key == ois.KC_S: helpers.toggleWindow("System") elif evt.key == ois.KC_I: helpers.toggleWindow("Information") elif evt.key == ois.KC_SPACE: wm = cegui.WindowManager.getSingleton() self.openOrdersMenu() elif evt.key == ois.KC_F11: cache = self.getCache() helpers.pickle_dump(cache.objects, "object") helpers.pickle_dump(cache.designs, "design") helpers.pickle_dump(cache.messages, "message") helpers.pickle_dump(cache.players, "player") helpers.pickle_dump(cache.resources, "resource") print "cache dumped" elif evt.key == ois.KC_ESCAPE: self.toggleMainMenu()
def __init__(self, window): self.config = helpers.loadWindowLayout("config.layout") window.addChildWindow(self.config) helpers.bindButtonEvent("Config/OK", self, "onConfigSave") helpers.bindButtonEvent("Config/Cancel", self, "onConfigCancel") helpers.bindButtonEvent("Config/Sound", self, "onSound") helpers.bindButtonEvent("Config/Graphics", self, "onGraphics") helpers.bindEvent("Config", self, "onConfigCancel", cegui.FrameWindow.EventCloseClicked) helpers.bindEvent("Config/Zoom", self, "onZoomChange", cegui.Slider.EventValueChanged) helpers.bindEvent("Config/ShowFps", self, "onShowFpsChange", cegui.Checkbox.EventCheckStateChanged) helpers.bindEvent("Sound", self, "onSoundCancel", cegui.FrameWindow.EventCloseClicked) helpers.bindButtonEvent("Sound/Cancel", self, "onSoundCancel") helpers.bindButtonEvent("Sound/OK", self, "onSoundSave") helpers.bindEvent("Graphics", self, "onGraphicsCancel", cegui.FrameWindow.EventCloseClicked) helpers.bindButtonEvent("Graphics/Cancel", self, "onGraphicsCancel") helpers.bindButtonEvent("Graphics/OK", self, "onGraphicsSave") helpers.toggleWindow("Config").activate() wm = cegui.WindowManager.getSingleton() wm.getWindow("Config/Zoom").currentValue = settings.icon_zoom_switch_level wm.getWindow("Config/ZoomSpeed").setMaxValue(self.max_zoom_speed) wm.getWindow("Config/ZoomSpeed").currentValue = settings.zoom_speed - 1 wm.getWindow("Config/StarsVisible").setSelected(settings.show_stars_during_icon_view) wm.getWindow("Config/ShowFps").setSelected(settings.show_fps) wm.getWindow("Config/ShowIntro").setSelected(settings.show_intro) helpers.toggleWindow("Config", True) helpers.toggleWindow("Sound", False) helpers.toggleWindow("Graphics", False)
def onSoundSave(self, evt): wm = cegui.WindowManager.getSingleton() changed = False sound_effects = wm.getWindow("Sound/Sound").isSelected() music = wm.getWindow("Sound/Music").isSelected() selected_device = wm.getWindow("Sound/Driver").getText() if settings.sound_effects != sound_effects: settings.sound_effects = sound_effects changed = True import sound if settings.sound_effects is False: for sfx in sound.sound_list: sfx.stop() else: for sfx in sound.sound_list: sfx.play() if settings.music != music: settings.music = music changed = True import sound if settings.music is False: for sfx in sound.music_list: sfx.stop() else: for sfx in sound.music_list: sfx.play() if settings.current_sound_device != selected_device: changed = True if changed: def convert(value): if value: return "Yes" else: return "No" lines = ["Music=%s\n" % convert(music), "Sound=%s\n" % convert(sound_effects)] try: f = open("sound.cfg", "w") f.writelines(lines) finally: f.close() self.cleanupSound() helpers.toggleWindow("Sound", False)
def __init__(self, parent): self.arguments = [] self.arguments_pending_update = [] self.parent = parent self.id = None self.order_subtype = None self.order_node = None self.selection_list = {} self.listbox_queue = {} self.update_list = {} self.attributes = {} self.object_list = {} helpers.bindEvent("Arguments", self, "hide", cegui.FrameWindow.EventCloseClicked) helpers.bindEvent("Arguments/Cancel", self, "hide", cegui.PushButton.EventClicked) helpers.bindEvent("Arguments/Save", self, "confirm", cegui.PushButton.EventClicked) for win in ['Turns', 'Position', 'List', 'Objects', 'String']: helpers.toggleWindow("Arguments/%s" % win, False) self.hide()
def onMessageOk(self, evt): helpers.toggleWindow("Message", False)
def showMessage(self, text): helpers.toggleWindow("Message", True).activate() helpers.setWidgetText("Message/Text", str(text))
def windowToggle(self, evt): """Toggles visibility of a window""" # assume buttons and windows have the same name, minus prefix name = evt.window.getName().c_str().split("/")[1] if name != None: helpers.toggleWindow(name)
def onGraphicsCancel(self, evt): wm = cegui.WindowManager.getSingleton() wm.getWindow("Graphics/Fullscreen").setSelected(self.full_screen) self.cleanupGraphics() helpers.toggleWindow("Graphics", False)
def onGraphicsSave(self, evt): changed = False wm = cegui.WindowManager.getSingleton() full_screen = wm.getWindow("Graphics/Fullscreen").isSelected() renderer = wm.getWindow("Graphics/Driver").getText() aa = wm.getWindow("Graphics/AA").getText() video_mode = wm.getWindow("Graphics/Resolution").getText() if self.full_screen != full_screen: width = settings.render_window.getWidth() height = settings.render_window.getHeight() settings.render_window.setFullscreen(full_screen, width, height) changed = True if self.current_system != renderer: changed = True if len(self.fsaa) > 0: if self.fsaa != aa: changed = True aa_name = "FSAA" if len(self.anti_aliasing) > 0: if self.anti_aliasing != aa: changed = True aa_name = "Anti aliasing" if self.video_mode != video_mode: changed = True renderer = renderer.c_str() aa = aa.c_str() video_mode = video_mode.c_str() print full_screen, renderer, aa, video_mode, aa_name if changed: try: f = open("ogre.cfg", "r") lines = f.readlines() section_reached = False for i in range(len(lines)): if lines[i].startswith("\n"): continue if lines[i].startswith("["): name = lines[i].strip("[]\n") if self.current_system == name: section_reached = True else: section_reached = False continue k, v = lines[i].split("=") if k == "Render System": lines[i] = "%s=%s\n" % (k, renderer) elif section_reached: if k == "Video Mode": lines[i] = "%s=%s\n" % (k, video_mode) elif k == "Full Screen": if full_screen: lines[i] = "%s=Yes\n" % k else: lines[i] = "%s=No\n" % k elif k == aa_name: lines[i] = "%s=%s\n" % (k, aa) finally: f.close() try: f = open("ogre.cfg", "w") f.writelines(lines) finally: f.close() self.cleanupGraphics() helpers.toggleWindow("Graphics", False)
def onSoundCancel(self, evt): wm = cegui.WindowManager.getSingleton() wm.getWindow("Sound/Sound").setSelected(settings.sound_effects) wm.getWindow("Sound/Music").setSelected(settings.music) self.cleanupSound() helpers.toggleWindow("Sound", False)
def hide(self): """Hides the window""" helpers.toggleWindow(self.base, False)
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()