Example #1
0
    def show_build_menu(self, update=False):
        """
		@param update: set when build possibilities change (e.g. after inhabitant tier upgrade)
		"""
        # check if build menu is already shown
        if hasattr(self.get_cur_menu(), 'name') and self.get_cur_menu(
        ).name == "build_menu_tab_widget":
            self.hide_menu()

            if not update:  # this was only a toggle call, don't reshow
                return

        self.set_cursor()  # set default cursor for build menu
        self.deselect_all()

        if not any(settlement.owner.is_local_player
                   for settlement in self.session.world.settlements):
            # player has not built any settlements yet. Accessing the build menu at such a point
            # indicates a mistake in the mental model of the user. Display a hint.
            tab = TabWidget(
                self, tabs=[TabInterface(widget="buildtab_no_settlement.xml")])
        else:
            btabs = BuildTab.create_tabs(self.session, self._build)
            tab = TabWidget(self,
                            tabs=btabs,
                            name="build_menu_tab_widget",
                            active_tab=BuildTab.last_active_build_tab)
        self.show_menu(tab)
	def show_menu(self, jump_to_tabclass=None):
		"""Shows tabs from self.__class__.tabs, if there are any.
		@param jump_to_tabclass: open the first tab that is a subclass to this parameter
		"""
		# this local import prevents circular imports
		from horizons.gui.tabs import TabWidget
		tablist = None
		if self.owner == self.session.world.player:
			tablist = self.__class__.tabs
		else: # this is an enemy instance with respect to the local player
			tablist = self.__class__.enemy_tabs

		if tablist:
			tabs = [ tabclass(self) for tabclass in tablist if tabclass.shown_for(self) ]
			tabwidget = TabWidget(self.session.ingame_gui, tabs=tabs)

			if jump_to_tabclass:
				num = None
				for i in xrange( len(tabs) ):
					if isinstance(tabs[i], jump_to_tabclass):
						num = i
						break
				if num is not None:
					tabwidget._show_tab(num)

			self.session.ingame_gui.show_menu( tabwidget )
Example #3
0
    def show_menu(self, jump_to_tabclass=None):
        """Shows tabwidget tabs of this instance.

		Opens the first such tab unless jump_to_tabclass specifies otherwise.
		@param jump_to_tabclass: open the first tab that is a subclass to this parameter
		"""
        from horizons.gui.tabs import TabWidget
        tablist = None
        if self.instance.owner is not None and self.instance.owner.is_local_player:
            tablist = self.tabs
        else:  # this is an enemy instance with respect to the local player
            tablist = self.enemy_tabs

        if not tablist:
            return

        tabclasses = [
            tabclass for tabclass in tablist
            if tabclass.shown_for(self.instance)
        ]
        try:
            active_tab_index = tabclasses.index(self.active_tab)
        except ValueError:
            active_tab_index = None
        tabs = [tabclass(self.instance) for tabclass in tabclasses]
        tabwidget = TabWidget(self.session.ingame_gui,
                              tabs=tabs,
                              active_tab=active_tab_index)

        if jump_to_tabclass:
            for i, tab in enumerate(tabs):
                if isinstance(tab, jump_to_tabclass):
                    tabwidget.show_tab(i)
                    break
        self.session.ingame_gui.show_menu(tabwidget)
