Skip to content

Commit

Permalink
significant ui improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Aug 14, 2022
1 parent a46f4b1 commit ea8d24c
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 22 deletions.
17 changes: 14 additions & 3 deletions mod.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@

displayName: "New Console"
name: "newconsole"
author: "Мнемотехник"
description: "Adds a much better console ui.\n\nAlso includes a file browser, a scripts menu, an events menu and much much more!\n\nSee README.md for more info."
version: 1.5
author: "Mnemotechnician"

description: '''
Adds a console ui superiour to the built-in one and the ones provided by any other mods.
User-friendly interface, a good log panel, execution history, monospace font - all that is included in this mod.

In addiction to the console, this mod offers:
- An ability to save as many scripts as you want, execute them or copy to the console
- An ability to execute scripts when certain events get fired
- A full-blown file browser (be careful, you can cause real harm with that!)

See README.md for more info.
'''
version: 1.6
subtitle: "Adds a much better console UI."
minGameVersion: 136
hidden: true
Expand Down
2 changes: 1 addition & 1 deletion src/newconsole/ui/CStyles.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void loadSync() {
}});
mono.getData().markupEnabled = true;

scriptbg = Tex.buttonOver;
scriptbg = Tex.button;

playIcon = Icon.play.tint(Color.green);
editIcon = Icon.edit.tint(Color.yellow);
Expand Down
6 changes: 3 additions & 3 deletions src/newconsole/ui/CodeSpinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import mindustry.ui.*;
import newconsole.ui.*;

/** Displays arbitrary code in a code block. Provides some optimisations. */
/** Displays arbitrary code in a code block. */
public class CodeSpinner extends Spinner {

public String code;
Expand All @@ -18,7 +18,7 @@ public CodeSpinner(String code) {

table.setBackground(CStyles.scriptbg);

codeLabel = table.labelWrap("").grow().get();
codeLabel = table.add("", CStyles.monoLabel).with(it -> it.setWrap(true)).grow().get();

this.code = Strings.stripColors(code);
}
Expand All @@ -29,4 +29,4 @@ public void show(boolean animate) {
super.show(animate);
}

}
}
29 changes: 17 additions & 12 deletions src/newconsole/ui/Spinner.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,25 @@ public Spinner(String header, TextButton.TextButtonStyle style, boolean unique,

if (col.getScene() != null) {
col.visible = true;
//col.toFront(); TODO: causes more harm than sudden disappearing of spinners
col.toFront();
col.color.a = parentAlpha * color.a;
col.setSize(width, col.getPrefHeight());

Vec2 point = localToStageCoordinates(Tmp.v1.set(0, 0));
float height = Math.min(point.y, table.getPrefHeight());
point = localToStageCoordinates(Tmp.v1.set(0, -height));

/*if (point.y < Core.scene.getHeight() / 2) {
point = localToStageCoordinates(Tmp.v1.set(0, getPrefHeight()));
height = Core.scene.getHeight() - point.y;
}*/
pane.setHeight(height);
col.setPosition(point.x, point.y);
var reverse = false;
var pos = localToStageCoordinates(Tmp.v1.set(0, -table.getPrefHeight()));
if (pos.y <= 0 && pos.y + table.getPrefHeight() * 2 + height < Core.scene.getHeight()) {
pos.y += table.getPrefHeight() + height;
reverse = true;
}

var freeHeight = reverse
? Core.scene.getHeight() - localToStageCoordinates(Tmp.v2.set(0, height)).y
: localToStageCoordinates(Tmp.v2.setZero()).y;

col.setSize(width, Math.min(freeHeight, table.getPrefHeight()));
pane.setSize(width, Math.min(freeHeight, table.getPrefHeight()));
table.setSize(width, Math.min(freeHeight, table.getPrefHeight()));
col.setPosition(pos.x, pos.y);
col.validate();
}

if (autoHide && col.getScene() != null) {
Expand Down
5 changes: 4 additions & 1 deletion src/newconsole/ui/dialogs/AutorunDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ public AutorunDialog() {
Vars.ui.showInfo("@newconsole.empty-script");
}
}).growX();
})).margin(4f).width(350f).with(it -> ((Spinner) it).setStyle(Styles.defaultt)).row();
})).margin(4f).width(350f).with(it -> {
((Spinner) it).setStyle(Styles.defaultt);
it.unique = false;
}).row();
})
).grow();
}
Expand Down
48 changes: 46 additions & 2 deletions src/newconsole/ui/dialogs/SavesDialog.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package newconsole.ui.dialogs;

import arc.struct.*;
import arc.graphics.*;
import arc.scene.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.*;
import mindustry.gen.*;
import mindustry.ui.*;
import mindustry.ui.dialogs.*;
import java.util.Comparator;

import newconsole.*;
import newconsole.io.*;
Expand Down Expand Up @@ -61,7 +64,16 @@ public SavesDialog() {

public void rebuild() {
scriptsTable.clearChildren();
ScriptsManager.eachScript((name, script) -> add(name, script));

// copy to a seq, then sort by name - fuck java.
Seq<Pair<String, String>> seq = new Seq<>(ScriptsManager.scripts.size);
ScriptsManager.eachScript((name, script) -> {
seq.add(new Pair(name, script));
});

seq.sort(new EntryComparator());

seq.each(it -> add(it.first, it.second));
}

@Override
Expand Down Expand Up @@ -98,5 +110,37 @@ public void add(String name, String script) {
});
}).growX().pad(2f).marginBottom(20).row();
}


/** Same as kotlin.Pair. */
public static class Pair<A, B> {
final A first;
final B second;

public Pair(A first, B second) {
this.first = first;
this.second = second;
}
}

public class EntryComparator implements Comparator<Pair<String, String>> {
@Override
public int compare(Pair<String, String> o1, Pair<String, String> o2) {
if (o1 == o2) return 0;

var left = Strings.stripColors(o1.first);
var right = Strings.stripColors(o2.first);

for (int i = 0; i < Math.min(left.length(), right.length()); i++) {
var diff = Character.toLowerCase(left.charAt(i)) - Character.toLowerCase(right.charAt(i));
if (diff != 0) return diff;
}

if (left.length() > right.length()) return -1;
return 1;
}

@Override
public boolean equals(Object o) { return o == this; }
}

}

0 comments on commit ea8d24c

Please sign in to comment.