Skip to content

Commit

Permalink
Carrier: Add the ability to hide the default fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
e3ndr committed Jan 11, 2024
1 parent 842fdcb commit 2807ab6
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 32 deletions.
36 changes: 5 additions & 31 deletions Base/src/main/java/co/casterlabs/caffeinated/sesl/SESL.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import co.casterlabs.caffeinated.pluginsdk.widgets.settings.items.WidgetSettingsDropdownBuilder;
import co.casterlabs.caffeinated.pluginsdk.widgets.settings.items.WidgetSettingsFileBuilder;
import co.casterlabs.caffeinated.pluginsdk.widgets.settings.items.WidgetSettingsFontBuilder;
import co.casterlabs.caffeinated.pluginsdk.widgets.settings.items.WidgetSettingsNumberBuilder;
import co.casterlabs.caffeinated.pluginsdk.widgets.settings.items.WidgetSettingsRangeBuilder;
import co.casterlabs.caffeinated.pluginsdk.widgets.settings.items.WidgetSettingsTextBuilder;
import co.casterlabs.caffeinated.util.MimeTypes;
Expand All @@ -55,36 +54,11 @@ public class SESL {
@SuppressWarnings("deprecation")
public static WidgetSettingsLayout generateLayout(SESLWidget widget) {
try {
WidgetSettingsLayout layout = new WidgetSettingsLayout();

Map<String, WidgetSettingsSection> sections = new HashMap<>();
sections.put("settings", new WidgetSettingsSection("settings", "Settings"));

// Default Streamlabs fields.
switch (widget.getShimType()) {
case "chatbox": {
// We intentionally leave out background_color.
sections.get("settings")
.addItem(
new WidgetSettingsColorBuilder()
.withId("text_color")
.withName("Text Color")
.withDefaultValue("#ffffff")
.build()
)
.addItem(
new WidgetSettingsNumberBuilder()
.withId("font_size")
.withName("Font Size (px)")
.withStep(1)
.withMin(0)
.withMax(80)
.withDefaultValue(18)
.build()
);
// TODO the rest...
break;
}

WidgetSettingsSection defaultSection = widget.getDefaultFields();
if (defaultSection != null) {
sections.put(defaultSection.getId(), defaultSection);
}

// Convert the custom fields.
Expand Down Expand Up @@ -243,10 +217,10 @@ public static WidgetSettingsLayout generateLayout(SESLWidget widget) {
section.addItem(input);
}

WidgetSettingsLayout layout = new WidgetSettingsLayout();
for (WidgetSettingsSection section : sections.values()) {
layout.addSection(section);
}

return layout;
} catch (Throwable t) {
LOGGER.fatal("An error occurred whilst building layout:\n%s", t);
Expand Down
36 changes: 36 additions & 0 deletions Base/src/main/java/co/casterlabs/caffeinated/sesl/SESLWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@

import java.io.IOException;

import org.jetbrains.annotations.Nullable;

import co.casterlabs.caffeinated.pluginsdk.widgets.Widget;
import co.casterlabs.caffeinated.pluginsdk.widgets.WidgetInstance;
import co.casterlabs.caffeinated.pluginsdk.widgets.WidgetInstanceMode;
import co.casterlabs.caffeinated.pluginsdk.widgets.settings.WidgetSettingsSection;
import co.casterlabs.caffeinated.pluginsdk.widgets.settings.items.WidgetSettingsColorBuilder;
import co.casterlabs.caffeinated.pluginsdk.widgets.settings.items.WidgetSettingsNumberBuilder;
import co.casterlabs.rakurai.json.element.JsonObject;
import lombok.NonNull;

Expand All @@ -45,6 +50,37 @@ public abstract class SESLWidget extends Widget {

public abstract @NonNull String getCustomHTML();

@SuppressWarnings("deprecation")
public @Nullable WidgetSettingsSection getDefaultFields() {
// Default Streamlabs fields.
switch (this.getShimType()) {
case "chatbox":
// We intentionally leave out background_color.
return new WidgetSettingsSection("settings", "Settings")
.addItem(
new WidgetSettingsColorBuilder()
.withId("text_color")
.withName("Text Color")
.withDefaultValue("#ffffff")
.build()
)
.addItem(
new WidgetSettingsNumberBuilder()
.withId("font_size")
.withName("Font Size (px)")
.withStep(1)
.withMin(0)
.withMax(80)
.withDefaultValue(18)
.build()
);

// TODO the rest...
default:
return null;
}
}

@Override
protected void onSettingsUpdate() {
this.setSettingsLayout(SESL.generateLayout(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static class ConfigWidget {
public String name;
public WidgetDetailsCategory category;
public String icon;
public boolean addDefaultFields;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

import java.nio.charset.StandardCharsets;

import org.jetbrains.annotations.Nullable;

import co.casterlabs.caffeinated.pluginsdk.widgets.settings.WidgetSettingsSection;
import co.casterlabs.caffeinated.sesl.SESL;
import co.casterlabs.caffeinated.sesl.SESLWidget;
import co.casterlabs.caffeinated.sesl.carrier_mode.CarrierConfig.ConfigWidget;
Expand Down Expand Up @@ -56,6 +59,15 @@ public CarrierWidget(ConfigWidget config) {
this.customHTML = StreamUtil.toString(CarrierPlugin.class.getResourceAsStream("/sesl/" + config.id + "/custom.html"), StandardCharsets.UTF_8);
}

@Override
public @Nullable WidgetSettingsSection getDefaultFields() {
if (this.config.addDefaultFields) {
return super.getDefaultFields();
} else {
return null;
}
}

@Override
public @NonNull String getShimType() {
return this.config.type;
Expand Down
3 changes: 2 additions & 1 deletion Modes/Carrier/src/main/resources/sesl/carrier.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"id": "my_chatbox",
"name": "My Chatbox",
"category": "OTHER",
"icon": "star"
"icon": "star",
"addDefaultFields": true
}
]
}

0 comments on commit 2807ab6

Please sign in to comment.