Moving files pre-refactor
This commit is contained in:
44
ui/component/AdvancedRichText.gd
Normal file
44
ui/component/AdvancedRichText.gd
Normal file
@@ -0,0 +1,44 @@
|
||||
@tool
|
||||
class_name AdvancedRichText extends RichTextLabel
|
||||
|
||||
@export_multiline var advancedText:String = "":
|
||||
get():
|
||||
return advancedText
|
||||
set(value):
|
||||
advancedText = value
|
||||
_parseAdvancedText()
|
||||
|
||||
@export var translate:bool = true:
|
||||
set(value):
|
||||
translate = value
|
||||
_parseAdvancedText()
|
||||
get():
|
||||
return translate
|
||||
|
||||
func _init() -> void:
|
||||
self._parseAdvancedText()
|
||||
|
||||
func _enter_tree() -> void:
|
||||
self._parseAdvancedText()
|
||||
|
||||
func _parseAdvancedText() -> void:
|
||||
if advancedText.is_empty():
|
||||
self.text = ""
|
||||
return
|
||||
var key = advancedText
|
||||
if self.translate:
|
||||
key = tr(key)
|
||||
self.text = processInputTags(key)
|
||||
|
||||
func processInputTags(text:String) -> String:
|
||||
var regex = RegEx.new()
|
||||
regex.compile(r"\[input action=(.*?)\](.*?)\[/input\]")
|
||||
var result = text
|
||||
for match in regex.search_all(text):
|
||||
var action = match.get_string(1).to_lower()
|
||||
var height:int = 32
|
||||
# var device = get_current_device_type()
|
||||
# var icon_path = get_icon_for_action(action, device)
|
||||
var img_tag = "[img height=%d valign=center,center]res://textures/input/%s.tres[/img]" % [ height, action ]
|
||||
result = result.replace(match.get_string(0), img_tag)
|
||||
return result
|
1
ui/component/AdvancedRichText.gd.uid
Normal file
1
ui/component/AdvancedRichText.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bjj6upgk1uvxd
|
34
ui/component/ClosableMenu.gd
Normal file
34
ui/component/ClosableMenu.gd
Normal file
@@ -0,0 +1,34 @@
|
||||
class_name ClosableMenu extends Control
|
||||
|
||||
@export var isOpen: bool:
|
||||
set(newValue):
|
||||
isOpen = newValue
|
||||
visible = newValue
|
||||
if newValue:
|
||||
opened.emit()
|
||||
else:
|
||||
closed.emit()
|
||||
get():
|
||||
return isOpen
|
||||
|
||||
signal closed
|
||||
signal opened
|
||||
|
||||
func _enter_tree() -> void:
|
||||
visible = isOpen
|
||||
|
||||
func _exit_tree() -> void:
|
||||
visible = false
|
||||
|
||||
func _ready() -> void:
|
||||
visible = isOpen
|
||||
print("ClosableMenu is ready, isOpen: ", isOpen)
|
||||
|
||||
func close() -> void:
|
||||
isOpen = false
|
||||
|
||||
func open() -> void:
|
||||
isOpen = true
|
||||
|
||||
func toggle() -> void:
|
||||
isOpen = !isOpen
|
1
ui/component/ClosableMenu.gd.uid
Normal file
1
ui/component/ClosableMenu.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://bcjfv6dw0ugvo
|
123
ui/component/VNTextbox.gd
Normal file
123
ui/component/VNTextbox.gd
Normal file
@@ -0,0 +1,123 @@
|
||||
class_name VNTextbox extends PanelContainer
|
||||
|
||||
const VN_REVEAL_TIME = 0.01
|
||||
const VISIBLE_LINES:int = 4
|
||||
|
||||
var label:RichTextLabel;
|
||||
var text:String = ""
|
||||
var parsedOutText = ""
|
||||
var visibleCharacters:int = 0;
|
||||
var revealTimer:float = 0;
|
||||
|
||||
var lineStarts:Array[int] = [];
|
||||
var newlineIndexes:Array[int] = [];
|
||||
var wrappedText:String = "";
|
||||
var currentLine = 0;
|
||||
var currentViewScrolled = true;
|
||||
var isSpeedupDown = false;
|
||||
var isMoreViews = false;
|
||||
var isClosed = true;
|
||||
|
||||
signal textboxClosing
|
||||
|
||||
func _ready() -> void:
|
||||
label = $MarginContainer/Label
|
||||
self.visible = false;
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if text == "":
|
||||
isClosed = true;
|
||||
return;
|
||||
|
||||
if currentViewScrolled:
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
if isMoreViews:
|
||||
visibleCharacters = 0;
|
||||
currentLine += VISIBLE_LINES;
|
||||
currentViewScrolled = false;
|
||||
recalculateWrapping();
|
||||
return
|
||||
setText("");
|
||||
textboxClosing.emit();
|
||||
return;
|
||||
|
||||
if visibleCharacters >= getCountOfCharactersToScrollInView():
|
||||
currentViewScrolled = true;
|
||||
#print("Scrolled view");
|
||||
#if isMoreViews:
|
||||
#print("More views");
|
||||
return;
|
||||
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
isSpeedupDown = true;
|
||||
elif Input.is_action_just_released("interact"):
|
||||
isSpeedupDown = false;
|
||||
elif !Input.is_action_pressed("interact"):
|
||||
isSpeedupDown = false;
|
||||
|
||||
revealTimer += delta;
|
||||
if isSpeedupDown:
|
||||
revealTimer += delta;
|
||||
|
||||
if revealTimer > VN_REVEAL_TIME:
|
||||
revealTimer = 0;
|
||||
visibleCharacters += 1;
|
||||
label.visible_characters = visibleCharacters;
|
||||
|
||||
func getCountOfCharactersToScrollInView() -> int:
|
||||
if lineStarts.size() <= VISIBLE_LINES:
|
||||
return wrappedText.length();
|
||||
if currentLine + VISIBLE_LINES >= lineStarts.size():
|
||||
return wrappedText.length() - lineStarts[currentLine];
|
||||
return lineStarts[min(lineStarts.size(), currentLine + VISIBLE_LINES)] - lineStarts[currentLine];
|
||||
|
||||
func recalculateWrapping():
|
||||
# Reset label to default.
|
||||
label.advancedText = text;
|
||||
label.visible_characters = -1;
|
||||
label.fit_content = true;
|
||||
isMoreViews = false;
|
||||
|
||||
# Determine where the wrapped newlines are
|
||||
lineStarts = [ 0 ];
|
||||
var line = 0;
|
||||
var wasNewLine = false;
|
||||
for i in range(0, text.length()):
|
||||
var tLine = label.get_character_line(i);
|
||||
if tLine == line:
|
||||
wasNewLine = false
|
||||
if text[i] == "\n":
|
||||
wasNewLine = true
|
||||
continue;
|
||||
if !wasNewLine:
|
||||
newlineIndexes.append(i);
|
||||
lineStarts.append(i);
|
||||
line = tLine;
|
||||
|
||||
# Create fake pre-wrapped text.
|
||||
wrappedText = "";
|
||||
for i in range(lineStarts[currentLine], text.length()):
|
||||
if newlineIndexes.find(i) != -1 and i != lineStarts[currentLine]:
|
||||
wrappedText += "\n";
|
||||
wrappedText += text[i];
|
||||
|
||||
label.advancedText = wrappedText;
|
||||
label.fit_content = false;
|
||||
label.visible_characters = 0;
|
||||
|
||||
if lineStarts.size() > currentLine + VISIBLE_LINES:
|
||||
isMoreViews = true;
|
||||
|
||||
func setText(text:String) -> void:
|
||||
self.text = text;
|
||||
if text == "":
|
||||
self.visible = false;
|
||||
return;
|
||||
|
||||
isClosed = false;
|
||||
revealTimer = 0;
|
||||
visibleCharacters = 0;
|
||||
currentLine = 0;
|
||||
currentViewScrolled = false;
|
||||
recalculateWrapping();
|
||||
self.visible = true;
|
1
ui/component/VNTextbox.gd.uid
Normal file
1
ui/component/VNTextbox.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://h8lw23ypcfty
|
38
ui/component/VNTextbox.tscn
Normal file
38
ui/component/VNTextbox.tscn
Normal file
@@ -0,0 +1,38 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bkx3l0kckf4a8"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://dm7ee4aqjr2dl" path="res://ui/UI Theme.tres" id="1_wx4lp"]
|
||||
[ext_resource type="Script" uid="uid://h8lw23ypcfty" path="res://ui/component/VNTextbox.gd" id="2_uo1gm"]
|
||||
[ext_resource type="Script" uid="uid://bjj6upgk1uvxd" path="res://ui/component/AdvancedRichText.gd" id="3_m60k3"]
|
||||
|
||||
[node name="VNTextbox" type="PanelContainer"]
|
||||
anchors_preset = 12
|
||||
anchor_top = 1.0
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_top = -58.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 0
|
||||
theme = ExtResource("1_wx4lp")
|
||||
script = ExtResource("2_uo1gm")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("1_wx4lp")
|
||||
theme_override_constants/margin_left = 4
|
||||
theme_override_constants/margin_top = 4
|
||||
theme_override_constants/margin_right = 4
|
||||
theme_override_constants/margin_bottom = 4
|
||||
|
||||
[node name="Label" type="RichTextLabel" parent="MarginContainer"]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("1_wx4lp")
|
||||
bbcode_enabled = true
|
||||
text = "TEST
|
||||
TEST
|
||||
TEST
|
||||
TEST"
|
||||
script = ExtResource("3_m60k3")
|
||||
advancedText = "TEST
|
||||
TEST
|
||||
TEST
|
||||
TEST"
|
Reference in New Issue
Block a user