feat: integrate minimap into dark fantasy HUD rail
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user