Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/gregtech/api/mui/GTGuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ private static String id(String path) {
public static final UITexture MENU_OVERLAY = fullImage("textures/gui/overlay/menu_overlay.png");

public static final UITexture RECIPE_LOCK = fullImage("textures/gui/widget/lock.png");
public static final UITexture RECIPE_LOCK_WHITE = fullImage("textures/gui/widget/lock_white.png");
public static final UITexture PRIMITIVE_FURNACE_OVERLAY = fullImage(
"textures/gui/primitive/overlay_primitive_furnace.png");
public static final UITexture PRIMITIVE_DUST_OVERLAY = fullImage(
Expand All @@ -290,6 +291,11 @@ private static String id(String path) {
public static final UITexture FLUID_LOCK_OVERLAY = fullImage("textures/gui/widget/button_lock.png",
ColorType.DEFAULT);

public static final UITexture TERMINAL_FRAME = fullImage("textures/gui/terminal/terminal_frame.png");
public static final UITexture HOME_BUTTON = fullImage("textures/gui/terminal/home_button.png");
public static final UITexture HOME_BUTTON_HOVER = fullImage("textures/gui/terminal/home_button_hover.png");
public static final UITexture CAPES_APP_ICON = fullImage("textures/gui/terminal/capes/icon.png");

// todo bronze/steel/primitive fluid slots?

// SLOT OVERLAYS
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/gregtech/api/mui/GTGuiTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ private static String gregtech(String s) {
.itemSlot(GTGuiTextures.IDs.PRIMITIVE_SLOT)
.build();

// TODO make this better
public static final GTGuiTheme TERMINAL = templateBuilder("gregtech_terminal")
.parent(Names.STANDARD)
.textColor(0xFFFDFDFD)
.build();

protected final String themeId;

protected final List<Consumer<JsonBuilder>> elementBuilder;
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/gregtech/api/terminal2/ITerminalApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package gregtech.api.terminal2;

import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.api.widget.IWidget;
import com.cleanroommc.modularui.drawable.GuiTextures;
import com.cleanroommc.modularui.factory.HandGuiData;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.UISettings;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;

public interface ITerminalApp {

/**
* Create the UI for your app.
*/
IWidget buildWidgets(HandGuiData guiData, PanelSyncManager guiSyncManager, UISettings settings, ModularPanel panel);

/**
* @return The drawable that will be used for the icon of your app on the terminal home screen.
*/
default IDrawable getIcon() {
return GuiTextures.IMAGE;
}

/**
* Called when the user opens your app from the terminal home screen.
*/
default void onOpen() {}

/**
* Called when the terminal is closed. Free any references to UI elements or sync handlers here.
*/
default void dispose() {}
}
59 changes: 59 additions & 0 deletions src/main/java/gregtech/api/terminal2/Terminal2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package gregtech.api.terminal2;

import gregtech.api.util.FileUtility;
import gregtech.api.util.GTUtility;
import gregtech.common.ConfigHolder;
import gregtech.common.terminal2.CapeSelectorApp;
import gregtech.common.terminal2.SettingsApp;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;

public class Terminal2 {

public static final int SCREEN_WIDTH = 340, SCREEN_HEIGHT = 240;
public static final Map<ResourceLocation, ITerminalApp> appMap = new LinkedHashMap<>();
public static final ResourceLocation HOME_ID = GTUtility.gregtechId("home");

@SideOnly(Side.CLIENT)
public static File TERMINAL_PATH;

public static void init() {
if (FMLCommonHandler.instance().getSide().isClient()) {
TERMINAL_PATH = new File(Loader.instance().getConfigDir(), ConfigHolder.client.terminalRootPath);
FileUtility.extractJarFiles("/assets/gregtech/terminal", TERMINAL_PATH, false);
Terminal2Theme.init();
}
registerApp(GTUtility.gregtechId("settings"), new SettingsApp());
registerApp(GTUtility.gregtechId("capes"), new CapeSelectorApp());

/*
* TODO potential apps to create/port:
* guide/tutorial app using mui2 rich text and markup files of some sort
* terminal games (minesweeper, pong, theseus' escape)
* recipe chart (if anyone actually wants to port it)
* teleporter (would require a system allowing gating apps behind some requirement, too powerful to be default)
*/
}

/**
* Register a terminal app. Call this during initialization.
*
* @param id A unique identifier for your app. This is used to determine the lang key for the app name tooltip.
* <p>
* e.g. <code>gregtech:capes</code> -> <code>terminal.app.gregtech.capes</code>
*/
public static void registerApp(ResourceLocation id, ITerminalApp app) {
if (appMap.containsKey(id) || HOME_ID.equals(id)) {
throw new AssertionError("A terminal app with id " + id + " already exists!");
}
appMap.put(id, app);
}
}
143 changes: 143 additions & 0 deletions src/main/java/gregtech/api/terminal2/Terminal2Theme.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package gregtech.api.terminal2;

import gregtech.api.util.FileUtility;
import gregtech.api.util.GTUtility;
import gregtech.common.mui.drawable.BoundRectangle;
import gregtech.common.mui.drawable.FileTexture;

import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.drawable.UITexture;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;

import java.awt.Color;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@SuppressWarnings("unused")
public class Terminal2Theme {

private static final String CONFIG_PATH = "config/theme.json";
private static IDrawable currentBackgroundDrawable = null;
private static final UITexture defaultBackground = UITexture
.fullImage(GTUtility.gregtechId("textures/gui/terminal/terminal_background.png"));
public static File backgroundsDir;
private static final Map<String, Integer> defaultColors = new Object2IntOpenHashMap<>();

public static String currentBackground = "default";
// theres enough colors here to make specifying stuff for all of them annoying
// therefore, we use reflection for its intended purpose
public static final List<String> colors = Arrays.stream(Terminal2Theme.class.getFields())
.map(Field::getName).filter(name -> name.startsWith("COLOR_")).collect(Collectors.toList());

public static BoundRectangle COLOR_BRIGHT_1 = new BoundRectangle()
.setColor(new Color(144, 243, 116).getRGB());
public static BoundRectangle COLOR_BRIGHT_2 = new BoundRectangle()
.setColor(new Color(243, 208, 116).getRGB());
public static BoundRectangle COLOR_BRIGHT_3 = new BoundRectangle()
.setColor(new Color(231, 95, 95).getRGB());
public static BoundRectangle COLOR_BRIGHT_4 = new BoundRectangle()
.setColor(new Color(230, 230, 230).getRGB());

public static BoundRectangle COLOR_DARK_1 = new BoundRectangle()
.setColor(new Color(0, 115, 255).getRGB());
public static BoundRectangle COLOR_DARK_2 = new BoundRectangle()
.setColor(new Color(113, 27, 217).getRGB());
public static BoundRectangle COLOR_DARK_3 = new BoundRectangle().setColor(new Color(30, 80, 30).getRGB());
public static BoundRectangle COLOR_DARK_4 = new BoundRectangle().setColor(new Color(30, 30, 30).getRGB());

public static BoundRectangle COLOR_FOREGROUND_BRIGHT = new BoundRectangle()
.setColor(new Color(148, 226, 193).getRGB());
public static BoundRectangle COLOR_FOREGROUND_DARK = new BoundRectangle()
.setColor(new Color(175, 0, 0, 131).getRGB());

public static BoundRectangle COLOR_BACKGROUND_1 = new BoundRectangle()
.setColor(new Color(0, 0, 0, 80).getRGB());
public static BoundRectangle COLOR_BACKGROUND_2 = new BoundRectangle()
.setColor(new Color(0, 0, 0, 160).getRGB());
public static BoundRectangle COLOR_BACKGROUND_3 = new BoundRectangle()
.setColor(new Color(246, 120, 120, 160).getRGB());

public static void init() {
backgroundsDir = new File(Terminal2.TERMINAL_PATH, "backgrounds");

JsonElement element = FileUtility.loadJson(new File(Terminal2.TERMINAL_PATH, CONFIG_PATH));
if (element == null || !element.isJsonObject()) {
saveConfig();
return;
}

JsonObject config = element.getAsJsonObject();

for (String color : colors) {
defaultColors.put(color, getColorRect(color).getColor());
if (config.has(color)) {
setColor(color, config.get(color).getAsInt());
}
}

if (config.has("BACKGROUND_FILE")) {
setBackground(config.get("BACKGROUND_FILE").getAsString());
}
}

public static boolean saveConfig() {
JsonObject config = new JsonObject();

for (String color : colors) {
config.addProperty(color, getColorRect(color).getColor());
}

config.addProperty("BACKGROUND_FILE", currentBackground);

return FileUtility.saveJson(new File(Terminal2.TERMINAL_PATH, CONFIG_PATH), config);
}

public static IDrawable getBackgroundDrawable() {
// noinspection ReplaceNullCheck
if (currentBackgroundDrawable == null) {
return defaultBackground;
}
return currentBackgroundDrawable;
}

public static void setBackground(String file) {
currentBackground = file;
if (file.equals("default")) {
currentBackgroundDrawable = null;
} else {
currentBackgroundDrawable = new FileTexture(new File(backgroundsDir, file));
}
}

public static BoundRectangle getColorRect(String color) {
try {
return (BoundRectangle) Terminal2Theme.class.getField(color).get(null);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new RuntimeException("Failed to get color rect " + color, e);
}
}

public static void setColor(String color, int i) {
getColorRect(color).setColor(i);
}

public static void resetToDefaultColor(String color) {
setColor(color, defaultColors.get(color));
}

public static boolean isDefaultColor(String color) {
return getColorRect(color).getColor() == defaultColors.get(color);
}

public static void gcBoundRects() {
for (String color : colors) {
getColorRect(color).gc();
}
}
}
27 changes: 25 additions & 2 deletions src/main/java/gregtech/api/util/CapesRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraftforge.fml.relauncher.SideOnly;

import crafttweaker.annotations.ZenRegister;
import org.jetbrains.annotations.ApiStatus;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;

Expand All @@ -37,7 +38,8 @@ public class CapesRegistry {
private static final Map<UUID, List<ResourceLocation>> UNLOCKED_CAPES = new HashMap<>();
private static final Map<UUID, ResourceLocation> WORN_CAPES = new HashMap<>();
private static final Map<Advancement, ResourceLocation> CAPE_ADVANCEMENTS = new HashMap<>();
private static final Set<ResourceLocation> FREE_CAPES = new HashSet<>();
private static final Set<ResourceLocation> ADVANCEMENT_CAPES = new LinkedHashSet<>();
private static final Set<ResourceLocation> FREE_CAPES = new LinkedHashSet<>();

public static void registerDevCapes() {
unlockCape(UUID.fromString("a24a9108-23d2-43fc-8db7-43f809d017db"), Textures.GREGTECH_CAPE_TEXTURE); // ALongStringOfNumbers
Expand Down Expand Up @@ -199,17 +201,27 @@ public static void registerCape(ResourceLocation advancement, ResourceLocation c
CAPE_ADVANCEMENTS.put(advObject, cape);
}
}
ADVANCEMENT_CAPES.add(cape);
}

/**
* Adds a cape that will always be unlocked for all players.
*
* @param cape A ResourceLocation pointing to the cape texture.
*/
public static void addFreeCape(ResourceLocation cape) {
public static void registerFreeCape(ResourceLocation cape) {
FREE_CAPES.add(cape);
}

/**
* Deprecated for naming consistency, use {@link #registerFreeCape(ResourceLocation)} instead
*/
@ApiStatus.ScheduledForRemoval(inVersion = "2.10")
@Deprecated
public static void addFreeCape(ResourceLocation cape) {
registerFreeCape(cape);
}

private static final List<Tuple<ResourceLocation, ResourceLocation>> ctRegisterCapes = new ArrayList<>();
private static final List<ResourceLocation> ctFreeCapes = new ArrayList<>();

Expand Down Expand Up @@ -250,6 +262,17 @@ public static void unlockCapeOnAdvancement(EntityPlayer player, Advancement adva
}
}

/**
* @return A list of all registered capes, with advancement capes sorted before free capes.
* This currently does not count capes that are manually unlocked by other mods.
*/
public static List<ResourceLocation> allCapes() {
List<ResourceLocation> result = new ArrayList<>();
result.addAll(ADVANCEMENT_CAPES);
result.addAll(FREE_CAPES);
return result;
}

public static void clearMaps() {
UNLOCKED_CAPES.clear();
WORN_CAPES.clear();
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/gregtech/common/items/MetaItem1.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import gregtech.common.items.behaviors.MultiblockBuilderBehavior;
import gregtech.common.items.behaviors.NanoSaberBehavior;
import gregtech.common.items.behaviors.ProspectorScannerBehavior;
import gregtech.common.items.behaviors.Terminal2Behavior;
import gregtech.common.items.behaviors.TooltipBehavior;
import gregtech.common.items.behaviors.TricorderBehavior;
import gregtech.common.items.behaviors.TurbineRotorBehavior;
Expand Down Expand Up @@ -832,6 +833,7 @@ public void registerSubItems() {
.setMaxStackSize(1)
.setCreativeTabs(GTCreativeTabs.TAB_GREGTECH_TOOLS);
TERMINAL = addItem(465, "terminal")
.addComponents(new Terminal2Behavior())
.setMaxStackSize(1)
.setCreativeTabs(GTCreativeTabs.TAB_GREGTECH_TOOLS);
PROSPECTOR_LV = addItem(466, "prospector.lv")
Expand Down
Loading
Loading