1 Star 0 Fork 0

kevinlights/rimworldripoff

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pnl_architect.gd 2.20 KB
一键复制 编辑 原始数据 按行查看 历史
Jake Wilkinson 提交于 2024-05-25 21:22 +08:00 . video 7 - Starting the UI
@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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kevinlights/rimworldripoff.git
git@gitee.com:kevinlights/rimworldripoff.git
kevinlights
rimworldripoff
rimworldripoff
master

搜索帮助