summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-25 20:59:18 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-25 20:59:18 +0100
commita46b7459b22c6c442e06c4147b6f445f45f8b744 (patch)
treeccc8736b762f6e513b074c7895fef39a0217f533
parentf39716fbbaa9ecdf94a9865309eaeef6f54a9560 (diff)
downloadnoctis-a46b7459b22c6c442e06c4147b6f445f45f8b744.tar.bz2
Very basic gui now working, needs next/prev buttons etc but we're getting there
-rw-r--r--src/main/java/net/flarn/noctis/Noctis.java3
-rw-r--r--src/main/java/net/flarn/noctis/client/gui/GuiHandler.java25
-rw-r--r--src/main/java/net/flarn/noctis/item/ItemJournal.java17
-rw-r--r--src/main/java/net/flarn/noctis/journal/JournalContentModel.java58
-rw-r--r--src/main/java/net/flarn/noctis/journal/JournalDayEntry.java24
-rw-r--r--src/main/java/net/flarn/noctis/journal/JournalEntry.java2
-rw-r--r--src/main/java/net/flarn/noctis/journal/gui/JournalGui.java169
-rw-r--r--src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java2
-rw-r--r--src/main/java/net/flarn/noctis/network/KnowledgeBaseTransfer.java6
-rw-r--r--src/main/java/net/flarn/noctis/refs/GuiIds.java6
-rw-r--r--src/main/java/net/flarn/noctis/refs/Strings.java3
-rw-r--r--src/main/java/net/flarn/noctis/utils/TimeHelper.java41
-rw-r--r--src/main/resources/assets/noctis/journal/en_GB.yaml2
-rw-r--r--src/main/resources/assets/noctis/lang/en_GB.lang10
14 files changed, 366 insertions, 2 deletions
diff --git a/src/main/java/net/flarn/noctis/Noctis.java b/src/main/java/net/flarn/noctis/Noctis.java
index 9128504..383d608 100644
--- a/src/main/java/net/flarn/noctis/Noctis.java
+++ b/src/main/java/net/flarn/noctis/Noctis.java
@@ -6,7 +6,9 @@ import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
+import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
+import net.flarn.noctis.client.gui.GuiHandler;
import net.flarn.noctis.handler.ConfigHandler;
import net.flarn.noctis.handler.PlayerHandler;
import net.flarn.noctis.init.ModItems;
@@ -42,6 +44,7 @@ public class Noctis {
// Guis, TileEntity, recipes, etc. (general event handlers)
Recipes.init();
Recipes.initCatalysedRecipes();
+ NetworkRegistry.INSTANCE.registerGuiHandler(Noctis.instance, new GuiHandler());
}
@Mod.EventHandler
diff --git a/src/main/java/net/flarn/noctis/client/gui/GuiHandler.java b/src/main/java/net/flarn/noctis/client/gui/GuiHandler.java
new file mode 100644
index 0000000..3ff6b3c
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/client/gui/GuiHandler.java
@@ -0,0 +1,25 @@
+package net.flarn.noctis.client.gui;
+
+
+import cpw.mods.fml.common.network.IGuiHandler;
+import net.flarn.noctis.journal.gui.JournalGui;
+import net.flarn.noctis.refs.GuiIds;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.world.World;
+
+public class GuiHandler implements IGuiHandler {
+
+ @Override
+ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
+ return null;
+ }
+
+ @Override
+ public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
+ switch (ID) {
+ case GuiIds.JOURNAL:
+ return new JournalGui();
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/net/flarn/noctis/item/ItemJournal.java b/src/main/java/net/flarn/noctis/item/ItemJournal.java
index 388039e..1e5c79d 100644
--- a/src/main/java/net/flarn/noctis/item/ItemJournal.java
+++ b/src/main/java/net/flarn/noctis/item/ItemJournal.java
@@ -1,13 +1,23 @@
package net.flarn.noctis.item;
+import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+import net.flarn.noctis.Noctis;
+import net.flarn.noctis.journal.JournalContentModel;
+import net.flarn.noctis.journal.gui.JournalGui;
+import net.flarn.noctis.knowledge.KnowledgeBase;
+import net.flarn.noctis.refs.GuiIds;
import net.flarn.noctis.refs.Names;
import net.flarn.noctis.refs.Strings;
+import net.flarn.noctis.utils.PlayerHelper;
+import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
+import net.minecraft.world.World;
import java.util.List;
@@ -23,4 +33,11 @@ public class ItemJournal extends ItemNoctisBase {
strs.add("");
strs.add(StatCollector.translateToLocal(Strings.JOURNAL_DESC));
}
+
+ @Override
+ public ItemStack onItemRightClick(ItemStack s, World w, EntityPlayer p) {
+ p.openGui(Noctis.instance, GuiIds.JOURNAL, w, 0, 0, 0);
+
+ return s;
+ }
}
diff --git a/src/main/java/net/flarn/noctis/journal/JournalContentModel.java b/src/main/java/net/flarn/noctis/journal/JournalContentModel.java
new file mode 100644
index 0000000..30cc362
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/journal/JournalContentModel.java
@@ -0,0 +1,58 @@
+package net.flarn.noctis.journal;
+
+
+import net.flarn.noctis.knowledge.KnowledgeBase;
+import net.flarn.noctis.knowledge.KnowledgeItem;
+import net.flarn.noctis.knowledge.KnowledgeVisibility;
+import net.flarn.noctis.refs.Numbers;
+import net.flarn.noctis.utils.LogHelper;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class JournalContentModel {
+ public List<List<JournalDayEntry>> journalPageGroups;
+ public JournalContentModel(KnowledgeBase kb) {
+ // Iterate the events from the knowledgebase in order, producing journal entries by day
+ long currentDayNum = -1;
+ journalPageGroups = new LinkedList<List<JournalDayEntry>>();
+ List<JournalDayEntry> currentDay = null;
+ for (KnowledgeBase.KnowledgeEvent event : kb.getEventSequence()) {
+ LogHelper.warn("Processing knowledge event: " + event.name + " @ " + event.time + " >> " + event.vis);
+ long thisday = event.time / Numbers.TICKS_PER_DAY;
+ if (thisday != currentDayNum) {
+ if (currentDay != null) {
+ journalPageGroups.add(currentDay);
+ }
+ currentDay = new LinkedList<JournalDayEntry>();
+ currentDayNum = thisday;
+ }
+ JournalDayEntry thisDayEntry = new JournalDayEntry(event.time);
+ KnowledgeItem ki = KnowledgeItem.findKnowledgeItem(event.name);
+ JournalEntry ji = JournalEntry.journalEntryMap.get(ki);
+ if (event.vis == KnowledgeVisibility.THEORY) {
+ thisDayEntry.pages.addAll(ji.theoryStack);
+ }
+ if (event.vis == KnowledgeVisibility.KNOWN) {
+ thisDayEntry.pages.addAll(ji.knownStack);
+ }
+ currentDay.add(thisDayEntry);
+ }
+ journalPageGroups.add(currentDay);
+ }
+ public void dumpJournalStructure() {
+ LogHelper.warn("There are " + journalPageGroups.size() + " page groups");
+ int n = 0;
+ for (List<JournalDayEntry> entries : journalPageGroups) {
+ n = n + 1;
+ LogHelper.warn("There are " + entries.size() + " entries in group " + n);
+ int ent = 0;
+ for (JournalDayEntry entry : entries) {
+ ent = ent + 1;
+ LogHelper.warn("There are " + entry.pages.size() + " pages in entry " + ent);
+ }
+ }
+ }
+
+ public static JournalContentModel currentContentModel = null;
+}
diff --git a/src/main/java/net/flarn/noctis/journal/JournalDayEntry.java b/src/main/java/net/flarn/noctis/journal/JournalDayEntry.java
new file mode 100644
index 0000000..3e9bfbd
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/journal/JournalDayEntry.java
@@ -0,0 +1,24 @@
+package net.flarn.noctis.journal;
+
+import net.flarn.noctis.refs.Numbers;
+import net.flarn.noctis.refs.Strings;
+import net.flarn.noctis.utils.TimeHelper;
+import net.minecraft.util.StatCollector;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class JournalDayEntry {
+ public final long basetime;
+ public final String localisedDate;
+ public final String timeOfDay;
+ public List<JournalEntry.Page> pages;
+
+ public JournalDayEntry(long time) {
+ basetime = time;
+ long day = time / Numbers.TICKS_PER_DAY;
+ localisedDate = String.format(StatCollector.translateToLocal(Strings.JOURNAL_DAYFMT), day + 1);
+ timeOfDay = TimeHelper.ApproxTime.getFromTicks(time).getLocalizedApproxTime();
+ pages = new LinkedList<JournalEntry.Page>();
+ }
+}
diff --git a/src/main/java/net/flarn/noctis/journal/JournalEntry.java b/src/main/java/net/flarn/noctis/journal/JournalEntry.java
index ceaabb8..b789828 100644
--- a/src/main/java/net/flarn/noctis/journal/JournalEntry.java
+++ b/src/main/java/net/flarn/noctis/journal/JournalEntry.java
@@ -91,7 +91,9 @@ public class JournalEntry {
public PageText(String _body) {
super(PageKind.TEXT);
body = _body;
+ renderedBody = null;
}
+ public List<List<String>> renderedBody;
}
public class PageRecipe extends Page {
public IRecipe recipe;
diff --git a/src/main/java/net/flarn/noctis/journal/gui/JournalGui.java b/src/main/java/net/flarn/noctis/journal/gui/JournalGui.java
new file mode 100644
index 0000000..b4d1325
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/journal/gui/JournalGui.java
@@ -0,0 +1,169 @@
+package net.flarn.noctis.journal.gui;
+
+
+import net.flarn.noctis.journal.JournalContentModel;
+import net.flarn.noctis.journal.JournalDayEntry;
+import net.flarn.noctis.journal.JournalEntry;
+import net.flarn.noctis.utils.TimeHelper;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiButton;
+import net.minecraft.client.gui.GuiScreen;
+import net.minecraft.util.ResourceLocation;
+import org.lwjgl.opengl.GL11;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+public class JournalGui extends GuiScreen {
+ private JournalContentModel contentModel;
+ private long updateCount;
+
+ /* We're borrowing a non-trivial amount of stuff from Minecraft's book implementation for now */
+ private static final ResourceLocation bookGuiTextures = new ResourceLocation("textures/gui/book.png");
+ private final int bookImageWidth = 192;
+ private final int bookImageHeight = 192;
+
+ private int dayIdx;
+ private List<JournalDayEntry> day;
+ private int entryIdx;
+ private JournalDayEntry entry;
+ private int pageIdx;
+ private JournalEntry.Page page;
+ private int subPageIdx;
+
+ public JournalGui() {
+ contentModel = JournalContentModel.currentContentModel;
+ dayIdx = 0;
+ day = contentModel.journalPageGroups.get(dayIdx);
+ entryIdx = 0;
+ entry = day.get(entryIdx);
+ pageIdx = 0;
+ page = entry.pages.get(0);
+ subPageIdx = 0;
+
+ updateCount = 0;
+ checkAndUpdatePageIterators();
+ }
+
+ private void checkAndUpdatePageIterators() {
+ if (contentModel == JournalContentModel.currentContentModel) {
+ return;
+ }
+ /* For now, if the journal updates while we're using it, we reopen where we are */
+ contentModel = JournalContentModel.currentContentModel;
+ day = contentModel.journalPageGroups.get(dayIdx);
+ entry = day.get(entryIdx);
+ page = entry.pages.get(0);
+ }
+
+ @Override
+ public void updateScreen() {
+ checkAndUpdatePageIterators();
+ super.updateScreen();
+ updateCount++;
+ }
+
+ @Override
+ public void initGui() {
+ this.buttonList.clear();
+ this.updateButtons();
+ }
+
+ private void updateButtons() {
+ }
+
+ @Override
+ protected void actionPerformed(GuiButton p_146284_1_) {
+ }
+
+ @Override
+ public boolean doesGuiPauseGame() {
+ return false;
+ }
+
+ public int getXOffset() {
+ return (this.width - this.bookImageWidth) / 2;
+ }
+
+ public int getYOffset() {
+ return (this.height - this.bookImageHeight) / 2;
+ }
+
+ @Override
+ public void drawScreen(int p1, int p2, float p3) {
+ boolean unicode = fontRendererObj.getUnicodeFlag();
+ fontRendererObj.setUnicodeFlag(true);
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ this.mc.getTextureManager().bindTexture(bookGuiTextures);
+ int x = (this.width - this.bookImageWidth) / 2;
+ int y = (this.height - this.bookImageHeight) / 2;
+
+ this.drawTexturedModalRect(getXOffset(), getYOffset(), 0, 0, this.bookImageWidth, this.bookImageHeight);
+
+ /* Render the currently page */
+ renderThisPage();
+ fontRendererObj.setUnicodeFlag(unicode);
+ super.drawScreen(p1, p2, p3);
+ }
+
+ private void renderThisPage() {
+ /* Determine the type of the page we're on and call an appropriate renderer */
+ switch (page.kind) {
+ case UNKNOWN:
+ break;
+ case TEXT:
+ renderTextPage((JournalEntry.PageText) page);
+ break;
+ case RECIPE:
+ break;
+ case CATALYSEDRECIPE:
+ break;
+ }
+ }
+
+ private void performTextBodyRender(JournalEntry.PageText page) {
+ String raw = page.body;
+ /* Since we're rendering the text, we're on the page, so note at the top the day and time */
+ String heading = entry.localisedDate + " " + entry.timeOfDay;
+ raw = heading + "\n\n" + raw;
+ raw = raw.replace("\n\n", "@{blankLine}").replace("\n", " ");
+ /* Really cheap replacement scheme for now, @{} -> repl.
+ */
+ while (raw.contains("@{")) {
+ String pfx = raw.substring(0, raw.indexOf("@{"));
+ String sfx = raw.substring(raw.indexOf("}", pfx.length()) + 1);
+ String mid = raw.substring(pfx.length() + 2, raw.indexOf("}", pfx.length()));
+ if (mid.equals("blankLine")) { mid = "\n\n"; }
+ else if (mid.equals("playerName")) { mid = Minecraft.getMinecraft().thePlayer.getCommandSenderName(); }
+ raw = pfx + mid + sfx;
+ }
+ List<String> rawLines = fontRendererObj.listFormattedStringToWidth(raw, 116);
+ int maxLines = (this.bookImageHeight - 32) / fontRendererObj.FONT_HEIGHT;
+ page.renderedBody = new LinkedList<List<String>>();
+ List<String> curLines = new LinkedList<String>();
+ for (String line : rawLines) {
+ curLines.add(line);
+ if (curLines.size() == maxLines) {
+ page.renderedBody.add(curLines);
+ curLines = new LinkedList<String>();
+ }
+ }
+ if (curLines.size() > 0) {
+ page.renderedBody.add(curLines);
+ }
+ }
+
+ private void renderTextPage(JournalEntry.PageText page) {
+ if (page.renderedBody == null) { performTextBodyRender(page); }
+ List<String> txt = page.renderedBody.get(subPageIdx);
+ int y = getYOffset() + 16;
+ int x = getXOffset() + 36;
+ for (String line : txt) {
+ fontRendererObj.drawString(line, x, y, 0);
+ y = y + fontRendererObj.FONT_HEIGHT;
+ }
+ }
+
+}
diff --git a/src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java b/src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java
index a595def..cd941a3 100644
--- a/src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java
+++ b/src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java
@@ -57,7 +57,7 @@ public class KnowledgeBase extends WorldSavedData {
if (s != null) {
World w = s.getEntityWorld();
if (w != null) {
- return w.getTotalWorldTime();
+ return w.getWorldTime();
}
}
return 0;
diff --git a/src/main/java/net/flarn/noctis/network/KnowledgeBaseTransfer.java b/src/main/java/net/flarn/noctis/network/KnowledgeBaseTransfer.java
index 6efde68..03a86b8 100644
--- a/src/main/java/net/flarn/noctis/network/KnowledgeBaseTransfer.java
+++ b/src/main/java/net/flarn/noctis/network/KnowledgeBaseTransfer.java
@@ -6,7 +6,9 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
+import net.flarn.noctis.journal.JournalContentModel;
import net.flarn.noctis.knowledge.KnowledgeBase;
+import net.flarn.noctis.refs.Names;
import net.flarn.noctis.refs.Tags;
import net.flarn.noctis.utils.LogHelper;
import net.flarn.noctis.utils.PlayerHelper;
@@ -43,6 +45,10 @@ public class KnowledgeBaseTransfer implements IMessage {
LogHelper.warn("Processing incoming knowledgebase: " + message.kbTag.toString());
NBTTagCompound noctisData = PlayerHelper.getNBTData(FMLClientHandler.instance().getClient().thePlayer);
noctisData.setTag(Tags.Player.KNOWLEDGE_BASE, message.kbTag);
+ KnowledgeBase kb = new KnowledgeBase(Names.KNOWLEDGE_BASE_NAME);
+ kb.readFromNBT(message.kbTag);
+ JournalContentModel.currentContentModel = new JournalContentModel(kb);
+ JournalContentModel.currentContentModel.dumpJournalStructure();
return null;
}
}
diff --git a/src/main/java/net/flarn/noctis/refs/GuiIds.java b/src/main/java/net/flarn/noctis/refs/GuiIds.java
new file mode 100644
index 0000000..57bbb7b
--- /dev/null
+++ b/src/main/java/net/flarn/noctis/refs/GuiIds.java
@@ -0,0 +1,6 @@
+package net.flarn.noctis.refs;
+
+
+public class GuiIds {
+ public static final int JOURNAL = 0;
+}
diff --git a/src/main/java/net/flarn/noctis/refs/Strings.java b/src/main/java/net/flarn/noctis/refs/Strings.java
index adcdd37..51d1f74 100644
--- a/src/main/java/net/flarn/noctis/refs/Strings.java
+++ b/src/main/java/net/flarn/noctis/refs/Strings.java
@@ -6,4 +6,7 @@ public class Strings {
public static final String CATALYST_LIFELESS = DESC_PREFIX + "catalyst.lifeless";
public static final String CATALYST_THRUMS = DESC_PREFIX + "catalyst.thrums";
public static final String JOURNAL_DESC = DESC_PREFIX + "journal";
+ public static final String JOURNAL_PREFIX = "noctis:journal.";
+ public static final String JOURNAL_DAYFMT = JOURNAL_PREFIX + "dayfmt";
+ public static final String TIME_PREFIX = Refs.MOD_ID.toLowerCase() + ":time.";
}
diff --git a/src/main/java/net/flarn/noctis/utils/TimeHelper.java b/src/main/java/net/flarn/noctis/utils/TimeHelper.java
index ab08186..a97afb3 100644
--- a/src/main/java/net/flarn/noctis/utils/TimeHelper.java
+++ b/src/main/java/net/flarn/noctis/utils/TimeHelper.java
@@ -1,5 +1,46 @@
package net.flarn.noctis.utils;
+import net.flarn.noctis.refs.Numbers;
+import net.flarn.noctis.refs.Strings;
+import net.minecraft.util.StatCollector;
+
public class TimeHelper {
+ public enum ApproxTime {
+ MORNING,
+ NOON,
+ AFTERNOON,
+ EVENING,
+ NIGHT;
+
+ public static ApproxTime getFromTicks(long totalticks) {
+ long dayticks = totalticks % Numbers.TICKS_PER_DAY;
+ if (dayticks < 5750) { return MORNING; }
+ if (dayticks < 6250) { return NOON; }
+ if (dayticks < 11750) { return AFTERNOON; }
+ if (dayticks < 13000) { return EVENING; }
+ return NIGHT;
+ }
+ public String getLocalizedApproxTime() {
+ String tagname = "unknown";
+ switch (this) {
+ case MORNING:
+ tagname = "morning";
+ break;
+ case NOON:
+ tagname = "noon";
+ break;
+ case AFTERNOON:
+ tagname = "afternoon";
+ break;
+ case EVENING:
+ tagname = "evening";
+ break;
+ case NIGHT:
+ tagname = "night";
+ break;
+ }
+ return StatCollector.translateToLocal(Strings.TIME_PREFIX + tagname);
+ }
+ }
}
diff --git a/src/main/resources/assets/noctis/journal/en_GB.yaml b/src/main/resources/assets/noctis/journal/en_GB.yaml
index d975d58..94e4168 100644
--- a/src/main/resources/assets/noctis/journal/en_GB.yaml
+++ b/src/main/resources/assets/noctis/journal/en_GB.yaml
@@ -33,7 +33,7 @@ pagestack:
body: |
Finally, the dreams I have been haunted with since childhood have come to fruition, by carefully combining
a mundane book with some ink, a quill, and the items I long suspected would help me harness the power I
- feel around me at night, I have created this journal. A journal I suspect only I #{playerName} will be
+ feel around me at night, I have created this journal. A journal I suspect only I @{playerName} will be
able to understand. I intend to document in this tome everything I learn about the powers of the night,
of the moon and of the spaces between the stars.
diff --git a/src/main/resources/assets/noctis/lang/en_GB.lang b/src/main/resources/assets/noctis/lang/en_GB.lang
index 1498a73..db997df 100644
--- a/src/main/resources/assets/noctis/lang/en_GB.lang
+++ b/src/main/resources/assets/noctis/lang/en_GB.lang
@@ -13,3 +13,13 @@ item.noctis:mixedCatalyst.name=Catalyst attuned to all the night can provide
desc.noctis:journal=Everything I know about the power of the night is in here.
desc.noctis:catalyst.lifeless=This seems dull somehow
desc.noctis:catalyst.thrums=An aura of %s infuses this
+
+# Stuff for the journal
+
+noctis:journal.dayfmt=Day %d
+
+noctis:time.morning=Morning
+noctis:time.noon=Noon
+noctis:time.afternoon=Afternoon
+noctis:time.evening=Evening
+noctis:time.night=Night