Commit a3f4f268 authored by Toast Engineer's avatar Toast Engineer

Some battle UX polish

parent 1c965e69
......@@ -159,7 +159,7 @@ class BattleWindow(windowmanager.GfxWindow):
menu["Inspect Inventory"] = text_menu.PopUpMenu({
str(item): lambda: functools.partial(text_menu.pop_up_notification, item.__doc__)
for item in character.inventory
}, loop_until_non_callable=True)
}, loop_until_non_callable=True, cancellable=True)
menu["Inspect Inventory"]["Back"] = None
if enemy:
......@@ -179,7 +179,7 @@ class BattleWindow(windowmanager.GfxWindow):
for action in all_actions
if getattr(action, "target", None) == enemy
and self.battle.external_PC_actions.get(action.user, None) != action
}, loop_until_non_callable = True)
}, loop_until_non_callable = True, cancellable=True)
menu["Attack"]["Back"] = None
elif gfx.main_window.bottom_textbox.selected_character:
......@@ -191,7 +191,7 @@ class BattleWindow(windowmanager.GfxWindow):
menu["Choose Action"] = text_menu.PopUpMenu({
str(action): functools.partial(register_action, action)
for action in character.collect_battle_actions(self.battle)
})
}, cancellable=True)
menu["Choose Action"]["Back"] = None
......@@ -262,7 +262,6 @@ class BattleState:
if self.state == "Getting PC actions":
active_pcs = set(pc for pc in self.player_characters if not pc.incapacitated)
print(self.external_PC_actions)
if set(self.external_PC_actions) >= active_pcs:
self.queued_actions.extend(self.external_PC_actions.values())
self.external_PC_actions.clear()
......
......@@ -198,7 +198,7 @@ class GameState:
def start_battle(self, enemies = None):
if not enemies:
enemies = []
for t in range(random.randint(3,16)):
for t in range(random.randint(3,5)):
enemy = character.MurderousJerk(f"Murderous Jerk {t}", random.randint(5, 9), random.randint(5, 9), random.randint(5, 9), random.randint(5, 9), random.randint(5, 9), random.randint(5, 9))
enemies.append(enemy)
enemy.inventory.append(random.choice(character.MeleeWeapon.__subclasses__())())
......
......@@ -107,8 +107,6 @@ class PopUpMenuWindow(windowmanager.TerminalWindow):
if mousey is not None:
try:
self.menu.currently_selected_key = label_ys[mousey]
#@TODO HACK!!! Get rid of _selection_idx and make setting currently_selected_key work!
self.menu._selection_idx = mousey - yorigin
except KeyError:
pass
......@@ -140,7 +138,6 @@ class PopUpMenu(dict):
if self.prompt and self.prompt[-2:] != "\n\n": self.prompt += "\n\n"
self.dontcall = dontcall
self.blocking = blocking
self._selection_idx = None
self.currently_selected_key = None
self.selection = None
self.window = None
......@@ -161,10 +158,8 @@ class PopUpMenu(dict):
self.currently_selected_key = self.initial_selection
if self.initial_selection is not None:
self.selection = self[self.currently_selected_key]
self._selection_idx = list(self).index(self.currently_selected_key)
else:
self.selection = None
self._selection_idx = None
controls.bindings.push_modal(self)
if self.blocking:
......@@ -176,25 +171,22 @@ class PopUpMenu(dict):
@controls.action("Menu Selection Up", (pygame.K_UP, pygame.K_w, "WheelUp"))
def selection_up(self):
if self._selection_idx is None:
self._selection_idx = len(self) - 1
self.currently_selected_key = list(self)[self._selection_idx]
return
self._selection_idx -= 1
self._selection_idx %= len(self)
self.currently_selected_key = list(self)[self._selection_idx]
try: idx = list(self).index(self.currently_selected_key)
except ValueError: idx = 0
idx -= 1
idx %= len(self)
self.currently_selected_key = list(self)[idx]
@controls.action("Menu Selection Down", (pygame.K_DOWN, pygame.K_s, "WheelDown"))
def selection_down(self):
if self._selection_idx is None:
self._selection_idx = 0
self.currently_selected_key = list(self)[self._selection_idx]
return
try: idx = list(self).index(self.currently_selected_key)
except ValueError: idx = -1
self._selection_idx += 1
self._selection_idx %= len(self)
self.currently_selected_key = list(self)[self._selection_idx]
idx += 1
idx %= len(self)
self.currently_selected_key = list(self)[idx]
@controls.action("Menu Select", (pygame.K_e, pygame.K_RETURN, pygame.K_KP_ENTER, "MouseLeft", "WheelClick"))
def select(self, button_up = True):
......@@ -219,7 +211,7 @@ class PopUpMenu(dict):
self.close()
@controls.action("Menu Close", (pygame.K_ESCAPE, "MouseRight"))
def cancel(self):
def cancel(self, _):
if not self.cancellable: return
self.selection = None
self.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment