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

@@ -373,11 +373,15 @@ public class Renderer implements ApplicationListener{
//draw objective markers
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()){
if(marker != null) marker.draw();
if(marker != null){
if(!marker.isHidden() && !marker.minimap) marker.drawWorld();
}
}
Draw.reset();

View File

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

View File

@@ -255,12 +255,14 @@ public class MinimapRenderer{
state.rules.objectives.eachRunning(obj -> {
for(var marker : obj.markers){
marker.drawMinimap(this);
if(marker.minimap) marker.drawMinimap(this);
}
});
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(type == LMarkerControl.text){
marker.setText((exec.obj(p1) != null ? exec.obj(p1).toString() : "null"), false);
}else if(type == LMarkerControl.flushText){
marker.setText(exec.textBuffer.toString(), true);
exec.textBuffer.setLength(0);
if(exec.bool(p1)){
marker.setText(exec.textBuffer.toString(), exec.bool(p3));
exec.textBuffer.setLength(0);
}else{
marker.setText((exec.obj(p2) != null ? exec.obj(p2).toString() : "null"), exec.bool(p3));
}
}else if(type == LMarkerControl.texture){
if(exec.obj(p1) != null){
StringBuilder res = new StringBuilder(exec.obj(p1).toString());
if(exec.obj(p2) != null) res.append("-").append(exec.obj(p2).toString());
if(exec.obj(p3) != null) res.append("-").append(exec.obj(p3).toString());
marker.setTexture(res.toString());
if(exec.bool(p1)){
marker.setTexture(exec.textBuffer.toString());
exec.textBuffer.setLength(0);
}else{
marker.setTexture((exec.obj(p2) != null ? exec.obj(p2).toString() : "null"));
}
}else{
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)
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);
if(marker != null){
if(type == LMarkerControl.text){
marker.setText(text, true);
}else if(type == LMarkerControl.flushText){
marker.setText(text, false);
marker.setText(text, fetch);
}
}
}

View File

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

View File

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