Example #4
0
	def show_menu(self, jump_to_tabclass=None):
		"""Shows tabwidget tabs of this instance.

		Opens the first such tab unless jump_to_tabclass specifies otherwise.
		@param jump_to_tabclass: open the first tab that is a subclass to this parameter
		"""
		from horizons.gui.tabs import TabWidget
		tablist = None
		if self.instance.owner is not None and self.instance.owner.is_local_player:
			tablist = self.tabs
		else: # this is an enemy instance with respect to the local player
			tablist = self.enemy_tabs

		if not tablist:
			return

		tabclasses = [tabclass for tabclass in tablist if tabclass.shown_for(self.instance)]
		try:
			active_tab_index = tabclasses.index(self.active_tab)
		except ValueError:
			active_tab_index = None
		tabs = [tabclass(self.instance) for tabclass in tabclasses]
		tabwidget = TabWidget(self.session.ingame_gui, tabs=tabs, active_tab=active_tab_index)

		if jump_to_tabclass:
			for i, tab in enumerate(tabs):
				if isinstance(tab, jump_to_tabclass):
					tabwidget.show_tab(i)
					break
		self.session.ingame_gui.show_menu(tabwidget)
    def show_menu(self, jump_to_tabclass=None):
        """Shows tabs from self.__class__.tabs, if there are any.
		@param jump_to_tabclass: open the first tab that is a subclass to this parameter
		"""
        from horizons.gui.tabs import TabWidget
        tablist = None
        if self.instance.owner is not None and self.instance.owner.is_local_player:
            tablist = self.tabs
        else:  # this is an enemy instance with respect to the local player
            tablist = self.enemy_tabs

        if tablist:
            tabs = [
                tabclass(self.instance) for tabclass in tablist
                if tabclass.shown_for(self.instance)
            ]
            tabwidget = TabWidget(self.session.ingame_gui, tabs=tabs)

            if jump_to_tabclass:
                for i, tab in enumerate(tabs):
                    if isinstance(tab, jump_to_tabclass):
                        tabwidget._show_tab(i)
                        break

            self.session.ingame_gui.show_menu(tabwidget)
	def show_menu(self, jump_to_tabclass=None):
		"""Shows tabs from self.__class__.tabs, if there are any.
		@param jump_to_tabclass: open the first tab that is a subclass to this parameter
		"""
		from horizons.gui.tabs import TabWidget
		tablist = None
		if self.instance.owner is not None and self.instance.owner.is_local_player:
			tablist = self.tabs
		else: # this is an enemy instance with respect to the local player
			tablist = self.enemy_tabs

		if tablist:
			tabs = [ tabclass(self.instance) for tabclass in tablist if
			         tabclass.shown_for(self.instance) ]
			tabwidget = TabWidget(self.session.ingame_gui, tabs=tabs)

			if jump_to_tabclass:
				for i, tab in enumerate(tabs):
					if isinstance(tab, jump_to_tabclass):
						tabwidget._show_tab(i)
						break

			self.session.ingame_gui.show_menu( tabwidget )
    def show_menu(self):
        """Shows tabs from self.__class__.tabs, if there are any"""
        # this local import prevents circular imports
        from horizons.gui.tabs import TabWidget
        tablist = []
        if self.owner == self.session.world.player:
            tablist = self.tabs
        else:  # this is an enemy instance with respect to the local player
            tablist = self.enemy_tabs

        if tablist:
            tabs = [tabclass(self) for tabclass in tablist]
            self.session.ingame_gui.show_menu(TabWidget(self.session.ingame_gui, \
                                                        tabs=tabs))
Example #8
0
	def show_build_menu(self):
		# check if build menu is already shown
		if hasattr(self.get_cur_menu(), 'name'):
			if self.get_cur_menu().name == "build_menu_tab_widget":
				self.hide_menu()
				return

		self.session.cursor = SelectionTool(self.session) # set cursor for build menu
		self.deselect_all()
		lvl = self.session.world.player.settler_level
		btabs = [BuildTab(i, self.callbacks_build[i]) for i in range(0, lvl+1)]
		tab = TabWidget(self, tabs=btabs, name="build_menu_tab_widget", \
								    active_tab=BuildTab.last_active_build_tab)
		self.show_menu(tab)
Example #9
0
 def show_multi_select_tab(self, instances):
     tab = TabWidget(self,
                     tabs=[SelectMultiTab(instances)],
                     name='select_multi')
     self.show_menu(tab)
