Fixed bbcode parsing for built-in RichTextEffects in RichTextLabel
RichTextEffect can now have a bbcode string starting like one of the built-in.
It was impossible before as the built-in would take precedence over the custom effect that has the same bbcode start.
Example : [fade] would take precedence over [fade_in]
(cherry picked from commit b4e3042cba
)
This commit is contained in:
parent
0573c8bf62
commit
3c26de316e
|
@ -2078,6 +2078,8 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
String tag = p_bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1);
|
String tag = p_bbcode.substr(brk_pos + 1, brk_end - brk_pos - 1);
|
||||||
|
Vector<String> split_tag_block = tag.split(" ", false);
|
||||||
|
String bbcode = !split_tag_block.empty() ? split_tag_block[0] : "";
|
||||||
if (tag.begins_with("/") && tag_stack.size()) {
|
if (tag.begins_with("/") && tag_stack.size()) {
|
||||||
|
|
||||||
bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length());
|
bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length());
|
||||||
|
@ -2310,15 +2312,14 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
|
||||||
pos = brk_end + 1;
|
pos = brk_end + 1;
|
||||||
tag_stack.push_front("font");
|
tag_stack.push_front("font");
|
||||||
|
|
||||||
} else if (tag.begins_with("fade")) {
|
} else if (bbcode == "fade") {
|
||||||
Vector<String> tags = tag.split(" ", false);
|
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
int length = 10;
|
int length = 10;
|
||||||
|
|
||||||
if (tags.size() > 1) {
|
if (split_tag_block.size() > 1) {
|
||||||
tags.remove(0);
|
split_tag_block.remove(0);
|
||||||
for (int i = 0; i < tags.size(); i++) {
|
for (int i = 0; i < split_tag_block.size(); i++) {
|
||||||
String expr = tags[i];
|
String expr = split_tag_block[i];
|
||||||
if (expr.begins_with("start=")) {
|
if (expr.begins_with("start=")) {
|
||||||
String start_str = expr.substr(6, expr.length());
|
String start_str = expr.substr(6, expr.length());
|
||||||
startIndex = start_str.to_int();
|
startIndex = start_str.to_int();
|
||||||
|
@ -2332,15 +2333,14 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
|
||||||
push_fade(startIndex, length);
|
push_fade(startIndex, length);
|
||||||
pos = brk_end + 1;
|
pos = brk_end + 1;
|
||||||
tag_stack.push_front("fade");
|
tag_stack.push_front("fade");
|
||||||
} else if (tag.begins_with("shake")) {
|
} else if (bbcode == "shake") {
|
||||||
Vector<String> tags = tag.split(" ", false);
|
|
||||||
int strength = 5;
|
int strength = 5;
|
||||||
float rate = 20.0f;
|
float rate = 20.0f;
|
||||||
|
|
||||||
if (tags.size() > 1) {
|
if (split_tag_block.size() > 1) {
|
||||||
tags.remove(0);
|
split_tag_block.remove(0);
|
||||||
for (int i = 0; i < tags.size(); i++) {
|
for (int i = 0; i < split_tag_block.size(); i++) {
|
||||||
String expr = tags[i];
|
String expr = split_tag_block[i];
|
||||||
if (expr.begins_with("level=")) {
|
if (expr.begins_with("level=")) {
|
||||||
String str_str = expr.substr(6, expr.length());
|
String str_str = expr.substr(6, expr.length());
|
||||||
strength = str_str.to_int();
|
strength = str_str.to_int();
|
||||||
|
@ -2355,15 +2355,14 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
|
||||||
pos = brk_end + 1;
|
pos = brk_end + 1;
|
||||||
tag_stack.push_front("shake");
|
tag_stack.push_front("shake");
|
||||||
set_process_internal(true);
|
set_process_internal(true);
|
||||||
} else if (tag.begins_with("wave")) {
|
} else if (bbcode == "wave") {
|
||||||
Vector<String> tags = tag.split(" ", false);
|
|
||||||
float amplitude = 20.0f;
|
float amplitude = 20.0f;
|
||||||
float period = 5.0f;
|
float period = 5.0f;
|
||||||
|
|
||||||
if (tags.size() > 1) {
|
if (split_tag_block.size() > 1) {
|
||||||
tags.remove(0);
|
split_tag_block.remove(0);
|
||||||
for (int i = 0; i < tags.size(); i++) {
|
for (int i = 0; i < split_tag_block.size(); i++) {
|
||||||
String expr = tags[i];
|
String expr = split_tag_block[i];
|
||||||
if (expr.begins_with("amp=")) {
|
if (expr.begins_with("amp=")) {
|
||||||
String amp_str = expr.substr(4, expr.length());
|
String amp_str = expr.substr(4, expr.length());
|
||||||
amplitude = amp_str.to_float();
|
amplitude = amp_str.to_float();
|
||||||
|
@ -2378,15 +2377,14 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
|
||||||
pos = brk_end + 1;
|
pos = brk_end + 1;
|
||||||
tag_stack.push_front("wave");
|
tag_stack.push_front("wave");
|
||||||
set_process_internal(true);
|
set_process_internal(true);
|
||||||
} else if (tag.begins_with("tornado")) {
|
} else if (bbcode == "tornado") {
|
||||||
Vector<String> tags = tag.split(" ", false);
|
|
||||||
float radius = 10.0f;
|
float radius = 10.0f;
|
||||||
float frequency = 1.0f;
|
float frequency = 1.0f;
|
||||||
|
|
||||||
if (tags.size() > 1) {
|
if (split_tag_block.size() > 1) {
|
||||||
tags.remove(0);
|
split_tag_block.remove(0);
|
||||||
for (int i = 0; i < tags.size(); i++) {
|
for (int i = 0; i < split_tag_block.size(); i++) {
|
||||||
String expr = tags[i];
|
String expr = split_tag_block[i];
|
||||||
if (expr.begins_with("radius=")) {
|
if (expr.begins_with("radius=")) {
|
||||||
String amp_str = expr.substr(7, expr.length());
|
String amp_str = expr.substr(7, expr.length());
|
||||||
radius = amp_str.to_float();
|
radius = amp_str.to_float();
|
||||||
|
@ -2401,16 +2399,15 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
|
||||||
pos = brk_end + 1;
|
pos = brk_end + 1;
|
||||||
tag_stack.push_front("tornado");
|
tag_stack.push_front("tornado");
|
||||||
set_process_internal(true);
|
set_process_internal(true);
|
||||||
} else if (tag.begins_with("rainbow")) {
|
} else if (bbcode == "rainbow") {
|
||||||
Vector<String> tags = tag.split(" ", false);
|
|
||||||
float saturation = 0.8f;
|
float saturation = 0.8f;
|
||||||
float value = 0.8f;
|
float value = 0.8f;
|
||||||
float frequency = 1.0f;
|
float frequency = 1.0f;
|
||||||
|
|
||||||
if (tags.size() > 1) {
|
if (split_tag_block.size() > 1) {
|
||||||
tags.remove(0);
|
split_tag_block.remove(0);
|
||||||
for (int i = 0; i < tags.size(); i++) {
|
for (int i = 0; i < split_tag_block.size(); i++) {
|
||||||
String expr = tags[i];
|
String expr = split_tag_block[i];
|
||||||
if (expr.begins_with("sat=")) {
|
if (expr.begins_with("sat=")) {
|
||||||
String sat_str = expr.substr(4, expr.length());
|
String sat_str = expr.substr(4, expr.length());
|
||||||
saturation = sat_str.to_float();
|
saturation = sat_str.to_float();
|
||||||
|
@ -2429,7 +2426,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
|
||||||
tag_stack.push_front("rainbow");
|
tag_stack.push_front("rainbow");
|
||||||
set_process_internal(true);
|
set_process_internal(true);
|
||||||
} else {
|
} else {
|
||||||
Vector<String> expr = tag.split(" ", false);
|
Vector<String> &expr = split_tag_block;
|
||||||
if (expr.size() < 1) {
|
if (expr.size() < 1) {
|
||||||
add_text("[");
|
add_text("[");
|
||||||
pos = brk_pos + 1;
|
pos = brk_pos + 1;
|
||||||
|
|
Loading…
Reference in New Issue