Noting it up.

This commit is contained in:
Lizbeth Rika committed 2015-07-24 04:17:44 +01:00
1 parent 49b607bbfc
commit 847c78abfb
10 files changed
+236 -19

No files matched your search

@@ -15,6 +15,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Set;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
@@ -30,6 +31,7 @@ public final class PresistantVariableHelper {
private static final String TAG_BOOKMARK_PREFIX = "bookmark";
private static final String TAG_BOOKMARKS = "bookmarks";
private static final String TAG_CHALLENGES = "challenges";
private static final String TAG_LEXICON_NOTES = "lexiconNotes";
private static final String TAG_FIRST_LOAD = "firstLoad";
private static File cacheFile;
@@ -56,6 +58,14 @@ public final class PresistantVariableHelper {
c.writeToNBT(challengesCmp);
cmp.setTag(TAG_CHALLENGES, challengesCmp);
NBTTagCompound notesCmp = new NBTTagCompound();
for(String s : GuiLexicon.notes.keySet()) {
String note = GuiLexicon.notes.get(s);
if(note != null && !note.trim().isEmpty())
notesCmp.setString(s, note);
}
cmp.setTag(TAG_LEXICON_NOTES, notesCmp);
cmp.setBoolean(TAG_FIRST_LOAD, firstLoad);
injectNBTToFile(cmp, getCacheFile());
@@ -81,6 +91,14 @@ public final class PresistantVariableHelper {
for(Challenge c : ModChallenges.challengeLookup.values())
c.readFromNBT(challengesCmp);
}
if(cmp.hasKey(TAG_LEXICON_NOTES)) {
NBTTagCompound notesCmp = cmp.getCompoundTag(TAG_LEXICON_NOTES);
Set<String> keys = notesCmp.func_150296_c();
GuiLexicon.notes.clear();
for(String key : keys)
GuiLexicon.notes.put(key, notesCmp.getString(key));
}
firstLoad = cmp.hasKey(TAG_FIRST_LOAD) ? cmp.getBoolean(TAG_FIRST_LOAD) : firstLoad;
if(firstLoad)
@@ -14,6 +14,7 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Queue;
@@ -22,12 +23,15 @@ import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatAllowedCharacters;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;
import vazkii.botania.api.BotaniaAPI;
@@ -46,22 +50,27 @@ import vazkii.botania.client.gui.lexicon.button.GuiButtonChallengeInfo;
import vazkii.botania.client.gui.lexicon.button.GuiButtonChallenges;
import vazkii.botania.client.gui.lexicon.button.GuiButtonHistory;
import vazkii.botania.client.gui.lexicon.button.GuiButtonInvisible;
import vazkii.botania.client.gui.lexicon.button.GuiButtonNotes;
import vazkii.botania.client.gui.lexicon.button.GuiButtonOptions;
import vazkii.botania.client.lib.LibResources;
import vazkii.botania.common.core.handler.SheddingHandler;
import vazkii.botania.common.item.ItemLexicon;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lexicon.page.PageText;
public class GuiLexicon extends GuiScreen {
public static GuiLexicon currentOpenLexicon = new GuiLexicon();
public static ItemStack stackUsed;
public static HashMap<String, String> notes = new HashMap();
private static final String TAG_TYPE = "type";
private static final int[] KONAMI_CODE = { 200, 200, 208, 208, 203, 205, 203, 205, 48, 30 };
public static final int BOOKMARK_START = 1337;
public static final int NOTES_BUTTON_ID = 1336; // random button tho
public static final int MAX_BOOKMARK_COUNT = 8;
public static List<GuiLexicon> bookmarks = new ArrayList();
boolean bookmarksNeedPopulation = false;
@@ -81,6 +90,11 @@ public class GuiLexicon extends GuiScreen {
int tutorialArrowX, tutorialArrowY;
int konamiIndex;
private static final int NOTE_TWEEN_TIME = 5;
public static boolean notesEnabled;
static int notesMoveTime;
public String note = "";
List<LexiconCategory> allCategories;
String title;
@@ -97,6 +111,10 @@ public class GuiLexicon extends GuiScreen {
PresistantVariableHelper.saveSafe();
}
String key = getNotesKey();
if(notes.containsKey(key))
note = notes.get(key);
onInitGui();
putTutorialArrow();
@@ -137,10 +155,19 @@ public class GuiLexicon extends GuiScreen {
}
populateBookmarks();
if(isMainPage()) {
buttonList.add(new GuiButtonOptions(-1, left - 6, top + 5));
buttonList.add(new GuiButtonAchievement(-2, left - 6, top + 18));
buttonList.add(new GuiButtonChallenges(-3, left - 6, top + 32));
buttonList.add(new GuiButtonOptions(-1, left - 6, top + 13));
buttonList.add(new GuiButtonAchievement(-2, left - 6, top + 26));
buttonList.add(new GuiButtonChallenges(-3, left - 6, top + 40));
}
buttonList.add(new GuiButtonNotes(this, NOTES_BUTTON_ID, left - 4, top - 4));
}
@Override
public void updateScreen() {
if(notesEnabled && notesMoveTime < NOTE_TWEEN_TIME)
notesMoveTime++;
else if(!notesEnabled && notesMoveTime > 0)
notesMoveTime--;
}
@Override
@@ -150,6 +177,10 @@ public class GuiLexicon extends GuiScreen {
lastTime = time;
partialTicks = par3;
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(texture);
drawNotes(par3);
GL11.glColor4f(1F, 1F, 1F, 1F);
mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(left, top, 0, 0, guiWidth, guiHeight);
@@ -209,6 +240,36 @@ public class GuiLexicon extends GuiScreen {
GL11.glDisable(GL11.GL_BLEND);
}
}
public void drawNotes(float part) {
int size = 105;
float time = notesMoveTime;
if(notesMoveTime < NOTE_TWEEN_TIME && notesEnabled)
time += part;
else if(notesMoveTime > 0 && !notesEnabled)
time -= part;
int drawSize = (int) ((float) size * time / (float) NOTE_TWEEN_TIME);
int x = left - drawSize;
int y = top + 10;
drawTexturedModalRect(x, y, 146, 0, drawSize, 125);
String noteDisplay = note;
if(notesEnabled && ClientTickHandler.ticksInGame % 20 < 10)
noteDisplay += "&r_";
fontRendererObj.drawString(StatCollector.translateToLocal("botaniamisc.notes"), x + 5, y - 7, 0x666666);
boolean unicode = fontRendererObj.getUnicodeFlag();
fontRendererObj.setUnicodeFlag(true);
PageText.renderText(x + 5, y - 3, 92, 120, noteDisplay);
//fontRendererObj.drawSplitString(noteDisplay, x + 7, y + 7, 92, 0);
fontRendererObj.setUnicodeFlag(unicode);
}
public void drawBookmark(int x, int y, String s, boolean drawLeft) {
// This function is called from the buttons so I can't use fontRendererObj
@@ -273,6 +334,8 @@ public class GuiLexicon extends GuiScreen {
mc.displayGuiScreen(new GuiAchievementsHacky(this, mc.thePlayer.getStatFileWriter()));
else if(par1GuiButton.id == -3)
mc.displayGuiScreen(new GuiLexiconChallengesList());
else if(par1GuiButton.id == NOTES_BUTTON_ID)
notesEnabled = !notesEnabled;
}
public void handleBookmark(GuiButton par1GuiButton) {
@@ -443,7 +506,9 @@ public class GuiLexicon extends GuiScreen {
@Override
protected void keyTyped(char par1, int par2) {
if(closeScreenOnInvKey() && mc.gameSettings.keyBindInventory.getKeyCode() == par2) {
handleNoteKey(par1, par2);
if(!notesEnabled && closeScreenOnInvKey() && mc.gameSettings.keyBindInventory.getKeyCode() == par2) {
mc.displayGuiScreen(null);
mc.setIngameFocus();
}
@@ -458,6 +523,34 @@ public class GuiLexicon extends GuiScreen {
super.keyTyped(par1, par2);
}
public void handleNoteKey(char par1, int par2) {
if(notesEnabled) {
Keyboard.enableRepeatEvents(true);
boolean changed = false;
if(par2 == 14 && note.length() > 0) {
if(isCtrlKeyDown())
note = "";
else {
if(note.endsWith("<br>"))
note = note.substring(0, note.length() - 5);
else note = note.substring(0, note.length() - 1);
}
changed = true;
}
if((ChatAllowedCharacters.isAllowedCharacter(par1) || par2 == 28) && note.length() < 250) {
note += par2 == 28 ? "<br>" : par1;
changed = true;
}
if(changed) {
notes.put(getNotesKey(), note);
PresistantVariableHelper.saveSafe();
}
} else Keyboard.enableRepeatEvents(false);
}
public static GuiLexicon create(NBTTagCompound cmp) {
String type = cmp.getString(TAG_TYPE);
@@ -478,6 +571,10 @@ public class GuiLexicon extends GuiScreen {
cmp.setString(TAG_TYPE, getClass().getName());
}
public String getNotesKey() {
return "index";
}
public void load(NBTTagCompound cmp) {
// NO-OP
}
@@ -59,7 +59,6 @@ public class GuiLexiconChallenge extends GuiLexicon implements IParented {
setCompleteButtonTitle();
}
@Override
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
@@ -85,7 +84,7 @@ public class GuiLexiconChallenge extends GuiLexicon implements IParented {
@Override
protected void keyTyped(char par1, int par2) {
if(par2 == 14) // Backspace
if(par2 == 14 && !notesEnabled) // Backspace
back();
else if(par2 == 199) { // Home
mc.displayGuiScreen(new GuiLexicon());
@@ -114,7 +113,8 @@ public class GuiLexiconChallenge extends GuiLexicon implements IParented {
challenge.complete = !challenge.complete;
setCompleteButtonTitle();
PresistantVariableHelper.saveSafe();
}
} else if(par1GuiButton.id == NOTES_BUTTON_ID)
notesEnabled = !notesEnabled;
}
void setCompleteButtonTitle() {
@@ -172,5 +172,10 @@ public class GuiLexiconChallenge extends GuiLexicon implements IParented {
challenge = c;
setTitle();
}
@Override
public String getNotesKey() {
return "challenge_" + challenge.unlocalizedName;
}
}
@@ -73,7 +73,7 @@ public class GuiLexiconChallengesList extends GuiLexicon implements IParented {
@Override
protected void keyTyped(char par1, int par2) {
if(par2 == 14) // Backspace
if(par2 == 14 && !notesEnabled) // Backspace
back();
else if(par2 == 199) { // Home
mc.displayGuiScreen(new GuiLexicon());
@@ -101,7 +101,8 @@ public class GuiLexiconChallengesList extends GuiLexicon implements IParented {
} else if(par1GuiButton instanceof GuiButtonChallengeIcon) {
GuiButtonChallengeIcon cbutton = (GuiButtonChallengeIcon) par1GuiButton;
mc.displayGuiScreen(new GuiLexiconChallenge(this, cbutton.challenge));
}
} else if(par1GuiButton.id == NOTES_BUTTON_ID)
notesEnabled = !notesEnabled;
}
void back() {
@@ -140,5 +141,10 @@ public class GuiLexiconChallengesList extends GuiLexicon implements IParented {
public GuiLexicon copy() {
return new GuiLexiconChallengesList();
}
@Override
public String getNotesKey() {
return "challengelist";
}
}
@@ -81,7 +81,7 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
buttonList.add(rightButton = new GuiButtonPage(2, left + guiWidth - 18, top + guiHeight - 10, true));
buttonList.add(new GuiButtonShare(3, left + guiWidth - 6, top - 2));
if(entry.getWebLink() != null)
buttonList.add(new GuiButtonViewOnline(4, left - 8, top + 8));
buttonList.add(new GuiButtonViewOnline(4, left - 8, top + 12));
if(!GuiLexicon.isValidLexiconGui(this)) {
currentOpenLexicon = new GuiLexicon();
@@ -134,6 +134,8 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
if(par1GuiButton.id >= BOOKMARK_START)
handleBookmark(par1GuiButton);
else if(par1GuiButton.id == NOTES_BUTTON_ID)
notesEnabled = !notesEnabled;
else
switch(par1GuiButton.id) {
case 0 :
@@ -192,10 +194,11 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
@Override
public void updateScreen() {
super.updateScreen();
LexiconPage page = entry.pages.get(this.page);
page.updateScreen(this);
if(this.page == entry.pages.size() - 1) {
LexiconEntry entry = tutorial.peek();
if(entry == this.entry) {
@@ -302,6 +305,8 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
@Override
protected void keyTyped(char par1, int par2) {
handleNoteKey(par1, par2);
LexiconPage page = entry.pages.get(this.page);
page.onKeyPressed(par1, par2);
@@ -309,14 +314,12 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
prevPage();
else if(par2 == 205 || par2 == 208 || par2 == 209) // Right, Down Page Down
nextPage();
else if(par2 == 14) // Backspace
if(par2 == 14 && !notesEnabled) // Backspace
back();
else if(par2 == 199) { // Home
mc.displayGuiScreen(new GuiLexicon());
ClientTickHandler.notifyPageChange();
}
super.keyTyped(par1, par2);
}
void back() {
@@ -330,6 +333,7 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
if(rightButton.enabled) {
actionPerformed(rightButton);
rightButton.func_146113_a(mc.getSoundHandler());
updateNote();
}
}
@@ -337,8 +341,16 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
if(leftButton.enabled) {
actionPerformed(leftButton);
leftButton.func_146113_a(mc.getSoundHandler());
updateNote();
}
}
void updateNote() {
String key = getNotesKey();
if(!notes.containsKey(key))
note = "";
else note = notes.get(key);
}
@Override
public List<GuiButton> getButtonList() {
@@ -390,4 +402,9 @@ public class GuiLexiconEntry extends GuiLexicon implements IGuiLexiconEntry, IPa
gui.setTitle();
return gui;
}
@Override
public String getNotesKey() {
return "entry_" + entry.unlocalizedName + "_" + page;
}
}
@@ -53,5 +53,10 @@ public class GuiLexiconHistory extends GuiLexiconIndex {
public void load(NBTTagCompound cmp) {
// NO-OP
}
@Override
public String getNotesKey() {
return "history";
}
}
@@ -188,6 +188,8 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented {
protected void actionPerformed(GuiButton par1GuiButton) {
if(par1GuiButton.id >= BOOKMARK_START)
handleBookmark(par1GuiButton);
else if(par1GuiButton.id == NOTES_BUTTON_ID)
notesEnabled = !notesEnabled;
else
switch(par1GuiButton.id) {
case 12 :
@@ -293,7 +295,7 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented {
prevPage();
else if(par2 == 205 || par2 == 208 || par2 == 209) // Right, Down Page Down
nextPage();
else if(par2 == 14 && searchField.getText().isEmpty()) // Backspace
else if(par2 == 14 && !notesEnabled && searchField.getText().isEmpty()) // Backspace
back();
else if(par2 == 199) { // Home
mc.displayGuiScreen(new GuiLexicon());
@@ -301,10 +303,12 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented {
} else if(par2 == 28 && entriesToDisplay.size() == 1) // Enter
openEntry(0);
String search = searchField.getText();
searchField.textboxKeyTyped(par1, par2);
if(!searchField.getText().equalsIgnoreCase(search))
updateAll();
if(!notesEnabled) {
String search = searchField.getText();
searchField.textboxKeyTyped(par1, par2);
if(!searchField.getText().equalsIgnoreCase(search))
updateAll();
}
super.keyTyped(par1, par2);
}
@@ -359,4 +363,9 @@ public class GuiLexiconIndex extends GuiLexicon implements IParented {
gui.setTitle();
return gui;
}
@Override
public String getNotesKey() {
return "category_" + category.unlocalizedName;
}
}
@@ -0,0 +1,57 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Jul 24, 2015, 2:49:36 AM (GMT)]
*/
package vazkii.botania.client.gui.lexicon.button;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.client.gui.lexicon.GuiLexicon;
public class GuiButtonNotes extends GuiButtonLexicon {
GuiLexicon parent;
public GuiButtonNotes(GuiLexicon parent, int id, int x, int y) {
super(id, x, y, 11, 11, "");
this.parent = parent;
}
@Override
public void drawButton(Minecraft par1Minecraft, int par2, int par3) {
field_146123_n = par2 >= xPosition && par3 >= yPosition && par2 < xPosition + width && par3 < yPosition + height;
int k = getHoverState(field_146123_n);
par1Minecraft.renderEngine.bindTexture(GuiLexicon.texture);
GL11.glColor4f(1F, 1F, 1F, 1F);
drawTexturedModalRect(xPosition, yPosition, k == 2 ? 130 : 120, 191, 10, 11);
List<String> tooltip = new ArrayList();
if(GuiLexicon.notesEnabled)
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("botaniamisc.hideNotes"));
else {
tooltip.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("botaniamisc.showNotes"));
if(parent.note != null && !parent.note.isEmpty())
Minecraft.getMinecraft().fontRenderer.drawStringWithShadow("!", xPosition + 10, yPosition, 0xFF0000);
}
int tooltipY = (tooltip.size() - 1) * 10;
if(k == 2)
RenderHelper.renderTooltip(par2, par3 + tooltipY, tooltip);
}
}