Example #10
0
class IngameGui(LivingObject):
    minimap = livingProperty()
    keylistener = livingProperty()
    message_widget = livingProperty()

    def __init__(self, session):
        self.session = session

        self.cursor = None
        self.coordinates_tooltip = None
        self.keylistener = IngameKeyListener(self.session)
        # used by NavigationTool
        LastActivePlayerSettlementManager.create_instance(self.session)

        # Mocks needed to act like the real IngameGui
        self.show_menu = Dummy
        self.hide_menu = Dummy
        # a logbook Dummy is necessary for message_widget to work
        self.logbook = Dummy()

        self.mainhud = load_uh_widget('minimap.xml')
        self.mainhud.position_technique = "right+0:top+0"

        icon = self.mainhud.findChild(name="minimap")
        self.minimap = Minimap(
            icon,
            targetrenderer=horizons.globals.fife.targetrenderer,
            imagemanager=horizons.globals.fife.imagemanager,
            session=self.session,
            view=self.session.view)

        self.mainhud.mapEvents({
            'zoomIn':
            self.session.view.zoom_in,
            'zoomOut':
            self.session.view.zoom_out,
            'rotateRight':
            Callback.ChainedCallbacks(self.session.view.rotate_right,
                                      self.minimap.rotate_right),
            'rotateLeft':
            Callback.ChainedCallbacks(self.session.view.rotate_left,
                                      self.minimap.rotate_left),
            'gameMenuButton':
            self.toggle_pause,
        })

        self.mainhud.show()
        ZoomChanged.subscribe(self._update_zoom)

        # Hide unnecessary buttons in hud
        for widget in ("build", "speedUp", "speedDown", "destroy_tool",
                       "diplomacyButton", "logbook"):
            self.mainhud.findChild(name=widget).hide()

        self.windows = WindowManager()
        self.message_widget = MessageWidget(self.session)
        self.pausemenu = PauseMenu(self.session,
                                   self,
                                   self.windows,
                                   in_editor_mode=True)
        self.help_dialog = HelpDialog(self.windows)

    def end(self):
        self.mainhud.mapEvents({
            'zoomIn': None,
            'zoomOut': None,
            'rotateRight': None,
            'rotateLeft': None,
            'gameMenuButton': None
        })
        self.mainhud.hide()
        self.mainhud = None
        self._settings_tab.hide()
        self._settings_tab = None

        self.windows.close_all()
        self.minimap = None
        self.keylistener = None
        LastActivePlayerSettlementManager().remove()
        LastActivePlayerSettlementManager.destroy_instance()
        ZoomChanged.unsubscribe(self._update_zoom)

        if self.cursor:
            self.cursor.remove()
            self.cursor.end()
            self.cursor = None

        super(IngameGui, self).end()

    def handle_selection_group(self, num, ctrl_pressed):
        # Someday, maybe cool stuff will be possible here.
        # That day is not today, I'm afraid.
        pass

    def toggle_pause(self):
        self.windows.toggle(self.pausemenu)

    def toggle_help(self):
        self.windows.toggle(self.help_dialog)

    def load(self, savegame):
        self.minimap.draw()

        self.cursor = SelectionTool(self.session)

    def setup(self):
        """Called after the world editor was initialized."""
        self._settings_tab = TabWidget(
            self, tabs=[SettingsTab(self.session.world_editor, self)])
        self._settings_tab.show()

    def minimap_to_front(self):
        """Make sure the full right top gui is visible and not covered by some dialog"""
        self.mainhud.hide()
        self.mainhud.show()

    def show_save_map_dialog(self):
        """Shows a dialog where the user can set the name of the saved map."""
        window = SelectSavegameDialog('editor-save', self.windows)
        savegamename = self.windows.open(window)
        if savegamename is None:
            return False  # user aborted dialog
        success = self.session.save(savegamename)
        if success:
            self.message_widget.add('SAVED_GAME')

    def on_escape(self):
        pass

    def on_key_press(self, action, evt):
        _Actions = KeyConfig._Actions
        if action == _Actions.QUICKSAVE:
            self.session.quicksave()
        if action == _Actions.ESCAPE:
            if self.windows.visible:
                self.windows.on_escape()
            elif hasattr(self.cursor, 'on_escape'):
                self.cursor.on_escape()
            else:
                self.toggle_pause()
        elif action == _Actions.HELP:
            self.toggle_help()
        else:
            return False
        return True

    def set_cursor(self, which='default', *args, **kwargs):
        """Sets the mousetool (i.e. cursor).
		This is done here for encapsulation and control over destructors.
		Further arguments are passed to the mouse tool constructor.
		"""
        self.cursor.remove()
        klass = {'default': SelectionTool, 'tile_layer': TileLayingTool}[which]
        self.cursor = klass(self.session, *args, **kwargs)

    def _update_zoom(self, message):
        """Enable/disable zoom buttons"""
        in_icon = self.mainhud.findChild(name='zoomIn')
        out_icon = self.mainhud.findChild(name='zoomOut')
        if message.zoom == VIEW.ZOOM_MIN:
            out_icon.set_inactive()
        else:
            out_icon.set_active()
        if message.zoom == VIEW.ZOOM_MAX:
            in_icon.set_inactive()
        else:
            in_icon.set_active()
