godot_experiments/SiteInfo.gd

62 lines
1.4 KiB
GDScript

@tool
extends Node2D
## 圆条颜色
@export var stripColor: Color = Color.DARK_GRAY:
get:
return stripColor
set(v):
stripColor = v
update()
## 车站名颜色
@export var nameColor: Color = Color.WHITE:
get:
return nameColor
set(v):
nameColor = v
update()
## 车站名
@export var stationName: String = "车站一":
get:
return stationName
set(v):
stationName = v
update()
## 车站英文/拼音名
@export var stationEnName: String = "CHEZHANYI":
get:
return stationEnName
set(v):
stationEnName = v
update()
var isReady = false
func update():
if not isReady:
return
# 更新背景色
$Strip["theme_override_styles/panel"].bg_color = stripColor
$Circle["theme_override_styles/panel"].border_color = stripColor
# 更新文字颜色
%Name.label_settings.font_color = nameColor
%EnName.label_settings.font_color = nameColor
# 更新文字
%Name.text = stationName
%EnName.text = stationEnName
func calculateWidth() -> float:
assert(isReady, "需要先添加到节点树中才可用")
var nameWidth =%Name.get_combined_minimum_size().x* cos($VBoxContainer.rotation)
var enNameWidth =%EnName.get_combined_minimum_size().x* cos($VBoxContainer.rotation)
print(%Name.text,%Name.get_combined_minimum_size(), %EnName.text,%EnName.get_combined_minimum_size(),$VBoxContainer.rotation)
var w = nameWidth if nameWidth > enNameWidth else enNameWidth
return w + 5
func _ready():
print("site info ready")
isReady = true
update()