Remove legacy string enum comparisons from InputState/Key/MouseButton, closes #306
Removed custom __eq__/__ne__ that allowed comparing enums to legacy string names (e.g., Key.ESCAPE == "Escape"). Removed _legacy_names dicts and to_legacy_string() functions. Kept from_legacy_string() in PyKey.cpp as it's used by C++ event dispatch. Updated ~50 Python test/demo/cookbook files to use enum members instead of string comparisons. Also updates grid.position -> grid.pos in files that had both types of changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
354faca838
commit
6d5e99a114
52 changed files with 372 additions and 533 deletions
|
|
@ -102,13 +102,13 @@ class Button:
|
|||
if not self._enabled:
|
||||
return
|
||||
|
||||
if button == "left":
|
||||
if action == "start":
|
||||
if button == mcrfpy.MouseButton.LEFT:
|
||||
if action == mcrfpy.InputState.PRESSED:
|
||||
self.is_pressed = True
|
||||
self.frame.fill_color = self.press_color
|
||||
# Animate a subtle press effect
|
||||
self._animate_press()
|
||||
elif action == "end":
|
||||
elif action == mcrfpy.InputState.RELEASED:
|
||||
self.is_pressed = False
|
||||
# Restore hover or normal state
|
||||
if self.is_hovered:
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ class ChoiceList:
|
|||
idx = i # Capture index in closure
|
||||
def make_click_handler(index):
|
||||
def handler(pos, button, action):
|
||||
if button == "left" and action == "end":
|
||||
if button == mcrfpy.MouseButton.LEFT and action == mcrfpy.InputState.RELEASED:
|
||||
self.set_selected(index)
|
||||
if self.on_select:
|
||||
self.on_select(index, self._choices[index])
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ class GridContainer:
|
|||
# Set up event handlers
|
||||
def make_click(cx, cy):
|
||||
def handler(pos, button, action):
|
||||
if button == "left" and action == "end":
|
||||
if button == mcrfpy.MouseButton.LEFT and action == mcrfpy.InputState.RELEASED:
|
||||
self._on_cell_clicked(cx, cy)
|
||||
return handler
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class ItemSlot(mcrfpy.Frame):
|
|||
return item.slot_type == self.slot_type
|
||||
|
||||
def _on_click(self, pos, button, action):
|
||||
if action != "start" or button != "left":
|
||||
if action != mcrfpy.InputState.PRESSED or button != mcrfpy.MouseButton.LEFT:
|
||||
return
|
||||
if self.manager:
|
||||
self.manager.handle_slot_click(self.slot_name)
|
||||
|
|
@ -274,14 +274,14 @@ class ItemManager:
|
|||
|
||||
def _on_grid_click(self, grid_name, pos, button, action):
|
||||
"""Handle click on a registered grid."""
|
||||
if action != "start":
|
||||
if action != mcrfpy.InputState.PRESSED:
|
||||
return
|
||||
|
||||
if button == "right":
|
||||
if button == mcrfpy.MouseButton.RIGHT:
|
||||
self.cancel_pickup()
|
||||
return
|
||||
|
||||
if button != "left":
|
||||
if button != mcrfpy.MouseButton.LEFT:
|
||||
return
|
||||
|
||||
grid, item_map, color_layer = self.grids[grid_name]
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ class Modal:
|
|||
|
||||
def make_click(cb):
|
||||
def handler(pos, button, action):
|
||||
if button == "left" and action == "end" and cb:
|
||||
if button == mcrfpy.MouseButton.LEFT and action == mcrfpy.InputState.RELEASED and cb:
|
||||
cb()
|
||||
return handler
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ class Modal:
|
|||
def _on_overlay_click(self, pos, button, action):
|
||||
"""Handle clicks on overlay (outside modal)."""
|
||||
# Check if click is outside modal
|
||||
if button == "left" and action == "end":
|
||||
if button == mcrfpy.MouseButton.LEFT and action == mcrfpy.InputState.RELEASED:
|
||||
mx, my = self.modal_frame.x, self.modal_frame.y
|
||||
mw, mh = self.modal_frame.w, self.modal_frame.h
|
||||
px, py = pos.x, pos.y
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class ScrollableList:
|
|||
# Set up click handler
|
||||
def make_click_handler(index):
|
||||
def handler(pos, button, action):
|
||||
if button == "left" and action == "end":
|
||||
if button == mcrfpy.MouseButton.LEFT and action == mcrfpy.InputState.RELEASED:
|
||||
self.select(index)
|
||||
return handler
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue