diff --git a/export_presets.cfg b/export_presets.cfg index e549a7b..0e43412 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -33,8 +33,8 @@ architectures/armeabi-v7a=false architectures/arm64-v8a=true architectures/x86=false architectures/x86_64=false -version/code=2 -version/name="1.1.2" +version/code=3 +version/name="1.1.3" package/unique_name="org.bulwark.game" package/name="Bulwark" package/signed=true diff --git a/project.godot b/project.godot index 995e140..bea268a 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 config/name="Bulwark" config/description="A minimalist tower defense. Hold the line." -config/version="1.1.2" +config/version="1.1.3" run/main_scene="res://scenes/main_menu.tscn" config/features=PackedStringArray("4.7", "GL Compatibility") config/icon="res://assets/icons/icon.png" diff --git a/src/game/enemy.gd b/src/game/enemy.gd index f2879b9..0e3a293 100644 --- a/src/game/enemy.gd +++ b/src/game/enemy.gd @@ -10,7 +10,6 @@ signal died(enemy: Enemy) signal leaked(enemy: Enemy) const SPRITE_DIR := "res://assets/sprites/enemies/" -const SPRITE_ANGLE_OFFSET := PI * 0.5 var def: Dictionary = {} var enemy_id: String = "" @@ -72,6 +71,10 @@ func setup(p_def: Dictionary, p_hp: float, p_speed: float, p_armor: float, var path_sprite := SPRITE_DIR + String(p_def.get("sprite", "grunt")) + ".png" if ResourceLoader.exists(path_sprite): _sprite.texture = load(path_sprite) + # Centre the sprite on the unit so rotating it spins around its own centre (the pivot is + # the node origin), not around a corner of the texture. + if _sprite.texture != null: + _sprite.offset = -_sprite.texture.get_size() * 0.5 _sprite.scale = Vector2(scale_factor, scale_factor) _sprite.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS add_child(_sprite) @@ -141,10 +144,13 @@ func _update_transform() -> void: position += Vector2(0, -6) else: position = base + _lane_offset - # Every sprite is drawn facing "up", so a quarter turn aligns it with the direction of - # travel. Ground units used to keep rotation 0 and always faced the top of the screen; they - # now turn at every bend like the fliers already did. - rotation = dir.angle() + SPRITE_ANGLE_OFFSET + # Sprites are drawn facing "right", so aiming the sprite along the direction of travel + # needs no extra offset. Only the sprite child is rotated: the enemy node itself stays + # unrotated so the health bar drawn above it stays horizontal (top of the screen), and + # ground units turn at every bend exactly like the fliers. + rotation = 0.0 + if _sprite != null: + _sprite.rotation = dir.angle() # --- Combat ------------------------------------------------------------------------------------- diff --git a/src/game/game_screen.gd b/src/game/game_screen.gd index 3a3522d..940e663 100644 --- a/src/game/game_screen.gd +++ b/src/game/game_screen.gd @@ -29,6 +29,7 @@ var lives_max: int = 0 var gold_earned: int = 0 var _board_root: Node2D +var _board_bg: ColorRect var _board: Board var _entities: Node2D var _projectile_layer: Node2D @@ -92,6 +93,16 @@ func _build_world() -> void: ground_path = PathModel.from_cells(level.get("path", []), grid.cell_size) air_path = _build_air_path(level.get("path", [])) + # Full-screen board-toned backdrop. On a phone the board is scaled to fill the screen, so + # this paints the areas outside the grid with the board's own background colour instead of + # the app background — the playfield reads as one continuous field. Hidden on desktop, where + # the board sits inset on the app background. + _board_bg = ColorRect.new() + _board_bg.color = Palette.BOARD_BG + _board_bg.mouse_filter = Control.MOUSE_FILTER_IGNORE + _board_bg.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) + add_child(_board_bg) + _board_root = Node2D.new() add_child(_board_root) @@ -175,15 +186,15 @@ func _apply_starting_state() -> void: ## Phones (and small windows) get the board at the full screen with the HUD floating on top of ## it; desktop keeps the inset layout with the HUD living in the reserved margins. func _compact_viewport() -> bool: - if OS.has_feature("mobile"): - return true - return size.x < 900.0 or size.y < 560.0 + return UIKit.is_compact() func _layout() -> void: if _board_root == null: return var compact := _compact_viewport() + if _board_bg != null: + _board_bg.visible = compact var margin_side := COMPACT_INSET if compact else BOARD_MARGIN_SIDE var margin_top := COMPACT_INSET if compact else BOARD_MARGIN_TOP var margin_bottom := COMPACT_INSET if compact else BOARD_MARGIN_BOTTOM diff --git a/src/ui/ability_button.gd b/src/ui/ability_button.gd index e80b720..31cae02 100644 --- a/src/ui/ability_button.gd +++ b/src/ui/ability_button.gd @@ -17,7 +17,8 @@ var _cooldown := 0.0 func setup(def: Dictionary) -> void: ability_id = String(def.get("id", "")) _cooldown = maxf(0.1, float(def.get("cooldown", 30.0))) - custom_minimum_size = Vector2(64, 64) + var compact := UIKit.is_compact() + custom_minimum_size = Vector2(64, 64) if not compact else Vector2(80, 80) focus_mode = Control.FOCUS_ALL theme_type_variation = "IconButton" _color = Palette.element_color(String(def.get("color", "energy"))) @@ -30,7 +31,7 @@ func setup(def: Dictionary) -> void: center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) center.mouse_filter = Control.MOUSE_FILTER_IGNORE add_child(center) - _glyph = Glyph.of(String(def.get("icon", "bolt")), 26, _color) + _glyph = Glyph.of(String(def.get("icon", "bolt")), 26 if not compact else 34, _color) center.add_child(_glyph) _mask = CooldownMask.new() diff --git a/src/ui/build_button.gd b/src/ui/build_button.gd index 351a885..45600ac 100644 --- a/src/ui/build_button.gd +++ b/src/ui/build_button.gd @@ -17,7 +17,8 @@ var _border: StyleBoxFlat func setup(id: String, def: Dictionary) -> void: tower_id = id cost = int(def.get("cost", 0)) - custom_minimum_size = Vector2(74, 82) + var compact := UIKit.is_compact() + custom_minimum_size = Vector2(74, 82) if not compact else Vector2(96, 104) focus_mode = Control.FOCUS_ALL theme_type_variation = "IconButton" tooltip_text = "%s\n%s\n%s %d" % [ @@ -33,7 +34,7 @@ func setup(id: String, def: Dictionary) -> void: add_child(column) _sprite = TextureRect.new() - _sprite.custom_minimum_size = Vector2(0, 46) + _sprite.custom_minimum_size = Vector2(0, 46 if not compact else 60) _sprite.expand_mode = TextureRect.EXPAND_IGNORE_SIZE _sprite.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED _sprite.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS @@ -47,9 +48,11 @@ func setup(id: String, def: Dictionary) -> void: price_row.alignment = BoxContainer.ALIGNMENT_CENTER price_row.add_theme_constant_override("separation", 3) price_row.mouse_filter = Control.MOUSE_FILTER_IGNORE - _coin = Glyph.of("coin", 12, Palette.GOLD) + _coin = Glyph.of("coin", 12 if not compact else 15, Palette.GOLD) price_row.add_child(_coin) _cost_label = UIKit.label(str(cost), "SmallLabel") + if compact: + _cost_label.add_theme_font_size_override("font_size", 16) price_row.add_child(_cost_label) column.add_child(price_row) diff --git a/src/ui/credits_screen.gd b/src/ui/credits_screen.gd index d46fe3c..3de778c 100644 --- a/src/ui/credits_screen.gd +++ b/src/ui/credits_screen.gd @@ -13,6 +13,7 @@ const ENTRIES := [ func _build() -> void: Audio.play_music("calm") + var compact := UIKit.is_compact() var column := UIKit.vbox(14) column.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) @@ -21,7 +22,7 @@ func _build() -> void: var header := UIKit.hbox(12) header.add_child(UIKit.icon_button("back", Palette.TEXT, func() -> void: Audio.play_sfx("ui_back", -6.0) - App.pop_scene(), 44)) + App.pop_scene(), 44 if not compact else 52)) header.add_child(UIKit.label(Loc.t("credits.title"), "TitleLabel")) column.add_child(header) @@ -37,11 +38,20 @@ func _build() -> void: for entry in ENTRIES: var card := UIKit.panel("InsetPanel") var inner := UIKit.card_body(card, 2) - inner.add_child(UIKit.label(Loc.t(String(entry["label"])), "TinyLabel")) - inner.add_child(UIKit.wrapped(String(entry["value"]), "SmallLabel", 720)) + var label := UIKit.label(Loc.t(String(entry["label"])), "TinyLabel") + if compact: + label.add_theme_font_size_override("font_size", 14) + inner.add_child(label) + var value := UIKit.wrapped(String(entry["value"]), "SmallLabel", 720) + if compact: + value.add_theme_font_size_override("font_size", 16) + inner.add_child(value) body.add_child(card) - body.add_child(UIKit.label(Loc.t("credits.made_with"), "TinyLabel")) + var made := UIKit.label(Loc.t("credits.made_with"), "TinyLabel") + if compact: + made.add_theme_font_size_override("font_size", 14) + body.add_child(made) func on_back() -> void: diff --git a/src/ui/hud.gd b/src/ui/hud.gd index d3739b0..d927801 100644 --- a/src/ui/hud.gd +++ b/src/ui/hud.gd @@ -22,6 +22,7 @@ signal module_pressed(module_id: String) signal panel_closed() const CHIP_HEIGHT := 40.0 +const CHIP_HEIGHT_COMPACT := 52.0 var _lives_label: Label var _gold_label: Label @@ -46,11 +47,13 @@ var _ability_buttons: Dictionary = {} var _bottom_slot: HBoxContainer var _selected_tower_id := "" var _wave_total: int = 1 +var _compact := false func _ready() -> void: set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) mouse_filter = Control.MOUSE_FILTER_IGNORE + _compact = UIKit.is_compact() _build() @@ -79,16 +82,24 @@ func _build_top_bar() -> Control: _wave_label = _chip(row, "wave", Palette.ACCENT) row.add_child(UIKit.spacer(true)) _speed_button = UIKit.button("1×", "ChipButton", func() -> void: speed_pressed.emit()) - _speed_button.custom_minimum_size = Vector2(58, CHIP_HEIGHT) + _speed_button.custom_minimum_size = Vector2(58 if not _compact else 70, _chip_height()) row.add_child(_speed_button) # Visible only while a tower is armed for placement, so the player has an explicit way out # (a "cancel zone") without tapping the armed build button again. _cancel_button = UIKit.button(Loc.t("common.cancel"), "ChipButton", func() -> void: cancel_pressed.emit()) - _cancel_button.custom_minimum_size = Vector2(96, CHIP_HEIGHT) + _cancel_button.custom_minimum_size = Vector2(96 if not _compact else 116, _chip_height()) _cancel_button.visible = false row.add_child(_cancel_button) - row.add_child(UIKit.icon_button("pause", Palette.TEXT, func() -> void: pause_pressed.emit(), CHIP_HEIGHT)) + # On a phone the ability bar moves up here: the bottom strip stays narrow so the board + # underneath is as free as possible, and abilities sit with the other always-visible + # controls where the right thumb reaches them easily. + if _compact: + _ability_row = UIKit.hbox(8) + _ability_row.mouse_filter = Control.MOUSE_FILTER_IGNORE + row.add_child(_ability_row) + row.add_child(UIKit.icon_button("pause", Palette.TEXT, func() -> void: pause_pressed.emit(), + _chip_height())) return row @@ -107,6 +118,9 @@ func _build_bottom_bar() -> Control: text_box.mouse_filter = Control.MOUSE_FILTER_IGNORE _status_label = UIKit.label("", "HeadingLabel") _status_hint = UIKit.label("", "TinyLabel") + if _compact: + _status_label.add_theme_font_size_override("font_size", 22) + _status_hint.add_theme_font_size_override("font_size", 14) text_box.add_child(_status_label) text_box.add_child(_status_hint) status_box.add_child(text_box) @@ -116,7 +130,8 @@ func _build_bottom_bar() -> Control: status_box.add_child(_preview_row) _call_button = UIKit.button(Loc.t("game.call_now"), "PrimaryButton", func() -> void: call_wave_pressed.emit()) - _call_button.custom_minimum_size = Vector2(196, 42) + _call_button.custom_minimum_size = Vector2(196 if not _compact else 240, + 42 if not _compact else 54) status_box.add_child(_call_button) var status_wrapper := UIKit.hbox(0) status_wrapper.mouse_filter = Control.MOUSE_FILTER_IGNORE @@ -141,14 +156,20 @@ func _build_bottom_bar() -> Control: _tower_panel.closed.connect(func() -> void: panel_closed.emit()) _bottom_slot.add_child(_tower_panel) - _bottom_slot.add_child(UIKit.spacer(true)) - _ability_row = UIKit.hbox(8) - _ability_row.mouse_filter = Control.MOUSE_FILTER_IGNORE - _bottom_slot.add_child(_ability_row) + if not _compact: + _bottom_slot.add_child(UIKit.spacer(true)) + _ability_row = UIKit.hbox(8) + _ability_row.mouse_filter = Control.MOUSE_FILTER_IGNORE + _bottom_slot.add_child(_ability_row) column.add_child(_bottom_slot) return column +## Height of the status chips; larger on compact screens so they stay finger-tappable. +func _chip_height() -> float: + return CHIP_HEIGHT_COMPACT if _compact else CHIP_HEIGHT + + func _build_toast() -> void: _toast = UIKit.panel("HudPanel") _toast.set_anchors_preset(Control.PRESET_CENTER_TOP) @@ -172,12 +193,13 @@ func _margin(child: Control, left: int, top: int, right: int, bottom: int) -> Ma func _chip(row: HBoxContainer, glyph: String, color: Color) -> Label: var panel := UIKit.panel("HudPanel") panel.mouse_filter = Control.MOUSE_FILTER_IGNORE + panel.custom_minimum_size.y = _chip_height() var box := UIKit.hbox(6) box.mouse_filter = Control.MOUSE_FILTER_IGNORE panel.add_child(box) - box.add_child(Glyph.of(glyph, 17, color)) + box.add_child(Glyph.of(glyph, 17 if not _compact else 21, color)) var value := UIKit.label("0", "NumberLabel") - value.add_theme_font_size_override("font_size", 18) + value.add_theme_font_size_override("font_size", 18 if not _compact else 22) box.add_child(value) row.add_child(panel) return value diff --git a/src/ui/level_select.gd b/src/ui/level_select.gd index e007d62..31f44a6 100644 --- a/src/ui/level_select.gd +++ b/src/ui/level_select.gd @@ -5,16 +5,20 @@ extends Screen ## row on a phone — so six missions stay readable without a horizontal scroll. const CARD_WIDTH := 280.0 +const CARD_WIDTH_COMPACT := 340.0 +const CARD_HEIGHT := 210.0 +const CARD_HEIGHT_COMPACT := 250.0 func _build() -> void: Audio.play_music("calm") + var compact := UIKit.is_compact() var column := UIKit.vbox(16) column.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) add_content(column) - column.add_child(_build_header()) + column.add_child(_build_header(compact)) var scroll := ScrollContainer.new() scroll.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED @@ -32,15 +36,15 @@ func _build() -> void: row.add_child(_build_card(index)) -func _build_header() -> Control: +func _build_header(compact: bool) -> Control: var row := UIKit.hbox(12) row.add_child(UIKit.icon_button("back", Palette.TEXT, func() -> void: Audio.play_sfx("ui_back", -6.0) - App.goto_scene(App.MENU_SCENE), 44)) + App.goto_scene(App.MENU_SCENE), 44 if not compact else 52)) row.add_child(UIKit.label(Loc.t("menu.levels"), "TitleLabel")) row.add_child(UIKit.spacer(true)) var stars := UIKit.hbox(6) - stars.add_child(Glyph.of("star", 18, Palette.GOLD)) + stars.add_child(Glyph.of("star", 18 if not compact else 22, Palette.GOLD)) stars.add_child(UIKit.label(str(App.total_stars()), "GoldLabel")) row.add_child(stars) return row @@ -53,28 +57,40 @@ func _build_card(index: int) -> Control: var unlocked := App.is_level_unlocked(index) var cleared := bool(progress.get("cleared", false)) var stars := int(progress.get("stars", 0)) + var compact := UIKit.is_compact() + var card_width := CARD_WIDTH_COMPACT if compact else CARD_WIDTH var card := UIKit.panel("CardPanel") - card.custom_minimum_size = Vector2(CARD_WIDTH, 210) + card.custom_minimum_size = Vector2(card_width, CARD_HEIGHT_COMPACT if compact else CARD_HEIGHT) card.size_flags_vertical = Control.SIZE_SHRINK_CENTER var body := UIKit.card_body(card, 10) var title_row := UIKit.hbox(8) - title_row.add_child(UIKit.label(Loc.t(String(level.get("name_key", ""))), "HeadingLabel")) + var title := UIKit.label(Loc.t(String(level.get("name_key", ""))), "HeadingLabel") + if compact: + title.add_theme_font_size_override("font_size", 22) + title_row.add_child(title) title_row.add_child(UIKit.spacer(true)) title_row.add_child(UIKit.label("%d" % (index + 1), "NumberLabel")) body.add_child(title_row) - body.add_child(UIKit.wrapped(Loc.t(String(level.get("desc_key", ""))), "SmallLabel", - CARD_WIDTH - 40)) + var desc := UIKit.wrapped(Loc.t(String(level.get("desc_key", ""))), "SmallLabel", + card_width - 40) + if compact: + desc.add_theme_font_size_override("font_size", 16) + body.add_child(desc) var star_row := UIKit.hbox(4) for i in range(3): - star_row.add_child(Glyph.of("star", 18, Palette.GOLD if i < stars else Palette.TEXT_DIM)) + star_row.add_child(Glyph.of("star", 18 if not compact else 22, + Palette.GOLD if i < stars else Palette.TEXT_DIM)) body.add_child(star_row) - body.add_child(UIKit.label( - Loc.tf("level.progress", [int(progress.get("best_wave", 0))]), "TinyLabel")) + var progress_label := UIKit.label( + Loc.tf("level.progress", [int(progress.get("best_wave", 0))]), "TinyLabel") + if compact: + progress_label.add_theme_font_size_override("font_size", 14) + body.add_child(progress_label) body.add_child(UIKit.spacer(false, true)) if not unlocked: diff --git a/src/ui/main_menu.gd b/src/ui/main_menu.gd index 9f67fba..45bcc1c 100644 --- a/src/ui/main_menu.gd +++ b/src/ui/main_menu.gd @@ -5,6 +5,7 @@ extends Screen func _build() -> void: Audio.play_music("calm") add_child(MenuBackdrop.new()) + var compact := UIKit.is_compact() var center := CenterContainer.new() center.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) @@ -16,7 +17,7 @@ func _build() -> void: center.add_child(column) var title := UIKit.label(Loc.t("app.title"), "DisplayLabel") - title.add_theme_font_size_override("font_size", 64) + title.add_theme_font_size_override("font_size", 64 if not compact else 72) title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER column.add_child(title) @@ -27,8 +28,8 @@ func _build() -> void: column.add_child(UIKit.spacer(false, true)) var play := UIKit.button(_play_label(), "PrimaryButton", _on_play) - play.custom_minimum_size.y = 54 - play.add_theme_font_size_override("font_size", 19) + play.custom_minimum_size.y = 54 if not compact else 66 + play.add_theme_font_size_override("font_size", 19 if not compact else 23) column.add_child(play) column.add_child(UIKit.button(Loc.t("menu.levels"), "", func() -> void: diff --git a/src/ui/overlay.gd b/src/ui/overlay.gd index 2c84b7d..d25bb0b 100644 --- a/src/ui/overlay.gd +++ b/src/ui/overlay.gd @@ -13,6 +13,7 @@ var _buttons: HBoxContainer var _title: Label var _subtitle: Label var _stars: HBoxContainer +var _compact := false static func open(parent: Node, title: String, subtitle: String = "") -> Overlay: @@ -26,6 +27,7 @@ func build(title: String, subtitle: String) -> void: process_mode = Node.PROCESS_MODE_ALWAYS set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) theme = ThemeFactory.get_theme() + _compact = UIKit.is_compact() var dim := ColorRect.new() dim.color = Color(0.03, 0.04, 0.05, 0.72) @@ -39,16 +41,20 @@ func build(title: String, subtitle: String) -> void: add_child(center) _card = UIKit.panel("OverlayPanel") - _card.custom_minimum_size = Vector2(420, 0) + _card.custom_minimum_size = Vector2(420 if not _compact else 580, 0) center.add_child(_card) var column := UIKit.card_body(_card, 14) - column.custom_minimum_size.x = 380 + column.custom_minimum_size.x = 380 if not _compact else 520 _title = UIKit.label(title, "TitleLabel") _title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + if _compact: + _title.add_theme_font_size_override("font_size", 30) column.add_child(_title) - _subtitle = UIKit.wrapped(subtitle, "SmallLabel", 360) + _subtitle = UIKit.wrapped(subtitle, "SmallLabel", 360 if not _compact else 500) _subtitle.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER + if _compact: + _subtitle.add_theme_font_size_override("font_size", 16) column.add_child(_subtitle) _stars = UIKit.hbox(6) @@ -65,7 +71,7 @@ func build(title: String, subtitle: String) -> void: # Animate in unless the player asked for less motion. if not bool(App.get_setting("reduce_motion")): _card.scale = Vector2(0.94, 0.94) - _card.pivot_offset = Vector2(190, 0) + _card.pivot_offset = Vector2(190 if not _compact else 260, 0) var tween := create_tween() tween.tween_property(_card, "scale", Vector2.ONE, 0.16).set_ease(Tween.EASE_OUT) modulate = Color(1, 1, 1, 0) @@ -80,7 +86,10 @@ func add_button(text: String, variation: String, callback: Callable) -> Button: var button := UIKit.button(text, variation, func() -> void: Audio.play_sfx("ui_click", -4.0) callback.call()) - button.custom_minimum_size = Vector2(140, 46) + button.custom_minimum_size = Vector2(140 if not _compact else 180, + 46 if not _compact else 58) + if _compact: + button.add_theme_font_size_override("font_size", 17) _buttons.add_child(button) return button @@ -88,10 +97,16 @@ func add_button(text: String, variation: String, callback: Callable) -> Button: func add_row(icon_name: String, label_text: String, value_text: String, color: Color = Palette.TEXT) -> void: var row := UIKit.hbox(8) - row.add_child(Glyph.of(icon_name, 16, color)) - row.add_child(UIKit.label(label_text, "SmallLabel")) + row.add_child(Glyph.of(icon_name, 16 if not _compact else 20, color)) + var label := UIKit.label(label_text, "SmallLabel") + if _compact: + label.add_theme_font_size_override("font_size", 16) + row.add_child(label) row.add_child(UIKit.spacer(true)) - row.add_child(UIKit.label(value_text, "HeadingLabel")) + var value := UIKit.label(value_text, "HeadingLabel") + if _compact: + value.add_theme_font_size_override("font_size", 20) + row.add_child(value) _body.add_child(row) @@ -101,7 +116,8 @@ func show_stars(count: int, maximum: int = 3) -> void: child.queue_free() for i in range(maximum): var filled := i < count - _stars.add_child(Glyph.of("star", 30, Palette.GOLD if filled else Palette.TEXT_DIM)) + _stars.add_child(Glyph.of("star", 30 if not _compact else 40, + Palette.GOLD if filled else Palette.TEXT_DIM)) func focus_default() -> void: diff --git a/src/ui/settings_panel.gd b/src/ui/settings_panel.gd index 91ed54b..d5757b3 100644 --- a/src/ui/settings_panel.gd +++ b/src/ui/settings_panel.gd @@ -22,6 +22,8 @@ signal layout_changed() ## Minimum panel width before the sections split into two columns. const TWO_COLUMN_MIN_WIDTH := 760.0 +var _compact := false + var _shake_slider: ValueSlider var _shake_value: Label var _body: Control @@ -30,6 +32,7 @@ var _columns := 1 func _ready() -> void: add_theme_constant_override("separation", 16) + _compact = UIKit.is_compact() _build() @@ -86,9 +89,17 @@ func _layout_sections() -> void: # --- Sections ------------------------------------------------------------------------------------ +## Section heading; larger on compact screens to match the enlarged rows. +func _heading(text: String) -> Label: + var label := UIKit.label(text, "HeadingLabel") + if _compact: + label.add_theme_font_size_override("font_size", 22) + return label + + func _audio_section() -> VBoxContainer: var box := _section_box() - box.add_child(UIKit.label(Loc.t("settings.audio"), "HeadingLabel")) + box.add_child(_heading(Loc.t("settings.audio"))) _slider_row(box, "sound", "settings.master", "master_volume") _slider_row(box, "music", "settings.music", "music_volume") _slider_row(box, "bolt", "settings.sfx", "sfx_volume") @@ -97,7 +108,7 @@ func _audio_section() -> VBoxContainer: func _gameplay_section() -> VBoxContainer: var box := _section_box() - box.add_child(UIKit.label(Loc.t("settings.gameplay"), "HeadingLabel")) + box.add_child(_heading(Loc.t("settings.gameplay"))) _choice_row(box, "settings.difficulty", _difficulty_options(), App.difficulty(), func(index: int) -> void: App.set_setting("difficulty", index)) _choice_row(box, "settings.language", _language_options(), @@ -108,7 +119,7 @@ func _gameplay_section() -> VBoxContainer: func _accessibility_section() -> VBoxContainer: var box := _section_box() - box.add_child(UIKit.label(Loc.t("settings.accessibility"), "HeadingLabel")) + box.add_child(_heading(Loc.t("settings.accessibility"))) _toggle_row(box, "grid", "settings.grid_overlay", "grid_overlay") _toggle_row(box, "target", "settings.damage_numbers", "damage_numbers") _toggle_row(box, "reset", "settings.reduce_motion", "reduce_motion") @@ -119,7 +130,7 @@ func _accessibility_section() -> VBoxContainer: func _licence_section() -> VBoxContainer: var box := _section_box() - box.add_child(UIKit.label(Loc.t("credits.license"), "HeadingLabel")) + box.add_child(_heading(Loc.t("credits.license"))) _button_row(box, "settings.reset_progress", "DangerButton", _confirm_reset) return box @@ -134,9 +145,11 @@ func _section_box() -> VBoxContainer: func _slider_row(parent: Control, icon_name: String, label_key: String, setting_key: String) -> void: var row := UIKit.hbox(10) - row.add_child(Glyph.of(icon_name, 18, Palette.TEXT_MUTED)) + row.add_child(Glyph.of(icon_name, 18 if not _compact else 22, Palette.TEXT_MUTED)) var label := UIKit.label(Loc.t(label_key), "SmallLabel") - label.custom_minimum_size.x = 150 + label.custom_minimum_size.x = 150 if not _compact else 170 + if _compact: + label.add_theme_font_size_override("font_size", 16) row.add_child(label) var slider := ValueSlider.new() slider.value = float(App.get_setting(setting_key)) @@ -150,8 +163,10 @@ func _slider_row(parent: Control, icon_name: String, label_key: String, setting_ func _toggle_row(parent: Control, icon_name: String, label_key: String, setting_key: String) -> void: var row := UIKit.hbox(10) - row.add_child(Glyph.of(icon_name, 18, Palette.TEXT_MUTED)) + row.add_child(Glyph.of(icon_name, 18 if not _compact else 22, Palette.TEXT_MUTED)) var label := UIKit.label(Loc.t(label_key), "SmallLabel") + if _compact: + label.add_theme_font_size_override("font_size", 16) label.size_flags_horizontal = Control.SIZE_EXPAND_FILL row.add_child(label) var toggle := ToggleSwitch.new() @@ -163,9 +178,11 @@ func _toggle_row(parent: Control, icon_name: String, label_key: String, setting_ func _shake_row(parent: Control) -> void: var row := UIKit.hbox(10) - row.add_child(Glyph.of("star", 18, Palette.TEXT_MUTED)) + row.add_child(Glyph.of("star", 18 if not _compact else 22, Palette.TEXT_MUTED)) var label := UIKit.label(Loc.t("settings.screen_shake"), "SmallLabel") - label.custom_minimum_size.x = 150 + label.custom_minimum_size.x = 150 if not _compact else 170 + if _compact: + label.add_theme_font_size_override("font_size", 16) row.add_child(label) _shake_slider = ValueSlider.new() _shake_slider.value = float(App.get_setting("screen_shake")) @@ -184,11 +201,19 @@ func _choice_row(parent: Control, label_key: String, options: Array[String], sel on_select: Callable) -> void: var column := VBoxContainer.new() column.add_theme_constant_override("separation", 6) - column.add_child(UIKit.label(Loc.t(label_key), "SmallLabel")) + var label := UIKit.label(Loc.t(label_key), "SmallLabel") + if _compact: + label.add_theme_font_size_override("font_size", 16) + column.add_child(label) var entries: Array[Dictionary] = [] for option in options: entries.append({"label": option}) var row := UIKit.chip_row(entries, selected) + if _compact: + for child in row.get_children(): + if child is Button: + (child as Button).custom_minimum_size.y = 48 + (child as Button).add_theme_font_size_override("font_size", 15) UIKit.wire_chips(row, on_select) column.add_child(row) parent.add_child(column) @@ -196,7 +221,9 @@ func _choice_row(parent: Control, label_key: String, options: Array[String], sel func _button_row(parent: Control, label_key: String, variation: String, on_press: Callable) -> void: var button := UIKit.button(Loc.t(label_key), variation, on_press) - button.custom_minimum_size = Vector2(0, 46) + button.custom_minimum_size = Vector2(0, 46 if not _compact else 58) + if _compact: + button.add_theme_font_size_override("font_size", 16) parent.add_child(button) diff --git a/src/ui/settings_screen.gd b/src/ui/settings_screen.gd index 86f7d92..88add7c 100644 --- a/src/ui/settings_screen.gd +++ b/src/ui/settings_screen.gd @@ -5,8 +5,10 @@ extends Screen ## 420 px column stretched down a desktop window, and never squeezed on a phone. The panel ## itself switches between one and two columns from its own size. -## Maximum panel width before it stops growing (centred on wider screens). +## Maximum panel width before it stops growing (centred on wider screens). On compact screens +## the panel is allowed to use more of the viewport so it never feels cramped on a phone. const PANEL_MAX_WIDTH := 1000.0 +const PANEL_MAX_WIDTH_COMPACT := 1200.0 var _panel: SettingsPanel var _viewport: Control @@ -15,6 +17,7 @@ var _resized_connected := false func _build() -> void: + var compact := UIKit.is_compact() var column := UIKit.vbox(14) column.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) add_content(column) @@ -22,7 +25,7 @@ func _build() -> void: var header := UIKit.hbox(12) header.add_child(UIKit.icon_button("back", Palette.TEXT, func() -> void: Audio.play_sfx("ui_back", -6.0) - on_back(), 44)) + on_back(), 44 if not compact else 52)) header.add_child(UIKit.label(Loc.t("settings.title"), "TitleLabel")) header.add_child(UIKit.spacer(true)) header.add_child(UIKit.label(Loc.t("settings.saved"), "TinyLabel")) @@ -73,7 +76,8 @@ func _layout_panel() -> void: return if _viewport.size.x <= 0.0: return - var width := mini(PANEL_MAX_WIDTH, maxf(420.0, _viewport.size.x - 32.0)) + var max_width := PANEL_MAX_WIDTH_COMPACT if UIKit.is_compact() else PANEL_MAX_WIDTH + var width := mini(max_width, maxf(420.0, _viewport.size.x - 32.0)) var height := maxf(_panel.min_size.y, 200.0) var x := maxf(8.0, (_viewport.size.x - width) * 0.5) _panel.offset_left = x diff --git a/src/ui/tower_panel.gd b/src/ui/tower_panel.gd index a721f29..5ddf5ee 100644 --- a/src/ui/tower_panel.gd +++ b/src/ui/tower_panel.gd @@ -24,10 +24,12 @@ var _target_button: Button var _module_row: HBoxContainer var _module_title: Label var _tower: Tower +var _compact := false func _ready() -> void: theme_type_variation = "HudPanel" + _compact = UIKit.is_compact() _build() @@ -42,7 +44,7 @@ func _build() -> void: root.add_child(header) _sprite = TextureRect.new() - _sprite.custom_minimum_size = Vector2(30, 30) + _sprite.custom_minimum_size = Vector2(30, 30) if not _compact else Vector2(42, 42) _sprite.expand_mode = TextureRect.EXPAND_IGNORE_SIZE _sprite.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED _sprite.texture_filter = CanvasItem.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS @@ -95,6 +97,12 @@ func _build() -> void: _module_row = HBoxContainer.new() _module_row.add_theme_constant_override("separation", 8) root.add_child(_module_row) + if _compact: + _name.add_theme_font_size_override("font_size", 22) + _stats.add_theme_font_size_override("font_size", 16) + _next.add_theme_font_size_override("font_size", 14) + _tags.add_theme_font_size_override("font_size", 14) + _dps.add_theme_font_size_override("font_size", 20) func refresh(tower: Tower, gold: int) -> void: @@ -164,9 +172,9 @@ func refresh(tower: Tower, gold: int) -> void: var button := UIKit.button(label, "ChipButton", func() -> void: module_pressed.emit(String(module_id))) button.size_flags_horizontal = Control.SIZE_EXPAND_FILL - button.custom_minimum_size.y = 56 + button.custom_minimum_size.y = 56 if not _compact else 72 button.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART - button.add_theme_font_size_override("font_size", 13) + button.add_theme_font_size_override("font_size", 13 if not _compact else 15) _module_row.add_child(button) diff --git a/src/ui/ui_kit.gd b/src/ui/ui_kit.gd index 70bbf2b..9e45ac0 100644 --- a/src/ui/ui_kit.gd +++ b/src/ui/ui_kit.gd @@ -8,6 +8,26 @@ extends RefCounted ## Minimum finger target on a phone, scaled by the UI stretch factor. const TOUCH := Vector2(48, 48) +## Enlarged finger target used on phones and small windows, where the layout is compact and +## the larger sizes stay comfortably tappable without dominating the screen. +const TOUCH_COMPACT := Vector2(58, 58) + + +## True when the UI should use the enlarged phone layout: mobile builds, or a window too small +## for the desktop insets. One source of truth shared by the game screen and every widget. +static func is_compact() -> bool: + if OS.has_feature("mobile"): + return true + var window := DisplayServer.window_get_size() + if window.x <= 0.0 or window.y <= 0.0: + # Headless or not-yet-created window: treat as compact so touch sizes stay safe. + return true + return window.x < 900.0 or window.y < 560.0 + + +## Minimum control height for the current screen (buttons, chips, ...). +static func touch_min() -> float: + return TOUCH_COMPACT.y if is_compact() else TOUCH.y static func vbox(separation: int = 10) -> VBoxContainer: @@ -58,7 +78,7 @@ static func button(text: String, variation: String = "", on_pressed: Callable = node.text = text if variation != "": node.theme_type_variation = variation - node.custom_minimum_size.y = TOUCH.y + node.custom_minimum_size.y = touch_min() node.focus_mode = Control.FOCUS_ALL if on_pressed.is_valid(): node.pressed.connect(on_pressed)