Finish off the Challenge System, now all its missing is a description and less lorem ispum...

This commit is contained in:
Lizbeth Rika committed 2015-06-29 18:23:58 +01:00
1 parent fab425f9be
commit 68cdcaa05b
7 files changed
+311 -35

No files matched your search

@@ -11,12 +11,14 @@
package vazkii.botania.client.challenge;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class Challenge {
public final String unlocalizedName;
public final ItemStack icon;
public final EnumChallengeLevel level;
public boolean complete = false;
public Challenge(String unlocalizedName, ItemStack icon, EnumChallengeLevel level) {
this.unlocalizedName = unlocalizedName;
@@ -24,4 +26,12 @@ public class Challenge {
this.level = level;
}
public void writeToNBT(NBTTagCompound cmp) {
cmp.setBoolean(unlocalizedName, complete);
}
public void readFromNBT(NBTTagCompound cmp) {
complete = cmp.getBoolean(unlocalizedName);
}
}
@@ -12,47 +12,54 @@ package vazkii.botania.client.challenge;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import vazkii.botania.common.item.ModItems;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import vazkii.botania.common.block.ModBlocks;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.item.block.ItemBlockSpecialFlower;
import vazkii.botania.common.lib.LibBlockNames;
public final class ModChallenges {
public static final EnumMap<EnumChallengeLevel, List<Challenge>> challenges = new EnumMap(EnumChallengeLevel.class);
public static final HashMap<String, Challenge> challengeLookup = new HashMap();
public static void init() {
for(EnumChallengeLevel level : EnumChallengeLevel.class.getEnumConstants())
challenges.put(level, new ArrayList());
ItemStack icon = new ItemStack(ModItems.lexicon); // TODO
addChallenge(EnumChallengeLevel.EASY, "flowerFarm", icon);
addChallenge(EnumChallengeLevel.EASY, "recordFarm", icon);
addChallenge(EnumChallengeLevel.EASY, "reedFarm", icon);
addChallenge(EnumChallengeLevel.EASY, "cobbleGen", icon);
addChallenge(EnumChallengeLevel.EASY, "pureDaisy", icon);
addChallenge(EnumChallengeLevel.EASY, "orechid", icon);
addChallenge(EnumChallengeLevel.EASY, "battery", icon);
addChallenge(EnumChallengeLevel.EASY, "flowerFarm", new ItemStack(ModBlocks.flower, 1, 6));
addChallenge(EnumChallengeLevel.EASY, "recordFarm", new ItemStack(Items.record_13));
addChallenge(EnumChallengeLevel.EASY, "reedFarm", new ItemStack(Items.reeds));
addChallenge(EnumChallengeLevel.EASY, "cobbleGen", new ItemStack(Blocks.cobblestone));
addChallenge(EnumChallengeLevel.EASY, "pureDaisy", ItemBlockSpecialFlower.ofType(LibBlockNames.SUBTILE_PUREDAISY));
addChallenge(EnumChallengeLevel.EASY, "battery", new ItemStack(ModBlocks.pool));
addChallenge(EnumChallengeLevel.NORMAL, "apothecaryRefill", icon);
addChallenge(EnumChallengeLevel.NORMAL, "treeFarm", icon);
addChallenge(EnumChallengeLevel.NORMAL, "fullCropFarm", icon);
addChallenge(EnumChallengeLevel.NORMAL, "animalFarm", icon);
addChallenge(EnumChallengeLevel.NORMAL, "boneMealFarm", icon);
addChallenge(EnumChallengeLevel.HARD, "mobTower", icon);
addChallenge(EnumChallengeLevel.HARD, "entropynniumSetup", icon);
addChallenge(EnumChallengeLevel.HARD, "spectrolusSetup", icon);
addChallenge(EnumChallengeLevel.HARD, "potionBrewer", icon);
addChallenge(EnumChallengeLevel.NORMAL, "apothecaryRefill", new ItemStack(ModBlocks.altar));
addChallenge(EnumChallengeLevel.NORMAL, "treeFarm", new ItemStack(Blocks.sapling));
addChallenge(EnumChallengeLevel.NORMAL, "fullCropFarm", new ItemStack(Items.wheat_seeds));
addChallenge(EnumChallengeLevel.NORMAL, "animalFarm", new ItemStack(Items.leather));
addChallenge(EnumChallengeLevel.NORMAL, "boneMealFarm", new ItemStack(Items.dye, 1, 15));
addChallenge(EnumChallengeLevel.NORMAL, "orechid", ItemBlockSpecialFlower.ofType(LibBlockNames.SUBTILE_ORECHID));
addChallenge(EnumChallengeLevel.LUNATIC, "autoQuarry", icon);
addChallenge(EnumChallengeLevel.LUNATIC, "runeCrafter", icon);
addChallenge(EnumChallengeLevel.LUNATIC, "kekimurusSetup", icon);
addChallenge(EnumChallengeLevel.HARD, "mobTower", new ItemStack(Items.bone));
addChallenge(EnumChallengeLevel.HARD, "entropinnyumSetup", ItemBlockSpecialFlower.ofType(LibBlockNames.SUBTILE_ENTROPINNYUM));
addChallenge(EnumChallengeLevel.HARD, "spectrolusSetup", ItemBlockSpecialFlower.ofType(LibBlockNames.SUBTILE_SPECTROLUS));
addChallenge(EnumChallengeLevel.HARD, "potionBrewer", new ItemStack(ModBlocks.brewery));
addChallenge(EnumChallengeLevel.LUNATIC, "autoQuarry", new ItemStack(Items.diamond_pickaxe));
addChallenge(EnumChallengeLevel.LUNATIC, "runeCrafter", new ItemStack(ModItems.rune));
addChallenge(EnumChallengeLevel.LUNATIC, "kekimurusSetup", ItemBlockSpecialFlower.ofType(LibBlockNames.SUBTILE_KEKIMURUS));
}
public static void addChallenge(EnumChallengeLevel level, String name, ItemStack icon) {
Challenge c = new Challenge("botania.challenge." + name, icon, level);
challenges.get(level).add(c);
challengeLookup.put(c.unlocalizedName, c);
}
}
@@ -18,6 +18,8 @@ import java.util.List;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import vazkii.botania.client.challenge.Challenge;
import vazkii.botania.client.challenge.ModChallenges;
import vazkii.botania.client.gui.lexicon.GuiLexicon;
import vazkii.botania.client.gui.lexicon.GuiLexiconEntry;
import vazkii.botania.common.lexicon.LexiconData;
@@ -27,6 +29,7 @@ public final class PresistantVariableHelper {
private static final String TAG_BOOKMARK_COUNT = "bookmarkCount";
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_FIRST_LOAD = "firstLoad";
private static File cacheFile;
@@ -47,6 +50,12 @@ public final class PresistantVariableHelper {
bookmarksCmp.setTag(TAG_BOOKMARK_PREFIX + i, bookmarkCmp);
}
cmp.setTag(TAG_BOOKMARKS, bookmarksCmp);
NBTTagCompound challengesCmp = new NBTTagCompound();
for(Challenge c : ModChallenges.challengeLookup.values())
c.writeToNBT(challengesCmp);
cmp.setTag(TAG_CHALLENGES, challengesCmp);
cmp.setBoolean(TAG_FIRST_LOAD, firstLoad);
injectNBTToFile(cmp, getCacheFile());
@@ -67,6 +76,12 @@ public final class PresistantVariableHelper {
}
}
if(cmp.hasKey(TAG_CHALLENGES)) {
NBTTagCompound challengesCmp = cmp.getCompoundTag(TAG_CHALLENGES);
for(Challenge c : ModChallenges.challengeLookup.values())
c.readFromNBT(challengesCmp);
}
firstLoad = cmp.hasKey(TAG_FIRST_LOAD) ? cmp.getBoolean(TAG_FIRST_LOAD) : firstLoad;
if(firstLoad)
GuiLexicon.currentOpenLexicon = new GuiLexiconEntry(LexiconData.welcome, new GuiLexicon());
@@ -0,0 +1,176 @@
/**
* 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 @ [Jun 29, 2015, 5:25:06 PM (GMT)]
*/
package vazkii.botania.client.gui.lexicon;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import vazkii.botania.client.challenge.Challenge;
import vazkii.botania.client.challenge.ModChallenges;
import vazkii.botania.client.core.handler.ClientTickHandler;
import vazkii.botania.client.core.handler.PresistantVariableHelper;
import vazkii.botania.client.gui.lexicon.button.GuiButtonBack;
import vazkii.botania.common.lexicon.page.PageText;
public class GuiLexiconChallenge extends GuiLexicon implements IParented {
private static final String TAG_CHALLENGE = "challenge";
Challenge challenge;
GuiLexicon parent;
GuiButton backButton, completeButton;
public GuiLexiconChallenge() {
parent = new GuiLexiconChallengesList();
}
public GuiLexiconChallenge(GuiLexicon parent, Challenge challenge) {
this.parent = parent;
this.challenge = challenge;
setTitle();
}
public void setTitle() {
title = challenge == null ? "(null)" : StatCollector.translateToLocal(challenge.unlocalizedName);
}
@Override
public void onInitGui() {
super.onInitGui();
setTitle();
buttonList.add(backButton = new GuiButtonBack(12, left + guiWidth / 2 - 8, top + guiHeight + 2));
buttonList.add(completeButton = new GuiButton(13, left + 20, top + guiHeight - 35, guiWidth - 40, 20, ""));
setCompleteButtonTitle();
}
@Override
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
RenderHelper.enableGUIStandardItemLighting();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
RenderItem.getInstance().renderItemIntoGUI(fontRendererObj, mc.renderEngine, challenge.icon, left + 18, top + 15);
RenderHelper.disableStandardItemLighting();
GL11.glEnable(GL11.GL_BLEND);
boolean unicode = fontRendererObj.getUnicodeFlag();
fontRendererObj.setUnicodeFlag(true);
fontRendererObj.drawString(EnumChatFormatting.BOLD + StatCollector.translateToLocal(challenge.unlocalizedName), left + 38, top + 13, 0);
fontRendererObj.drawString(StatCollector.translateToLocal(challenge.level.getName()) + " / " + (challenge.complete ? EnumChatFormatting.DARK_GREEN : EnumChatFormatting.DARK_RED) + StatCollector.translateToLocal(challenge.complete ? "botaniamisc.completed" : "botaniamisc.notCompleted"), left + 38, top + 23, 0);
int width = guiWidth - 30;
int x = left + 16;
int y = top + 28;
PageText.renderText(x, y, width, guiHeight, challenge.unlocalizedName + ".desc");
fontRendererObj.setUnicodeFlag(unicode);
}
@Override
protected void keyTyped(char par1, int par2) {
if(par2 == 14) // Backspace
back();
else if(par2 == 199) { // Home
mc.displayGuiScreen(new GuiLexicon());
ClientTickHandler.notifyPageChange();
}
super.keyTyped(par1, par2);
}
@Override
protected void mouseClicked(int par1, int par2, int par3) {
super.mouseClicked(par1, par2, par3);
if(par3 == 1)
back();
}
@Override
protected void actionPerformed(GuiButton par1GuiButton) {
if(par1GuiButton.id >= BOOKMARK_START)
handleBookmark(par1GuiButton);
else if(par1GuiButton.id == 12) {
mc.displayGuiScreen(parent);
ClientTickHandler.notifyPageChange();
} else if(par1GuiButton.id == 13) {
challenge.complete = !challenge.complete;
setCompleteButtonTitle();
PresistantVariableHelper.saveSafe();
}
}
void setCompleteButtonTitle() {
completeButton.displayString = StatCollector.translateToLocal(challenge.complete ? "botaniamisc.markNotCompleted" : "botaniamisc.markCompleted");
}
void back() {
if(backButton.enabled) {
actionPerformed(backButton);
backButton.func_146113_a(mc.getSoundHandler());
}
}
@Override
public void setParent(GuiLexicon gui) {
parent = gui;
}
@Override
boolean isMainPage() {
return false;
}
@Override
String getTitle() {
return title;
}
@Override
boolean isChallenge() {
return true;
}
@Override
boolean isCategoryIndex() {
return false;
}
@Override
public GuiLexicon copy() {
return new GuiLexiconChallenge(parent, challenge);
}
@Override
public void serialize(NBTTagCompound cmp) {
super.serialize(cmp);
cmp.setString(TAG_CHALLENGE, challenge.unlocalizedName);
}
@Override
public void load(NBTTagCompound cmp) {
super.load(cmp);
String challengeName = cmp.getString(TAG_CHALLENGE);
Challenge c = ModChallenges.challengeLookup.get(challengeName);
challenge = c;
setTitle();
}
}
@@ -10,7 +10,10 @@
*/
package vazkii.botania.client.gui.lexicon;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import vazkii.botania.client.challenge.Challenge;
import vazkii.botania.client.challenge.EnumChallengeLevel;
@@ -32,15 +35,17 @@ public class GuiLexiconChallengesList extends GuiLexicon implements IParented {
@Override
public void onInitGui() {
super.onInitGui();
title = StatCollector.translateToLocal("botaniamisc.challenges");
buttonList.add(backButton = new GuiButtonBack(12, left + guiWidth / 2 - 8, top + guiHeight + 2));
int perline = 6;
int i = 13;
int y = top + 21;
int y = top + 20;
for(EnumChallengeLevel level : EnumChallengeLevel.class.getEnumConstants()) {
int j = 0;
for(Challenge c : ModChallenges.challenges.get(level)) {
buttonList.add(new GuiButtonChallengeIcon(i, left + 20 + (j % 6) * 18, y + (j / 6) * 17, c));
buttonList.add(new GuiButtonChallengeIcon(i, left + 20 + (j % perline) * 18, y + (j / perline) * 17, c));
i++;
j++;
}
@@ -52,8 +57,18 @@ public class GuiLexiconChallengesList extends GuiLexicon implements IParented {
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
for(EnumChallengeLevel level : EnumChallengeLevel.class.getEnumConstants())
fontRendererObj.drawString(StatCollector.translateToLocal(level.getName()), left + 20, top + 12 + level.ordinal() * 44, 0);
boolean unicode = fontRendererObj.getUnicodeFlag();
fontRendererObj.setUnicodeFlag(true);
for(EnumChallengeLevel level : EnumChallengeLevel.class.getEnumConstants()) {
List<Challenge> list = ModChallenges.challenges.get(level);
int complete = 0;
for(Challenge c : list)
if(c.complete)
complete++;
fontRendererObj.drawString(EnumChatFormatting.BOLD + StatCollector.translateToLocal(level.getName()) + EnumChatFormatting.RESET + " (" + complete + "/" + list.size() + ")", left + 20, top + 11 + level.ordinal() * 44, 0);
}
fontRendererObj.setUnicodeFlag(unicode);
}
@Override
@@ -81,14 +96,12 @@ public class GuiLexiconChallengesList extends GuiLexicon implements IParented {
if(par1GuiButton.id >= BOOKMARK_START)
handleBookmark(par1GuiButton);
else
switch(par1GuiButton.id) {
case 12 :
if(par1GuiButton.id == 12) {
mc.displayGuiScreen(parent);
ClientTickHandler.notifyPageChange();
break;
default :
//int index = par1GuiButton.id + page * 12;
//openEntry(index);
} else if(par1GuiButton instanceof GuiButtonChallengeIcon) {
GuiButtonChallengeIcon cbutton = (GuiButtonChallengeIcon) par1GuiButton;
mc.displayGuiScreen(new GuiLexiconChallenge(this, cbutton.challenge));
}
}
@@ -123,7 +136,6 @@ public class GuiLexiconChallengesList extends GuiLexicon implements IParented {
boolean isCategoryIndex() {
return false;
}
@Override
public GuiLexicon copy() {
@@ -26,7 +26,7 @@ import vazkii.botania.client.challenge.Challenge;
public class GuiButtonChallengeIcon extends GuiButtonLexicon {
Challenge challenge;
public Challenge challenge;
public GuiButtonChallengeIcon(int id, int x, int y, Challenge challenge) {
super(id, x, y, 16, 16, "");
@@ -43,6 +43,14 @@ public class GuiButtonChallengeIcon extends GuiButtonLexicon {
RenderItem.getInstance().renderItemIntoGUI(par1Minecraft.fontRenderer, par1Minecraft.renderEngine, challenge.icon, xPosition, yPosition);
RenderHelper.disableStandardItemLighting();
GL11.glEnable(GL11.GL_BLEND);
if(challenge.complete) {
GL11.glDisable(GL11.GL_DEPTH_TEST);
par1Minecraft.fontRenderer.drawStringWithShadow("\u2714", xPosition + 10, yPosition + 9, 0x004C00);
par1Minecraft.fontRenderer.drawStringWithShadow("\u2714", xPosition + 10, yPosition + 8, 0x0BD20D);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
List<String> tooltip = new ArrayList();
tooltip.add(EnumChatFormatting.AQUA + StatCollector.translateToLocal(challenge.unlocalizedName));