Skip to content

Commit

Permalink
style: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharlottes committed Dec 6, 2023
1 parent 54ffbe0 commit 42a76ab
Show file tree
Hide file tree
Showing 28 changed files with 93 additions and 83 deletions.
8 changes: 4 additions & 4 deletions src/informatis/SVars.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import static arc.Core.atlas;

public class SVars {
public static TextureRegion
clear = atlas.find("clear"),
error = atlas.find("error");
public static RangeShader turretRange = new RangeShader();
public static final TextureRegion
clear = atlas.find("clear");
public static final TextureRegion error = atlas.find("error");
public static final RangeShader turretRange = new RangeShader();
public static informatis.core.Pathfinder pathfinder;

public static void init() {
Expand Down
2 changes: 1 addition & 1 deletion src/informatis/core/EventEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import informatis.SUtils;

public class EventEmitter<T> {
ObjectMap<T, ObjectSet<Runnable>> events = new ObjectMap<>();
final ObjectMap<T, ObjectSet<Runnable>> events = new ObjectMap<>();

public Runnable subscribe(T event, Runnable listener) {
ObjectSet<Runnable> listeners = events.get(event);
Expand Down
6 changes: 3 additions & 3 deletions src/informatis/core/Pathfinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ public class Pathfinder implements Runnable{
/** unordered array of path data for iteration only. DO NOT iterate or access this in the main thread. */
Seq<Flowfield> threadList = new Seq<>(), mainList = new Seq<>();
/** handles task scheduling on the update thread. */
TaskQueue queue = new TaskQueue();
final TaskQueue queue = new TaskQueue();
/** Current pathfinding thread */
@Nullable
Thread thread;
IntSeq tmpArray = new IntSeq();
final IntSeq tmpArray = new IntSeq();

public Pathfinder(){
clearCache();
Expand Down Expand Up @@ -512,7 +512,7 @@ public static abstract class Flowfield{
/** search IDs of each position - the highest, most recent search is prioritized and overwritten */
public int[] searches;
/** search frontier, these are Pos objects */
IntQueue frontier = new IntQueue();
final IntQueue frontier = new IntQueue();
/** all target positions; these positions have a cost of 0, and must be synchronized on! */
final IntSeq targets = new IntSeq();
/** current search ID */
Expand Down
31 changes: 16 additions & 15 deletions src/informatis/core/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
import static arc.Core.*;
import static mindustry.Vars.*;

abstract class SharSetting extends SettingsMenuDialog.SettingsTable.Setting {

public SharSetting(String name) {
super(name);
}

public SharSetting(String name, Object def) {
this(name);
Core.settings.defaults(name, def);
}

public void add(Table table) { }
public void add(SettingsMenuDialog.SettingsTable table) { }
}

public class Setting {
public static SettingsMenuDialog.SettingsTable sharset;

Expand Down Expand Up @@ -158,18 +173,4 @@ public static void init(){
settingUi.button(bundle.get("setting.shar-title"), Styles.cleart, dialog::show);
});
}
}
abstract class SharSetting extends SettingsMenuDialog.SettingsTable.Setting {

public SharSetting(String name) {
super(name);
}

public SharSetting(String name, Object def) {
this(name);
Core.settings.defaults(name, def);
}

public void add(Table table) { }
public void add(SettingsMenuDialog.SettingsTable table) { }
}
}
2 changes: 1 addition & 1 deletion src/informatis/core/UpdateChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static void checkUpdate(Boolc done) {
updateBuild = version;
showUpdateDialog();
done.get(true);
};
}
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/informatis/ui/components/IntervalTableWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

public
class IntervalTableWrapper {
Cons<Table> tableCons;
Boolf<Table> condition;
int interval;
final Cons<Table> tableCons;
final Boolf<Table> condition;
final int interval;

public IntervalTableWrapper() {
this(t -> {});
Expand Down
10 changes: 5 additions & 5 deletions src/informatis/ui/components/SBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SBar extends Element {
barSprite = SUtils.getDrawable(Core.atlas.find("informatis-barS"), 10, 10, 9, 9),
barTopSprite = SUtils.getDrawable(Core.atlas.find("informatis-barS-top"), 10, 10, 9, 9);

public UnitWindow.BarData barData;
public final UnitWindow.BarData barData;
float value, lastValue, blink;

public SBar(String name, Color color, Floatp fraction){
Expand Down Expand Up @@ -66,10 +66,10 @@ private void drawBarSprite(Color color, float width) {
}

public static class SBarData {
public String name;
public Floatp fraction;
public Color fromColor;
public Color toColor;
public final String name;
public final Floatp fraction;
public final Color fromColor;
public final Color toColor;

public SBarData(String name, Color fromColor, Color toColor, Floatp fraction) {
this.name = name;
Expand Down
14 changes: 7 additions & 7 deletions src/informatis/ui/components/SIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import arc.graphics.g2d.TextureRegion;

public class SIcons {
public static TextureRegion health = Core.atlas.find("informatis-health");
public static TextureRegion shield = Core.atlas.find("informatis-shield");
public static TextureRegion item = Core.atlas.find("informatis-item");
public static TextureRegion liquid = Core.atlas.find("informatis-liquid");
public static TextureRegion power = Core.atlas.find("informatis-power");
public static TextureRegion ammo = Core.atlas.find("informatis-ammo");
public static TextureRegion reload = Core.atlas.find("informatis-reload");
public static final TextureRegion health = Core.atlas.find("informatis-health");
public static final TextureRegion shield = Core.atlas.find("informatis-shield");
public static final TextureRegion item = Core.atlas.find("informatis-item");
public static final TextureRegion liquid = Core.atlas.find("informatis-liquid");
public static final TextureRegion power = Core.atlas.find("informatis-power");
public static final TextureRegion ammo = Core.atlas.find("informatis-ammo");
public static final TextureRegion reload = Core.atlas.find("informatis-reload");
}
2 changes: 1 addition & 1 deletion src/informatis/ui/components/TabsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class TabsFragment extends Table {
public int currentTabIndex = 0;
public EventEmitter<Event> eventEmitter = new EventEmitter<>();
public final EventEmitter<Event> eventEmitter = new EventEmitter<>();

public TabsFragment(String... tabs) {
super();
Expand Down
3 changes: 1 addition & 2 deletions src/informatis/ui/fragments/QuickSchemFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ void buildTags(Schematic schem, Table t, boolean name){

}).fillX().left().height(42f).scrollY(false);

Seq<String> finalTags1 = tags;
t.button(Icon.addSmall, () -> {
var dialog = new BaseDialog("@schematic.addtag");
dialog.addCloseButton();
Expand All @@ -276,7 +275,7 @@ void buildTags(Schematic schem, Table t, boolean name){

float sum = 0f;
Table current = new Table().left();
for(var tag : finalTags1){
for(var tag : tags){
if(schem.labels.contains(tag)) continue;

var next = Elem.newButton(tag, () -> {
Expand Down
4 changes: 2 additions & 2 deletions src/informatis/ui/fragments/ServerSearchFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import static mindustry.Vars.*;

public class ServerSearchFragment extends Table {
ObjectMap<ServerGroup, ObjectSet<Host>> servers = new ObjectMap<>();
static String[] modeNames = new String[]{ "Survival", "PvP", "Attack", "Sandbox", "Custom" };
final ObjectMap<ServerGroup, ObjectSet<Host>> servers = new ObjectMap<>();
static final String[] modeNames = new String[]{ "Survival", "PvP", "Attack", "Sandbox", "Custom" };

public ServerSearchFragment() {
super();
Expand Down
7 changes: 6 additions & 1 deletion src/informatis/ui/fragments/SidebarSwitcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class SidebarSwitcher {
private int showIndex = 0;
private final Table sidebarTable = new Table();
private Table[] sidebars;
private final Table[] sidebars;

private final ImageButton switchButton = new ImageButton(style) {
@Override
Expand All @@ -25,6 +25,7 @@ public void draw() {
}
{
clicked(() -> {
Table[] sidebars = getSidebars();
Element currentSidebar = sidebars[showIndex];
showIndex = (showIndex + 1) % sidebars.length;
Element nextSidebar = sidebars[showIndex];
Expand Down Expand Up @@ -97,4 +98,8 @@ public void rebuildSidebarTable() {
sidebarTable.row();
sidebarTable.add(switchButton).growX();
}

private Table[] getSidebars() {
return sidebars;
}
}
4 changes: 2 additions & 2 deletions src/informatis/ui/fragments/TileInfoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

public class TileInfoFragment {
private boolean waveShown;
Table tileInfoTable = new Table(Tex.buttonEdge4);
Stack tileInfoContainer;
final Table tileInfoTable = new Table(Tex.buttonEdge4);
final Stack tileInfoContainer;

public TileInfoFragment() {
Table waveTable = (Table) scene.find("waves");
Expand Down
2 changes: 1 addition & 1 deletion src/informatis/ui/fragments/sidebar/TroopingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import mindustry.gen.Unit;

public class TroopingManager {
static Seq<IntSeq> troops = new Seq<>(10) {{
static final Seq<IntSeq> troops = new Seq<>(10) {{
SUtils.loop(10, (i) -> {
add(new IntSeq());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ Table buildColors(Class<?> colorClass) {
sum -= getWidth();
t.row();
}
};
}
}, table -> {
if(!Objects.equals(cachedId[0], getWidth() + ":" + tabsFragment.currentTabIndex)) {
cachedId[0] = getWidth()+":"+tabsFragment.currentTabIndex;
Expand Down
25 changes: 15 additions & 10 deletions src/informatis/ui/fragments/sidebar/windows/CoreWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class CoreWindow extends Window {
Table window;
float heat;
ObjectMap<Team, ItemData> itemData = new ObjectMap<>();
final ObjectMap<Team, ItemData> itemData = new ObjectMap<>();

public CoreWindow() {
super(Icon.list, "core");
Expand Down Expand Up @@ -92,13 +92,7 @@ public Table setTable(Team team){
tt.stack(
new Table(s -> {
s.center();
Image image = new Image(core.block.uiIcon);
image.clicked(() -> SUtils.moveCamera(core));
HandCursorListener listener1 = new HandCursorListener();
image.addListener(listener1);
image.update(() -> {
image.color.lerp(!listener1.isOver() ? Color.lightGray : Color.white, Mathf.clamp(0.4f * Time.delta));
});
Image image = getCoreImage(core);
Tooltip.Tooltips option = new Tooltip.Tooltips();
option.animations=false;
s.add(image).size(iconLarge).get().addListener(new Tooltip(tool -> {
Expand Down Expand Up @@ -168,9 +162,20 @@ public Table setTable(Team team){
});
}

private static Image getCoreImage(CoreBlock.CoreBuild core) {
Image image = new Image(core.block.uiIcon);
image.clicked(() -> SUtils.moveCamera(core));
HandCursorListener listener1 = new HandCursorListener();
image.addListener(listener1);
image.update(() -> {
image.color.lerp(!listener1.isOver() ? Color.lightGray : Color.white, Mathf.clamp(0.4f * Time.delta));
});
return image;
}

static class ItemData {
Seq<ItemStack> prevItems = new Seq<>();
Seq<ItemStack> updateItems = new Seq<>();
final Seq<ItemStack> prevItems = new Seq<>();
final Seq<ItemStack> updateItems = new Seq<>();

ItemData() {
resetItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Table rebuildEditor() {
return new Table(table-> {
table.top();
Seq<Block> blocks = Vars.content.blocks().copy();
if(search.getText().length() > 0){
if(!search.getText().isEmpty()){
blocks.filter(p -> p.name.toLowerCase().contains(search.getText().toLowerCase())||p.localizedName.toLowerCase().contains(search.getText().toLowerCase()));
}
table.table(select-> this.buildBlockSelection(null, select, blocks, ()-> drawBlock, block-> drawBlock =block, false)).marginTop(16f).marginBottom(16f).row();
Expand Down Expand Up @@ -378,7 +378,7 @@ public void drawBlocks(int x, int y, Boolf<Tile> tester){
drawBlocks(x, y, false, tester);
}

int rotation = 0;
final int rotation = 0;
public void drawBlocks(int x, int y, boolean square, Boolf<Tile> tester){
if(drawBlock.isMultiblock()){
x = Mathf.clamp(x, (drawBlock.size - 1) / 2, world.width() - drawBlock.size / 2 - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import informatis.ui.fragments.sidebar.windows.ToolConfigable;

public class SettingConfiger implements ToolConfigable {
public String name;
public final String name;
private boolean enabled;

public SettingConfiger(String name) {
Expand Down
12 changes: 6 additions & 6 deletions src/informatis/ui/fragments/sidebar/windows/UnitWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public boolean isLocked() {
}

public static class BarData {
public Prov<String> name;
public Floatp fraction;
public Prov<Color> color;
public final Prov<String> name;
public final Floatp fraction;
public final Prov<Color> color;
public final TextureRegion icon;

public BarData(String name, Color color, float fraction) {
Expand Down Expand Up @@ -109,7 +109,7 @@ public BarData(Prov<String> name, Prov<Color> color, Floatp fraction, TextureReg

static class UnitWindowBody extends Table implements VDOM.IRebuildable {
public boolean locked;
private Seq<BarData> barDataSeq = new Seq<>();
private final Seq<BarData> barDataSeq = new Seq<>();

public UnitWindowBody() {
super();
Expand Down Expand Up @@ -229,7 +229,7 @@ private Table buildContent(Teamc target) {
bar.add(barIcon).size(iconMed * 0.75f).padLeft(8f);
}).growX();
bars.row();
};
}
});
});
}
Expand Down Expand Up @@ -662,7 +662,7 @@ public void draw() {
}
}
private static class BarIconImage extends Image {
public BarData barData;
public final BarData barData;

public BarIconImage(BarData barData) {
super(barData.icon);
Expand Down
10 changes: 6 additions & 4 deletions src/informatis/ui/fragments/sidebar/windows/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ public class Window extends Table {
public final Cons<Table> content;
public boolean shown = false, disableRootScroll = false;

public float minWindowWidth = 160, minWindowHeight = 60;
public static float maxWindowWidth = Float.MAX_VALUE, maxWindowHeight = Float.MAX_VALUE;
public float minWindowWidth = 160;
public final float minWindowHeight = 60;
public static final float maxWindowWidth = Float.MAX_VALUE;
public static final float maxWindowHeight = Float.MAX_VALUE;

public Window(String name){
this(new TextureRegionDrawable(Core.atlas.find("clear")), name, null);
Expand Down Expand Up @@ -109,7 +111,7 @@ public void touchDragged(InputEvent event, float dx, float dy, int pointer) {
}

private static class DragHandleListener extends TouchPosInputListener {
Window targetWindow;
final Window targetWindow;
public DragHandleListener(Window targetWindow) {
this.targetWindow = targetWindow;
}
Expand All @@ -133,7 +135,7 @@ public void touchDragged(InputEvent event, float dx, float dy, int pointer) {
}

private static class ScaleInputListener extends TouchPosInputListener {
Window targetWindow;
final Window targetWindow;
public ScaleInputListener(Window targetWindow) {
this.targetWindow = targetWindow;
}
Expand Down
Loading

0 comments on commit 42a76ab

Please sign in to comment.