godot-psd-training/trainings/trainTip.gd
joylink_fanyuhong 25f84cc02c 实训调整
2024-05-21 11:09:24 +08:00

46 lines
1.3 KiB
GDScript

extends Window
# Called when the node enters the scene tree for the first time.
func _ready():
self.hide()
self.transparent_bg = true
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
var right_theme_resource = load("res://training_tip_right.tres")
var left_theme_resource = load("res://training_tip_left.tres")
func setTrainingTip(text):
$PanelContainer/Label.text = text
if text!= '':
self.show()
var position = computed_position()
self.position = position
self.size = self.get_contents_minimum_size()
else:
self.hide()
func _on_panel_container_resized():
if $PanelContainer/Label.text != "":
var cp = computed_position()
if self.position.x != cp.x or self.position.y != cp.y:
self.position = cp
self.size = self.get_contents_minimum_size()
func computed_position():
var position = $"../total".allClickEquipmentPostion($"..".stepOperation[$"..".stepOperationIndex])
if position.x - $PanelContainer.size.x < 0:
position.x = position.x - 10
position.y = position.y + 10
$PanelContainer.theme = right_theme_resource
else:
position.x = position.x - $PanelContainer.size.x + 10
position.y = position.y - $PanelContainer.size.y - 10
$PanelContainer.theme = left_theme_resource
return position