Formatting Icons (#10359)
* formatIcons
* Smarter end check
I think it's smarter?
* unecessary
* oop
* Update UI.java
* Just don't check for adjacent colons.
The hasUnicodeStr already checks for validity
* Copy from I18NBundle
* Revert "Copy from I18NBundle"
This reverts commit ac660fcd9f.
* If get and format refer to parent, then just set the existing bundle as parent
* Test with Ground Zero objectives
* Update MBundle.java
* That didn't work
* Slip the method into reasonable places like objectives and chat
* Check for Icons as well
* More testing with objective text
* Apply to hints
* Optimized formatIcons
No longer scans through every character
* TIME UPDATE THE BUNDLES YIPPEEEEEEEEEEE
* residual
* Apply to message blocks
* IntelliJ lied
* Suggestions
* Format before sending
This commit is contained in:
@@ -33,6 +33,8 @@ import static arc.scene.actions.Actions.*;
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
public class UI implements ApplicationListener, Loadable{
|
||||
|
||||
private static final StringBuilder buffer = new StringBuilder();
|
||||
public static String billions, millions, thousands;
|
||||
|
||||
public static PixmapPacker packer;
|
||||
@@ -682,6 +684,40 @@ public class UI implements ApplicationListener, Loadable{
|
||||
followUpMenus.remove(menuId).hide();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all :name: in a string and replaces them with the icon, if such exists.
|
||||
* Based on TextFormatter::simpleFormat
|
||||
*/
|
||||
public static String formatIcons(String s){
|
||||
if(!s.contains(":")) return s;
|
||||
|
||||
buffer.setLength(0);
|
||||
boolean changed = false;
|
||||
|
||||
boolean checkIcon = false;
|
||||
String[] tokens = s.split(":");
|
||||
for(String token : tokens){
|
||||
if(checkIcon){
|
||||
if(Iconc.codes.containsKey(token)){
|
||||
buffer.append((char)Iconc.codes.get(token));
|
||||
changed = true;
|
||||
checkIcon = false;
|
||||
}else if(Fonts.hasUnicodeStr(token)){
|
||||
buffer.append(Fonts.getUnicodeStr(token));
|
||||
changed = true;
|
||||
checkIcon = false;
|
||||
}else{
|
||||
buffer.append(":").append(token);
|
||||
}
|
||||
}else{
|
||||
buffer.append(token);
|
||||
checkIcon = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed ? buffer.toString() : s;
|
||||
}
|
||||
|
||||
/** Formats time with hours:minutes:seconds. */
|
||||
public static String formatTime(float ticks){
|
||||
int seconds = (int)(ticks / 60);
|
||||
|
||||
@@ -11,6 +11,7 @@ import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.game.MapObjectives.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -661,17 +662,19 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
|
||||
if(text.startsWith("@")){
|
||||
String key = text.substring(1);
|
||||
|
||||
String out;
|
||||
if(mobile){
|
||||
return state.mapLocales.containsProperty(key + ".mobile") ?
|
||||
state.mapLocales.getProperty(key + ".mobile") :
|
||||
Core.bundle.get(key + ".mobile", Core.bundle.get(key));
|
||||
out = state.mapLocales.containsProperty(key + ".mobile") ?
|
||||
state.mapLocales.getProperty(key + ".mobile") :
|
||||
Core.bundle.get(key + ".mobile", Core.bundle.get(key));
|
||||
}else{
|
||||
return state.mapLocales.containsProperty(key) ?
|
||||
state.mapLocales.getProperty(key) :
|
||||
Core.bundle.get(key);
|
||||
out = state.mapLocales.containsProperty(key) ?
|
||||
state.mapLocales.getProperty(key) :
|
||||
Core.bundle.get(key);
|
||||
}
|
||||
return UI.formatIcons(out);
|
||||
}else{
|
||||
return text;
|
||||
return UI.formatIcons(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import arc.scene.ui.layout.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.input.*;
|
||||
@@ -161,14 +162,15 @@ public class ChatFragment extends Table{
|
||||
|
||||
float theight = offsety + spacing + getMarginBottom() + scene.marginBottom;
|
||||
for(int i = scrollPos; i < messages.size && i < messagesShown + scrollPos && (i < fadetime || shown); i++){
|
||||
String message = messages.get(i);
|
||||
|
||||
layout.setText(font, messages.get(i), Color.white, textWidth, Align.bottomLeft, true);
|
||||
layout.setText(font, message, Color.white, textWidth, Align.bottomLeft, true);
|
||||
theight += layout.height + textspacing;
|
||||
if(i - scrollPos == 0) theight -= textspacing + 1;
|
||||
|
||||
font.getCache().clear();
|
||||
font.getCache().setColor(Color.white);
|
||||
font.getCache().addText(messages.get(i), fontoffsetx + offsetx, offsety + theight, textWidth, Align.bottomLeft, true);
|
||||
font.getCache().addText(message, fontoffsetx + offsetx, offsety + theight, textWidth, Align.bottomLeft, true);
|
||||
|
||||
if(!shown && fadetime - i < 1f && fadetime - i >= 0f){
|
||||
font.getCache().setAlphas((fadetime - i) * opacity);
|
||||
@@ -200,6 +202,8 @@ public class ChatFragment extends Table{
|
||||
|
||||
history.insert(1, message);
|
||||
|
||||
message = UI.formatIcons(message);
|
||||
|
||||
Events.fire(new ClientChatEvent(message));
|
||||
|
||||
Call.sendChatMessage(message);
|
||||
|
||||
@@ -13,6 +13,7 @@ import arc.util.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ai.types.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.game.EventType.*;
|
||||
import mindustry.game.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -250,7 +251,7 @@ public class HintsFragment{
|
||||
text = Vars.mobile && Core.bundle.has("hint." + name() + ".mobile") ? Core.bundle.get("hint." + name() + ".mobile") : Core.bundle.get("hint." + name());
|
||||
if(!Vars.mobile) text = text.replace("tap", "click").replace("Tap", "Click");
|
||||
}
|
||||
return text;
|
||||
return UI.formatIcons(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,7 @@ import arc.scene.ui.layout.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.pooling.*;
|
||||
import mindustry.core.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.ui.dialogs.*;
|
||||
@@ -79,7 +80,7 @@ public class MessageBlock extends Block{
|
||||
font.getData().setScale(1 / 4f / Scl.scl(1f));
|
||||
font.setUseIntegerPositions(false);
|
||||
|
||||
CharSequence text = message == null || message.length() == 0 ? "[lightgray]" + Core.bundle.get("empty") : message;
|
||||
String text = message == null || message.length() == 0 ? "[lightgray]" + Core.bundle.get("empty") : UI.formatIcons(message.toString());
|
||||
|
||||
l.setText(font, text, Color.white, 90f, Align.left, true);
|
||||
float offset = 1f;
|
||||
|
||||
Reference in New Issue
Block a user