Skip to content

Commit

Permalink
Info Overlays: Move width related setting serialization to the base w…
Browse files Browse the repository at this point in the history
…idget
  • Loading branch information
maruohon committed Jun 26, 2022
1 parent 3c24e52 commit 9a3a928
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public MessageRendererWidgetEditScreen(MessageRendererWidget widget)
{
this.widget = widget;
this.useTitleHierarchy = false;

// Unconditionally save here, since we don't track the individual info container widget changes
this.screenCloseListener = Registry.INFO_WIDGET_MANAGER::saveToFile;

this.setTitle("malilib.title.screen.message_renderer_configuration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public StringListRendererWidgetEditScreen(StringListRendererWidget widget)
{
this.widget = widget;
this.useTitleHierarchy = false;

// Unconditionally save here, since we don't track the individual info container widget changes
this.screenCloseListener = Registry.INFO_WIDGET_MANAGER::saveToFile;

this.setTitle("malilib.title.screen.string_list_renderer_configuration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public ToastRendererWidgetEditScreen(ToastRendererWidget widget)
{
this.widget = widget;
this.useTitleHierarchy = false;

// Unconditionally save here, since we don't track the individual info container widget changes
this.screenCloseListener = Registry.INFO_WIDGET_MANAGER::saveToFile;

this.setTitle("malilib.title.screen.toast_renderer_configuration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ public JsonObject toJson()
obj.addProperty("type", this.getWidgetTypeId());
obj.addProperty("enabled", this.isEnabled());

if (this.automaticWidth)
{
obj.addProperty("auto_width", true);
}

if (this.hasMaxWidth())
{
obj.addProperty("max_width", this.maxWidth);
}

obj.addProperty("width", this.getWidth());

if (this.margin.isEmpty() == false)
{
obj.add("margin", this.margin.toJson());
Expand All @@ -146,7 +158,9 @@ public JsonObject toJson()
public void fromJson(JsonObject obj)
{
this.enabled = JsonUtils.getBooleanOrDefault(obj, "enabled", true);

JsonUtils.readBooleanIfExists(obj, "auto_width", v -> this.automaticWidth = v);
JsonUtils.readIntegerIfExists(obj, "max_width", this::setMaxWidth);
JsonUtils.readIntegerIfExists(obj, "width", this::setWidth);
JsonUtils.readArrayIfExists(obj, "padding", this.padding::fromJson);
JsonUtils.readArrayIfExists(obj, "margin", this.margin::fromJson);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,6 @@ public JsonObject toJson()
JsonObject obj = super.toJson();
obj.addProperty("msg_gap", this.messageGap);
obj.addProperty("max_messages", this.maxMessages);
obj.addProperty("width", this.getWidth());

if (this.hasMaxWidth())
{
obj.addProperty("max_width", this.maxWidth);
}

if (this.automaticWidth)
{
obj.addProperty("width_auto", true);
}

if (this.renderAboveScreen)
{
obj.addProperty("above_screen", true);
}

return obj;
}
Expand All @@ -286,13 +270,5 @@ public void fromJson(JsonObject obj)

this.messageGap = JsonUtils.getIntegerOrDefault(obj, "msg_gap", this.messageGap);
this.maxMessages = JsonUtils.getIntegerOrDefault(obj, "max_messages", this.maxMessages);
this.renderAboveScreen = JsonUtils.getBooleanOrDefault(obj, "above_screen", this.renderAboveScreen);
this.automaticWidth = JsonUtils.getBooleanOrDefault(obj, "width_auto", this.automaticWidth);
this.setWidth(JsonUtils.getIntegerOrDefault(obj, "width", this.getWidth()));

if (JsonUtils.hasInteger(obj, "max_width"))
{
this.setMaxWidth(JsonUtils.getInteger(obj, "max_width"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ public JsonObject toJson()
JsonObject obj = super.toJson();

obj.addProperty("max_toasts", this.maxToasts);
obj.addProperty("max_width", this.maxWidth);
obj.addProperty("message_gap", this.messageGap);
obj.addProperty("toast_lifetime", this.defaultLifeTime);
obj.addProperty("toast_fade_in", this.defaultFadeInTime);
Expand All @@ -381,7 +380,6 @@ public void fromJson(JsonObject obj)

this.maxToasts = JsonUtils.getIntegerOrDefault(obj, "max_toasts", this.maxToasts);
this.messageGap = JsonUtils.getIntegerOrDefault(obj, "message_gap", this.messageGap);
this.setMaxWidth(JsonUtils.getIntegerOrDefault(obj, "max_width", this.maxWidth));
this.defaultLifeTime = JsonUtils.getIntegerOrDefault(obj, "toast_lifetime", this.defaultLifeTime);
this.defaultFadeInTime = JsonUtils.getIntegerOrDefault(obj, "toast_fade_in", this.defaultFadeInTime);
this.defaultFadeOutTime = JsonUtils.getIntegerOrDefault(obj, "toast_fade_out", this.defaultFadeOutTime);
Expand Down

0 comments on commit 9a3a928

Please sign in to comment.