Improve local post-move action UI
This commit is contained in:
@@ -65,11 +65,10 @@ const SHOP_ITEM_ICON_SIZE := Vector2(48, 48)
|
||||
const HUD_UNIT_PORTRAIT_SIZE := Vector2(92, 104)
|
||||
const HUD_UNIT_PORTRAIT_STACK_SIZE := Vector2(88, 100)
|
||||
const POST_MOVE_MENU_SIZE := Vector2(228, 120)
|
||||
const POST_MOVE_MENU_OFFSET := Vector2(20, -34)
|
||||
const POST_MOVE_PICKER_PANEL_SIZE := Vector2(320, 210)
|
||||
const POST_MOVE_PICKER_PANEL_OFFSET := Vector2(20, 92)
|
||||
const TARGETING_HINT_PANEL_SIZE := Vector2(240, 94)
|
||||
const TARGETING_HINT_PANEL_OFFSET := Vector2(18, 88)
|
||||
const LOCAL_COMMAND_PANEL_GAP := 8.0
|
||||
const LOCAL_COMMAND_PANEL_BOARD_PADDING := 4.0
|
||||
|
||||
var state: BattleState = BattleStateScript.new()
|
||||
var campaign_state: CampaignState = CampaignStateScript.new()
|
||||
@@ -565,7 +564,7 @@ func _create_hud() -> void:
|
||||
|
||||
post_move_picker_cancel_move_button = Button.new()
|
||||
post_move_picker_cancel_move_button.text = "Cancel Move"
|
||||
post_move_picker_cancel_move_button.tooltip_text = "Return to the starting cell."
|
||||
post_move_picker_cancel_move_button.tooltip_text = "Right-click also returns to the starting cell."
|
||||
post_move_picker_cancel_move_button.pressed.connect(_on_post_move_picker_cancel_move_pressed)
|
||||
picker_button_row.add_child(post_move_picker_cancel_move_button)
|
||||
|
||||
@@ -3771,6 +3770,9 @@ func _on_tactic_pressed() -> void:
|
||||
var selected := state.get_selected_unit()
|
||||
if selected.is_empty():
|
||||
return
|
||||
if _has_pending_move():
|
||||
_on_post_move_tactic_pressed()
|
||||
return
|
||||
if state.is_unit_skill_sealed(selected["id"]):
|
||||
_play_ui_cancel()
|
||||
selected_skill_id = ""
|
||||
@@ -3803,6 +3805,9 @@ func _on_item_pressed() -> void:
|
||||
var selected := state.get_selected_unit()
|
||||
if selected.is_empty():
|
||||
return
|
||||
if _has_pending_move():
|
||||
_on_post_move_item_pressed()
|
||||
return
|
||||
_play_ui_click()
|
||||
if item_menu != null and item_menu.visible:
|
||||
_hide_item_menu()
|
||||
@@ -6076,19 +6081,51 @@ func _update_post_move_menu() -> void:
|
||||
post_move_cancel_button.tooltip_text = "Right-click also returns to the starting cell."
|
||||
|
||||
|
||||
func _local_command_panel_position_for_cell(cell: Vector2i, panel_size: Vector2) -> Vector2:
|
||||
if not state.is_inside(cell):
|
||||
return BOARD_OFFSET + Vector2(LOCAL_COMMAND_PANEL_BOARD_PADDING, LOCAL_COMMAND_PANEL_BOARD_PADDING)
|
||||
var cell_rect := _rect_for_cell(cell)
|
||||
var centered_y := cell_rect.position.y + (TILE_SIZE - panel_size.y) * 0.5
|
||||
var centered_x := cell_rect.position.x + (TILE_SIZE - panel_size.x) * 0.5
|
||||
var candidates: Array[Vector2] = [
|
||||
Vector2(cell_rect.end.x + LOCAL_COMMAND_PANEL_GAP, centered_y),
|
||||
Vector2(cell_rect.position.x - panel_size.x - LOCAL_COMMAND_PANEL_GAP, centered_y),
|
||||
Vector2(centered_x, cell_rect.end.y + LOCAL_COMMAND_PANEL_GAP),
|
||||
Vector2(centered_x, cell_rect.position.y - panel_size.y - LOCAL_COMMAND_PANEL_GAP)
|
||||
]
|
||||
var avoid_rect := cell_rect.grow(2.0)
|
||||
var best_position := _clamped_local_command_panel_position(candidates[0], panel_size)
|
||||
var best_score := 1000000000.0
|
||||
for candidate in candidates:
|
||||
var next_position := _clamped_local_command_panel_position(candidate, panel_size)
|
||||
var panel_rect := Rect2(next_position, panel_size)
|
||||
var score := next_position.distance_squared_to(candidate)
|
||||
if panel_rect.intersects(avoid_rect):
|
||||
score += 1000000.0
|
||||
if score < best_score:
|
||||
best_score = score
|
||||
best_position = next_position
|
||||
if score < 1.0 and not panel_rect.intersects(avoid_rect):
|
||||
break
|
||||
return best_position
|
||||
|
||||
|
||||
func _clamped_local_command_panel_position(position: Vector2, panel_size: Vector2) -> Vector2:
|
||||
var board_size := Vector2(state.map_size.x, state.map_size.y) * TILE_SIZE
|
||||
var board_min := BOARD_OFFSET + Vector2(LOCAL_COMMAND_PANEL_BOARD_PADDING, LOCAL_COMMAND_PANEL_BOARD_PADDING)
|
||||
var board_max := BOARD_OFFSET + board_size - panel_size - Vector2(LOCAL_COMMAND_PANEL_BOARD_PADDING, LOCAL_COMMAND_PANEL_BOARD_PADDING)
|
||||
board_max.x = maxf(board_min.x, board_max.x)
|
||||
board_max.y = maxf(board_min.y, board_max.y)
|
||||
return Vector2(
|
||||
clampf(position.x, board_min.x, board_max.x),
|
||||
clampf(position.y, board_min.y, board_max.y)
|
||||
)
|
||||
|
||||
|
||||
func _position_post_move_menu() -> void:
|
||||
if post_move_menu == null:
|
||||
return
|
||||
var cell_rect := _rect_for_cell(pending_move_to_cell)
|
||||
var next_position := cell_rect.position + Vector2(TILE_SIZE, 0.0) + POST_MOVE_MENU_OFFSET
|
||||
var board_size := Vector2(state.map_size.x, state.map_size.y) * TILE_SIZE
|
||||
var board_min := BOARD_OFFSET + Vector2(4.0, 4.0)
|
||||
var board_max := BOARD_OFFSET + board_size - POST_MOVE_MENU_SIZE - Vector2(4.0, 4.0)
|
||||
board_max.x = maxf(board_min.x, board_max.x)
|
||||
board_max.y = maxf(board_min.y, board_max.y)
|
||||
next_position.x = clampf(next_position.x, board_min.x, board_max.x)
|
||||
next_position.y = clampf(next_position.y, board_min.y, board_max.y)
|
||||
post_move_menu.position = next_position
|
||||
post_move_menu.position = _local_command_panel_position_for_cell(pending_move_to_cell, POST_MOVE_MENU_SIZE)
|
||||
|
||||
|
||||
func _show_post_move_picker(mode: String) -> void:
|
||||
@@ -6160,16 +6197,7 @@ func _clear_post_move_picker_list() -> void:
|
||||
func _position_post_move_picker() -> void:
|
||||
if post_move_picker_panel == null:
|
||||
return
|
||||
var cell_rect := _rect_for_cell(pending_move_to_cell)
|
||||
var next_position := cell_rect.position + POST_MOVE_PICKER_PANEL_OFFSET
|
||||
var board_size := Vector2(state.map_size.x, state.map_size.y) * TILE_SIZE
|
||||
var board_min := BOARD_OFFSET + Vector2(4.0, 4.0)
|
||||
var board_max := BOARD_OFFSET + board_size - POST_MOVE_PICKER_PANEL_SIZE - Vector2(4.0, 4.0)
|
||||
board_max.x = maxf(board_min.x, board_max.x)
|
||||
board_max.y = maxf(board_min.y, board_max.y)
|
||||
next_position.x = clampf(next_position.x, board_min.x, board_max.x)
|
||||
next_position.y = clampf(next_position.y, board_min.y, board_max.y)
|
||||
post_move_picker_panel.position = next_position
|
||||
post_move_picker_panel.position = _local_command_panel_position_for_cell(pending_move_to_cell, POST_MOVE_PICKER_PANEL_SIZE)
|
||||
|
||||
|
||||
func _post_move_picker_title_text(selected: Dictionary) -> String:
|
||||
@@ -6433,16 +6461,7 @@ func _position_targeting_hint_panel(selected: Dictionary) -> void:
|
||||
var cell: Vector2i = selected.get("pos", Vector2i(-1, -1))
|
||||
if not state.is_inside(cell):
|
||||
return
|
||||
var cell_rect := _rect_for_cell(cell)
|
||||
var next_position := cell_rect.position + TARGETING_HINT_PANEL_OFFSET
|
||||
var board_size := Vector2(state.map_size.x, state.map_size.y) * TILE_SIZE
|
||||
var board_min := BOARD_OFFSET + Vector2(4.0, 4.0)
|
||||
var board_max := BOARD_OFFSET + board_size - TARGETING_HINT_PANEL_SIZE - Vector2(4.0, 4.0)
|
||||
board_max.x = maxf(board_min.x, board_max.x)
|
||||
board_max.y = maxf(board_min.y, board_max.y)
|
||||
next_position.x = clampf(next_position.x, board_min.x, board_max.x)
|
||||
next_position.y = clampf(next_position.y, board_min.y, board_max.y)
|
||||
targeting_hint_panel.position = next_position
|
||||
targeting_hint_panel.position = _local_command_panel_position_for_cell(cell, TARGETING_HINT_PANEL_SIZE)
|
||||
|
||||
|
||||
func _targeting_hint_title_text() -> String:
|
||||
|
||||
Reference in New Issue
Block a user