Don't use twice the same setting
This commit is contained in:
parent
1366e6a54d
commit
526a1a1e27
|
@ -76,12 +76,14 @@ class SettingsMenu(Menu):
|
||||||
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str,
|
def handle_key_pressed(self, key: Optional[KeyValues], raw_key: str,
|
||||||
game: Any) -> None:
|
game: Any) -> None:
|
||||||
"""
|
"""
|
||||||
For now, in the settings mode, we can only go backwards.
|
Update settings
|
||||||
"""
|
"""
|
||||||
if not self.waiting_for_key:
|
if not self.waiting_for_key:
|
||||||
|
# Navigate normally through the menu.
|
||||||
if key == KeyValues.SPACE or \
|
if key == KeyValues.SPACE or \
|
||||||
key == KeyValues.ENTER and \
|
key == KeyValues.ENTER and \
|
||||||
self.position == len(self.values) - 1:
|
self.position == len(self.values) - 1:
|
||||||
|
# Go back
|
||||||
game.display_actions(DisplayActions.UPDATE)
|
game.display_actions(DisplayActions.UPDATE)
|
||||||
game.state = GameMode.MAINMENU
|
game.state = GameMode.MAINMENU
|
||||||
if key == KeyValues.DOWN:
|
if key == KeyValues.DOWN:
|
||||||
|
@ -89,6 +91,7 @@ class SettingsMenu(Menu):
|
||||||
if key == KeyValues.UP:
|
if key == KeyValues.UP:
|
||||||
self.go_up()
|
self.go_up()
|
||||||
if key == KeyValues.ENTER and self.position < len(self.values) - 3:
|
if key == KeyValues.ENTER and self.position < len(self.values) - 3:
|
||||||
|
# Change a setting
|
||||||
option = list(game.settings.settings_keys)[self.position]
|
option = list(game.settings.settings_keys)[self.position]
|
||||||
if option == "TEXTURE_PACK":
|
if option == "TEXTURE_PACK":
|
||||||
game.settings.TEXTURE_PACK = \
|
game.settings.TEXTURE_PACK = \
|
||||||
|
@ -101,6 +104,10 @@ class SettingsMenu(Menu):
|
||||||
self.update_values(game.settings)
|
self.update_values(game.settings)
|
||||||
else:
|
else:
|
||||||
option = list(game.settings.settings_keys)[self.position]
|
option = list(game.settings.settings_keys)[self.position]
|
||||||
|
# Don't use an already mapped key
|
||||||
|
if any(getattr(game.settings, opt) == raw_key
|
||||||
|
for opt in game.settings.settings_keys if opt != option):
|
||||||
|
return
|
||||||
setattr(game.settings, option, raw_key)
|
setattr(game.settings, option, raw_key)
|
||||||
game.settings.write_settings()
|
game.settings.write_settings()
|
||||||
self.waiting_for_key = False
|
self.waiting_for_key = False
|
||||||
|
|
|
@ -168,6 +168,9 @@ class TestGame(unittest.TestCase):
|
||||||
# Define the "move up" key to 'a'
|
# Define the "move up" key to 'a'
|
||||||
self.game.handle_key_pressed(KeyValues.ENTER)
|
self.game.handle_key_pressed(KeyValues.ENTER)
|
||||||
self.assertTrue(self.game.settings_menu.waiting_for_key)
|
self.assertTrue(self.game.settings_menu.waiting_for_key)
|
||||||
|
# Can't used a mapped key
|
||||||
|
self.game.handle_key_pressed(None, 's')
|
||||||
|
self.assertTrue(self.game.settings_menu.waiting_for_key)
|
||||||
self.game.handle_key_pressed(None, 'a')
|
self.game.handle_key_pressed(None, 'a')
|
||||||
self.assertFalse(self.game.settings_menu.waiting_for_key)
|
self.assertFalse(self.game.settings_menu.waiting_for_key)
|
||||||
self.assertEqual(self.game.settings.KEY_LEFT_PRIMARY, 'a')
|
self.assertEqual(self.game.settings.KEY_LEFT_PRIMARY, 'a')
|
||||||
|
|
Loading…
Reference in New Issue