godot_experiments/station_info_panel/style1/site_info.gd

65 lines
1.5 KiB
GDScript3
Raw Normal View History

2024-04-27 10:02:45 +08:00
@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()
2024-04-30 18:09:56 +08:00
## 站点圆圈样式
@export var siteCircleStyle: StyleBoxFlat
## 站点条样式
@export var siteStripStyle: StyleBoxFlat
2024-04-27 10:02:45 +08:00
var isReady = false
func update():
if not isReady:
return
# 更新背景色
2024-04-30 18:09:56 +08:00
$Strip["theme_override_styles/panel"] = siteStripStyle
$Circle["theme_override_styles/panel"] = siteCircleStyle
2024-04-27 10:02:45 +08:00
# 更新文字颜色
2024-04-30 18:09:56 +08:00
%Name["theme_override_colors/font_color"] = nameColor
%EnName["theme_override_colors/font_color"] = nameColor
2024-04-27 10:02:45 +08:00
# 更新文字
%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():
isReady = true
update()