Skip to content

Commit

Permalink
Fix right-click on tile palette assigning to the primary tile instead…
Browse files Browse the repository at this point in the history
… of secondary.
  • Loading branch information
jaythebusinessgoose committed Dec 19, 2023
1 parent a0a04c9 commit 1d6ecde
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/modlunky2/ui/levels/shared/palette_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,31 @@ def update_with_palette(self, new_palette, suggestions, biome, lvl):
new_tile.grid(row=count_row, column=count_col)
new_tile.bind(
"<Button-1>",
lambda event, r=count_row, c=count_col: self.tile_pick(event, r, c),
lambda event, r=count_row, c=count_col: self.tile_pick(
event, r, c, True
),
)
new_tile.bind(
"<Button-3>",
lambda event, r=count_row, c=count_col: self.tile_pick(event, r, c),
lambda event, r=count_row, c=count_col: self.tile_pick(
event, r, c, False
),
)

# Bind first ten tiles to number keys
tile_index = count_col + (count_row * TILES_PER_ROW) + 1
if tile_index <= 10:
self.bind_all(
f"{tile_index%10}",
lambda event, r=count_row, c=count_col: self.tile_pick(event, r, c),
lambda event, r=count_row, c=count_col: self.tile_pick(
event, r, c, True
),
)
self.bind_all(
f"<Alt-Key-{tile_index%10}>",
lambda event, r=count_row, c=count_col: self.tile_pick(event, r, c),
lambda event, r=count_row, c=count_col: self.tile_pick(
event, r, c, False
),
)

if suggestions and len(suggestions):
Expand Down Expand Up @@ -303,11 +311,10 @@ def update_with_palette(self, new_palette, suggestions, biome, lvl):
self.new_tile_panel.reset()
self.new_tile_panel.enable()

def tile_pick(self, event, row, col):
def tile_pick(self, event, row, col, is_primary):
if not self.palette.scrollable_frame.grid_slaves(row, col):
return
selected_tile = self.palette.scrollable_frame.grid_slaves(row, col)[0]
is_primary = (event.num == 1) or (event.state & 0x20000 == 0)
self.select_tile(
selected_tile["text"], selected_tile["image"], is_primary, True
)
Expand Down

0 comments on commit 1d6ecde

Please sign in to comment.