Anonymous avatar Anonymous committed c54be15

moved click handling from input to UiState.

Comments (0)

Files changed (2)

         self.selected = None
         self.logic.model.turn_finished()
 
+    def click(self, x, y): 
+        """Forwarded mouse input."""
+        hex_x, hex_y = coordinate_to_hexgrid(x, y)
+        # TODO: move if/else into a state-machine in the UiState: Check if the action fits one of the possible commands.
+        # if we’re dragging something, we act on that. 
+        if self.selected is not None:
+            # we only move the item and show the commands, if there’s no overlay. 
+            if not self.command_overlay.is_visible:
+                if self.movement_overlay.fields.get((hex_x, hex_y), None) is not None: 
+                    self.drop_selected_unit(hex_x, hex_y)
+            # if there’s already an overlay, we check if we resolved an item.
+            else:
+                action = self.command_overlay.on_mouse_release(x, y)
+                if action is not None:
+                    # global (UI) actions
+                    if action == "abort move":
+                        self.abort_selected_move()
+                        self.command_overlay.hide()
+                        self.turn_finished_selected()
+                    # actions by the unit
+                    actions = self.selected.act(action)
+                else:
+                    actions = None
+                # if we get new actions, let them appear around the unit.
+                if actions is not None:
+                    self.command_overlay.show(self.selected.hex_x,
+                                              self.selected.hex_y,
+                                              actions)
+                else:
+                    # unit turn finished
+                    self.command_overlay.hide()
+                    self.turn_finished_selected()
+        elif not self.command_overlay.is_visible and self.logic.model.hexmap.get((hex_x, hex_y), None) is not None:
+            pass # no action. All selecting is done by the computer.
+        else:
+            self.command_overlay.on_mouse_release(x, y)
+
 
 class Presentation:
     def __init__(self, state):
     
     def on_mouse_release(self, x, y, buttons, modifiers): 
         """Forwarded mouse input."""
-        hex_x, hex_y = coordinate_to_hexgrid(x, y)
-        # TODO: move if/else into a state-machine in the UiState: Check if the action fits one of the possible commands.
-        # if we’re dragging something, we act on that. 
-        if self.state.selected is not None:
-            # we only move the item and show the commands, if there’s no overlay. 
-            if not self.state.command_overlay.is_visible:
-                if self.state.movement_overlay.fields.get((hex_x, hex_y), None) is not None: 
-                    self.state.drop_selected_unit(hex_x, hex_y)
-            # if there’s already an overlay, we check if we resolved an item.
-            else:
-                action = self.state.command_overlay.on_mouse_release(x, y, buttons, modifiers)
-                if action is not None:
-                    # global (UI) actions
-                    if action == "abort move":
-                        self.state.abort_selected_move()
-                        self.state.command_overlay.hide()
-                        self.state.turn_finished_selected()
-                    # actions by the unit
-                    actions = self.state.selected.act(action)
-                else:
-                    actions = None
-                # if we get new actions, let them appear around the unit.
-                if actions is not None:
-                    self.state.command_overlay.show(self.state.selected.hex_x,
-                                              self.state.selected.hex_y,
-                                              actions)
-                else:
-                    # unit turn finished
-                    self.state.command_overlay.hide()
-                    self.state.turn_finished_selected()
-        elif not self.state.command_overlay.is_visible and self.state.logic.model.hexmap.get((hex_x, hex_y), None) is not None:
-            pass # no action. All selecting is done by the computer.
-        else:
-            self.state.command_overlay.on_mouse_release(x, y, buttons, modifiers)
+        self.state.click(x, y)
     
     def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
         """Forwarded mouse input."""

hexbattle_overlays.py

             except KeyError: print "no such item in overlay hexmap", pos
         self.fields = {}
 
-    def on_mouse_release(self, x, y, buttons, modifiers):
+    def on_mouse_release(self, x, y, buttons=None, modifiers=None):
         """Process a mouse event."""
         hex_pos = coordinate_to_hexgrid(x, y)
         act = self.fields.get(hex_pos, None)
             except KeyError: print "no such item in overlay hexmap", pos
         self.fields = {}
 
-    def on_mouse_release(self, x, y, buttons, modifiers):
+    def on_mouse_release(self, x, y, buttons=None, modifiers=None):
         """Process a mouse event."""
         hex_pos = coordinate_to_hexgrid(x, y)
         act = self.fields.get(hex_pos, None)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.