140 lines
4.4 KiB
GDScript
140 lines
4.4 KiB
GDScript
extends CanvasLayer
|
|
class_name NoticeDialog
|
|
|
|
const DEFAULT_PAGES: Array[Dictionary] = [
|
|
{
|
|
"text": "[center][color=#2f6b73]小镇新闻[/color][/center]\n\n线上新闻接口接入后,这里会同步 Datawhale Town 的最新动态、活动公告和版本消息。\n\n当前请先通过欢迎板查看新人引导手册。",
|
|
"image_path": "res://assets/maps/square/v1/props/center_whale_fountain_v2_hd_clean.png",
|
|
},
|
|
]
|
|
|
|
@onready var contentLabel: RichTextLabel = $CenterContainer/PanelContainer/VBoxContainer/ContentContainer/TextPanel/ContentLabel
|
|
@onready var prevButton: Button = $CenterContainer/PanelContainer/VBoxContainer/Footer/PrevButton
|
|
@onready var nextButton: Button = $CenterContainer/PanelContainer/VBoxContainer/Footer/NextButton
|
|
@onready var dotsContainer: HBoxContainer = $CenterContainer/PanelContainer/VBoxContainer/Footer/DotsContainer
|
|
@onready var contentContainer: Container = $CenterContainer/PanelContainer/VBoxContainer/ContentContainer
|
|
@onready var imageRect: TextureRect = $CenterContainer/PanelContainer/VBoxContainer/ContentContainer/ImagePanel/ImageRect
|
|
@onready var imageLabel: Label = $CenterContainer/PanelContainer/VBoxContainer/ContentContainer/ImagePanel/ImageLabel
|
|
|
|
var pages: Array[Dictionary] = DEFAULT_PAGES.duplicate(true)
|
|
var currentPage: int = 0
|
|
var tween: Tween
|
|
var _chatUi: Control
|
|
var _chatUiPrevMouseFilter: Control.MouseFilter = Control.MOUSE_FILTER_STOP
|
|
var _chatUiMouseDisabled: bool = false
|
|
|
|
func _ready() -> void:
|
|
add_to_group("whaletown_escape_dismissible")
|
|
get_tree().paused = true
|
|
_disableChatUiMouseInput()
|
|
|
|
var closeButton := $CenterContainer/PanelContainer/VBoxContainer/Header/RightContainer/CloseButton as Button
|
|
closeButton.pressed.connect(_onClosePressed)
|
|
prevButton.pressed.connect(_onPrevPressed)
|
|
nextButton.pressed.connect(_onNextPressed)
|
|
|
|
contentContainer.modulate.a = 1.0
|
|
_setupDots()
|
|
_updateUi(false)
|
|
|
|
func _exit_tree() -> void:
|
|
_restoreChatUiMouseInput()
|
|
|
|
func is_escape_dismissible() -> bool:
|
|
return is_inside_tree()
|
|
|
|
func get_escape_priority() -> int:
|
|
return 1000
|
|
|
|
func request_escape_close() -> void:
|
|
_onClosePressed()
|
|
|
|
func _setupDots() -> void:
|
|
for child in dotsContainer.get_children():
|
|
child.queue_free()
|
|
|
|
for index in range(pages.size()):
|
|
var dot := ColorRect.new()
|
|
dot.custom_minimum_size = Vector2(12, 12)
|
|
dotsContainer.add_child(dot)
|
|
|
|
func _updateUi(animate: bool = true) -> void:
|
|
if pages.is_empty():
|
|
return
|
|
|
|
prevButton.disabled = currentPage == 0
|
|
nextButton.disabled = currentPage == pages.size() - 1
|
|
|
|
var dots := dotsContainer.get_children()
|
|
for index in range(dots.size()):
|
|
var dot := dots[index] as ColorRect
|
|
if dot == null:
|
|
continue
|
|
if index == currentPage:
|
|
dot.color = Color(0.15, 0.36, 0.44, 1.0)
|
|
dot.custom_minimum_size = Vector2(18, 12)
|
|
else:
|
|
dot.color = Color(0.72, 0.78, 0.72, 1.0)
|
|
dot.custom_minimum_size = Vector2(12, 12)
|
|
|
|
if animate:
|
|
_animateContentChange()
|
|
else:
|
|
_setContentImmediate()
|
|
|
|
func _setContentImmediate() -> void:
|
|
var page := pages[currentPage]
|
|
contentLabel.text = page.get("text", "") as String
|
|
|
|
var imagePath := page.get("image_path", "") as String
|
|
if imagePath != "" and ResourceLoader.exists(imagePath):
|
|
imageRect.texture = load(imagePath) as Texture2D
|
|
imageLabel.visible = false
|
|
else:
|
|
imageRect.texture = null
|
|
imageLabel.visible = true
|
|
imageLabel.text = "暂无图片"
|
|
|
|
func _animateContentChange() -> void:
|
|
if tween != null and tween.is_valid():
|
|
tween.kill()
|
|
|
|
tween = create_tween()
|
|
tween.tween_property(contentContainer, "modulate:a", 0.0, 0.15)
|
|
tween.tween_callback(_setContentImmediate)
|
|
tween.tween_property(contentContainer, "modulate:a", 1.0, 0.15)
|
|
|
|
func _onPrevPressed() -> void:
|
|
if currentPage > 0:
|
|
currentPage -= 1
|
|
_updateUi()
|
|
|
|
func _onNextPressed() -> void:
|
|
if currentPage < pages.size() - 1:
|
|
currentPage += 1
|
|
_updateUi()
|
|
|
|
func _onClosePressed() -> void:
|
|
get_tree().paused = false
|
|
queue_free()
|
|
|
|
func _disableChatUiMouseInput() -> void:
|
|
var currentScene := get_tree().current_scene
|
|
if currentScene != null:
|
|
_chatUi = currentScene.get_node_or_null("UILayer/ChatUI") as Control
|
|
|
|
if _chatUi == null:
|
|
_chatUi = get_tree().root.find_child("ChatUI", true, false) as Control
|
|
|
|
if _chatUi != null:
|
|
_chatUiPrevMouseFilter = _chatUi.mouse_filter
|
|
_chatUi.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
_chatUiMouseDisabled = true
|
|
|
|
func _restoreChatUiMouseInput() -> void:
|
|
if _chatUiMouseDisabled and is_instance_valid(_chatUi):
|
|
_chatUi.mouse_filter = _chatUiPrevMouseFilter
|
|
|
|
_chatUiMouseDisabled = false
|
|
_chatUi = null
|