代码拉取完成,页面将自动刷新
@tool
extends Panel
@export var reset : bool = false
@onready var UI = $".."
var buttons = []
var current_buildable : String = ""
var columnCount : int = 2
func _ready():
LoadButtons()
for button in buttons:
button.connect("pressed", OnButtonPressed.bind(button))
func _process(delta):
if reset:
reset = false
LoadButtons()
ArrangeSelf()
ArrangeButtons()
func OnButtonPressed(button : Button):
OpenSubmenu(button.text)
func OpenSubmenu(menu):
if menu == current_buildable:
find_child("pnl_buildable").set_visible(false)
current_buildable = ""
else:
current_buildable = menu
find_child("pnl_buildable").set_visible(true)
match menu:
"Structure":
LoadArchitectBuildableMenu()
func LoadArchitectBuildableMenu():
var pnl_buildable = find_child("pnl_buildable")
for i in range(pnl_buildable.get_child_count()):
pnl_buildable.get_child(i).queue_free()
var buildables = ["Cancel", "Wall", "Door", "Fence", "and another thing"]
for i in range(len(buildables)):
var button = Button.new()
pnl_buildable.add_child(button)
button.text = buildables[i]
var buttonSize = pnl_buildable.size.x / 20
button.position = Vector2(buttonSize * i, pnl_buildable.size.y - buttonSize)
button.size = Vector2(buttonSize, buttonSize)
button.add_theme_font_size_override("font_size", 10)
func LoadButtons():
buttons = []
for child in get_children():
if child is Button:
buttons.append(child)
func ArrangeSelf():
anchor_left = 0
anchor_right = 0.2
anchor_bottom = 1 - UI.buttonHeight
var rows = (len(buttons)+1)/columnCount
anchor_top = anchor_bottom - UI.buttonHeight * rows
offset_bottom = 0
offset_top = 0
offset_left = 0
offset_right = 0
func ArrangeButtons():
var rows = (len(buttons)+1)/columnCount
for i in range(len(buttons)):
var column = i%columnCount
var row = i / columnCount
buttons[i].anchor_top = row * 1/float(rows)
buttons[i].anchor_bottom = 1/float(rows) + row * 1/float(rows)
buttons[i].anchor_left = column * 1/float(columnCount)
buttons[i].anchor_right = 1/float(columnCount) + column * 1/float(columnCount)
buttons[i].offset_bottom = 0
buttons[i].offset_top = 0
buttons[i].offset_left = 0
buttons[i].offset_right = 0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。