feat: integrate minimap into dark fantasy HUD rail
This commit is contained in:
+36
-25
@@ -3,27 +3,23 @@
|
||||
[ext_resource type="Script" path="res://scripts/presentation/minimap.gd" id="1_minimap"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBox_minimap"]
|
||||
bg_color = Color(0.025, 0.045, 0.085, 0.94)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.45, 0.75, 0.9, 0.9)
|
||||
corner_radius_top_left = 6
|
||||
corner_radius_top_right = 6
|
||||
corner_radius_bottom_right = 6
|
||||
corner_radius_bottom_left = 6
|
||||
bg_color = Color(0.045, 0.035, 0.025, 0.96)
|
||||
border_width_left = 3
|
||||
border_width_top = 3
|
||||
border_width_right = 3
|
||||
border_width_bottom = 3
|
||||
border_color = Color(0.67, 0.48, 0.19, 0.95)
|
||||
corner_radius_top_left = 8
|
||||
corner_radius_top_right = 8
|
||||
corner_radius_bottom_right = 8
|
||||
corner_radius_bottom_left = 8
|
||||
shadow_color = Color(0, 0, 0, 0.55)
|
||||
shadow_size = 5
|
||||
|
||||
[node name="Minimap" type="Control"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -188.0
|
||||
offset_top = 184.0
|
||||
offset_right = -20.0
|
||||
offset_bottom = 352.0
|
||||
grow_horizontal = 0
|
||||
offset_right = 280.0
|
||||
offset_bottom = 300.0
|
||||
mouse_filter = 2
|
||||
script = ExtResource("1_minimap")
|
||||
|
||||
@@ -43,13 +39,28 @@ layout_mode = 1
|
||||
anchors_preset = 10
|
||||
anchor_left = 0.5
|
||||
anchor_right = 0.5
|
||||
offset_left = -70.0
|
||||
offset_top = 4.0
|
||||
offset_right = 70.0
|
||||
offset_bottom = 20.0
|
||||
offset_left = -120.0
|
||||
offset_top = 7.0
|
||||
offset_right = 120.0
|
||||
offset_bottom = 29.0
|
||||
grow_horizontal = 2
|
||||
theme_override_colors/font_color = Color(0.78, 0.94, 1, 1)
|
||||
theme_override_font_sizes/font_size = 12
|
||||
text = "CARTE — Tab"
|
||||
theme_override_colors/font_color = Color(0.86, 0.78, 0.58, 1)
|
||||
theme_override_font_sizes/font_size = 13
|
||||
text = "CARTOGRAPHIE — TAB"
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="MapRegion" type="Control" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 14.0
|
||||
offset_top = 40.0
|
||||
offset_right = -14.0
|
||||
offset_bottom = -14.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
clip_contents = true
|
||||
|
||||
@@ -2,12 +2,17 @@ class_name Minimap
|
||||
extends Control
|
||||
|
||||
const CROP_RADIUS := 6
|
||||
const CELL_SIZE := 12.0
|
||||
const UNKNOWN_COLOR := Color(0.025, 0.04, 0.09, 0.94)
|
||||
const EXPLORED_COLOR := Color(0.18, 0.32, 0.48, 0.96)
|
||||
const VISIBLE_COLOR := Color(0.72, 0.84, 0.9, 1.0)
|
||||
const PLAYER_COLOR := Color(1.0, 0.92, 0.32, 1.0)
|
||||
const THREAT_COLOR := Color(0.95, 0.42, 0.18, 1.0)
|
||||
const UNKNOWN_COLOR := Color(0.035, 0.03, 0.025, 0.96)
|
||||
const EXPLORED_COLOR := Color(0.24, 0.29, 0.25, 0.98)
|
||||
const VISIBLE_COLOR := Color(0.72, 0.66, 0.51, 1.0)
|
||||
const PLAYER_COLOR := Color(0.96, 0.78, 0.3, 1.0)
|
||||
const THREAT_COLOR := Color(0.84, 0.22, 0.14, 1.0)
|
||||
const COMPACT_SIZE := Vector2(280.0, 300.0)
|
||||
const EXPANDED_SIZE := Vector2(520.0, 560.0)
|
||||
const COMPACT_RAIL_INSET := 20.0
|
||||
const EXPANDED_FRAME_INSET := 28.0
|
||||
|
||||
@onready var map_region: Control = $MapRegion
|
||||
|
||||
var expanded := false
|
||||
var _crop_radius := CROP_RADIUS
|
||||
@@ -17,6 +22,17 @@ var _visible_cells: Dictionary[Vector2i, bool] = {}
|
||||
var _explored_cells: Dictionary[Vector2i, bool] = {}
|
||||
var _threat_cells: Dictionary[Vector2i, bool] = {}
|
||||
|
||||
func _ready() -> void:
|
||||
resized.connect(queue_redraw)
|
||||
map_region.resized.connect(queue_redraw)
|
||||
get_viewport().size_changed.connect(_on_viewport_size_changed)
|
||||
call_deferred("_layout_in_hud")
|
||||
|
||||
func _on_viewport_size_changed() -> void:
|
||||
# GameHud updates the rail rectangles from the same signal; defer until those
|
||||
# rectangles have received their new responsive dimensions.
|
||||
call_deferred("_layout_in_hud")
|
||||
|
||||
func set_state(map: GridMapState, player_cell: Vector2i, visible_cells: Dictionary[Vector2i, bool], explored_cells: Dictionary[Vector2i, bool], threat_cells: Dictionary[Vector2i, bool]) -> void:
|
||||
_map = map
|
||||
_player_cell = player_cell
|
||||
@@ -49,28 +65,55 @@ func get_cell_visibility_state(cell: Vector2i) -> StringName:
|
||||
|
||||
func get_threat_marker_cells() -> Dictionary[Vector2i, bool]:
|
||||
var threats: Dictionary[Vector2i, bool] = {}
|
||||
var displayed := get_displayed_cells()
|
||||
for cell in _threat_cells:
|
||||
if _visible_cells.has(cell) and get_displayed_cells().has(cell):
|
||||
if _visible_cells.has(cell) and displayed.has(cell):
|
||||
threats[cell] = true
|
||||
return threats
|
||||
|
||||
## Returns the local rectangle exclusively available to map cells and markers.
|
||||
func get_drawable_map_rect() -> Rect2:
|
||||
if not is_instance_valid(map_region):
|
||||
return Rect2()
|
||||
var region_size := map_region.size
|
||||
var square_side := minf(region_size.x, region_size.y)
|
||||
return Rect2(map_region.position + (region_size - Vector2.ONE * square_side) * 0.5, Vector2.ONE * square_side)
|
||||
|
||||
func toggle_expanded() -> void:
|
||||
expanded = not expanded
|
||||
_crop_radius = CROP_RADIUS * 2 if expanded else CROP_RADIUS
|
||||
set_anchors_and_offsets_preset(Control.PRESET_CENTER_TOP if expanded else Control.PRESET_TOP_RIGHT)
|
||||
size = Vector2(312, 312) if expanded else Vector2(168, 168)
|
||||
position = Vector2(484, 72) if expanded else Vector2(-188, 184)
|
||||
_layout_in_hud()
|
||||
queue_redraw()
|
||||
|
||||
func _layout_in_hud() -> void:
|
||||
if not is_inside_tree():
|
||||
return
|
||||
var layout := get_node_or_null("../ResponsiveLayout") as Control
|
||||
if layout == null:
|
||||
return
|
||||
var host := layout.get_node_or_null("PlayAreaFrame" if expanded else "RightRail") as Control
|
||||
if host == null:
|
||||
return
|
||||
var requested_size := EXPANDED_SIZE if expanded else COMPACT_SIZE
|
||||
var inset := EXPANDED_FRAME_INSET if expanded else COMPACT_RAIL_INSET
|
||||
var available_size := host.size - Vector2.ONE * inset * 2.0
|
||||
var panel_size := Vector2(minf(requested_size.x, available_size.x), minf(requested_size.y, available_size.y))
|
||||
size = panel_size
|
||||
position = host.position + (host.size - panel_size) * 0.5
|
||||
|
||||
func _draw() -> void:
|
||||
if _map == null:
|
||||
return
|
||||
var drawable_rect := get_drawable_map_rect()
|
||||
if drawable_rect.size.x <= 0.0 or drawable_rect.size.y <= 0.0:
|
||||
return
|
||||
var displayed := get_displayed_cells()
|
||||
var threat_cells := get_threat_marker_cells()
|
||||
var cells_across := _crop_radius * 2 + 1
|
||||
var draw_cell_size := size.x / float(cells_across)
|
||||
var draw_cell_size := drawable_rect.size.x / float(cells_across)
|
||||
for cell in displayed:
|
||||
var local := cell - _player_cell + Vector2i(cells_across / 2, cells_across / 2)
|
||||
var rect := Rect2(Vector2(local) * draw_cell_size, Vector2.ONE * (draw_cell_size - 1.0))
|
||||
var local := cell - _player_cell + Vector2i(_crop_radius, _crop_radius)
|
||||
var rect := Rect2(drawable_rect.position + Vector2(local) * draw_cell_size, Vector2.ONE * (draw_cell_size - 1.0))
|
||||
var color := UNKNOWN_COLOR
|
||||
if get_cell_visibility_state(cell) == &"visible":
|
||||
color = VISIBLE_COLOR
|
||||
@@ -79,5 +122,5 @@ func _draw() -> void:
|
||||
draw_rect(rect, color)
|
||||
if cell == _player_cell:
|
||||
draw_circle(rect.get_center(), draw_cell_size * 0.28, PLAYER_COLOR)
|
||||
elif get_threat_marker_cells().has(cell):
|
||||
elif threat_cells.has(cell):
|
||||
draw_circle(rect.get_center(), draw_cell_size * 0.25, THREAT_COLOR)
|
||||
|
||||
@@ -58,6 +58,15 @@ func test_map_renderer_returns_the_contract_cell_rectangle() -> void:
|
||||
|
||||
assert_eq(renderer.get_cell_rect(Vector2i(2, 3)), Rect2(64, 96, 32, 32))
|
||||
|
||||
func test_minimap_root_is_enclosed_by_the_right_rail_at_reference_viewport() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
var minimap := game.get_node("HUD/Minimap") as Minimap
|
||||
var right_rail := game.get_node("HUD/ResponsiveLayout/RightRail") as Control
|
||||
|
||||
assert_true(right_rail.get_global_rect().encloses(minimap.get_global_rect()))
|
||||
|
||||
func test_camera_tracks_player_after_a_valid_action_and_uses_map_limits() -> void:
|
||||
var game := GameScene.instantiate() as Game
|
||||
add_child_autofree(game)
|
||||
|
||||
@@ -9,6 +9,31 @@ func before_each() -> void:
|
||||
add_child_autofree(game)
|
||||
await get_tree().process_frame
|
||||
|
||||
func test_minimap_lives_in_right_rail_and_draws_only_in_its_inner_map_region() -> void:
|
||||
var minimap := game.get_node_or_null("HUD/Minimap") as Minimap
|
||||
var layout := game.get_node("HUD/ResponsiveLayout") as Control
|
||||
var right_rail := layout.get_node("RightRail") as Control
|
||||
var play_frame := layout.get_node("PlayAreaFrame") as Control
|
||||
var map_region := minimap.get_node("MapRegion") as Control
|
||||
var caption := minimap.get_node("Caption") as Label
|
||||
|
||||
assert_not_null(minimap)
|
||||
assert_true(right_rail.get_global_rect().encloses(minimap.get_global_rect()))
|
||||
assert_true(map_region.get_rect().encloses(minimap.get_drawable_map_rect()))
|
||||
assert_false(caption.get_rect().intersects(minimap.get_drawable_map_rect()))
|
||||
assert_lt(minimap.get_drawable_map_rect().size.x, minimap.size.x)
|
||||
|
||||
minimap.toggle_expanded()
|
||||
await get_tree().process_frame
|
||||
assert_true(minimap.expanded)
|
||||
assert_true(play_frame.get_global_rect().encloses(minimap.get_global_rect()))
|
||||
assert_true(map_region.get_rect().encloses(minimap.get_drawable_map_rect()))
|
||||
|
||||
minimap.toggle_expanded()
|
||||
await get_tree().process_frame
|
||||
assert_false(minimap.expanded)
|
||||
assert_true(right_rail.get_global_rect().encloses(minimap.get_global_rect()))
|
||||
|
||||
func test_minimap_crops_to_player_camera_fov_and_never_reveals_hidden_threats() -> void:
|
||||
var minimap := game.get_node_or_null("HUD/Minimap") as Minimap
|
||||
var state := game.get_game_state()
|
||||
|
||||
Reference in New Issue
Block a user