Example #11
0
 def setup(self):
     """Called after the world editor was initialized."""
     self._settings_tab = TabWidget(
         self, tabs=[SettingsTab(self.session.world_editor, self)])
     self._settings_tab.show()
Example #12
0
class IngameGui(LivingObject):
	minimap = livingProperty()
	keylistener = livingProperty()
	message_widget = livingProperty()

	def __init__(self, session):
		self.session = session

		self.cursor = None
		self.coordinates_tooltip = None
		self.keylistener = IngameKeyListener(self.session)
		# used by NavigationTool
		LastActivePlayerSettlementManager.create_instance(self.session)

		# Mocks needed to act like the real IngameGui
		self.show_menu = lambda x: 0
		self.hide_menu = lambda: 0
		# a logbook Dummy is necessary for message_widget to work
		self.logbook = DummyLogbook()

		self.mainhud = load_uh_widget('minimap.xml')
		self.mainhud.position_technique = "right+0:top+0"

		icon = self.mainhud.findChild(name="minimap")
		self.minimap = Minimap(icon,
		                       targetrenderer=horizons.globals.fife.targetrenderer,
		                       imagemanager=horizons.globals.fife.imagemanager,
		                       session=self.session,
		                       view=self.session.view)

		self.mainhud.mapEvents({
			'zoomIn': self.session.view.zoom_in,
			'zoomOut': self.session.view.zoom_out,
			'rotateRight': Callback.ChainedCallbacks(self.session.view.rotate_right, self.minimap.rotate_right),
			'rotateLeft': Callback.ChainedCallbacks(self.session.view.rotate_left, self.minimap.rotate_left),
			'gameMenuButton': self.toggle_pause,
		})

		self.mainhud.show()
		ZoomChanged.subscribe(self._update_zoom)

		# Hide unnecessary buttons in hud
		for widget in ("build", "speedUp", "speedDown", "destroy_tool", "diplomacyButton", "logbook"):
			self.mainhud.findChild(name=widget).hide()

		self.windows = WindowManager()
		self.message_widget = MessageWidget(self.session)
		self.pausemenu = PauseMenu(self.session, self, self.windows, in_editor_mode=True)
		self.help_dialog = HelpDialog(self.windows)

	def end(self):
		self.mainhud.mapEvents({
			'zoomIn': None,
			'zoomOut': None,
			'rotateRight': None,
			'rotateLeft': None,
			'gameMenuButton': None
		})
		self.mainhud.hide()
		self.mainhud = None
		self._settings_tab.hide()
		self._settings_tab = None

		self.windows.close_all()
		self.minimap = None
		self.keylistener = None
		LastActivePlayerSettlementManager().remove()
		LastActivePlayerSettlementManager.destroy_instance()
		ZoomChanged.unsubscribe(self._update_zoom)

		if self.cursor:
			self.cursor.remove()
			self.cursor.end()
			self.cursor = None

		super(IngameGui, self).end()

	def handle_selection_group(self, num, ctrl_pressed):
		# Someday, maybe cool stuff will be possible here.
		# That day is not today, I'm afraid.
		pass

	def toggle_pause(self):
		self.windows.toggle(self.pausemenu)

	def toggle_help(self):
		self.windows.toggle(self.help_dialog)

	def load(self, savegame):
		self.minimap.draw()

		self.cursor = SelectionTool(self.session)

	def setup(self):
		"""Called after the world editor was initialized."""
		self._settings_tab = TabWidget(self, tabs=[SettingsTab(self.session.world_editor, self)])
		self._settings_tab.show()

	def minimap_to_front(self):
		"""Make sure the full right top gui is visible and not covered by some dialog"""
		self.mainhud.hide()
		self.mainhud.show()

	def show_save_map_dialog(self):
		"""Shows a dialog where the user can set the name of the saved map."""
		window = SelectSavegameDialog('editor-save', self.windows)
		savegamename = self.windows.open(window)
		if savegamename is None:
			return False # user aborted dialog
		success = self.session.save(savegamename)
		if success:
				self.message_widget.add('SAVED_GAME')

	def on_escape(self):
		pass

	def on_key_press(self, action, evt):
		_Actions = KeyConfig._Actions
		if action == _Actions.QUICKSAVE:
			self.session.quicksave()
		if action == _Actions.ESCAPE:
			if self.windows.visible:
				self.windows.on_escape()
			elif hasattr(self.cursor, 'on_escape'):
				self.cursor.on_escape()
			else:
				self.toggle_pause()
		elif action == _Actions.HELP:
			self.toggle_help()
		else:
			return False
		return True

	def set_cursor(self, which='default', *args, **kwargs):
		"""Sets the mousetool (i.e. cursor).
		This is done here for encapsulation and control over destructors.
		Further arguments are passed to the mouse tool constructor.
		"""
		self.cursor.remove()
		klass = {
			'default': SelectionTool,
			'tile_layer': TileLayingTool
		}[which]
		self.cursor = klass(self.session, *args, **kwargs)

	def _update_zoom(self, message):
		"""Enable/disable zoom buttons"""
		in_icon = self.mainhud.findChild(name='zoomIn')
		out_icon = self.mainhud.findChild(name='zoomOut')
		if message.zoom == VIEW.ZOOM_MIN:
			out_icon.set_inactive()
		else:
			out_icon.set_active()
		if message.zoom == VIEW.ZOOM_MAX:
			in_icon.set_inactive()
		else:
			in_icon.set_active()
