Changeset 233
- Timestamp:
- 01/04/07 03:46:43 (5 years ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
NEWS.txt (modified) (1 diff)
-
src/pyspacewar/ui.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/NEWS.txt
r232 r233 4 4 - Bugfix: after remapping the controls the old keys used to continue to 5 5 perform the same actions. 6 - Allow up to two keys bound to the same action. 6 7 7 8 December 25, 2006: Released version 0.9.3: the Christmas release. -
trunk/src/pyspacewar/ui.py
r232 r233 129 129 130 130 """ 131 for action, key in controls.items():132 text = text.replace(action, key_name(key ))131 for action, keys in controls.items(): 132 text = text.replace(action, key_name(keys[0])) 133 133 return text 134 134 … … 1165 1165 """Handle any keys that are pressed.""" 1166 1166 for key, (handler, args) in self._keymap_repeat.items(): 1167 key = self.ui.controls.get(key, key)1168 ifpressed[key]:1169 handler(*args)1167 for key in self.ui.controls.get(key, [key]): 1168 if key is not None and pressed[key]: 1169 handler(*args) 1170 1170 1171 1171 def handle_mouse_press(self, event): … … 1488 1488 """Mode: controls menu.""" 1489 1489 1490 def init(self): 1491 MenuMode.init(self) 1492 self.on_key(K_BACKSPACE, self.clear_item) 1493 self.on_key(K_DELETE, self.clear_item) 1494 self.on_key(K_KP_PERIOD, self.clear_item) 1495 1490 1496 def items(self, label, items): 1491 1497 return ([(label, )] + 1492 [(title + '\t' + key_name(self.ui.controls[action]), 1498 [(title + '\t' + ', '.join(map(key_name, 1499 self.ui.controls[action])), 1493 1500 self.set_control, title, action) 1494 1501 for title, action in items]) … … 1523 1530 """Change a control""" 1524 1531 self.ui.ui_mode = WaitingForControlMode(self.ui, action, key) 1532 1533 def clear_item(self): 1534 """Clear the selected menu item.""" 1535 action = self.menu_items[self.menu.selected_item][1:] 1536 if action: 1537 handler = action[0] 1538 args = action[1:] 1539 if handler == self.set_control: 1540 title, action = args 1541 self.ui.set_control(action, None) 1542 self.reinit_menu() 1525 1543 1526 1544 … … 1767 1785 def __init__(self): 1768 1786 self.rng = random.Random() 1769 self.controls = dict(DEFAULT_CONTROLS) 1770 self.rev_controls = dict([(value, key) 1771 for (key, value) in self.controls.items()]) 1772 assert len(self.controls) == len(self.rev_controls) 1787 self.controls = {} 1788 for action in DEFAULT_CONTROLS: 1789 self.controls[action] = [None] 1790 self.rev_controls = {} 1791 for action, key in DEFAULT_CONTROLS.items(): 1792 self.set_control(action, key) 1773 1793 1774 1794 def load_settings(self, filename=None): … … 1789 1809 for action in self.controls: 1790 1810 key = config.get('controls', action) 1791 try: 1792 key = int(key) 1793 except ValueError: 1794 key = None 1795 self.set_control(action, key) 1811 if key: 1812 # clear all current keys first 1813 self.set_control(action, None) 1814 for key in key.split(): 1815 try: 1816 key = int(key) 1817 except ValueError: 1818 key = None 1819 self.set_control(action, key) 1796 1820 1797 1821 def save_settings(self, filename=None): … … 1814 1838 str(self.show_missile_trails)) 1815 1839 config.add_section('controls') 1816 for action, key in self.controls.items():1817 config.set('controls', action, key)1840 for action, keys in self.controls.items(): 1841 config.set('controls', action, ' '.join(map(str, keys))) 1818 1842 return config 1819 1843 … … 2150 2174 """Change a key mapping""" 2151 2175 if key in self.rev_controls: 2152 # key was previously bound to something else2153 2176 old_action = self.rev_controls[key] 2154 self.controls[old_action] = None 2155 old_key = self.controls[action] 2156 if old_key: 2157 # some other key was previously bound to this action 2158 del self.rev_controls[old_key] 2159 self.controls[action] = key 2177 self.controls[old_action].remove(key) 2178 if not self.controls[old_action]: 2179 self.controls[old_action] = [None] 2180 keys = self.controls[action] 2181 if len(keys) > 1 or key is None or keys == [None]: 2182 for old_key in keys: 2183 if old_key is not None: 2184 del self.rev_controls[old_key] 2185 self.controls[action] = [] 2186 self.controls[action].append(key) 2160 2187 if key is not None: 2161 2188 self.rev_controls[key] = action
