diff --git a/src/main/java/com/mrcrayfish/device/api/app/Dialog.java b/src/main/java/com/mrcrayfish/device/api/app/Dialog.java index 08610c84a..fd38e980f 100644 --- a/src/main/java/com/mrcrayfish/device/api/app/Dialog.java +++ b/src/main/java/com/mrcrayfish/device/api/app/Dialog.java @@ -193,37 +193,37 @@ public void close() public static class Message extends Dialog { - private String messageText = ""; + private String message; + private Text text = null; + private int foreground = Color.DARK_GRAY.getRGB(); + private int background = Color.LIGHT_GRAY.getRGB(); private ClickListener positiveListener; private Button buttonPositive; public Message(String messageText) { - this.messageText = messageText; + this.message = messageText; } - + @Override public void init() { super.init(); - int lines = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(messageText, getWidth() - 10).size(); + int lines = Minecraft.getMinecraft().fontRenderer.listFormattedStringToWidth(message, getWidth() - 10).size(); defaultLayout.height += (lines - 1) * 9; super.init(); - defaultLayout.setBackground(new Background() - { - @Override - public void render(Gui gui, Minecraft mc, int x, int y, int width, int height, int mouseX, int mouseY, boolean windowActive) - { - Gui.drawRect(x, y, x + width, y + height, Color.LIGHT_GRAY.getRGB()); - } - }); + defaultLayout.setBackground( + (gui, mc, x, y, width, height, mouseX, mouseY, windowActive)-> + Gui.drawRect(x, y, x + width, y + height, background) + ); - Text message = new Text(messageText, 5, 5, getWidth() - 10); - this.addComponent(message); + text = new Text(message, 5, 5, getWidth() - 10); + text.setTextColor(foreground); + this.addComponent(text); buttonPositive = new Button(getWidth() - 41, getHeight() - 20, "Close"); buttonPositive.setSize(36, 16); @@ -237,6 +237,14 @@ public void render(Gui gui, Minecraft mc, int x, int y, int width, int height, i }); this.addComponent(buttonPositive); } + + public void setForeground(int color){ + this.foreground = color; + } + + public void setBackground(int color){ + this.background = color; + } } /** diff --git a/src/main/java/com/mrcrayfish/device/api/app/component/Text.java b/src/main/java/com/mrcrayfish/device/api/app/component/Text.java index cebe09d18..5dc4d9741 100644 --- a/src/main/java/com/mrcrayfish/device/api/app/component/Text.java +++ b/src/main/java/com/mrcrayfish/device/api/app/component/Text.java @@ -53,12 +53,20 @@ public void setText(String text) } /** - * Sets the text color for this component + * Sets the text color. * * @param color the text color */ - public void setTextColor(Color color) + public void setTextColor(int color) { + this.textColor = color; + } + + /** + * Sets the text color. Keeping this to prevent breaking + * @param color + */ + public void setTextColor(Color color){ this.textColor = color.getRGB(); } diff --git a/src/main/java/com/mrcrayfish/device/object/AppInfo.java b/src/main/java/com/mrcrayfish/device/object/AppInfo.java index 2c7f9af1c..131ee9030 100644 --- a/src/main/java/com/mrcrayfish/device/object/AppInfo.java +++ b/src/main/java/com/mrcrayfish/device/object/AppInfo.java @@ -24,11 +24,13 @@ public class AppInfo private String name; private String author; + private String[] authors; private String description; private String version; private String icon; private String[] screenshots; private Support support; + private String[] contributors; public AppInfo(ResourceLocation identifier, boolean isSystemApp) { @@ -70,6 +72,12 @@ public String getAuthor() { return author; } + + public boolean hasSingleAuthor(){ + return (this.author != null && this.authors == null); + } + + public String[] getAuthors(){ return authors; } public String getDescription() { @@ -111,6 +119,14 @@ public boolean isSystemApp() return systemApp; } + public boolean hasContributors(){ + return this.contributors != null && this.contributors.length > 0; + } + + public String[] getContributors(){ + return this.contributors; + } + @Override public boolean equals(Object obj) { @@ -160,6 +176,16 @@ public static class Deserializer implements JsonDeserializer { private static final Pattern LANG = Pattern.compile("\\$\\{[a-z]+}"); + private static final String NAME = "name"; + private static final String AUTHOR = "author"; + private static final String AUTHORS = "authors"; + private static final String CONTRIBS = "contributors"; + private static final String DESC = "description"; + private static final String VERSION = "version"; + private static final String SCREENS = "screenshots"; + private static final String ICON = "icon"; + private static final String SUPPORT = "support"; + private AppInfo info; public Deserializer(AppInfo info) @@ -172,24 +198,31 @@ public AppInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo { try { - info.name = convertToLocal(json.getAsJsonObject().get("name").getAsString()); - info.author = convertToLocal(json.getAsJsonObject().get("author").getAsString()); - info.description = convertToLocal(json.getAsJsonObject().get("description").getAsString()); - info.version = json.getAsJsonObject().get("version").getAsString(); + info.name = convertToLocal(json.getAsJsonObject().get(NAME).getAsString()); + if(json.getAsJsonObject().has(AUTHOR)) + info.author = convertToLocal(json.getAsJsonObject().get(AUTHOR).getAsString()); + else if(json.getAsJsonObject().has(AUTHORS) && json.getAsJsonObject().get(AUTHORS).isJsonArray()){ + info.authors = context.deserialize(json.getAsJsonObject().get(AUTHORS), new TypeToken(){}.getType()); + } + if(json.getAsJsonObject().has(CONTRIBS) && json.getAsJsonObject().get(CONTRIBS).isJsonArray()){ + info.contributors = this.deserializeArray(json, CONTRIBS, context); + } + info.description = convertToLocal(json.getAsJsonObject().get(DESC).getAsString()); + info.version = json.getAsJsonObject().get(VERSION).getAsString(); - if(json.getAsJsonObject().has("screenshots") && json.getAsJsonObject().get("screenshots").isJsonArray()) + if(json.getAsJsonObject().has(SCREENS) && json.getAsJsonObject().get(SCREENS).isJsonArray()) { - info.screenshots = context.deserialize(json.getAsJsonObject().get("screenshots"), new TypeToken(){}.getType()); + info.screenshots = context.deserialize(json.getAsJsonObject().get(SCREENS), new TypeToken(){}.getType()); } - if(json.getAsJsonObject().has("icon") && json.getAsJsonObject().get("icon").isJsonPrimitive()) + if(json.getAsJsonObject().has(ICON) && json.getAsJsonObject().get(ICON).isJsonPrimitive()) { - info.icon = json.getAsJsonObject().get("icon").getAsString(); + info.icon = json.getAsJsonObject().get(ICON).getAsString(); } - if(json.getAsJsonObject().has("support") && json.getAsJsonObject().get("support").getAsJsonObject().size() > 0) + if(json.getAsJsonObject().has(SUPPORT) && json.getAsJsonObject().get(SUPPORT).getAsJsonObject().size() > 0) { - JsonObject supportObj = json.getAsJsonObject().get("support").getAsJsonObject(); + JsonObject supportObj = json.getAsJsonObject().get(SUPPORT).getAsJsonObject(); Support support = new Support(); if(supportObj.has("paypal")) @@ -220,6 +253,10 @@ public AppInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationCo return info; } + private String[] deserializeArray(JsonElement json, String name, JsonDeserializationContext context){ + return context.deserialize(json.getAsJsonObject().get(name), new TypeToken(){}.getType()); + } + private String convertToLocal(String s) { Matcher m = LANG.matcher(s); diff --git a/src/main/java/com/mrcrayfish/device/programs/system/ApplicationAppStore.java b/src/main/java/com/mrcrayfish/device/programs/system/ApplicationAppStore.java index 9f0d62a39..8b1f23005 100644 --- a/src/main/java/com/mrcrayfish/device/programs/system/ApplicationAppStore.java +++ b/src/main/java/com/mrcrayfish/device/programs/system/ApplicationAppStore.java @@ -1,5 +1,6 @@ package com.mrcrayfish.device.programs.system; +import com.mrcrayfish.device.api.app.Dialog; import com.mrcrayfish.device.api.app.Icons; import com.mrcrayfish.device.api.app.Layout; import com.mrcrayfish.device.api.app.component.Button; diff --git a/src/main/java/com/mrcrayfish/device/programs/system/layout/LayoutAppPage.java b/src/main/java/com/mrcrayfish/device/programs/system/layout/LayoutAppPage.java index 28011acc3..4d2362429 100644 --- a/src/main/java/com/mrcrayfish/device/programs/system/layout/LayoutAppPage.java +++ b/src/main/java/com/mrcrayfish/device/programs/system/layout/LayoutAppPage.java @@ -1,6 +1,7 @@ package com.mrcrayfish.device.programs.system.layout; import com.mrcrayfish.device.MrCrayfishDeviceMod; +import com.mrcrayfish.device.api.app.Dialog; import com.mrcrayfish.device.api.app.Icons; import com.mrcrayfish.device.api.app.Layout; import com.mrcrayfish.device.api.app.component.Button; @@ -22,6 +23,8 @@ import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; +import java.util.Arrays; +import java.util.Iterator; import java.util.List; /** @@ -35,8 +38,10 @@ public class LayoutAppPage extends Layout private Image imageBanner; private Image imageIcon; private Label labelTitle; + private Label labelAuthor; private Label labelVersion; private Text textDescription; + private Button contribbutton; public LayoutAppPage(Laptop laptop, AppInfo info) { @@ -65,8 +70,23 @@ public void init() labelTitle.setScale(2); this.addComponent(labelTitle); - labelVersion = new Label("v" + info.getVersion() + " - " + info.getAuthor(), 38, 50); + String vstr = "v" + info.getVersion(); + this.labelVersion = new Label(vstr, this.width - Minecraft.getMinecraft().fontRenderer.getStringWidth(vstr), 2); + + if(info.hasSingleAuthor()) + labelAuthor = new Label("By: " + info.getAuthor(), 38, 50); + else{ + StringBuilder sb = new StringBuilder(); + List names = Arrays.asList(info.getAuthors()); + for(String a : names){ + sb.append(a); + if(names.indexOf(a) != info.getAuthors().length - 1) + sb.append(", "); + } + labelAuthor = new Label("By: " + sb.toString(), labelTitle.left, 50); + } this.addComponent(labelVersion); + this.addComponent(labelAuthor); textDescription = new Text(info.getDescription(), 130, 70, 115); this.addComponent(textDescription); diff --git a/src/main/java/com/mrcrayfish/device/programs/system/layout/LayoutSearchApps.java b/src/main/java/com/mrcrayfish/device/programs/system/layout/LayoutSearchApps.java index 992985679..a75fa0ab1 100644 --- a/src/main/java/com/mrcrayfish/device/programs/system/layout/LayoutSearchApps.java +++ b/src/main/java/com/mrcrayfish/device/programs/system/layout/LayoutSearchApps.java @@ -2,6 +2,7 @@ import com.mrcrayfish.device.api.ApplicationManager; import com.mrcrayfish.device.api.app.Application; +import com.mrcrayfish.device.api.app.Dialog; import com.mrcrayfish.device.api.app.Icons; import com.mrcrayfish.device.api.app.Layout; import com.mrcrayfish.device.api.app.component.*; @@ -96,6 +97,21 @@ private void openApplication(AppInfo info) { app.setCurrentLayout(this); }); + + if(info.hasContributors()){ + String contrbstr = "Contributors"; + Button contribbutton = new Button(this.width - Minecraft.getMinecraft().fontRenderer.getStringWidth(contrbstr) + 3, 10, contrbstr); + contribbutton.setClickListener((x, y, b)->{ + StringBuilder sb = new StringBuilder(); + for(String c : info.getContributors()){ + sb.append(c); + sb.append("\n"); + } + Dialog.Message message = new Dialog.Message(sb.toString()); + app.openDialog(message); + }); + layout.addComponent(contribbutton); + } layout.addComponent(btnPrevious); } } diff --git a/src/main/resources/assets/cdm/apps/test.json b/src/main/resources/assets/cdm/apps/test.json index e6538eb23..9bafe53d7 100644 --- a/src/main/resources/assets/cdm/apps/test.json +++ b/src/main/resources/assets/cdm/apps/test.json @@ -1,6 +1,7 @@ { "name": "Test", - "author": "MrCrayfish", + "authors": ["MrCrayfish", "Alex Couch"], + "contributors": ["SomeOtherGuy", "Winner", "Loser"], "description": "", "version": "1.0", "screenshots": [