Skip to content

Commit

Permalink
add more info on the config screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed May 25, 2024
1 parent cf46e97 commit 00f77ca
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
7 changes: 6 additions & 1 deletion src/main/java/io/ix0rai/rainglow/Rainglow.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

public class Rainglow implements ModInitializer {
public static final String MOD_ID = "rainglow";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
Expand All @@ -27,10 +30,12 @@ public class Rainglow implements ModInitializer {
public static final Gson GSON = new Gson();

public static final String CUSTOM_NBT_KEY = "Colour";
public static final Identifier SERVER_MODE_DATA_ID = id("server_mode_data");
public static final List<String> RAINGLOW_DATAPACKS = new ArrayList<>();

@Override
public void onInitialize() {
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener((RainglowResourceReloader) () -> id("server_mode_data"));
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener((RainglowResourceReloader) () -> SERVER_MODE_DATA_ID);

PayloadTypeRegistry.playS2C().register(RainglowNetworking.ConfigSyncPayload.PACKET_ID, RainglowNetworking.ConfigSyncPayload.PACKET_CODEC);
PayloadTypeRegistry.playS2C().register(RainglowNetworking.ModeSyncPayload.PACKET_ID, RainglowNetworking.ModeSyncPayload.PACKET_CODEC);
Expand Down
26 changes: 11 additions & 15 deletions src/main/java/io/ix0rai/rainglow/config/RainglowConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import net.minecraft.client.gui.widget.layout.LinearLayoutWidget;
import net.minecraft.client.gui.widget.text.TextWidget;
import net.minecraft.client.option.Option;
import net.minecraft.client.toast.SystemToast;
import net.minecraft.client.toast.Toast;
import net.minecraft.text.CommonTexts;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -49,6 +47,16 @@ public RainglowConfigScreen(@Nullable Screen parent) {
this.saveButton.active = false;
}

private TextWidget getInfoText() {
if (MinecraftClient.getInstance().isInSingleplayer()) {
return new TextWidget(Rainglow.translatableText("config.loaded_datapacks", RainglowMode.values().size(), Rainglow.RAINGLOW_DATAPACKS.size()), this.textRenderer).setTextColor(0x00FFFF);
} else if (MinecraftClient.getInstance().world != null) {
return new TextWidget(Rainglow.translatableText("config.server_locked"), this.textRenderer).setTextColor(0xFF0000);
} else {
return new TextWidget(Rainglow.translatableText("config.no_world"), this.textRenderer).setTextColor(0xFF0000);
}
}

@Override
public void init() {
HeaderFooterLayoutWidget headerFooterWidget = new HeaderFooterLayoutWidget(this, 61, 33);
Expand All @@ -58,9 +66,7 @@ public void init() {
// header
headerLayout.add(new TextWidget(TITLE, this.textRenderer), settings -> settings.alignHorizontallyCenter().alignVerticallyTop().setPadding(12));
headerLayout.add(createModeButton(), LayoutSettings::alignVerticallyBottom);
if (MinecraftClient.getInstance().world == null) {
headerLayout.add(new TextWidget(Rainglow.translatableText("config.no_world"), this.textRenderer).setTextColor(0xc21919), LayoutSettings::alignHorizontallyCenter);
}
headerLayout.add(getInfoText(), LayoutSettings::alignHorizontallyCenter);

// contents
LinearLayoutWidget contentLayout = LinearLayoutWidget.createVertical();
Expand Down Expand Up @@ -194,17 +200,7 @@ public void closeScreen() {
this.isConfirming = true;
this.clearAndInit();
} else {
// overrides will exist when connected to a server syncing its values
if (Rainglow.CONFIG.mode.isBeingOverridden()) {
sendConfigLockedToast();
}

MinecraftClient.getInstance().setScreen(this.parent);
}
}

private static void sendConfigLockedToast() {
Toast toast = new SystemToast(SystemToast.Id.PACK_LOAD_FAILURE, Rainglow.translatableText("config.server_locked_title"), Rainglow.translatableText("config.server_locked_description"));
MinecraftClient.getInstance().getToastManager().add(toast);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ default void reload(ResourceManager manager) {
// this only clears modes that exist on both the server and the client
// otherwise we would have to re-request the mode data packet on every reload
RainglowMode.clearUniversalModes();
Rainglow.RAINGLOW_DATAPACKS.clear();

// load custom modes from rainglow/custom_modes in the datapack
// we only load files whose name ends with .json
Expand All @@ -36,6 +37,11 @@ default void reload(ResourceManager manager) {
Reader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
RainglowMode.JsonMode result = Rainglow.GSON.fromJson(reader, RainglowMode.JsonMode.class);
RainglowMode.addMode(new RainglowMode(result, true));

String name = entry.getValue().getSourceName();
if (this.getFabricId().equals(Rainglow.SERVER_MODE_DATA_ID) && !Rainglow.RAINGLOW_DATAPACKS.contains(name)) {
Rainglow.RAINGLOW_DATAPACKS.add(name);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/assets/rainglow/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
"rainglow.config.enable_glow_squid": "Rainbow squids",
"rainglow.config.enable_slime": "Rainbow slimes",
"rainglow.config.enable_allay": "Rainbow allays",
"rainglow.config.server_locked_title": "Config is locked by server",
"rainglow.config.server_locked_description": "Changes applied will only be visible once you join a world without a locked config.",
"rainglow.config.server_locked": "Config is server-locked: these values are your local config.",
"rainglow.config.no_custom_colours": "Cannot save with no colours selected!",
"rainglow.config.no_custom_colours_description": "Please select at least one colour to save the settings.",
"rainglow.config.no_world": "No world loaded: only default modes are available.",
"rainglow.config.unsaved_warning": "Config is not saved and changes will be lost! Leave without saving?",
"rainglow.config.continue_editing": "Continue editing",
"rainglow.config.loaded_datapacks": "Loaded %s modes from %s datapacks.",
"rainglow.config.slime_rarity.value": "Slime rarity: %s",
"rainglow.tooltip.rarity": "Rarity determines what percent chance mobs have to spawn with a colour.",
"rainglow.tooltip.entity_toggle": "Enable or disable rainbow colours for this entity.",
Expand Down

0 comments on commit 00f77ca

Please sign in to comment.