Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Added basic i18n for Notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
jochembroekhoff committed May 23, 2018
1 parent 72e6986 commit 42be04b
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 36 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ At this moment, the following components are supported out of the box:
- TextArea
- TextField

And the following layouts:
- Layout (default)
- ScrollableLayout

To find out which attributes you can set on each component, checkout the DTD (in src/main/resources/assets/cdmlloader).

> **Using i18n**: All the core components support i18n (Internationalization) on all text attributes.
Expand All @@ -112,8 +116,9 @@ To find out which attributes you can set on each component, checkout the DTD (in
> The key in the lang files is composed like this: `app.MOD_ID.APP_ID.value.RAWVALUE`.
> So in this case CDMLLoader tries to load the i18n value of `app.mymod.myapp.value.labelText`.
>
> Please note that Notifications the only _unsupported_ part is. In the future, you will be able
> to use the i18n notation there too.
> Note: Notifications are translated on the client which opens the application, this means that when you send a
> notification to another player whose client is set to a different language, the text is displayed in the language of
> the client that instantiated the notification.
_To be continued._
Expand Down Expand Up @@ -186,7 +191,6 @@ They are located at `nl.jochembroekhoff.cdmlloader.defaulthandlers.component.*`
- Per-layout controllers
- UI Designer
- Element child items processing
- Update the XSD

## Thanks / Credits

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'java'
apply plugin: 'maven'

version = "0.2.0"
version = "0.2.1"
group = "nl.jochembroekhoff.cdmlloader" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "cdmlloader"

Expand Down
15 changes: 9 additions & 6 deletions src/main/java/nl/jochembroekhoff/cdmlloader/CDMLLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mrcrayfish.device.api.app.Application;
import com.mrcrayfish.device.api.app.IIcon;
import com.mrcrayfish.device.api.app.Icons;
import com.mrcrayfish.device.api.app.Notification;
import com.mrcrayfish.device.api.app.component.RadioGroup;
import lombok.val;
Expand All @@ -17,7 +16,7 @@
import nl.jochembroekhoff.cdmlloader.meta.ComponentMeta;
import nl.jochembroekhoff.cdmlloader.meta.ListenerDefinition;
import nl.jochembroekhoff.cdmlloader.meta.NotificationMeta;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLDemoMod;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLLoaderMod;
import org.apache.logging.log4j.Logger;
import org.xml.sax.SAXException;

Expand All @@ -44,7 +43,7 @@ public class CDMLLoader {
private final static Map<String, Class<? extends IIcon>> iconSets = new HashMap<>();
private final static Map<String, List<String>> iconNames = new HashMap<>();

public static final Logger LOGGER = CDMLDemoMod.getLogger();
public static final Logger LOGGER = CDMLLoaderMod.getLogger();

/**
* Load a CDML document and inject the constructed values in this class (controller class).
Expand Down Expand Up @@ -261,11 +260,15 @@ public static IIcon getIcon(String iconName, String iconSet) {
if (iconSet == null || iconSet.isEmpty())
iconSet = "Icons";

if (!hasIconSet(iconSet))
return null;
if (!hasIconSet(iconSet)) {
LOGGER.warn("==> No icon set found for {}. Falling back to the icon set 'Icons'.", iconSet);
iconSet = "Icons";
}

if (!getIconNames(iconSet).contains(iconName))
if (!getIconNames(iconSet).contains(iconName)) {
LOGGER.error("==> The icon set {} does not define the icon {}", iconSet, iconName);
return null;
}

return getIconSet(iconSet)
.getEnumConstants()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import nl.jochembroekhoff.cdmlloader.util.ReflectionUtil;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLDemoMod;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLLoaderMod;
import nl.jochembroekhoff.cdmlloaderdemo.Reference;

import java.io.File;
Expand Down Expand Up @@ -60,7 +60,7 @@ static Configuration getConfiguration() {
configuration = entryOptional.get().getValue();
}
} catch (Throwable throwable) {
CDMLDemoMod.getLogger().error("Failed to get Configuration instance", throwable);
CDMLLoaderMod.getLogger().error("Failed to get Configuration instance", throwable);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import nl.jochembroekhoff.cdmlloader.annotate.CdmlComponent;
import nl.jochembroekhoff.cdmlloader.handler.CdmlComponentHandler;
import nl.jochembroekhoff.cdmlloader.meta.ComponentMeta;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLDemoMod;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLLoaderMod;

import java.awt.*;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -75,7 +75,7 @@ public Image createComponent(ComponentMeta meta) {
m.setAccessible(true);
m.invoke(img, borderColor);
} catch (Exception e) {
CDMLDemoMod.getLogger().error("==> Couldn't set border color: {}", e.getMessage());
CDMLLoaderMod.getLogger().error("==> Couldn't set border color: {}", e.getMessage());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,16 @@ private void handleListeners(Element listenersElem, Component component) {

private void handleNotification(Element elem) {
String name = elem.getAttribute("name");
String title = elem.getAttribute("title");
String subTitle = elem.getAttribute("subTitle");
String title = getI18nValue(elem, "title");
String subTitle = getI18nValue(elem, "subTitle");
String iconName = elem.getAttribute("iconName");
String iconSet = elem.getAttribute("iconSet");

if (iconSet == null || iconSet.isEmpty())
iconSet = "Icons";

if (mappingNotifications.containsKey(name))
LOGGER.warn("==> Duplicate creation of notification with name: {}", name);
LOGGER.warn("==> Duplicate creation of notification with name: {}. Overwriting previously registered notification.", name);

//Register notification
mappingNotifications.put(name, new NotificationMeta(name, title, subTitle, iconName, iconSet));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author Jochem Broekhoff
*/
@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.MOD_VERSION, acceptedMinecraftVersions = Reference.MC_VERSION, dependencies = Reference.DEPENDS)
public class CDMLDemoMod {
public class CDMLLoaderMod {
private static Logger logger;

@SidedProxy(clientSide = Reference.Proxy.CLIENT_SIDE, serverSide = Reference.Proxy.SERVER_SIDE)
Expand All @@ -45,7 +45,6 @@ public void init(FMLInitializationEvent event) {
CDMLLoader.registerIconSet("Icons", Icons.class);
CDMLLoader.registerIconSet("Alphabet", Alphabet.class);


/* Register tasks */
TaskManager.registerTask(TaskTestCDMLNotification.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class Reference {
public static final String MOD_ID = "cdmlloader";
public static final String MOD_NAME = "CDMLLoader";
public static final String MOD_VERSION = "0.2.0";
public static final String MOD_VERSION = "0.2.1";
public static final String MC_VERSION = "[1.12.2]";
public static final String DEPENDS = "required-after:cdm@[0.4.0,)";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
import com.mrcrayfish.device.api.app.listener.KeyListener;
import com.mrcrayfish.device.api.app.listener.SlideListener;
import com.mrcrayfish.device.api.task.TaskManager;
import com.mrcrayfish.device.core.Laptop;
import com.mrcrayfish.device.object.AppInfo;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import nl.jochembroekhoff.cdmlloader.CDMLLoader;
import nl.jochembroekhoff.cdmlloader.annotate.Cdml;
import nl.jochembroekhoff.cdmlloader.annotate.CdmlApp;
import nl.jochembroekhoff.cdmlloader.handler.CDMLDocumentHandler;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLDemoMod;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLLoaderMod;
import nl.jochembroekhoff.cdmlloaderdemo.task.TaskTestCDMLNotification;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -65,24 +62,22 @@ public void init(@Nullable NBTTagCompound intent) {
}

@Cdml
InitListener layout1init = () -> CDMLDemoMod.getLogger().info("Layout one has been initialized.");
InitListener layout1init = () -> CDMLLoaderMod.getLogger().info("Layout one has been initialized.");

@Cdml
ClickListener clickHandler = (x, y, mousebtn) -> {
CDMLDemoMod.getLogger().info("Clicked with mouse button {}", mousebtn);
CDMLLoaderMod.getLogger().info("Clicked with mouse button {}", mousebtn);
TaskManager.sendTask(new TaskTestCDMLNotification(handler.getNotificationMeta("notifyTest1")));

Laptop.getSystem().openApplication(new AppInfo(new ResourceLocation("cdm", "note_stash"), true));

/*
try {
val tmp = new File(System.getProperty("java.io.tmpdir"));
val img = new File(tmp, "cdmlloader/capture.tga.gz");
val capt = new FramebufferCapturer();
val fbw = new FramebufferWriter(img, capt);
fbw.write();
CDMLDemoMod.getLogger().info("[Capture] Captured Minecraft. Saved at: {}", img);
CDMLDemoMod.getLogger().info("[Capture] Laptop screen rectangle: {}", fbw.getFramebufferCapturer().getScreenRectangle());
CDMLLoaderMod.getLogger().info("[Capture] Captured Minecraft. Saved at: {}", img);
CDMLLoaderMod.getLogger().info("[Capture] Laptop screen rectangle: {}", fbw.getFramebufferCapturer().getScreenRectangle());
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -94,7 +89,7 @@ public void init(@Nullable NBTTagCompound intent) {

@Cdml
KeyListener keyPressed = (key) -> {
CDMLDemoMod.getLogger().info("Pressed key: {}", key);
CDMLLoaderMod.getLogger().info("Pressed key: {}", key);
return true;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package nl.jochembroekhoff.cdmlloaderdemo.task;

import com.mrcrayfish.device.api.app.Notification;
import com.mrcrayfish.device.api.task.Task;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import nl.jochembroekhoff.cdmlloader.CDMLLoader;
import nl.jochembroekhoff.cdmlloader.meta.NotificationMeta;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLDemoMod;
import nl.jochembroekhoff.cdmlloaderdemo.CDMLLoaderMod;

public class TaskTestCDMLNotification extends Task {

Expand Down Expand Up @@ -41,9 +42,10 @@ public void processRequest(NBTTagCompound nbt, World world, EntityPlayer player)
nbt.getString("iconSet")
);

CDMLDemoMod.getLogger().info(nbt);
CDMLLoaderMod.getLogger().info(nbt);

CDMLLoader.createNotification(meta).pushTo((EntityPlayerMP) player);
Notification notification = CDMLLoader.createNotification(meta);
notification.pushTo((EntityPlayerMP) player);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/cdmlloader/cdml/cdml_demo.cdml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ The layout is based on the 'UI Components' system application.
</layout>
</layouts>
<notifications>
<notification name="notifyTest1" title="Notification Title" subTitle="Subtitle" iconName="CHEVRON_DOWN"/>
<notification name="notifyTest1"
title=":notification_title" subTitle=":notification_subtitle"
iconName="DOLLAR_SIGN" iconSet="Alphabet"/>
</notifications>
</application>
3 changes: 3 additions & 0 deletions src/main/resources/assets/cdmlloader/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ app.cdmlloader.cdml_demo.value.item3=Item #3

app.cdmlloader.cdml_demo.value.first=First
app.cdmlloader.cdml_demo.value.second=Second

app.cdmlloader.cdml_demo.value.notification_title=Notification Title
app.cdmlloader.cdml_demo.value.notification_subtitle=Subtitle
2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"modid": "cdmlloader",
"name": "CDMLLoader",
"description": "CDML Loading utilities.",
"version": "0.2.0",
"version": "0.2.1",
"mcversion": "1.12.2",
"url": "",
"updateUrl": "",
Expand Down

0 comments on commit 42be04b

Please sign in to comment.