Wheelmenu, Bug fixes

* Implement disabled state for wheelmenu buttons
* Simplify wheelmenu definitions
* Fix bogus warning for doll elements during stale displayable evaluation (cache)
This commit is contained in:
LoafyLemon 2024-09-24 19:59:59 +01:00
parent e8a2873fd7
commit 1d3a12f0f6
4 changed files with 41 additions and 37 deletions

View File

@ -106,7 +106,7 @@ init -1 python:
try: try:
os.unlink(syspath) os.unlink(syspath)
except FileNotFoundError: except FileNotFoundError:
print(f"Warning! Cached file {syspath} not found") print(f"Warning! Cannot remove non-existent cached file: {syspath}")
except PermissionError: except PermissionError:
print(f"Warning! Permission denied to remove cached file: {syspath}") print(f"Warning! Permission denied to remove cached file: {syspath}")
except Exception as e: except Exception as e:

View File

@ -83,6 +83,14 @@ init python:
except AttributeError: except AttributeError:
renpy.store.states.dolls = {name} renpy.store.states.dolls = {name}
# TODO: Experiment with cache for full dolls, maybe for android?
def is_stale(self):
curr_hash = self.generate_hash()
# if (stale := curr_hash != self._hash):
# self.remove_disk_cache(self._hash)
self._hash = curr_hash
return stale
def generate_hash(self): def generate_hash(self):
clothes_hash = str([x[0]._hash for x in self.states.values() if istype(x[0], (DollCloth, DollClothDynamic, DollMakeup)) and x[2]]) clothes_hash = str([x[0]._hash for x in self.states.values() if istype(x[0], (DollCloth, DollClothDynamic, DollMakeup)) and x[2]])
salt = str( [self.name, self.pose, str(self.body._hash), str(self.face._hash), str(self.cum._hash), clothes_hash] ) salt = str( [self.name, self.pose, str(self.body._hash), str(self.face._hash), str(self.cum._hash), clothes_hash] )

View File

@ -13,26 +13,18 @@ init python in wheelmenu:
for i in range(num_buttons)] for i in range(num_buttons)]
return positions return positions
def button(displayable, action, condition, state=None, **kwargs): def button(displayable, action, condition, disabled, **kwargs):
""" """
displayable - Ren'Py displayable displayable - Ren'Py displayable
action - Ren'Py screen action action - Ren'Py screen action
condition - Boolean condition - Boolean
state - disabled - Boolean
None - No change
"hidden" - Hidden if condition==False
"disabled" - Disabled if condition==False
""" """
if state == "hidden":
return None
elif state == "disabled":
return renpy.store.Button(displayable, action=action, style="wheelmenu_disabled_button", **kwargs)
if condition: if condition:
if action is None or disabled:
return renpy.store.Button(renpy.store.Transform(displayable, matrixcolor=renpy.store.SaturationMatrix(0)*renpy.store.BrightnessMatrix(-0.25)*renpy.store.OpacityMatrix(0.5)), action=action, style="wheelmenu_disabled_button", **kwargs)
return renpy.store.Button(displayable, action=action, style="wheelmenu_button", **kwargs) return renpy.store.Button(displayable, action=action, style="wheelmenu_button", **kwargs)
elif action is None:
return renpy.store.Button(displayable, action=action, style="wheelmenu_disabled_button", **kwargs)
else: else:
return None return None
@ -41,19 +33,23 @@ init python:
# Proxy function; We cannot evaluate in a named store without side effects. # Proxy function; We cannot evaluate in a named store without side effects.
buttons = [] buttons = []
for name, (displayable, action, condition) in elements.items(): for name, (displayable, action, *tail) in elements.items():
condition = eval(condition) if tail:
condition = eval(tail[0])
disabled = eval(tail[1]) if len(tail) > 1 else False
else:
condition = True
disabled = False
if not condition: if not condition and disabled:
continue continue
buttons.append(wheelmenu.button(displayable, action, condition, tooltip=name)) buttons.append(wheelmenu.button(displayable, action, condition, disabled, tooltip=name))
if not buttons: if not buttons:
return None return None
positions = wheelmenu.pos(len(buttons)) return None if not buttons else tuple(zip(buttons, wheelmenu.pos(len(buttons)))) # Nonhashable types cannot be used in a screen, so we use a tuple instead.
return tuple(zip(buttons, positions)) # Nonhashable types cannot be used in a screen, so we use a tuple instead.
config.per_frame_screens.append("wheelmenu") config.per_frame_screens.append("wheelmenu")
@ -101,8 +97,8 @@ style wheelmenu_button is empty:
anchor (0.5, 0.5) anchor (0.5, 0.5)
style wheelmenu_disabled_button is wheelmenu_button: style wheelmenu_disabled_button is wheelmenu_button:
background "#ffffff80" background Transform("wheelmenu_button", xysize=(48,48), matrixcolor=BrightnessMatrix(0.2))
foreground "#ff00ff" hover_background At(Transform("wheelmenu_button_opaque", xysize=(48,48), matrixcolor=BrightnessMatrix(0.2)), wheelmenu_hover_anim)
xysize (48, 48) xysize (48, 48)
anchor (0.5, 0.5) anchor (0.5, 0.5)

View File

