summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-25 23:25:35 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-10-25 23:25:35 +0100
commit3f7c0082894caed759d3234e98ca1b9866107171 (patch)
tree2ee8d0f70f0c8e9277f43aff20a24d3a6105be35
parenta46b7459b22c6c442e06c4147b6f445f45f8b744 (diff)
downloadnoctis-3f7c0082894caed759d3234e98ca1b9866107171.tar.bz2
More of the Journal supported
-rw-r--r--src/main/java/net/flarn/noctis/journal/JournalContentModel.java2
-rw-r--r--src/main/java/net/flarn/noctis/journal/JournalDayEntry.java5
-rw-r--r--src/main/java/net/flarn/noctis/journal/gui/JournalGui.java131
-rw-r--r--src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java29
-rw-r--r--src/main/java/net/flarn/noctis/refs/Tags.java2
5 files changed, 160 insertions, 9 deletions
diff --git a/src/main/java/net/flarn/noctis/journal/JournalContentModel.java b/src/main/java/net/flarn/noctis/journal/JournalContentModel.java
index 30cc362..79a082e 100644
--- a/src/main/java/net/flarn/noctis/journal/JournalContentModel.java
+++ b/src/main/java/net/flarn/noctis/journal/JournalContentModel.java
@@ -27,7 +27,7 @@ public class JournalContentModel {
currentDay = new LinkedList<JournalDayEntry>();
currentDayNum = thisday;
}
- JournalDayEntry thisDayEntry = new JournalDayEntry(event.time);
+ JournalDayEntry thisDayEntry = new JournalDayEntry(event.time, event.vis);
KnowledgeItem ki = KnowledgeItem.findKnowledgeItem(event.name);
JournalEntry ji = JournalEntry.journalEntryMap.get(ki);
if (event.vis == KnowledgeVisibility.THEORY) {
diff --git a/src/main/java/net/flarn/noctis/journal/JournalDayEntry.java b/src/main/java/net/flarn/noctis/journal/JournalDayEntry.java
index 3e9bfbd..5523a1f 100644
--- a/src/main/java/net/flarn/noctis/journal/JournalDayEntry.java
+++ b/src/main/java/net/flarn/noctis/journal/JournalDayEntry.java
@@ -1,5 +1,6 @@
package net.flarn.noctis.journal;
+import net.flarn.noctis.knowledge.KnowledgeVisibility;
import net.flarn.noctis.refs.Numbers;
import net.flarn.noctis.refs.Strings;
import net.flarn.noctis.utils.TimeHelper;
@@ -12,13 +13,15 @@ public class JournalDayEntry {
public final long basetime;
public final String localisedDate;
public final String timeOfDay;
+ public final KnowledgeVisibility vis;
public List<JournalEntry.Page> pages;
- public JournalDayEntry(long time) {
+ public JournalDayEntry(long time, KnowledgeVisibility _vis) {
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();
+ vis = _vis;
pages = new LinkedList<JournalEntry.Page>();
}
}
diff --git a/src/main/java/net/flarn/noctis/journal/gui/JournalGui.java b/src/main/java/net/flarn/noctis/journal/gui/JournalGui.java
index b4d1325..9ea0f18 100644
--- a/src/main/java/net/flarn/noctis/journal/gui/JournalGui.java
+++ b/src/main/java/net/flarn/noctis/journal/gui/JournalGui.java
@@ -4,10 +4,12 @@ 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.knowledge.KnowledgeVisibility;
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.client.gui.GuiScreenBook;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
@@ -32,6 +34,8 @@ public class JournalGui extends GuiScreen {
private int pageIdx;
private JournalEntry.Page page;
private int subPageIdx;
+ private NavigationButton buttonNext;
+ private NavigationButton buttonPrev;
public JournalGui() {
contentModel = JournalContentModel.currentContentModel;
@@ -68,14 +72,84 @@ public class JournalGui extends GuiScreen {
@Override
public void initGui() {
this.buttonList.clear();
+ this.buttonList.add(buttonNext = new NavigationButton(0, getXOffset() + 120, getYOffset() + bookImageHeight - 24, NavigationButton.ButtonType.NEXT));
+ this.buttonList.add(buttonPrev = new NavigationButton(1, getXOffset() + 38, getYOffset() + bookImageHeight - 24, NavigationButton.ButtonType.PREV));
this.updateButtons();
}
private void updateButtons() {
+ buttonPrev.visible = (dayIdx != 0) || (entryIdx != 0) || (pageIdx != 0) || (subPageIdx != 0);
+ buttonNext.visible = (dayIdx < (contentModel.journalPageGroups.size() - 1)) ||
+ (entryIdx < (day.size() - 1)) ||
+ (pageIdx < (entry.pages.size() - 1)) ||
+ (subPageIdx < (countSubPages(page) - 1));
+ }
+
+ private int countSubPages(JournalEntry.Page page) {
+ if (page.kind != JournalEntry.PageKind.TEXT) { return 1; }
+ JournalEntry.PageText pageText = (JournalEntry.PageText) page;
+ if (pageText.renderedBody == null) { performTextBodyRender(pageText); }
+ return pageText.renderedBody.size();
+ }
+
+ private void nextPage() {
+ // Attempt to advance to the next page
+ if (subPageIdx < (countSubPages(page) - 1)) {
+ subPageIdx++;
+ } else if (pageIdx < (entry.pages.size() - 1)) {
+ subPageIdx = 0;
+ pageIdx++;
+ page = entry.pages.get(pageIdx);
+ } else if (entryIdx < (day.size() - 1)) {
+ subPageIdx = 0;
+ pageIdx = 0;
+ entryIdx++;
+ entry = day.get(entryIdx);
+ page = entry.pages.get(pageIdx);
+ } else {
+ subPageIdx = 0;
+ pageIdx = 0;
+ entryIdx = 0;
+ dayIdx++;
+ day = contentModel.journalPageGroups.get(dayIdx);
+ entry = day.get(entryIdx);
+ page = entry.pages.get(pageIdx);
+ }
+ }
+
+ private void prevPage() {
+ // Attempt to go back to the previous page
+ if (subPageIdx > 0) {
+ subPageIdx--;
+ } else if (pageIdx > 0) {
+ pageIdx--;
+ page = entry.pages.get(pageIdx);
+ subPageIdx = countSubPages(page) - 1;
+ } else if (entryIdx > 0) {
+ entryIdx--;
+ entry = day.get(entryIdx);
+ pageIdx = entry.pages.size() - 1;
+ page = entry.pages.get(pageIdx);
+ subPageIdx = countSubPages(page) - 1;
+ } else {
+ dayIdx--;
+ day = contentModel.journalPageGroups.get(dayIdx);
+ entryIdx = day.size() - 1;
+ entry = day.get(entryIdx);
+ pageIdx = entry.pages.size() - 1;
+ page = entry.pages.get(pageIdx);
+ subPageIdx = countSubPages(page) - 1;
+ }
}
@Override
- protected void actionPerformed(GuiButton p_146284_1_) {
+ protected void actionPerformed(GuiButton button) {
+ if (button == buttonNext) {
+ nextPage();
+ } else if (button == buttonPrev) {
+ prevPage();
+ }
+ updateButtons();
}
@Override
@@ -108,6 +182,13 @@ public class JournalGui extends GuiScreen {
super.drawScreen(p1, p2, p3);
}
+ private void renderRecipePage(JournalEntry.PageRecipe page) {
+ String msg = "This would be a recipe render\n";
+ msg = msg + "Visibility level is: " + entry.vis + "\n";
+ msg = msg + "Recipe for: " + page.recipe.getRecipeOutput().getDisplayName();
+ fontRendererObj.drawSplitString(msg, getXOffset() + 36, getYOffset() + 16, 116, 0);
+ }
+
private void renderThisPage() {
/* Determine the type of the page we're on and call an appropriate renderer */
switch (page.kind) {
@@ -117,12 +198,23 @@ public class JournalGui extends GuiScreen {
renderTextPage((JournalEntry.PageText) page);
break;
case RECIPE:
+ renderRecipePage((JournalEntry.PageRecipe) page);
break;
case CATALYSEDRECIPE:
+ renderCatalysedRecipePage((JournalEntry.PageCatalysedRecipe) page);
break;
}
}
+ private void renderCatalysedRecipePage(JournalEntry.PageCatalysedRecipe page) {
+ String msg = "This would be a catalysed recipe render\n";
+ msg = msg + "Visibility level is: " + entry.vis + "\n";
+ msg = msg + "Catalyst required: " + page.recipe.catalyst + "\n";
+ msg = msg + "Recipe for: " + page.recipe.output.getDisplayName();
+ fontRendererObj.drawSplitString(msg, getXOffset() + 36, getYOffset() + 16, 116, 0);
+
+ }
+
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 */
@@ -166,4 +258,41 @@ public class JournalGui extends GuiScreen {
}
}
+ private static class NavigationButton extends GuiButton {
+ public enum ButtonType {
+ PREV, BACK, TOP, NEXT;
+ }
+ private ButtonType buttonType;
+ public NavigationButton(int id, int x, int y, ButtonType bt) {
+ super(id, x, y, 23, 13, "");
+ buttonType = bt;
+ }
+
+ @Override
+ public void drawButton(Minecraft mc, int p_146112_2_, int p_146112_3_)
+ {
+ if (this.visible)
+ {
+ boolean flag = p_146112_2_ >= this.xPosition && p_146112_3_ >= this.yPosition && p_146112_2_ < this.xPosition + this.width && p_146112_3_ < this.yPosition + this.height;
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ mc.getTextureManager().bindTexture(JournalGui.bookGuiTextures);
+ int k = 0;
+ int l = 192;
+
+ if (flag)
+ {
+ k += 23;
+ }
+
+ if (buttonType == ButtonType.PREV)
+ {
+ l += 13;
+ }
+
+ this.drawTexturedModalRect(this.xPosition, this.yPosition, k, l, 23, 13);
+ }
+ }
+
+ }
+
}
diff --git a/src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java b/src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java
index cd941a3..b896943 100644
--- a/src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java
+++ b/src/main/java/net/flarn/noctis/knowledge/KnowledgeBase.java
@@ -19,15 +19,20 @@ public class KnowledgeBase extends WorldSavedData {
public final String name;
public final KnowledgeVisibility vis;
public final long time;
- public KnowledgeEvent(String _name, KnowledgeVisibility _vis, long _time) {
+ private final long seq;
+ public KnowledgeEvent(String _name, KnowledgeVisibility _vis, long _time, long _seq) {
name = _name;
vis = _vis;
time = _time;
+ seq = _seq;
}
@Override
public int compareTo(KnowledgeEvent knowledgeEvent) {
- int ret = Long.compare(time, knowledgeEvent.time);
+ int ret = Long.compare(seq, knowledgeEvent.seq);
+ if (ret == 0) {
+ ret = Long.compare(time, knowledgeEvent.time);
+ }
if (ret == 0) {
ret = Long.compare(name.length(), knowledgeEvent.name.length());
}
@@ -37,6 +42,8 @@ public class KnowledgeBase extends WorldSavedData {
private Map<String, KnowledgeVisibility> visiblityMap;
private Map<String, Long> theoryMap;
private Map<String, Long> knownMap;
+ private Map<String, Long> theorySequenceMap;
+ private Map<String, Long> knownSequenceMap;
private List<KnowledgeEvent> eventSequence;
public KnowledgeBase(String tagName) {
@@ -68,11 +75,13 @@ public class KnowledgeBase extends WorldSavedData {
visiblityMap.put(name, visOnGet);
if (visOnGet == KnowledgeVisibility.THEORY) {
theoryMap.put(name, getTime());
- eventSequence.add(new KnowledgeEvent(name, visOnGet, getTime()));
+ theorySequenceMap.put(name, (long)eventSequence.size());
+ eventSequence.add(new KnowledgeEvent(name, visOnGet, getTime(), eventSequence.size()));
}
if (visOnGet == KnowledgeVisibility.KNOWN) {
knownMap.put(name, getTime());
- eventSequence.add(new KnowledgeEvent(name, visOnGet, getTime()));
+ knownSequenceMap.put(name, (long)eventSequence.size());
+ eventSequence.add(new KnowledgeEvent(name, visOnGet, getTime(), eventSequence.size()));
}
markDirty();
return true;
@@ -84,9 +93,11 @@ public class KnowledgeBase extends WorldSavedData {
comp.setInteger(Tags.KnowledgeBase.VISIBILITY, visiblityMap.get(key).toInteger());
if (theoryMap.containsKey(key)) {
comp.setLong(Tags.KnowledgeBase.THEORYTIME, theoryMap.get(key));
+ comp.setLong(Tags.KnowledgeBase.THEORYIDX, theorySequenceMap.get(key));
}
if (knownMap.containsKey(key)) {
comp.setLong(Tags.KnowledgeBase.KNOWNTIME, knownMap.get(key));
+ comp.setLong(Tags.KnowledgeBase.KNOWNIDX, knownSequenceMap.get(key));
}
tagCompound.setTag(key, comp);
}
@@ -102,12 +113,16 @@ public class KnowledgeBase extends WorldSavedData {
if (comp.hasKey(Tags.KnowledgeBase.THEORYTIME)) {
long time = comp.getLong(Tags.KnowledgeBase.THEORYTIME);
theoryMap.put(key, time);
- eventSequence.add(new KnowledgeEvent(key, KnowledgeVisibility.THEORY, time));
+ long seq = comp.hasKey(Tags.KnowledgeBase.THEORYIDX) ? comp.getLong(Tags.KnowledgeBase.THEORYIDX) : 0;
+ eventSequence.add(new KnowledgeEvent(key, KnowledgeVisibility.THEORY, time, seq));
+ theorySequenceMap.put(key, seq);
}
if (comp.hasKey(Tags.KnowledgeBase.KNOWNTIME)) {
long time = comp.getLong(Tags.KnowledgeBase.KNOWNTIME);
knownMap.put(key, time);
- eventSequence.add(new KnowledgeEvent(key, KnowledgeVisibility.KNOWN, time));
+ long seq = comp.hasKey(Tags.KnowledgeBase.KNOWNIDX) ? comp.getLong(Tags.KnowledgeBase.KNOWNIDX) : 0;
+ eventSequence.add(new KnowledgeEvent(key, KnowledgeVisibility.KNOWN, time, seq));
+ knownSequenceMap.put(key, seq);
}
}
}
@@ -119,6 +134,8 @@ public class KnowledgeBase extends WorldSavedData {
theoryMap = new HashMap<String, Long>();
knownMap = new HashMap<String, Long>();
eventSequence = new LinkedList<KnowledgeEvent>();
+ theorySequenceMap = new HashMap<String, Long>();
+ knownSequenceMap = new HashMap<String, Long>();
}
public List<KnowledgeEvent> getEventSequence() { return eventSequence; }
diff --git a/src/main/java/net/flarn/noctis/refs/Tags.java b/src/main/java/net/flarn/noctis/refs/Tags.java
index b5433c8..e309933 100644
--- a/src/main/java/net/flarn/noctis/refs/Tags.java
+++ b/src/main/java/net/flarn/noctis/refs/Tags.java
@@ -14,5 +14,7 @@ public class Tags {
public static final String VISIBILITY = "visibility";
public static final String THEORYTIME = "theorytime";
public static final String KNOWNTIME = "knowntime";
+ public static final String THEORYIDX = "theoryidx";
+ public static final String KNOWNIDX = "knownidx";
}
}