Skip to content

Commit

Permalink
chest window is now screen-size-responsive
Browse files Browse the repository at this point in the history
  • Loading branch information
efroemling committed Jan 23, 2025
1 parent 447d7df commit 81b83dc
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 89 deletions.
48 changes: 24 additions & 24 deletions .efrocachemap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 1.7.37 (build 22243, api 9, 2025-01-23)
### 1.7.37 (build 22245, api 9, 2025-01-23)
- Bumping api version to 9. As you'll see below, there's some UI changes that
will require a bit of work for any UI mods to adapt to. If your mods don't
touch UI stuff at all you can simply bump your api version and call it a day.
Expand Down
2 changes: 1 addition & 1 deletion src/assets/ba_data/python/baenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

# Build number and version of the ballistica binary we expect to be
# using.
TARGET_BALLISTICA_BUILD = 22243
TARGET_BALLISTICA_BUILD = 22245
TARGET_BALLISTICA_VERSION = '1.7.37'


Expand Down
105 changes: 61 additions & 44 deletions src/assets/ba_data/python/bauiv1lib/chest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def __init__(
assert bui.app.classic is not None
uiscale = bui.app.ui_v1.uiscale
self._width = 1200 if uiscale is bui.UIScale.SMALL else 650
self._height = 550 if uiscale is bui.UIScale.SMALL else 450
self._xoffs = 70 if uiscale is bui.UIScale.SMALL else 0
self._yoffs = -50 if uiscale is bui.UIScale.SMALL else -35
self._height = 800 if uiscale is bui.UIScale.SMALL else 450
self._action_in_flight = False
self._open_now_button: bui.Widget | None = None
self._open_now_spinner: bui.Widget | None = None
Expand All @@ -57,23 +55,40 @@ def __init__(
# The set of widgets we keep when doing a clear.
self._core_widgets: list[bui.Widget] = []

# Do some fancy math to fill all available screen area up to the
# size of our backing container. This lets us fit to the exact
# screen shape at small ui scale.
screensize = bui.get_virtual_screen_size()
scale = (
1.8
if uiscale is bui.UIScale.SMALL
else 1.1 if uiscale is bui.UIScale.MEDIUM else 0.9
)
# Calc screen size in our local container space and clamp to a
# bit smaller than our container size.
target_height = min(self._height - 120, screensize[1] / scale)

# To get top/left coords, go to the center of our window and
# offset by half the width/height of our target area.
self._yoffstop = 0.5 * self._height + 0.5 * target_height + 18

# Offset for stuff we want centered.
self._yoffs = 0.5 * self._height + (
220 if uiscale is bui.UIScale.SMALL else 190
)

self._chest_yoffs = self._yoffs - 223

super().__init__(
root_widget=bui.containerwidget(
size=(self._width, self._height),
toolbar_visibility='menu_full',
scale=(
1.8
if uiscale is bui.UIScale.SMALL
else 1.1 if uiscale is bui.UIScale.MEDIUM else 0.9
),
stack_offset=(
(0, 0)
if uiscale is bui.UIScale.SMALL
else (0, 0) if uiscale is bui.UIScale.MEDIUM else (0, 0)
),
scale=scale,
),
transition=transition,
origin_widget=origin_widget,
# We're affected by screen size only at small ui-scale.
refresh_on_screen_size_changes=uiscale is bui.UIScale.SMALL,
)

# Tell the root-ui to stop updating toolbar values immediately;
Expand All @@ -84,14 +99,18 @@ def __init__(

self._title_text = bui.textwidget(
parent=self._root_widget,
position=(0, self._height - 50 + self._yoffs),
size=(self._width, 25),
position=(
self._width * 0.5,
self._yoffstop - (36 if uiscale is bui.UIScale.SMALL else 10),
),
size=(0, 0),
text=bui.Lstr(
resource='chests.slotText',
subs=[('${NUM}', str(index + 1))],
),
color=bui.app.ui_v1.title_color,
maxwidth=150.0,
maxwidth=110.0 if uiscale is bui.UIScale.SMALL else 200,
scale=0.9 if uiscale is bui.UIScale.SMALL else 1.1,
h_align='center',
v_align='center',
)
Expand All @@ -104,7 +123,7 @@ def __init__(
else:
btn = bui.buttonwidget(
parent=self._root_widget,
position=(self._xoffs + 50, self._height - 55 + self._yoffs),
position=(50, self._yoffs - 44),
size=(60, 55),
scale=0.8,
label=bui.charstr(bui.SpecialChar.BACK),
Expand All @@ -127,7 +146,7 @@ def __init__(

self._infotext = bui.textwidget(
parent=self._root_widget,
position=(self._width * 0.5, self._height - 200 + self._yoffs),
position=(self._width * 0.5, self._yoffs - 200),
size=(0, 0),
text='',
maxwidth=700,
Expand Down Expand Up @@ -306,7 +325,8 @@ def _show_chest_actions(
parent=self._root_widget,
position=(
self._width * 0.5 - imgsize * 0.5,
self._height - 223 + self._yoffs,
# self._height - 223 + self._yoffs,
self._chest_yoffs,
),
color=self._chestdisplayinfo.color,
size=(imgsize, imgsize),
Expand All @@ -328,7 +348,8 @@ def _show_chest_actions(
parent=self._root_widget,
position=(
self._width * 0.5 - imgsize * 0.4 - lsize * 0.5,
self._height - 223 + 27.0 + self._yoffs,
# self._height - 223 + 27.0 + self._yoffs,
self._chest_yoffs + 27.0,
),
size=(lsize, lsize),
texture=bui.gettexture('lock'),
Expand All @@ -338,7 +359,11 @@ def _show_chest_actions(
if chest.unlock_tokens != 0:
self._time_string_text = bui.textwidget(
parent=self._root_widget,
position=(self._width * 0.5, self._height - 85 + self._yoffs),
position=(
self._width * 0.5,
# self._height - 85 + self._yoffs
self._yoffs - 85,
),
size=(0, 0),
text='',
maxwidth=700,
Expand Down Expand Up @@ -372,7 +397,7 @@ def _show_chest_actions(
parent=self._root_widget,
position=(
self._width * 0.5 - bwidth * 0.5 + boffsx,
self._height + bposy + self._yoffs,
self._yoffs + bposy,
),
size=(bwidth, bheight),
label='',
Expand All @@ -394,7 +419,7 @@ def _show_chest_actions(
text=bui.Lstr(resource='openText'),
position=(
self._width * 0.5 + boffsx,
self._height + bposy + self._yoffs + bheight * 0.5,
self._yoffs + bposy + bheight * 0.5,
),
color=(0, 1, 0),
draw_controller=self._open_now_button,
Expand All @@ -412,7 +437,7 @@ def _show_chest_actions(
text=bui.Lstr(resource='openNowText'),
position=(
self._width * 0.5 + boffsx,
self._height + bposy + self._yoffs + bheight * 1.15,
self._yoffs + bposy + bheight * 1.15,
),
maxwidth=bwidth * 0.8,
scale=0.7,
Expand All @@ -428,7 +453,7 @@ def _show_chest_actions(
size=(iconsize, iconsize),
position=(
self._width * 0.5 - iconsize * 0.5 + boffsx,
self._height + bposy + self._yoffs + bheight * 0.35,
self._yoffs + bposy + bheight * 0.35,
),
draw_controller=self._open_now_button,
texture=bui.gettexture('coin'),
Expand All @@ -443,7 +468,7 @@ def _show_chest_actions(
),
position=(
self._width * 0.5 + boffsx,
self._height + bposy + self._yoffs + bheight * 0.25,
self._yoffs + bposy + bheight * 0.25,
),
scale=0.65,
color=(0, 1, 0),
Expand All @@ -458,7 +483,7 @@ def _show_chest_actions(
parent=self._root_widget,
position=(
self._width * 0.5 + boffsx,
self._height + bposy + self._yoffs + 0.5 * bheight,
self._yoffs + bposy + 0.5 * bheight,
),
visible=False,
)
Expand All @@ -469,7 +494,7 @@ def _show_chest_actions(
text=bui.Lstr(resource='chests.reduceWaitText'),
position=(
self._width * 0.5 + hspace * 0.5 + bwidth * 0.5,
self._height + bposy + self._yoffs + bheight * 1.15,
self._yoffs + bposy + bheight * 1.15,
),
maxwidth=bwidth * 0.8,
scale=0.7,
Expand All @@ -482,7 +507,7 @@ def _show_chest_actions(
parent=self._root_widget,
position=(
self._width * 0.5 + hspace * 0.5,
self._height + bposy + self._yoffs,
self._yoffs + bposy,
),
size=(bwidth, bheight),
label='',
Expand All @@ -499,7 +524,7 @@ def _show_chest_actions(
+ hspace * 0.5
+ bwidth * 0.5
- iconsize * 0.5,
self._height + bposy + self._yoffs + bheight * 0.35,
self._yoffs + bposy + bheight * 0.35,
),
draw_controller=self._watch_ad_button,
color=(1.5, 1.0, 2.0),
Expand All @@ -512,7 +537,7 @@ def _show_chest_actions(
text=bui.Lstr(resource='watchAnAdText'),
position=(
self._width * 0.5 + hspace * 0.5 + bwidth * 0.5,
self._height + bposy + self._yoffs + bheight * 0.25,
self._yoffs + bposy + bheight * 0.25,
),
scale=0.65,
color=(0, 1, 0),
Expand Down Expand Up @@ -561,7 +586,7 @@ def _show_odds(
rowheight = 25
totalheight = (len(self._prizesets) + 1) * rowheight
x = self._width * 0.5 + xoffs
y = self._height + self._yoffs - 150.0 + totalheight * 0.5
y = self._yoffs - 150.0 + totalheight * 0.5

# Title.
bui.textwidget(
Expand Down Expand Up @@ -852,11 +877,7 @@ def _set_img(x: float, scale: float) -> None:
edit=img,
position=(
self._width * 0.5 - imgsize * scale * 0.5 + x,
self._height
- 223
+ self._yoffs
+ imgsize * 0.5
- imgsize * scale * 0.5,
self._yoffs - 223 + imgsize * 0.5 - imgsize * scale * 0.5,
),
size=(imgsize * scale, imgsize * scale),
)
Expand Down Expand Up @@ -934,7 +955,7 @@ def _set_img(x: float, scale: float) -> None:
self._root_widget,
pos=(
self._width * 0.5 + xoffs,
self._height - 250.0 + self._yoffs,
self._yoffs - 250.0,
),
width=width,
),
Expand Down Expand Up @@ -995,11 +1016,7 @@ def _set_img(x: float, scale: float) -> None:
edit=img,
position=(
self._width * 0.5 - imgsize * scale * 0.5 + x,
self._height
- 223
+ self._yoffs
+ imgsize * 0.5
- imgsize * scale * 0.5,
self._yoffs - 223 + imgsize * 0.5 - imgsize * scale * 0.5,
),
size=(imgsize * scale, imgsize * scale),
)
Expand Down Expand Up @@ -1047,7 +1064,7 @@ def _show_done_button(self) -> None:
parent=self._root_widget,
position=(
self._width * 0.5 - bwidth * 0.5,
self._height - 350 + self._yoffs,
self._yoffs - 350,
),
size=(bwidth, bheight),
label=bui.Lstr(resource='doneText'),
Expand Down
Loading

0 comments on commit 81b83dc

Please sign in to comment.