Focus large maps on deployment
This commit is contained in:
@@ -5212,8 +5212,8 @@ func _board_scroll_offset_for_cell_focus(cell: Vector2i, force_center := false)
|
||||
return _clamped_board_scroll_offset(next_offset)
|
||||
|
||||
|
||||
func _focus_board_on_cell(cell: Vector2i, force_center := false) -> bool:
|
||||
if not battle_started or not state.is_inside(cell):
|
||||
func _focus_board_on_cell(cell: Vector2i, force_center := false, allow_prebattle := false) -> bool:
|
||||
if (not battle_started and not allow_prebattle) or not state.is_inside(cell):
|
||||
return false
|
||||
var previous_offset := board_scroll_offset
|
||||
board_scroll_offset = _board_scroll_offset_for_cell_focus(cell, force_center)
|
||||
@@ -5228,6 +5228,40 @@ func _focus_board_on_cell(cell: Vector2i, force_center := false) -> bool:
|
||||
return true
|
||||
|
||||
|
||||
func _player_deployment_focus_cell() -> Vector2i:
|
||||
var units := state.get_controllable_player_units()
|
||||
if units.is_empty():
|
||||
units = state.get_living_units(BattleState.TEAM_PLAYER)
|
||||
if units.is_empty():
|
||||
return Vector2i(-1, -1)
|
||||
var min_x := state.map_size.x
|
||||
var min_y := state.map_size.y
|
||||
var max_x := 0
|
||||
var max_y := 0
|
||||
for unit in units:
|
||||
var cell: Vector2i = unit.get("pos", Vector2i(-1, -1))
|
||||
if not state.is_inside(cell):
|
||||
continue
|
||||
min_x = mini(min_x, cell.x)
|
||||
min_y = mini(min_y, cell.y)
|
||||
max_x = maxi(max_x, cell.x)
|
||||
max_y = maxi(max_y, cell.y)
|
||||
if min_x > max_x or min_y > max_y:
|
||||
return Vector2i(-1, -1)
|
||||
return Vector2i(clampi(int(round(float(min_x + max_x) * 0.5)), 0, state.map_size.x - 1), clampi(int(round(float(min_y + max_y) * 0.5)), 0, state.map_size.y - 1))
|
||||
|
||||
|
||||
func _focus_board_on_player_deployment(force_center := false) -> bool:
|
||||
return _focus_board_on_cell(_player_deployment_focus_cell(), force_center)
|
||||
|
||||
|
||||
func _focus_board_on_formation_unit(force_center := false) -> bool:
|
||||
var unit := state.get_unit(formation_unit_id)
|
||||
if unit.is_empty():
|
||||
return false
|
||||
return _focus_board_on_cell(unit.get("pos", Vector2i(-1, -1)), force_center, true)
|
||||
|
||||
|
||||
func _activate_presentation_focus_if_ready(entry: Dictionary) -> void:
|
||||
if bool(entry.get("focused", false)):
|
||||
return
|
||||
@@ -7375,8 +7409,10 @@ func _start_battle_from_briefing() -> void:
|
||||
_hide_save_menu()
|
||||
_clear_pending_move_state()
|
||||
state.run_battle_begin_events()
|
||||
_focus_board_on_player_deployment(true)
|
||||
_show_next_dialogue()
|
||||
_update_hud()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _on_chapter_pressed() -> void:
|
||||
@@ -7937,6 +7973,7 @@ func _on_formation_pressed() -> void:
|
||||
_hide_save_menu()
|
||||
_rebuild_formation_menu()
|
||||
formation_menu.visible = true
|
||||
_focus_board_on_formation_unit(true)
|
||||
_update_hud()
|
||||
queue_redraw()
|
||||
|
||||
@@ -8216,6 +8253,7 @@ func _on_formation_unit_pressed(unit_id: String) -> void:
|
||||
_play_ui_click()
|
||||
formation_unit_id = unit_id
|
||||
_rebuild_formation_menu()
|
||||
_focus_board_on_formation_unit(true)
|
||||
_update_hud()
|
||||
queue_redraw()
|
||||
|
||||
@@ -8229,6 +8267,7 @@ func _handle_formation_board_click(screen_position: Vector2) -> void:
|
||||
if state.try_set_prebattle_formation(formation_unit_id, cell):
|
||||
_play_ui_confirm()
|
||||
_rebuild_formation_menu()
|
||||
_focus_board_on_formation_unit()
|
||||
_update_hud()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user