@ -7,9 +7,9 @@ default cupboard_OBJ = RoomObject(
pos=(260, 280), pos=(260, 280),
idle="cupboard_idle", idle="cupboard_idle",
action={ action={
"Open Inventory": (Text("🎒", align=(0.5, 0.5)), Jump("inventory"), "True"), "Open Inventory": (Text("🎒", align=(0.5, 0.5)), Jump("inventory")),
"Rummage": (Text("🖐️", align=(0.5, 0.5)), Jump("cupboard"), "True"), "Rummage": (Text("🖐️", align=(0.5, 0.5)), Jump("cupboard")),
"Calendar": (Text("📆", align=(0.5, 0.5)), Jump("calendar"), "True"), "Calendar": (Text("📆", align=(0.5, 0.5)), Jump("calendar")),
}, },
tooltip="Cupboard" tooltip="Cupboard"
) )
@ -21,8 +21,8 @@ default phoenix_OBJ = RoomObject(
focus_mask="phoenix_idle", focus_mask="phoenix_idle",
background="phoenix_feather", background="phoenix_feather",
action={ action={
"Feed": (Text("🍔", align=(0.5, 0.5)), Jump("phoenix_feed"), "True"), "Feed": (Text("🍔", align=(0.5, 0.5)), Jump("phoenix_feed")),
"Pet": (Text("🖐️", align=(0.5, 0.5)), Jump("phoenix_pet"), "True") "Pet": (Text("🖐️", align=(0.5, 0.5)), Jump("phoenix_pet"))
}, },
tooltip="Phoenix" tooltip="Phoenix"
) )
@ -33,14 +33,14 @@ default door_OBJ = RoomObject(
idle="door_idle", idle="door_idle",
focus_mask="door_hover", focus_mask="door_hover",
action={ action={
"Summon Snape": (Transform("wheelmenu_snape", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.sna.busy", None, Jump("summon_snape")), "states.sna.unlocked"), "Summon Snape": (Transform("wheelmenu_snape", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.sna.busy", None, Jump("summon_snape")), "states.sna.unlocked", "states.sna.busy"),
"Summon Tonks": (Transform("wheelmenu_tonks", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.ton.busy", None, Jump("summon_tonks")), "states.ton.unlocked"), "Summon Tonks": (Transform("wheelmenu_tonks", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.ton.busy", None, Jump("summon_tonks")), "states.ton.unlocked", "states.ton.busy"),
"Summon Hermione": (Transform("wheelmenu_hermione", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.her.busy", None, Jump("summon_hermione")), "states.her.unlocked"), "Summon Hermione": (Transform("wheelmenu_hermione", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.her.busy", None, Jump("summon_hermione")), "states.her.unlocked", "states.her.busy"),
"Summon Cho": (Transform("wheelmenu_cho", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.cho.busy", None, Jump("summon_cho")), "states.cho.unlocked"), "Summon Cho": (Transform("wheelmenu_cho", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.cho.busy", None, Jump("summon_cho")), "states.cho.unlocked", "states.cho.busy"),
"Summon Luna": (Transform("wheelmenu_luna", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.lun.busy", None, Jump("summon_luna")), "states.lun.unlocked"), "Summon Luna": (Transform("wheelmenu_luna", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.lun.busy", None, Jump("summon_luna")), "states.lun.unlocked", "states.lun.busy"),
"Summon Astoria": (Transform("wheelmenu_astoria", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.ast.busy", None, Jump("summon_astoria")), "states.ast.unlocked"), "Summon Astoria": (Transform("wheelmenu_astoria", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.ast.busy", None, Jump("summon_astoria")), "states.ast.unlocked", "states.ast.busy"),
"Summon Susan": (Transform("wheelmenu_susan", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.sus.busy", None, Jump("summon_susan")), "states.sus.unlocked"), "Summon Susan": (Transform("wheelmenu_susan", align=(0.5, 0.5), xysize=(32, 32)), IfExpr("states.sus.busy", None, Jump("summon_susan")), "states.sus.unlocked", "states.sus.busy"),
"Exit": (Text("🚪", align=(0.5, 0.5)), IfExpr("states.map.unlocked", Jump("map"), Jump("door")), "True"), "Exit": (Text("🚪", align=(0.5, 0.5)), IfExpr("states.map.unlocked", Jump("map"), Jump("door"))),
}, },
tooltip="Door" tooltip="Door"
) )
@ -54,12 +54,12 @@ default desk_OBJ = RoomObject(
hover="ch_gen sit_behind_desk_hover", hover="ch_gen sit_behind_desk_hover",
focus_mask="ch_gen sit_behind_desk", focus_mask="ch_gen sit_behind_desk",
action={ action={
"Sleep": (Text("💤", align=(0.5, 0.5)), IfExpr("states.env.daytime", Jump("night_start"), Jump("day_start")), "True"), "Sleep": (Text("💤", align=(0.5, 0.5)), IfExpr("states.env.daytime", Jump("night_start"), Jump("day_start"))),
"Jerk Off": (Text("🍆", align=(0.5, 0.5)), Jump("jerk_off"), "True"), "Jerk Off": (Text("🍆", align=(0.5, 0.5)), Jump("jerk_off")),
"Do Paperwork": (Text("📝", align=(0.5, 0.5)), Jump("paperwork"), "states.paperwork_unlocked"), "Do Paperwork": (Text("📝", align=(0.5, 0.5)), Jump("paperwork"), "states.paperwork_unlocked"),
"Open Deck Builder": (Text("🃏", align=(0.5, 0.5)), Jump("deck_builder"), "states.cardgame.unlocked"), "Open Deck Builder": (Text("🃏", align=(0.5, 0.5)), Jump("deck_builder"), "states.cardgame.unlocked"),
"Open Cheats Menu": (Text("🕹️", align=(0.5, 0.5)), Jump("cheats"), "states.env.cheats"), "Open Cheats Menu": (Text("🕹️", align=(0.5, 0.5)), Jump("cheats"), "states.env.cheats"),
"Open Achievements Menu": (Text("⭐", align=(0.5, 0.5)), Jump("achievements"), "True"), "Open Achievements Menu": (Text("⭐", align=(0.5, 0.5)), Jump("achievements")),
}, },
hovered=Show( hovered=Show(
"gui_tooltip", "gui_tooltip",