/
PGStudio
/
DiplomaProject
Обзор
Документация
Войти
/
PGStudio
/
DiplomaProject
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/Textbox.gd
75 строк
2 KB
PGStudio
first_commit
21 июн 2026, 21:56
21 июн 2026, 21:56
69ac2dc
Код
Авторство
О чём код?
extends Node2D # INITIALIZATION @onready var CurrentSubViewport: SubViewport = $SubViewport @onready var CurrentTextbox: Node2D = null @onready var CurrentSprite2D: Sprite2D = null @onready var CurrentMessage: RichTextLabel = null @onready var CurrentCharacterName: Label = null var timer_character: float = 0.05 var current_speed_scroll: float = 32.0 var sleep_timer: Timer # BASE FUNCTIONS func _ready() -> void: CurrentSubViewport.transparent_bg = true sleep_timer = Timer.new() sleep_timer.timeout.connect(next_symbol) add_child(sleep_timer) func _process(_delta: float) -> void: pass # PUBLIC FUNCTIONS func set_textbox(textbox: PackedScene) -> void: if textbox != null: CurrentTextbox = textbox.instantiate() CurrentSubViewport.add_child(CurrentTextbox) CurrentSprite2D = CurrentTextbox.find_child("Image") CurrentMessage = CurrentTextbox.find_child("Message") CurrentCharacterName = CurrentTextbox.find_child("CharacterName") CurrentSubViewport.size = CurrentSprite2D.get_rect().size CurrentTextbox.position = CurrentSubViewport.size / 2.0 CurrentMessage.text = "" CurrentCharacterName.text = "" func send_message(message: String = "", name_character: String = "", new_timer_character: float = timer_character) -> void: CurrentCharacterName.text = name_character if CurrentMessage != null: CurrentMessage.text = message CurrentMessage.visible_characters = 0 sleep_timer.wait_time = new_timer_character sleep_timer.start() func next_symbol() -> void: if !is_finish_message(): sleep_timer.start() CurrentMessage.visible_characters += 1 func set_timer_character(timer: float) -> void: timer_character = timer func skip_animation_message() -> void: sleep_timer.stop() CurrentMessage.visible_characters = CurrentMessage.get_total_character_count() func scroll_up() -> void: if CurrentMessage != null && is_finish_message() && CurrentSubViewport.get_visible_rect().has_point(get_local_mouse_position()): CurrentMessage.get_v_scroll_bar().value -= current_speed_scroll func scroll_down() -> void: if CurrentMessage != null && is_finish_message() && CurrentSubViewport.get_visible_rect().has_point(get_local_mouse_position()): CurrentMessage.get_v_scroll_bar().value += current_speed_scroll func is_finish_message() -> bool: return CurrentMessage.visible_characters == CurrentMessage.get_total_character_count() func get_size() -> Vector2: return Vector2(CurrentSubViewport.size) func get_aspect() -> float: return CurrentSubViewport.size.aspect()