コード例 #1
0
 def keyReleased(self, evt):
     keyval = evt.getKey().getValue()
     _Actions = KeyConfig._Actions
     action = KeyConfig().translate(evt)
     try:
         self.keys_pressed.remove(keyval)
     except:
         return
     stop_horizontal = action in (_Actions.LEFT, _Actions.RIGHT)
     stop_vertical = action in (_Actions.UP, _Actions.DOWN)
     if stop_horizontal:
         self.key_scroll[0] = 0
     elif stop_vertical:
         self.key_scroll[1] = 0
     self.session.view.autoscroll_keys(*self.key_scroll)
コード例 #2
0
 def keyReleased(self, evt):
     keyval = evt.getKey().getValue()
     _Actions = KeyConfig._Actions
     action = KeyConfig().translate(evt)
     try:
         self.keysPressed.remove(keyval)
     except:
         return
     if action == _Actions.LEFT or \
        action == _Actions.RIGHT:
         self.key_scroll[0] = 0
     if action == _Actions.UP or \
        action == _Actions.DOWN:
         self.key_scroll[1] = 0
     self.session.view.autoscroll_keys(self.key_scroll[0],
                                       self.key_scroll[1])
コード例 #3
0
    def keyPressed(self, evt):
        if evt.isConsumed():
            return

        action = KeyConfig().translate(evt)
        _Actions = KeyConfig._Actions
        keyval = evt.getKey().getValue()

        key_event_handled = True

        if action == _Actions.ESCAPE:
            self.gui.on_escape()
        elif keyval == fife.Key.ENTER:
            self.gui.on_return()
        elif action == _Actions.CONSOLE:
            self.gui.fps_display.toggle()
        elif action == _Actions.HELP:
            self.gui.on_help()
        elif action == _Actions.SCREENSHOT:
            # save the screenshot into a temporary file because fife doesn't support unicode paths
            temp_handle, temp_path = tempfile.mkstemp()
            os.close(temp_handle)
            horizons.globals.fife.engine.getRenderBackend().captureScreen(
                temp_path)

            # move the screenshot into the final location
            filename = datetime.datetime.now().isoformat('.').replace(
                ":", "-") + ".png"
            final_path = os.path.join(PATHS.SCREENSHOT_DIR, filename)
            shutil.move(temp_path, final_path)

            # ingame message if there is a session and it is fully initialized:
            # pressing S on loading screen finds a session but no gui usually.
            session = horizons.main._modules.session
            if session and hasattr(session, 'ingame_gui'):
                session.ingame_gui.message_widget.add(
                    'SCREENSHOT', message_dict={'file': final_path})
        elif action == _Actions.QUICKLOAD:
            horizons.main._load_last_quicksave()
        else:
            key_event_handled = False  # nope, nothing triggered

        if key_event_handled:
            evt.consume()  # prevent other listeners from being called
コード例 #4
0
    def keyPressed(self, evt):
        if evt.isConsumed():
            return

        action = KeyConfig().translate(evt)
        _Actions = KeyConfig._Actions

        key_event_handled = True

        if action == _Actions.ESCAPE:
            self.gui.on_escape()
        elif action == _Actions.CONSOLE:
            horizons.globals.fife.console.toggleShowHide()
        elif action == _Actions.HELP:
            self.gui.on_help()
        elif action == _Actions.SCREENSHOT:
            # save the screenshot into a temporary file because fife doesn't support unicode paths
            temp_handle, temp_path = tempfile.mkstemp()
            os.close(temp_handle)
            horizons.globals.fife.engine.getRenderBackend().captureScreen(
                temp_path)

            # move the screenshot into the final location
            filename = datetime.datetime.now().isoformat('.').replace(
                ":", "-") + ".png"
            final_path = os.path.join(PATHS.SCREENSHOT_DIR, filename)
            shutil.move(temp_path, final_path)

            # ingame message if there is a session
            if self.gui.session is not None:
                self.gui.session.ingame_gui.message_widget.add(
                    point=None,
                    string_id='SCREENSHOT',
                    message_dict={'file': final_path})
        elif action == _Actions.QUICKLOAD:
            from horizons.main import _load_last_quicksave
            _load_last_quicksave(self.gui.session)
        else:
            key_event_handled = False  # nope, nothing triggered

        if key_event_handled:
            evt.consume()  # prevent other listeners from being called
