Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.
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
36 changes: 22 additions & 14 deletions src/main/java/com/mrcrayfish/device/api/app/Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}

/**
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/mrcrayfish/device/api/app/component/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
57 changes: 47 additions & 10 deletions src/main/java/com/mrcrayfish/device/object/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -160,6 +176,16 @@ public static class Deserializer implements JsonDeserializer<AppInfo>
{
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)
Expand All @@ -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<String[]>(){}.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<String[]>(){}.getType());
info.screenshots = context.deserialize(json.getAsJsonObject().get(SCREENS), new TypeToken<String[]>(){}.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"))
Expand Down Expand Up @@ -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<String[]>(){}.getType());
}

private String convertToLocal(String s)
{
Matcher m = LANG.matcher(s);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

/**
Expand All @@ -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)
{
Expand Down Expand Up @@ -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<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/cdm/apps/test.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "Test",
"author": "MrCrayfish",
"authors": ["MrCrayfish", "Alex Couch"],
"contributors": ["SomeOtherGuy", "Winner", "Loser"],
"description": "",
"version": "1.0",
"screenshots": [
Expand Down