idk richtext stuff
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
@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,8 +1,9 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bkx3l0kckf4a8"]
|
||||
[gd_scene load_steps=5 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"]
|
||||
[ext_resource type="Script" uid="uid://c6av3xe4m2ujl" path="res://addons/madtalk/runtime/madtalk_runtime.gd" id="3_2x6s1"]
|
||||
[ext_resource type="Script" uid="uid://bjj6upgk1uvxd" path="res://ui/component/advancedrichtext/AdvancedRichText.gd" id="3_m60k3"]
|
||||
|
||||
[node name="VNTextbox" type="PanelContainer"]
|
||||
anchors_preset = 12
|
||||
@@ -15,6 +16,12 @@ grow_vertical = 0
|
||||
theme = ExtResource("1_wx4lp")
|
||||
script = ExtResource("2_uo1gm")
|
||||
|
||||
[node name="MadTalk" type="Node" parent="."]
|
||||
script = ExtResource("3_2x6s1")
|
||||
DialogMainControl = NodePath("..")
|
||||
DialogMessageBox = NodePath("../MarginContainer")
|
||||
DialogMessageLabel = NodePath("../MarginContainer/Label")
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||
layout_mode = 2
|
||||
theme = ExtResource("1_wx4lp")
|
||||
@@ -27,12 +34,8 @@ theme_override_constants/margin_bottom = 4
|
||||
layout_mode = 2
|
||||
theme = ExtResource("1_wx4lp")
|
||||
bbcode_enabled = true
|
||||
text = "TEST
|
||||
TEST
|
||||
TEST
|
||||
TEST"
|
||||
text = "To get through tight spaces, press[input action=down][/input]"
|
||||
fit_content = true
|
||||
script = ExtResource("3_m60k3")
|
||||
advancedText = "TEST
|
||||
TEST
|
||||
TEST
|
||||
TEST"
|
||||
userText = "To get through tight spaces, press[input action=down][/input]"
|
||||
finalText = "To get through tight spaces, press[img height=12 valign=center,center]res://ui/input/down.tres[/img]"
|
||||
|
104
ui/component/advancedrichtext/AdvancedRichText.gd
Normal file
104
ui/component/advancedrichtext/AdvancedRichText.gd
Normal file
@@ -0,0 +1,104 @@
|
||||
@tool
|
||||
class_name AdvancedRichText extends RichTextLabel
|
||||
|
||||
@export_multiline var userText:String = "" # The text the user is asking for
|
||||
@export_multiline var finalText:String = "" # The final text after processing (translation, wrapping, etc.)
|
||||
|
||||
# Hides the original RichTextLabel text property
|
||||
func _set(property: StringName, value) -> bool:
|
||||
if property == "text":
|
||||
userText = value
|
||||
_recalcText()
|
||||
return true
|
||||
elif property == "richtextlabel_text":
|
||||
text = value
|
||||
return true
|
||||
return false
|
||||
|
||||
func _get(property: StringName):
|
||||
if property == "text":
|
||||
return userText
|
||||
elif property == "richtextlabel_text":
|
||||
return text
|
||||
return null
|
||||
|
||||
@export var translate:bool = true:
|
||||
set(value):
|
||||
translate = value
|
||||
_recalcText()
|
||||
get():
|
||||
return translate
|
||||
|
||||
@export var smartWrap:bool = true:
|
||||
set(value):
|
||||
smartWrap = value
|
||||
_recalcText()
|
||||
get():
|
||||
return smartWrap
|
||||
|
||||
func _init() -> void:
|
||||
_recalcText()
|
||||
|
||||
func _enter_tree() -> void:
|
||||
_recalcText()
|
||||
self.resized.connect(_recalcText)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
self.resized.disconnect(_recalcText)
|
||||
|
||||
func _recalcText() -> void:
|
||||
if userText.is_empty():
|
||||
self.richtextlabel_text = ""
|
||||
return
|
||||
|
||||
# Translate if needed
|
||||
var textTranslated = userText
|
||||
if self.translate:
|
||||
textTranslated = tr(textTranslated)
|
||||
|
||||
# Replace input bb tags.
|
||||
var regex = RegEx.new()
|
||||
regex.compile(r"\[input action=(.*?)\](.*?)\[/input\]")
|
||||
var inputIconText = textTranslated
|
||||
for match in regex.search_all(textTranslated):
|
||||
var action = match.get_string(1).to_lower()
|
||||
var height:int = get_theme_font_size("normal_font_size")
|
||||
# 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://ui/input/%s.tres[/img]" % [ height, action ]
|
||||
inputIconText = inputIconText.replace(match.get_string(0), img_tag)
|
||||
|
||||
# Perform smart wrapping
|
||||
var wrappedText = inputIconText
|
||||
if smartWrap:
|
||||
var unwrappedText = wrappedText.strip_edges()
|
||||
|
||||
self.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART;
|
||||
self.richtextlabel_text = unwrappedText
|
||||
self.visible_characters = -1;
|
||||
self.fit_content = true;
|
||||
var newlineIndexes = [];
|
||||
|
||||
# Determine where the wrapped newlines are
|
||||
var line = 0;
|
||||
var wasNewLine = false;
|
||||
for i in range(0, unwrappedText.length()):
|
||||
var tLine = self.get_character_line(i);
|
||||
if tLine == line || tLine == -1:
|
||||
wasNewLine = false
|
||||
if unwrappedText[i] == "\n":
|
||||
wasNewLine = true
|
||||
continue;
|
||||
if !wasNewLine:
|
||||
newlineIndexes.append(i);
|
||||
line = tLine;
|
||||
|
||||
# Create fake pre-wrapped text.
|
||||
wrappedText = "";
|
||||
for i in range(0, unwrappedText.length()):
|
||||
if newlineIndexes.find(i) != -1 and i != 0:
|
||||
wrappedText += "\n";
|
||||
wrappedText += unwrappedText[i];
|
||||
|
||||
finalText = wrappedText
|
||||
self.richtextlabel_text = wrappedText
|
@@ -1,6 +1,6 @@
|
||||
[gd_resource type="Texture2D" script_class="ControllerIconTexture" load_steps=2 format=3 uid="uid://vb20551utmet"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddxpo5u73ssi2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_iw3l5"]
|
||||
[ext_resource type="Script" uid="uid://cxab4gf8nejc2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_iw3l5"]
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = false
|
||||
@@ -8,5 +8,6 @@ resource_name = ""
|
||||
script = ExtResource("1_iw3l5")
|
||||
path = "debug"
|
||||
show_mode = 0
|
||||
force_controller_icon_style = -1
|
||||
force_type = 0
|
||||
metadata/_custom_type_script = "uid://ddxpo5u73ssi2"
|
||||
force_device = 16
|
||||
|
@@ -1,12 +1,13 @@
|
||||
[gd_resource type="Texture2D" script_class="ControllerIconTexture" load_steps=2 format=3 uid="uid://cyfh2wyhh1cjg"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddxpo5u73ssi2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_p6b3a"]
|
||||
[ext_resource type="Script" uid="uid://cxab4gf8nejc2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_p6b3a"]
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = false
|
||||
resource_name = ""
|
||||
script = ExtResource("1_p6b3a")
|
||||
path = "down"
|
||||
path = "move_back"
|
||||
show_mode = 0
|
||||
force_controller_icon_style = -1
|
||||
force_type = 0
|
||||
metadata/_custom_type_script = "uid://ddxpo5u73ssi2"
|
||||
force_device = 16
|
||||
|
@@ -1,12 +1,13 @@
|
||||
[gd_resource type="Texture2D" script_class="ControllerIconTexture" load_steps=2 format=3 uid="uid://b3ii1cu3mc7jc"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddxpo5u73ssi2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_ngf5d"]
|
||||
[ext_resource type="Script" uid="uid://cxab4gf8nejc2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_ngf5d"]
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = false
|
||||
resource_name = ""
|
||||
script = ExtResource("1_ngf5d")
|
||||
path = "up"
|
||||
path = "interact"
|
||||
show_mode = 0
|
||||
force_controller_icon_style = -1
|
||||
force_type = 0
|
||||
metadata/_custom_type_script = "uid://ddxpo5u73ssi2"
|
||||
force_device = 16
|
||||
|
@@ -1,12 +1,13 @@
|
||||
[gd_resource type="Texture2D" script_class="ControllerIconTexture" load_steps=2 format=3 uid="uid://thb0gnik8oo3"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddxpo5u73ssi2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_fijpq"]
|
||||
[ext_resource type="Script" uid="uid://cxab4gf8nejc2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_fijpq"]
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = false
|
||||
resource_name = ""
|
||||
script = ExtResource("1_fijpq")
|
||||
path = "left"
|
||||
path = "move_left"
|
||||
show_mode = 0
|
||||
force_controller_icon_style = -1
|
||||
force_type = 0
|
||||
metadata/_custom_type_script = "uid://ddxpo5u73ssi2"
|
||||
force_device = 16
|
||||
|
@@ -1,6 +1,6 @@
|
||||
[gd_resource type="Texture2D" script_class="ControllerIconTexture" load_steps=2 format=3 uid="uid://byijoyarhygot"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddxpo5u73ssi2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_o0qtj"]
|
||||
[ext_resource type="Script" uid="uid://cxab4gf8nejc2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_o0qtj"]
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = false
|
||||
@@ -8,5 +8,6 @@ resource_name = ""
|
||||
script = ExtResource("1_o0qtj")
|
||||
path = "pause"
|
||||
show_mode = 0
|
||||
force_controller_icon_style = -1
|
||||
force_type = 0
|
||||
metadata/_custom_type_script = "uid://ddxpo5u73ssi2"
|
||||
force_device = 16
|
||||
|
@@ -1,12 +1,13 @@
|
||||
[gd_resource type="Texture2D" script_class="ControllerIconTexture" load_steps=2 format=3 uid="uid://dajlk4u1q8rsp"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddxpo5u73ssi2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_guxqd"]
|
||||
[ext_resource type="Script" uid="uid://cxab4gf8nejc2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_guxqd"]
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = false
|
||||
resource_name = ""
|
||||
script = ExtResource("1_guxqd")
|
||||
path = "right"
|
||||
path = "move_right"
|
||||
show_mode = 0
|
||||
force_controller_icon_style = -1
|
||||
force_type = 0
|
||||
metadata/_custom_type_script = "uid://ddxpo5u73ssi2"
|
||||
force_device = 16
|
||||
|
@@ -1,12 +1,13 @@
|
||||
[gd_resource type="Texture2D" script_class="ControllerIconTexture" load_steps=2 format=3 uid="uid://blut4glc4n0ck"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ddxpo5u73ssi2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_y6k0e"]
|
||||
[ext_resource type="Script" uid="uid://cxab4gf8nejc2" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_y6k0e"]
|
||||
|
||||
[resource]
|
||||
resource_local_to_scene = false
|
||||
resource_name = ""
|
||||
script = ExtResource("1_y6k0e")
|
||||
path = "left"
|
||||
path = "move_left"
|
||||
show_mode = 0
|
||||
force_controller_icon_style = -1
|
||||
force_type = 0
|
||||
metadata/_custom_type_script = "uid://ddxpo5u73ssi2"
|
||||
force_device = 16
|
||||
|
Reference in New Issue
Block a user