Example #13
0
	def setup(self):
		"""Called after the world editor was initialized."""
		self._settings_tab = TabWidget(self, tabs=[SettingsTab(self.session.world_editor, self)])
		self._settings_tab.show()
Example #14
0
 def show_multi_select_tab(self):
     tab = TabWidget(self,
                     tabs=[SelectMultiTab(self.session)],
                     name='select_multi')
     self.show_menu(tab)
Example #15
0
 def _show_settings(self):
     """Display settings widget to change brush size and select tiles."""
     tab = TabWidget(self._ingame_gui,
                     tabs=[SettingsTab(self._world_editor, self._session)])
     self._ingame_gui.show_menu(tab)
Example #16
0
class IngameGui(LivingObject):
	minimap = livingProperty()
	keylistener = livingProperty()

	def __init__(self, session, main_gui):
		self.session = session
		self.main_gui = main_gui

		self.cursor = None
		self.coordinates_tooltip = None
		self.keylistener = IngameKeyListener(self.session)
		# used by NavigationTool
		LastActivePlayerSettlementManager.create_instance(self.session)

		# Mocks needed to act like the real IngameGui
		self.show_menu = Dummy
		self.hide_menu = Dummy

		self.mainhud = load_uh_widget('minimap.xml')
		self.mainhud.position_technique = "right+0:top+0"

		icon = self.mainhud.findChild(name="minimap")
		self.minimap = Minimap(icon,
		                       targetrenderer=horizons.globals.fife.targetrenderer,
		                       imagemanager=horizons.globals.fife.imagemanager,
		                       session=self.session,
		                       view=self.session.view)

		self.mainhud.mapEvents({
			'zoomIn': self.session.view.zoom_in,
			'zoomOut': self.session.view.zoom_out,
			'rotateRight': Callback.ChainedCallbacks(self.session.view.rotate_right, self.minimap.rotate_right),
			'rotateLeft': Callback.ChainedCallbacks(self.session.view.rotate_left, self.minimap.rotate_left),
			'gameMenuButton': self.toggle_pause,
		})

		self.mainhud.show()
		self.session.view.add_change_listener(self._update_zoom)

		# Hide unnecessary buttons in hud
		for widget in ("build", "speedUp", "speedDown", "destroy_tool", "diplomacyButton", "logbook"):
			self.mainhud.findChild(name=widget).hide()

		self.save_map_dialog = SaveMapDialog(self.main_gui, self, self.session)
		self.pausemenu = PauseMenu(self.session, self.main_gui, self, in_editor_mode=True)

	def end(self):
		self.mainhud.mapEvents({
			'zoomIn': None,
			'zoomOut': None,
			'rotateRight': None,
			'rotateLeft': None,
			'gameMenuButton': None
		})
		self.minimap = None
		self.keylistener = None
		LastActivePlayerSettlementManager().remove()
		LastActivePlayerSettlementManager.destroy_instance()
		self.session.view.remove_change_listener(self._update_zoom)

		if self.cursor:
			self.cursor.remove()
			self.cursor.end()
			self.cursor = None

		super(IngameGui, self).end()

	def toggle_pause(self):
		self.pausemenu.toggle()

	def load(self, savegame):
		self.minimap.draw()

		self.cursor = SelectionTool(self.session)

	def setup(self):
		"""Called after the world editor was initialized."""
		self._settings_tab = TabWidget(self, tabs=[SettingsTab(self.session.world_editor, self)])
		self._settings_tab.show()

	def minimap_to_front(self):
		"""Make sure the full right top gui is visible and not covered by some dialog"""
		self.mainhud.hide()
		self.mainhud.show()

	def show_save_map_dialog(self):
		"""Shows a dialog where the user can set the name of the saved map."""
		self.save_map_dialog.show()

	def on_escape(self):
		pass

	def on_key_press(self, action, evt):
		_Actions = KeyConfig._Actions
		if action == _Actions.ESCAPE:
			return self.on_escape()

	def set_cursor(self, which='default', *args, **kwargs):
		"""Sets the mousetool (i.e. cursor).
		This is done here for encapsulation and control over destructors.
		Further arguments are passed to the mouse tool constructor.
		"""
		self.cursor.remove()
		klass = {
			'default': SelectionTool,
			'tile_layer': TileLayingTool
		}[which]
		self.cursor = klass(self.session, *args, **kwargs)

	def _update_zoom(self):
		"""Enable/disable zoom buttons"""
		zoom = self.session.view.get_zoom()
		in_icon = self.mainhud.findChild(name='zoomIn')
		out_icon = self.mainhud.findChild(name='zoomOut')
		if zoom == VIEW.ZOOM_MIN:
			out_icon.set_inactive()
		else:
			out_icon.set_active()
		if zoom == VIEW.ZOOM_MAX:
			in_icon.set_inactive()
		else:
			in_icon.set_active()