fix: resolve godot warnings and runtime error in tile menu
- rename margin var to margin_container (shadowed field) - use btn.minimum_size instead of custom_min_size (Godot 4 API) - mark unused _end_drag mouse_pos param with underscore - hoist new_cols/new_rows decl to eliminate confusable scope - rename hidden/visible to hidden_style/visible_style (shadowed CanvasItem) - rename _show_cells(show) param to do_show (shadowed show() method)
This commit is contained in:
parent
ebf97a6fc8
commit
40ba0f3ee1
1 changed files with 45 additions and 42 deletions
|
|
@ -143,16 +143,16 @@ func _show_tile_menu(mouse_pos: Vector2) -> void:
|
||||||
panel.position = Vector2i(get_screen_position()) + Vector2i(mouse_pos)
|
panel.position = Vector2i(get_screen_position()) + Vector2i(mouse_pos)
|
||||||
add_child(panel)
|
add_child(panel)
|
||||||
|
|
||||||
var margin := MarginContainer.new()
|
var margin_container := MarginContainer.new()
|
||||||
margin.add_theme_constant_override("margin_left", 8)
|
margin_container.add_theme_constant_override("margin_left", 8)
|
||||||
margin.add_theme_constant_override("margin_right", 8)
|
margin_container.add_theme_constant_override("margin_right", 8)
|
||||||
margin.add_theme_constant_override("margin_top", 8)
|
margin_container.add_theme_constant_override("margin_top", 8)
|
||||||
margin.add_theme_constant_override("margin_bottom", 8)
|
margin_container.add_theme_constant_override("margin_bottom", 8)
|
||||||
panel.add_child(margin)
|
panel.add_child(margin_container)
|
||||||
|
|
||||||
var vbox := VBoxContainer.new()
|
var vbox := VBoxContainer.new()
|
||||||
vbox.add_theme_constant_override("separation", 6)
|
vbox.add_theme_constant_override("separation", 6)
|
||||||
margin.add_child(vbox)
|
margin_container.add_child(vbox)
|
||||||
|
|
||||||
# -- toolbar row --
|
# -- toolbar row --
|
||||||
var toolbar := HBoxContainer.new()
|
var toolbar := HBoxContainer.new()
|
||||||
|
|
@ -196,7 +196,7 @@ func _make_menu_button(text: String, tooltip: String) -> Button:
|
||||||
btn.text = text
|
btn.text = text
|
||||||
btn.tooltip_text = tooltip
|
btn.tooltip_text = tooltip
|
||||||
btn.flat = true
|
btn.flat = true
|
||||||
btn.custom_min_size = MENU_BUTTON_MIN_SIZE
|
btn.minimum_size = MENU_BUTTON_MIN_SIZE
|
||||||
btn.add_theme_font_size_override("font_size", MENU_BUTTON_FONT_SIZE)
|
btn.add_theme_font_size_override("font_size", MENU_BUTTON_FONT_SIZE)
|
||||||
return btn
|
return btn
|
||||||
|
|
||||||
|
|
@ -674,7 +674,7 @@ func _update_drag(mouse_pos: Vector2) -> void:
|
||||||
_highlight_cell(_hover_col, _hover_row, true)
|
_highlight_cell(_hover_col, _hover_row, true)
|
||||||
|
|
||||||
|
|
||||||
func _end_drag(mouse_pos: Vector2) -> void:
|
func _end_drag(_mouse_pos: Vector2) -> void:
|
||||||
if _drag_module == null:
|
if _drag_module == null:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -807,12 +807,15 @@ func _rebuild_grid() -> void:
|
||||||
|
|
||||||
var avail := size - Vector2(margin * 2.0, margin * 2.0)
|
var avail := size - Vector2(margin * 2.0, margin * 2.0)
|
||||||
|
|
||||||
|
var new_cols: int
|
||||||
|
var new_rows: int
|
||||||
|
|
||||||
if avail.x < cell_min_size.x or avail.y < cell_min_size.y:
|
if avail.x < cell_min_size.x or avail.y < cell_min_size.y:
|
||||||
if _cells.size() > 0:
|
if _cells.size() > 0:
|
||||||
_layout_cells()
|
_layout_cells()
|
||||||
return
|
return
|
||||||
var new_cols := 1
|
new_cols = 1
|
||||||
var new_rows := 1
|
new_rows = 1
|
||||||
if new_cols == columns and new_rows == rows and _cells.size() > 0:
|
if new_cols == columns and new_rows == rows and _cells.size() > 0:
|
||||||
_layout_cells()
|
_layout_cells()
|
||||||
return
|
return
|
||||||
|
|
@ -825,12 +828,12 @@ func _rebuild_grid() -> void:
|
||||||
_layout_cells()
|
_layout_cells()
|
||||||
return
|
return
|
||||||
|
|
||||||
var new_cols := maxi(1, int(avail.x / (cell_min_size.x + cell_spacing)))
|
new_cols = maxi(1, int(avail.x / (cell_min_size.x + cell_spacing)))
|
||||||
|
|
||||||
var module_count := _module_list.size()
|
var module_count := _module_list.size()
|
||||||
var min_rows := maxi(1, ceili(float(module_count) / float(new_cols)))
|
var min_rows := maxi(1, ceili(float(module_count) / float(new_cols)))
|
||||||
var avail_rows := maxi(1, int(avail.y / (cell_min_size.y + cell_spacing)))
|
var avail_rows := maxi(1, int(avail.y / (cell_min_size.y + cell_spacing)))
|
||||||
var new_rows := maxi(avail_rows, min_rows)
|
new_rows = maxi(avail_rows, min_rows)
|
||||||
|
|
||||||
if new_cols == columns and new_rows == rows and _cells.size() > 0:
|
if new_cols == columns and new_rows == rows and _cells.size() > 0:
|
||||||
_layout_cells()
|
_layout_cells()
|
||||||
|
|
@ -877,44 +880,44 @@ func _build_cells() -> void:
|
||||||
|
|
||||||
|
|
||||||
func _style_cell(cell: PanelContainer, col: int, row: int) -> void:
|
func _style_cell(cell: PanelContainer, col: int, row: int) -> void:
|
||||||
var hidden := StyleBoxFlat.new()
|
var hidden_style := StyleBoxFlat.new()
|
||||||
hidden.bg_color = Color.TRANSPARENT
|
hidden_style.bg_color = Color.TRANSPARENT
|
||||||
hidden.border_width_left = 1
|
hidden_style.border_width_left = 1
|
||||||
hidden.border_width_top = 1
|
hidden_style.border_width_top = 1
|
||||||
hidden.border_width_right = 1
|
hidden_style.border_width_right = 1
|
||||||
hidden.border_width_bottom = 1
|
hidden_style.border_width_bottom = 1
|
||||||
hidden.border_color = Color.TRANSPARENT
|
hidden_style.border_color = Color.TRANSPARENT
|
||||||
hidden.corner_radius_top_left = 12
|
hidden_style.corner_radius_top_left = 12
|
||||||
hidden.corner_radius_top_right = 12
|
hidden_style.corner_radius_top_right = 12
|
||||||
hidden.corner_radius_bottom_right = 12
|
hidden_style.corner_radius_bottom_right = 12
|
||||||
hidden.corner_radius_bottom_left = 12
|
hidden_style.corner_radius_bottom_left = 12
|
||||||
|
|
||||||
var visible := StyleBoxFlat.new()
|
var visible_style := StyleBoxFlat.new()
|
||||||
visible.bg_color = Color(0.14, 0.14, 0.18, 1.0)
|
visible_style.bg_color = Color(0.14, 0.14, 0.18, 1.0)
|
||||||
visible.border_width_left = 1
|
visible_style.border_width_left = 1
|
||||||
visible.border_width_top = 1
|
visible_style.border_width_top = 1
|
||||||
visible.border_width_right = 1
|
visible_style.border_width_right = 1
|
||||||
visible.border_width_bottom = 1
|
visible_style.border_width_bottom = 1
|
||||||
visible.border_color = Color(0.25, 0.25, 0.35, 1.0)
|
visible_style.border_color = Color(0.25, 0.25, 0.35, 1.0)
|
||||||
visible.corner_radius_top_left = 12
|
visible_style.corner_radius_top_left = 12
|
||||||
visible.corner_radius_top_right = 12
|
visible_style.corner_radius_top_right = 12
|
||||||
visible.corner_radius_bottom_right = 12
|
visible_style.corner_radius_bottom_right = 12
|
||||||
visible.corner_radius_bottom_left = 12
|
visible_style.corner_radius_bottom_left = 12
|
||||||
|
|
||||||
cell.add_theme_stylebox_override("panel", hidden)
|
cell.add_theme_stylebox_override("panel", hidden_style)
|
||||||
cell.add_theme_stylebox_override("panel_focused", hidden)
|
cell.add_theme_stylebox_override("panel_focused", hidden_style)
|
||||||
cell.set_meta("hidden_style", hidden)
|
cell.set_meta("hidden_style", hidden_style)
|
||||||
cell.set_meta("visible_style", visible)
|
cell.set_meta("visible_style", visible_style)
|
||||||
_cell_styles["%d,%d" % [col, row]] = visible
|
_cell_styles["%d,%d" % [col, row]] = visible_style
|
||||||
|
|
||||||
|
|
||||||
func _show_cells(show: bool) -> void:
|
func _show_cells(do_show: bool) -> void:
|
||||||
for row_idx in range(_cells.size()):
|
for row_idx in range(_cells.size()):
|
||||||
for col_idx in range(_cells[row_idx].size()):
|
for col_idx in range(_cells[row_idx].size()):
|
||||||
var cell: PanelContainer = _cells[row_idx][col_idx]
|
var cell: PanelContainer = _cells[row_idx][col_idx]
|
||||||
if not is_instance_valid(cell):
|
if not is_instance_valid(cell):
|
||||||
continue
|
continue
|
||||||
var style: StyleBoxFlat = cell.get_meta("visible_style") if show else cell.get_meta("hidden_style")
|
var style: StyleBoxFlat = cell.get_meta("visible_style") if do_show else cell.get_meta("hidden_style")
|
||||||
cell.add_theme_stylebox_override("panel", style)
|
cell.add_theme_stylebox_override("panel", style)
|
||||||
cell.add_theme_stylebox_override("panel_focused", style)
|
cell.add_theme_stylebox_override("panel_focused", style)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue