WIP marker changes, fix server name not appearing for saved hosts in join dialog

This commit is contained in:
ApsZoldat
2023-12-10 22:44:30 +03:00
parent 2b0a6a6f97
commit 4802076bf8
7 changed files with 51 additions and 33 deletions

View File

@@ -2480,6 +2480,7 @@ lenum.getblock = Fetch a building, floor and type at coordinates.\nUnit must be
lenum.within = Check if unit is near a position. lenum.within = Check if unit is near a position.
lenum.boost = Start/stop boosting. lenum.boost = Start/stop boosting.
lenum.texture = Texture name straight from game's texture atlas (using kebab-case naming style).\nSecond and third arguments are additional suffixes added using "-" separator.\nIf additional arguments are not strings, nothing is added to first string. lenum.text = Set marker text, if applicable to marker's type.\nIf printFlush is set to true, consumes text buffer content as text argument.\nIf fetch is set to true, tries to fetch properties from map locale bundle or game's bundle.
lenum.texture = Texture name straight from game's texture atlas (using kebab-case naming style).\nIf printFlush is set to true, consumes text buffer content as text argument.
lenum.texturesize = Size of texture in tiles. Zero value scales marker width to original texture's size. lenum.texturesize = Size of texture in tiles. Zero value scales marker width to original texture's size.
lenum.autoscale = Whether to scale marker corresponding to player's zoom level. lenum.autoscale = Whether to scale marker corresponding to player's zoom level.

View File

@@ -373,11 +373,15 @@ public class Renderer implements ApplicationListener{
//draw objective markers //draw objective markers
state.rules.objectives.eachRunning(obj -> { state.rules.objectives.eachRunning(obj -> {
for(var marker : obj.markers) marker.draw(); for(var marker : obj.markers){
if(!marker.minimap) marker.drawWorld();
}
}); });
for(var marker : state.markers.values()){ for(var marker : state.markers.values()){
if(marker != null) marker.draw(); if(marker != null){
if(!marker.isHidden() && !marker.minimap) marker.drawWorld();
}
} }
Draw.reset(); Draw.reset();

View File

@@ -638,14 +638,18 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
/** On which z-sorting layer is marker drawn. */ /** On which z-sorting layer is marker drawn. */
protected float drawLayer = Layer.overlayUI; protected float drawLayer = Layer.overlayUI;
/** Called in the overlay draw layer.*/ /** Called in the main renderer */
public void draw(){} public void drawWorld(){}
/** Called in the small and large map. */ /** Called in the small and large map. */
public void drawMinimap(MinimapRenderer minimap){} public void drawMinimap(MinimapRenderer minimap){}
/** Add any UI elements necessary. */ /** Add any UI elements necessary. */
public void added(){} public void added(){}
/** Remove any UI elements, if necessary. */ /** Remove any UI elements, if necessary. */
public void removed(){} public void removed(){}
/** Whether the marker is hidden */
public boolean isHidden(){
return hidden;
}
/** Control marker with world processor code. Ignores NaN (null) values. */ /** Control marker with world processor code. Ignores NaN (null) values. */
public void control(LMarkerControl type, double p1, double p2, double p3){ public void control(LMarkerControl type, double p1, double p2, double p3){
if(Double.isNaN(p1)) return; if(Double.isNaN(p1)) return;
@@ -730,7 +734,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public ShapeTextMarker(){} public ShapeTextMarker(){}
@Override @Override
public void draw(){ public void drawWorld(){
if(hidden || minimap) return; if(hidden || minimap) return;
//in case some idiot decides to make 9999999 sides and freeze the game //in case some idiot decides to make 9999999 sides and freeze the game
@@ -844,6 +848,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public MinimapMarker(int x, int y, Color color){ public MinimapMarker(int x, int y, Color color){
this.pos.set(x, y); this.pos.set(x, y);
this.color = color; this.color = color;
minimap = true;
} }
public MinimapMarker(int x, int y, float radius, float stroke, Color color){ public MinimapMarker(int x, int y, float radius, float stroke, Color color){
@@ -851,10 +856,16 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
this.stroke = stroke; this.stroke = stroke;
this.radius = radius; this.radius = radius;
this.color = color; this.color = color;
minimap = true;
} }
public MinimapMarker(){} public MinimapMarker(){}
@Override
public void drawWorld(){
minimap = true;
}
@Override @Override
public void drawMinimap(MinimapRenderer minimap){ public void drawMinimap(MinimapRenderer minimap){
if(hidden) return; if(hidden) return;
@@ -879,6 +890,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
case radius -> radius = (float)p1; case radius -> radius = (float)p1;
case stroke -> stroke = (float)p1; case stroke -> stroke = (float)p1;
case color -> color.set(Tmp.c1.fromDouble(p1)); case color -> color.set(Tmp.c1.fromDouble(p1));
case minimap -> minimap = true;
default -> super.control(type, p1, p2, p3); default -> super.control(type, p1, p2, p3);
} }
} }
@@ -914,7 +926,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public ShapeMarker(){} public ShapeMarker(){}
@Override @Override
public void draw(){ public void drawWorld(){
if(hidden || minimap) return; if(hidden || minimap) return;
//in case some idiot decides to make 9999999 sides and freeze the game //in case some idiot decides to make 9999999 sides and freeze the game
@@ -1023,7 +1035,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public TextMarker(){} public TextMarker(){}
@Override @Override
public void draw(){ public void drawWorld(){
// font size cannot be 0 // font size cannot be 0
if(hidden || Mathf.equal(fontSize, 0f) || minimap) return; if(hidden || Mathf.equal(fontSize, 0f) || minimap) return;
@@ -1118,7 +1130,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
public LineMarker(){} public LineMarker(){}
@Override @Override
public void draw(){ public void drawWorld(){
if(hidden || minimap) return; if(hidden || minimap) return;
float scl = autoscale ? 4f / renderer.getDisplayScale() : 1f; float scl = autoscale ? 4f / renderer.getDisplayScale() : 1f;
@@ -1210,7 +1222,7 @@ public class MapObjectives implements Iterable<MapObjective>, Eachable<MapObject
} }
@Override @Override
public void draw(){ public void drawWorld(){
if(hidden || textureName.isEmpty() || minimap) return; if(hidden || textureName.isEmpty() || minimap) return;
if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName); if(fetchedRegion == null) fetchedRegion = Core.atlas.find(textureName);

View File

@@ -255,12 +255,14 @@ public class MinimapRenderer{
state.rules.objectives.eachRunning(obj -> { state.rules.objectives.eachRunning(obj -> {
for(var marker : obj.markers){ for(var marker : obj.markers){
marker.drawMinimap(this); if(marker.minimap) marker.drawMinimap(this);
} }
}); });
for(var marker : state.markers.values()){ for(var marker : state.markers.values()){
if(marker != null) marker.drawMinimap(this); if(marker != null){
if(!marker.isHidden() && marker.minimap) marker.drawMinimap(this);
}
} }
} }

View File

@@ -1988,16 +1988,18 @@ public class LExecutor{
if(marker == null) return; if(marker == null) return;
if(type == LMarkerControl.text){ if(type == LMarkerControl.text){
marker.setText((exec.obj(p1) != null ? exec.obj(p1).toString() : "null"), false); if(exec.bool(p1)){
}else if(type == LMarkerControl.flushText){ marker.setText(exec.textBuffer.toString(), exec.bool(p3));
marker.setText(exec.textBuffer.toString(), true); exec.textBuffer.setLength(0);
exec.textBuffer.setLength(0); }else{
marker.setText((exec.obj(p2) != null ? exec.obj(p2).toString() : "null"), exec.bool(p3));
}
}else if(type == LMarkerControl.texture){ }else if(type == LMarkerControl.texture){
if(exec.obj(p1) != null){ if(exec.bool(p1)){
StringBuilder res = new StringBuilder(exec.obj(p1).toString()); marker.setTexture(exec.textBuffer.toString());
if(exec.obj(p2) != null) res.append("-").append(exec.obj(p2).toString()); exec.textBuffer.setLength(0);
if(exec.obj(p3) != null) res.append("-").append(exec.obj(p3).toString()); }else{
marker.setTexture(res.toString()); marker.setTexture((exec.obj(p2) != null ? exec.obj(p2).toString() : "null"));
} }
}else{ }else{
marker.control(type, exec.numOrNan(p1), exec.numOrNan(p2), exec.numOrNan(p3)); marker.control(type, exec.numOrNan(p1), exec.numOrNan(p2), exec.numOrNan(p3));
@@ -2053,13 +2055,11 @@ public class LExecutor{
} }
@Remote(called = Loc.server, variants = Variant.both, unreliable = true) @Remote(called = Loc.server, variants = Variant.both, unreliable = true)
public static void updateMarkerText(int id, LMarkerControl type, String text){ public static void updateMarkerText(int id, LMarkerControl type, boolean fetch, String text){
var marker = state.markers.get(id); var marker = state.markers.get(id);
if(marker != null){ if(marker != null){
if(type == LMarkerControl.text){ if(type == LMarkerControl.text){
marker.setText(text, true); marker.setText(text, fetch);
}else if(type == LMarkerControl.flushText){
marker.setText(text, false);
} }
} }
} }

View File

@@ -13,12 +13,11 @@ public enum LMarkerControl{
stroke("stroke"), stroke("stroke"),
rotation("rotation"), rotation("rotation"),
shape("sides", "fill", "outline"), shape("sides", "fill", "outline"),
text("text"), text("printFlush", "text", "fetch"),
flushText,
fontSize("size"), fontSize("size"),
textHeight("height"), textHeight("height"),
labelFlags("background", "outline"), labelFlags("background", "outline"),
texture("name", "-", "-"), texture("printFlush", "name"),
textureSize("width", "height"); textureSize("width", "height");
public final String[] params; public final String[] params;

View File

@@ -247,10 +247,10 @@ public class JoinDialog extends BaseDialog{
void setupServer(Server server, Host host){ void setupServer(Server server, Host host){
server.lastHost = host; server.lastHost = host;
server.content.clear(); server.content.clear();
buildServer(host, server.content, false); buildServer(host, server.content, false, true);
} }
void buildServer(Host host, Table content, boolean local){ void buildServer(Host host, Table content, boolean local, boolean addName){
content.top().left(); content.top().left();
boolean isBanned = local && Vars.steam && host.description != null && host.description.equals("[banned]"); boolean isBanned = local && Vars.steam && host.description != null && host.description.equals("[banned]");
String versionString = getVersionString(host) + (isBanned ? "[red] [banned]" : ""); String versionString = getVersionString(host) + (isBanned ? "[red] [banned]" : "");
@@ -261,7 +261,7 @@ public class JoinDialog extends BaseDialog{
Color color = Pal.gray; Color color = Pal.gray;
if(local){ if(addName){
content.table(Tex.whiteui, t -> { content.table(Tex.whiteui, t -> {
t.left(); t.left();
t.setColor(color); t.setColor(color);
@@ -513,7 +513,7 @@ public class JoinDialog extends BaseDialog{
button[0].row(); button[0].row();
buildServer(host, button[0].table(t -> {}).grow().get(), false); buildServer(host, button[0].table(t -> {}).grow().get(), false, false);
if((container.getChildren().size) % columns() == 0){ if((container.getChildren().size) % columns() == 0){
container.row(); container.row();
@@ -544,7 +544,7 @@ public class JoinDialog extends BaseDialog{
local.row(); local.row();
} }
local.button(b -> buildServer(host, b, true), style, () -> { local.button(b -> buildServer(host, b, true, true), style, () -> {
Events.fire(new ClientPreConnectEvent(host)); Events.fire(new ClientPreConnectEvent(host));
safeConnect(host.address, host.port, host.version); safeConnect(host.address, host.port, host.version);
}).width(w).top().left().growY(); }).width(w).top().left().growY();