Skip to content

Commit

Permalink
bump version to 3.0.1; fix loading completely broken config;
Browse files Browse the repository at this point in the history
  • Loading branch information
4rg0n committed Sep 15, 2024
1 parent 31358e0 commit 8344de6
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public Button(SPRITE label, @Nullable CharSequence description) {
super(label, description);
}

@Override
public Button searchTerm(@Nullable String searchTerm) {
super.searchTerm(searchTerm);
return this;
}

@Override
protected Button element() {
return this;
Expand Down
265 changes: 264 additions & 1 deletion mod-sdk/src/main/java/com/github/argon/sos/mod/sdk/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class YourModScript extends AbstractModSdkScript {
// create a window with the dialog and show() it on button click
// the window is bound to the game render loop and will display anything in it
// a GuiSection or any other RENDEROBJ alone can not be displayed without the renderer
new Window<NotificationDialog>("Notify", new NotificationDialog(
new Window<NotificationDialog>("Notification", new NotificationDialog(
ModSdkModule.notificator()
)).show());

Expand Down Expand Up @@ -144,3 +144,266 @@ public class YourModScript extends AbstractModSdkScript {
All [AbstractController](controller/AbstractController.java)s will be added into `ModSdkModule.controllers()` and can be accessed through it.
You can also access any other controller from inside an `AbstractController` via `getControllers().get(YourOtherController.class);`

## Elements

### [Button](Button.java)

A `Button` is one of the simplest ui elements.

```java
public class YourUiElement extends GuiSection {
public YourUiElement() {
// with a name only
addDownC(0, new Button("Name"));
// with a name and a description tooltip when hovered
addDownC(0, new Button("Name", "Description"));
// with an icon as sprite
addDownC(0, new Button(UI.icons().m.cancel));
// with an icon as sprite and a description tooltip when hovered
addDownC(0, new Button(UI.icons().m.cancel, "Description"));

// add an action when the button is clicked
Button button = new Button("Name");
button.clickActionSet(() ->
System.out.println("CLICK!"));
}
}
```

### [ButtonMenu](ButtonMenu.java)

A `ButtonMenu` is a collection of buttons in form of a menu. It can be displayed horizontally or vertically.

```java
public class YourUiElement extends GuiSection {
public YourUiElement() {
add(ButtonMenu.builder()
.displaySearch(true) // displays a search bar, which will look into the searchTerm of each button
.search(null) // you can also pass your own search bar here
.horizontal(false) // vertical menu
.sameWidth(true) // all buttons will get the width of the widest one
.buttonColor(COLOR.BLUE50) // custom color for all buttons
.notHoverable(false) // you can disable whether the buttons shall be hover-able and therefore clickable
// these are the actual menu entries as buttons
.button("menu1", new Button("Menu #1").searchTerm("1"))
.button("menu2", new Button("Menu #2").searchTerm("2"))
.button("menu3", new Button("Menu #3").searchTerm("3"))
.build());
}
}
```

### [ColorBox](ColorBox.java)

The `ColorBox` is a simple box with a certain color as background.

```java
public class YourUiElement extends GuiSection {
public YourUiElement() {
// 100 x 100 green box
addDownC(0, new ColorBox(100, COLOR.GREEN40));
// 100 x 50 red box
addDownC(0, new ColorBox(100, 50, COLOR.RED50));
}
}
```

### [VerticalLine](VerticalLine.java) and [HorizontalLine](HorizontalLine.java)

The `VerticalLine` and `HorizontalLine` are simple thin lines used to separate ui elements from each other.

```java
public class YourUiElement extends GuiSection {
public YourUiElement() {
// 300 px wide line with a 5 px high space above it
addDownC(0, new HorizontalLine(300, 5));

// 300 px high line with a 5 px wide space next to it
addRightC(0, new VerticalLine(5, 300));
}
}
```

### [Checkbox](Checkbox.java)

A `Checkbox` is a toggleable box with an on and off state.

```java
public class YourUiElement extends GuiSection {
public YourUiElement() {
// checked
addDownC(0, new Checkbox(true));
// unchecked
addDownC(0, new Checkbox(false));

// add an action when the checkbox is toggled
Checkbox checkbox = new Checkbox(true);
checkbox.toggleAction(checked ->
System.out.println("Checked? " + checked));
}
}
```

### [Label](Label.java)

A `Label` is a short text, which is commonly used to describe something. Like "Name:" in front of a text input.

```java
public class YourUiElement extends GuiSection {
public YourUiElement() {
Label errorLabel = Label.builder()
.name("Error")
.style(Label.Style.ERROR) // makes it reddish
.font(UI.FONT().H1) // a big label =)
.build();

GText errorText = new GText(UI.FONT().M, "Ooooh noooo... it happened!");

addRightC(0, errorLabel);
addRightC(10, errorText);
}
}
```

### [Spacer](Spacer.java)

The `Spacer` is an invisible box element you can give a certain dimension.
This is used mainly for laying out your ui elements.

```java
public class YourUiElement extends GuiSection {
public YourUiElement() {
GText text1 = new GText(UI.FONT().H1, "TOP");
GText text2 = new GText(UI.FONT().H1, "DOWN");

// 0 px wide, but 100 px high
Spacer spacer = new Spacer(0, 100);

addDownC(0, text1);
addDownC(0, spacer);
addDownC(0, text2);
}
}
```

### [Input](Input.java) and [InputInt](InputInt.java)

`Input` and `InputInt` are fields where the player can enter a text or a number into it.

```java
public class YourUiElement extends GuiSection {
public YourUiElement() {
// holds the text the user enters
StringInputSprite stringInputSprite = new StringInputSprite(32, UI.FONT().S)
.placeHolder("Input text here");
// the actual text input field shown in the ui
Input stringInput = new Input(stringInputSprite);

// holds the number the user enters. In this case it can be from 0 to 255
INT.INTE.IntImp integerInputValue = new INT.INTE.IntImp(0, 255);
// the actual integer input field shown in the ui
InputInt integerInput = new InputInt(integerInputValue);

addDownC(0, stringInput);
addDownC(10, integerInput);

// this would give you the entered text or number; it is empty at this point though
stringInputSprite.text();
integerInputValue.get();
}
}
```

### [Section](Section.java)

A `Section` is a somewhat advanced version of the games `GuiSection`.
It implements some actions and their functionality such as:

* [Hidable](../game/action/Hideable.java)
* [Renderable](../game/action/Renderable.java)
* [Showable](../game/action/Showable.java)

```java
public class YourUiElement extends Section {
public YourUiElement() {
hideAction(() -> System.out.println("Hiding"));
renderAction(() -> System.out.println("Rendering"));
show(() -> System.out.println("Showing"));
}
}
```

### [Window](Window.java) and [FullWindow](FullWindow.java)

The `Window` and `FullWindow` classes are containers, which display any `GuiSection` in them when shown.

A `Window` is a popup in the game UI. Here an example:
```java
public class YourModScript extends AbstractModSdkScript {
@Override
public void initSettlementUiPresent() {
super.initSettlementUiPresent();

Button button = new Button("ColorBox");
ColorBox colorBox = new ColorBox(100, COLOR.RED50);
button.clickActionSet(() ->
// inject anything which is an instance of GuiSection into the Window
// the last "true" will tell the window to be a "Modal", which blacks out the background
new Window<ColorBox>("Red50", colorBox, true)
.show());

ModSdkModule.gameApis().ui().injectIntoUITopPanels(button);
}
}
```

The `FillWindow` takes up the whole screen and can have an optional [Switcher](Switcher.java) menu.
This menu can be used to switch between different views in the window.
So it's possible to display a different ui on a button click in the open window.

```java
public class YourModScript extends AbstractModSdkScript {
@Override
public void initSettlementUiPresent() {
super.initSettlementUiPresent();

Button button = new Button("ColorBoxes");
// a switcher menu containing the buttons; the key e.g. "RED50" must match the keys of tha tabs further down
Switcher.SwitcherBuilder<String> menu = Switcher.builder()
.menu(ButtonMenu.builder()
.button("RED50", new Button("Red50"))
.button("GREEN40", new Button("Green40"))
.button("BLUE50", new Button("Blue50"))
.build());

// a tabulator is able to switch between views via the switcher menu
Tabulator<Object, RENDEROBJ, Object> tabulator = Tabulator.builder()
// the different views, in our case simple color boxes
// the keys must match the button keys defined in the switcher menu
.tabs(Maps.of(
"RED50", new ColorBox(100, COLOR.RED50),
"GREEN40", new ColorBox(100, COLOR.GREEN40),
"BLUE50", new ColorBox(100, COLOR.BLUE50)
))
// this would force the tabulator to show its own menu above it, but we want the menu to be in the FullWindow
//.direction(DIR.S)
.tabMenu(menu)
.build();

button.clickActionSet(() ->
// inject anything which is an instance of GuiSection into the FullWindow
// the "menu" is optional; you can also only just display one single view
new FullWindow<ColorBox>("Colors", tabulator, menu)
.show());

ModSdkModule.gameApis().ui().injectIntoUITopPanels(button);
}
}
```







2 changes: 1 addition & 1 deletion mod/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>local</version>
</parent>

<version>3.0.0</version>
<version>3.0.1</version>
<artifactId>sos-mod-more-options</artifactId>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ public MetricsConfig newMetrics() {
return metricsConfig;
}

public ConfigMeta newConfigMeta() {
return ConfigMeta.builder().build();
}

public static Range boosterAdd() {
return Range.builder()
.value(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@ public class ConfigStore implements Phases {

@Override
public void initBeforeGameCreated() {
// load configs into store
configService.getMeta().ifPresent(meta -> configMeta = meta);
ConfigMeta configMetaDefault = configDefaults.newConfigMeta();
try {
// load configs into store
configMeta = configService.getMeta()
.orElse(configMetaDefault);
} catch (Exception e) {
configMeta = configMetaDefault;
log.warn("Could not read config meta information. Using defaults.", e);
log.trace("Defaults: %s", configMetaDefault);
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion mod/src/main/resources/mo-i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ErrorDialog.button.copy.desc=Copies the error with details into the clipboard.
ErrorDialog.button.report.name=Report
ErrorDialog.button.report.desc=Opens the report website.
ErrorDialog.button.clean.name=Clean Config
ErrorDialog.button.clean.desc=Will delete possible faulty config files and fall back to defaults (REQUIRES RESTART).
ErrorDialog.button.clean.desc=Will delete possible faulty config files and fall back to defaults.
ErrorDialog.button.close.name=Close
ErrorDialog.button.close.desc=Close this window.

Expand Down
2 changes: 1 addition & 1 deletion mod/src/main/resources/mo-i18n_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ErrorDialog.button.copy.desc=Copies the error with details into the clipboard.
ErrorDialog.button.report.name=Report
ErrorDialog.button.report.desc=Opens the report website.
ErrorDialog.button.clean.name=Clean Config
ErrorDialog.button.clean.desc=Will delete possible faulty config files and fall back to defaults (REQUIRES RESTART).
ErrorDialog.button.clean.desc=Will delete possible faulty config files and fall back to defaults.
ErrorDialog.button.close.name=Close
ErrorDialog.button.close.desc=Close this window.

Expand Down

0 comments on commit 8344de6

Please sign in to comment.