コード例 #5
0
    def keyPressed(self, evt):
        keyval = evt.getKey().getValue()
        action = KeyConfig().translate(evt)

        _Actions = KeyConfig._Actions

        was_pressed = keyval in self.keys_pressed
        if not was_pressed:
            self.keys_pressed.append(keyval)
            if action == _Actions.LEFT:
                self.key_scroll[0] -= 25
            if action == _Actions.RIGHT:
                self.key_scroll[0] += 25
            if action == _Actions.UP:
                self.key_scroll[1] -= 25
            if action == _Actions.DOWN:
                self.key_scroll[1] += 25

        # We scrolled, do autoscroll
        if self.key_scroll[0] != 0 or self.key_scroll[1] != 0:
            self.session.view.autoscroll_keys(*self.key_scroll)

        if self.session.ingame_gui.on_key_press(action, evt):
            evt.consume()  # prevent other listeners from being called
コード例 #6
0
    def keyPressed(self, evt):
        keyval = evt.getKey().getValue()
        action = KeyConfig().translate(evt)

        _Actions = KeyConfig._Actions

        was = keyval in self.keysPressed
        if not was:
            self.keysPressed.append(keyval)
        if action == _Actions.LEFT:
            if not was: self.key_scroll[0] -= 25
        if action == _Actions.RIGHT:
            if not was: self.key_scroll[0] += 25
        if action == _Actions.UP:
            if not was: self.key_scroll[1] -= 25
        if action == _Actions.DOWN:
            if not was: self.key_scroll[1] += 25

        # We scrolled, do autoscroll
        if self.key_scroll[0] != 0 or self.key_scroll != 0:
            self.session.view.autoscroll_keys(self.key_scroll[0],
                                              self.key_scroll[1])

        key_event_handled = True

        if action == _Actions.ESCAPE:
            handled_by_ingame_gui = self.session.ingame_gui.on_escape()
            if not handled_by_ingame_gui:
                key_event_handled = False  # let the MainListener handle this
        elif action == _Actions.GRID:
            gridrenderer = self.session.view.renderer['GridRenderer']
            gridrenderer.setEnabled(not gridrenderer.isEnabled())
        elif action == _Actions.COORD_TOOLTIP:
            self.session.coordinates_tooltip.toggle()
        elif action == _Actions.DESTROY_TOOL:
            self.session.toggle_destroy_tool()
        elif action == _Actions.REMOVE_SELECTED:
            self.session.remove_selected()
        elif action == _Actions.ROAD_TOOL:
            self.session.ingame_gui.toggle_road_tool()
        elif action == _Actions.SPEED_UP:
            SpeedUpCommand().execute(self.session)
        elif action == _Actions.SPEED_DOWN:
            SpeedDownCommand().execute(self.session)
        elif action == _Actions.PAUSE:
            TogglePauseCommand().execute(self.session)
        elif action == _Actions.PLAYERS_OVERVIEW:
            self.session.ingame_gui.logbook.toggle_stats_visibility(
                widget='players')
        elif action == _Actions.SETTLEMENTS_OVERVIEW:
            self.session.ingame_gui.logbook.toggle_stats_visibility(
                widget='settlements')
        elif action == _Actions.SHIPS_OVERVIEW:
            self.session.ingame_gui.logbook.toggle_stats_visibility(
                widget='ships')
        elif action == _Actions.LOGBOOK:
            self.session.ingame_gui.logbook.toggle_visibility()
        elif action == _Actions.DEBUG:
            pass
            #import pdb; pdb.set_trace()
            #debug code to check for memory leaks:
            """
			import gc
			import weakref
			all_lists = []
			for island in self.session.world.islands:
				buildings_weakref = []
				for b in island.buildings:
					buildings_weakref.append( weakref.ref(b) )
				import random
				random.shuffle(buildings_weakref)
				all_lists.extend(buildings_weakref)

				for b in buildings_weakref:
					if b().id == 17: continue
					if b().id == 1: continue # warehouse is unremovable

					#if b().id != 2: continue # test storage now

					print 'gonna remove: ', b()
					b().remove()
					collected = gc.collect()
					print 'collected: ', collected

					if b() is not None:
						import pdb ; pdb.set_trace()
						print 'referrers: ', gc.get_referrers(b())
						a = gc.get_referrers(b())
						print

			#print all_lists
			"""

        elif action == _Actions.BUILD_TOOL:
            self.session.ingame_gui.show_build_menu()
        elif action == _Actions.ROTATE_RIGHT:
            if hasattr(self.session.cursor, "rotate_right"):
                # used in e.g. build preview to rotate building instead of map
                self.session.cursor.rotate_right()
            else:
                self.session.view.rotate_right()
                self.session.ingame_gui.minimap.rotate_right()
        elif action == _Actions.ROTATE_LEFT:
            if hasattr(self.session.cursor, "rotate_left"):
                self.session.cursor.rotate_left()
            else:
                self.session.view.rotate_left()
                self.session.ingame_gui.minimap.rotate_left()
        elif action == _Actions.CHAT:
            self.session.ingame_gui.show_chat_dialog()
        elif action == _Actions.TRANSLUCENCY:
            self.session.world.toggle_translucency()
        elif action == _Actions.TILE_OWNER_HIGHLIGHT:
            self.session.world.toggle_owner_highlight()
        elif keyval in (fife.Key.NUM_0, fife.Key.NUM_1, fife.Key.NUM_2,
                        fife.Key.NUM_3, fife.Key.NUM_4, fife.Key.NUM_5,
                        fife.Key.NUM_6, fife.Key.NUM_7, fife.Key.NUM_8,
                        fife.Key.NUM_9):
            num = int(keyval - fife.Key.NUM_0)
            if evt.isControlPressed():
                # create new group (only consider units owned by the player)
                self.session.selection_groups[num] = \
                    set(filter(lambda unit : unit.owner.is_local_player,
                               self.session.selected_instances))
                # drop units of the new group from all other groups
                for group in self.session.selection_groups:
                    if group is not self.session.selection_groups[num]:
                        group -= self.session.selection_groups[num]
            else:
                # deselect
                # we need to make sure to have a cursor capable of selection (for apply_select())
                # this handles deselection implicitly in the destructor
                self.session.set_cursor('selection')

                # apply new selection
                for instance in self.session.selection_groups[num]:
                    instance.get_component(SelectableComponent).select(
                        reset_cam=True)
                # assign copy since it will be randomly changed, the unit should only be changed on ctrl-events
                self.session.selected_instances = self.session.selection_groups[
                    num].copy()
                # show menu depending on the entities selected
                if self.session.selected_instances:
                    self.session.cursor.apply_select()
                else:
                    # nothing is selected here, we need to hide the menu since apply_select doesn't handle that case
                    self.session.ingame_gui.show_menu(None)
        elif action == _Actions.QUICKSAVE:
            self.session.quicksave(
            )  # load is only handled by the MainListener
        elif action == _Actions.SAVE_MAP:
            # require shift to make it less likely that an ordinary user stumbles upon this
            # this is done because the maps aren't usable without moving them to the right places
            self.session.ingame_gui.show_save_map_dialog()
        elif action == _Actions.PIPETTE:
            # copy mode: pipette tool
            self.session.toggle_cursor('pipette')
        elif action == _Actions.HEALTH_BAR:
            # shows health bar of every instance with an health component
            self.session.world.toggle_health_for_all_health_instances()
        elif action == _Actions.SHOW_SELECTED:
            if self.session.selected_instances:
                # scroll to first one, we can never guarantee to display all selected units
                instance = iter(self.session.selected_instances).next()
                self.session.view.center(*instance.position.center.to_tuple())
                for instance in self.session.selected_instances:
                    if hasattr(instance,
                               "path") and instance.owner.is_local_player:
                        self.session.ingame_gui.minimap.show_unit_path(
                            instance)
        else:
            key_event_handled = False  # nope, nothing triggered

        if key_event_handled:
            evt.consume()  # prevent other listeners from being called