House Points and Currencies

* Added common style properties for houses
* Added unique displayable for gold when in the main room
* Unified currency screen to support arbitrary displayables and properties.
* Unified transforms
* Put interface elements onto interface layer
* Hooked house points into the new currency screen
* Improved animation and display of values during animation.
* Allow independent animation of each supplied displayable
* Remove redundant code
This commit is contained in:
LoafyLemon 2024-04-27 18:12:13 +01:00
parent 7069cc1294
commit df724981d2
4 changed files with 76 additions and 46 deletions

View File

@ -123,6 +123,18 @@ transform pulse_hover(t=2.0, strength=0.2, pause=0.0):
pause pause pause pause
repeat repeat
transform smooth_swipe(start_yoffset=0, target_yoffset=-50):
subpixel True
alpha 0.0
yoffset start_yoffset
parallel:
easeout 0.5 alpha 1.0
parallel:
easein 4.0 yoffset target_yoffset
parallel:
pause 2.5
easein 1.5 alpha 0.0
transform gui_animation: transform gui_animation:
nearest True nearest True
events False events False

View File

@ -12,8 +12,8 @@ init python:
return d, 0.01 return d, 0.01
screen currency(old, new, prefix): screen currency(old, new, prefix):
tag gold tag currency
zorder 50 layer "interface"
default d = DynamicDisplayable(animate_int_value, old, new, prefix) default d = DynamicDisplayable(animate_int_value, old, new, prefix)
@ -27,3 +27,20 @@ screen currency(old, new, prefix):
add d yoffset 3 add d yoffset 3
timer 3.0 action Hide("currency") timer 3.0 action Hide("currency")
screen currency_alt(displayables, properties):
tag currency_alt
layer "interface"
hbox:
properties properties
for d in displayables:
add d
timer 4.0 action Hide("currency")
style currency_alt_text:
outlines [(2, "#000000", 0, 0)]
size 24
color "#daa520"

View File

@ -35,38 +35,3 @@ init python:
points[house] = renpy.random.randint(point // 2, point) + house_points[house] points[house] = renpy.random.randint(point // 2, point) + house_points[house]
states.env.set_points(points) states.env.set_points(points)
screen house_points(gryffindor=None, slytherin=None, ravenclaw=None, hufflepuff=None, prefix="+", direction="up"):
tag house_points
layer "interface"
hbox:
spacing 15
align (0.5, 0.1)
if direction == "up":
at transform:
on start:
alpha 0.0
on show:
alpha 1.0
yoffset 0
easein 4.0 yoffset -50 alpha 0.0
else:
at transform:
on start:
alpha 0.0
on show:
alpha 1.0
yoffset -50
easein 4.0 yoffset 0 alpha 0.0
if gryffindor:
text "[prefix][gryffindor]" outlines [(1, "#000000BF", 1, 0)] size 24 color "#A74D2A"
if slytherin:
text "[prefix][slytherin]" outlines [(1, "#000000BF", 1, 0)] size 24 color "#3A734B"
if ravenclaw:
text "[prefix][ravenclaw]" outlines [(1, "#000000BF", 1, 0)] size 24 color "#5974C2"
if hufflepuff:
text "[prefix][hufflepuff]" outlines [(1, "#000000BF", 1, 0)] size 24 color "#FBC60A"
timer 4.0 action Hide("house_points")

View File

@ -48,6 +48,28 @@ init python:
self.difficulty = 2 self.difficulty = 2
self.cheats = False self.cheats = False
self.moon = True self.moon = True
self.houses = {
"gryffindor": {
"properties": {
"color": "#A74D2A",
}
},
"slytherin": {
"properties": {
"color": "#3A734B",
}
},
"ravenclaw": {
"properties": {
"color": "#5974C2",
}
},
"hufflepuff": {
"properties": {
"color": "#FBC60A",
}
}
}
# Currencies # Currencies
@property @property
@ -56,12 +78,25 @@ init python:
@gold.setter @gold.setter
def gold(self, value): def gold(self, value):
old = self._gold old_value = self._gold
properties = {"pos": (70, 370)}
if (adjusted := value - old_value) < 0:
displayables = (Text(f"-{adjusted}{{color=#FF0000}}{{size=-12}}{{unicode}} ▼{{/unicode}}{{/size}}{{/color}}", style="currency_alt_text"),)
properties["at"] = smooth_swipe(-50, 0)
else:
displayables = (Text(f"+{adjusted}{{color=#00FF00}}{{size=-12}}{{unicode}} ▲{{/unicode}}{{/size}}{{/color}}", style="currency_alt_text"),)
properties["at"] = smooth_swipe(0, -50)
self._gold = max(0, min(value, 99999)) self._gold = max(0, min(value, 99999))
if not renpy.in_rollback() and not _in_replay: if not renpy.in_rollback() and not _in_replay:
renpy.hide_screen("currency") renpy.hide_screen("currency")
renpy.show_screen("currency", old, self._gold, "💰") renpy.show_screen("currency", old_value, value, "💰")
if states.room == "main_room":
renpy.hide_screen("currency_alt")
renpy.show_screen("currency_alt", displayables, properties)
@property @property
def tokens(self): def tokens(self):
@ -96,22 +131,23 @@ init python:
# House Points # House Points
def set_points(self, d): def set_points(self, d):
properties = {"spacing": 15, "align": (0.5, 0.1)}
displayables = []
difference = {} difference = {}
for house, value in d.items(): for house, value in d.items():
old_value = self._points[house] old_value = self._points[house]
if (adjusted := value - old_value) < 0: if (adjusted := value - old_value) < 0:
prefix = "-" disp = At(Text(f"-{adjusted}{{color=#FF0000}}{{size=-12}}{{unicode}} ▼{{/unicode}}{{/size}}{{/color}}", style="currency_alt_text", **self.houses[house]["properties"]), smooth_swipe(-50, 0))
direction = "down"
else: else:
prefix = "+" disp = At(Text(f"+{adjusted}{{color=#00FF00}}{{size=-12}}{{unicode}} ▲{{/unicode}}{{/size}}{{/color}}", style="currency_alt_text", **self.houses[house]["properties"]), smooth_swipe(0, -50))
direction = "up" displayables.append(disp)
value = min(max(1, value), 99999) value = min(max(1, value), 99999)
self._points[house] = value self._points[house] = value
difference[house] = adjusted difference[house] = adjusted
if not renpy.in_rollback() and not _in_replay: if not renpy.in_rollback() and not _in_replay:
renpy.hide_screen("house_points") renpy.hide_screen("currency_alt")
renpy.show_screen("house_points", prefix=prefix, direction=direction, **difference) renpy.show_screen("currency_alt", displayables, properties)
@property @property
def gryffindor(self): def gryffindor(self):