Wardrobe 2.0 - Wheelmenu

* Implemented wheelmenu for the wardrobe
* Implemented hide/show functions for singular items
* Implemented quick jumps
* Fixed wheelmenu overflowing screen positions (needed a clamp)
This commit is contained in:
LoafyLemon 2024-10-29 11:57:39 +00:00
parent 06797f9b3c
commit 93c899cd44
3 changed files with 99 additions and 11 deletions

View File

@ -234,8 +234,9 @@ init python:
hbox = []
overlay = []
action = [Function(wardrobe.equip, self), self.build_button]
action = [Function(wardrobe.wheelmenu, self), self.build_button]
unhovered = None
alternate = None
if is_inadequate:
warnings.append("Character level too low")
@ -270,7 +271,13 @@ init python:
if is_inadequate:
style = "wardrobe_item_button_inadequate"
return Button(child=child, focus_mask=None, xysize=(96, 96), action=action, tooltip=("\n".join(warnings)), unhovered=unhovered, style=style, selected=is_equipped)
if is_equipped:
alternate = Function(wardrobe.jump_to_item, self, "color_picker")
else:
alternate = [Function(wardrobe.equip, self), Function(wardrobe.jump_to_item, self, "color_picker")]
return Button(child=child, focus_mask=None, xysize=(96, 96), action=action, tooltip=("\n".join(warnings)), unhovered=unhovered, style=style, selected=is_equipped, alternate=alternate)
@functools.cache
def build_button(self, _=None):

View File

@ -1,10 +1,11 @@
init python in wheelmenu:
import math
reference_num_buttons = 32
reference_radius = 0.5
def pos(num_buttons):
num_buttons = max(num_buttons, 2)
reference_num_buttons = 32
reference_radius = 0.5
radius = reference_radius * (num_buttons / reference_num_buttons) ** 0.5
angle_step = 2 * math.pi / num_buttons
start_angle = angle_step / 2 if num_buttons % 2 else 0
@ -28,6 +29,14 @@ init python in wheelmenu:
else:
return None
def clamp_to_screen(num_buttons, pos):
num_buttons = max(num_buttons, 2)
radius = reference_radius * (num_buttons / reference_num_buttons) ** 0.5
diameter = int(radius * min(renpy.store.config.screen_width, renpy.store.config.screen_height))
x = max(diameter, min(renpy.store.config.screen_width - diameter, pos[0]))
y = max(diameter, min(renpy.store.config.screen_height - diameter, pos[1]))
return (x, y)
init python:
def create_wheelmenu(elements):
# Proxy function; We cannot evaluate in a named store without side effects.
@ -59,16 +68,16 @@ label wheelmenu(btns, ret, pos=None):
jump expression ret
screen wheelmenu(btns, pos):
screen wheelmenu(btns, pos=None, close_action=Return("Close")):
layer "interface"
tag wheelmenu
zorder 1
style_prefix "wheelmenu"
$ mpos = renpy.get_mouse_pos()
default start_pos = pos or mpos
default start_pos = wheelmenu.clamp_to_screen(len(btns), pos or mpos)
use close_button_background(keysym="game_menu")
use close_button_background(action=close_action, keysym="game_menu")
window at wheelmenu_anim:
id "wheelmenu"

File diff suppressed because it is too large Load Diff