mirror of
https://github.com/GTNewHorizons/waila.git
synced 2026-11-25 22:44:27 +00:00
First shoot at wiki display.
Added registration of files to modules, handler, etc.
This commit is contained in:
1 parent
3c048e9795
commit
bc424e1d01
12 files changed
+146
-19
No files matched your search
@@ -1,12 +1,22 @@
|
||||
package mcp.mobius.waila.addons;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
import codechicken.nei.api.API;
|
||||
|
||||
import mcp.mobius.waila.mod_Waila;
|
||||
import mcp.mobius.waila.api.IWailaDataProvider;
|
||||
import mcp.mobius.waila.api.IWailaRegistrar;
|
||||
import mcp.mobius.waila.handlers.HUDHandlerExternal;
|
||||
@@ -24,6 +34,8 @@ public class ExternalModulesHandler implements IWailaRegistrar {
|
||||
public LinkedHashMap<Class, ArrayList<IWailaDataProvider>> tailBlockProviders = new LinkedHashMap<Class, ArrayList<IWailaDataProvider>>();
|
||||
public LinkedHashMap<Class, ArrayList<IWailaDataProvider>> stackBlockProviders = new LinkedHashMap<Class, ArrayList<IWailaDataProvider>>();
|
||||
|
||||
public LinkedHashMap<String, LinkedHashMap <String, String>> wikiDescriptions = new LinkedHashMap<String, LinkedHashMap <String, String>>();
|
||||
|
||||
private ExternalModulesHandler() {
|
||||
instance = this;
|
||||
}
|
||||
@@ -182,5 +194,71 @@ public class ExternalModulesHandler implements IWailaRegistrar {
|
||||
if (clazz.isInstance(block))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDocTextFile(String modid, String filename) {
|
||||
String docData = null;
|
||||
int nentries = 0;
|
||||
|
||||
try{
|
||||
docData = this.readFileAsString(filename);
|
||||
} catch (IOException e){
|
||||
mod_Waila.log.log(Level.WARNING, String.format("Error while accessing file %s : %s", filename, e));
|
||||
return;
|
||||
}
|
||||
|
||||
String[] sections = docData.split("^>>>>");
|
||||
for (String s : sections){
|
||||
s.trim();
|
||||
if (!s.equals("")){
|
||||
try{
|
||||
String name = s.split("\r?\n",0)[0];
|
||||
String desc = s.split("\r?\n",0)[1].trim();
|
||||
if (!this.wikiDescriptions.containsKey(modid))
|
||||
this.wikiDescriptions.put(modid, new LinkedHashMap <String, String>());
|
||||
this.wikiDescriptions.get(modid).put(name, desc);
|
||||
nentries += 1;
|
||||
}catch (Exception e){
|
||||
System.out.printf("%s\n", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
mod_Waila.instance.log.log(Level.INFO, String.format("Registered %s entries from %s", nentries, filename));
|
||||
}
|
||||
|
||||
public boolean hasDocText(String modid, String name){
|
||||
if (this.wikiDescriptions.containsKey(modid))
|
||||
return this.wikiDescriptions.get(modid).containsKey(name);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDocText(String modid, String name){
|
||||
return this.wikiDescriptions.get(modid).get(name);
|
||||
}
|
||||
|
||||
private String readFileAsString(String filePath) throws IOException {
|
||||
// URL fileURL = this.getClass().getResource(filePath);
|
||||
// File filedata = new File(fileURL);
|
||||
// Reader paramReader = new InputStreamReader(this.getClass().getResourceAsStream(filePath));
|
||||
|
||||
InputStream in = getClass().getResourceAsStream(filePath);
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(in));
|
||||
|
||||
StringBuffer fileData = new StringBuffer();
|
||||
//BufferedReader reader = new BufferedReader(paramReader);
|
||||
|
||||
char[] buf = new char[1024];
|
||||
int numRead=0;
|
||||
while((numRead=input.read(buf)) != -1){
|
||||
String readData = String.valueOf(buf, 0, numRead);
|
||||
fileData.append(readData);
|
||||
}
|
||||
input.close();
|
||||
return fileData.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
>>>>buildcraft.transport.ItemPlug:*
|
||||
This is a plug for pipes.
|
||||
@@ -137,7 +137,9 @@ public class HUDHandlerVanilla implements IWailaDataProvider {
|
||||
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), comparatorAct);
|
||||
ExternalModulesHandler.instance().registerHeadProvider(new HUDHandlerVanilla(), redstone);
|
||||
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), redstone);
|
||||
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), jukebox);
|
||||
ExternalModulesHandler.instance().registerBodyProvider(new HUDHandlerVanilla(), jukebox);
|
||||
|
||||
ExternalModulesHandler.instance().registerDocTextFile("Minecraft", "/mcp/mobius/waila/addons/vanillamc/WikiData.txt");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
>>>>tile.stone
|
||||
This is basic stone.
|
||||
@@ -17,4 +17,6 @@ public interface IWailaRegistrar {
|
||||
/* Same thing, but works on a class hierarchy instead */
|
||||
public void registerHeadProvider (IWailaDataProvider dataProvider, Class block);
|
||||
public void registerBodyProvider (IWailaDataProvider dataProvider, Class block);
|
||||
|
||||
public void registerDocTextFile (String modid, String filename);
|
||||
}
|
||||
@@ -25,16 +25,16 @@ public class ConfigKeyHandler extends KeyHandler {
|
||||
super(new KeyBinding[]{
|
||||
new KeyBinding("key.wailaconfig", Keyboard.KEY_NUMPAD0),
|
||||
new KeyBinding("key.wailadisplay", Keyboard.KEY_NUMPAD1),
|
||||
new KeyBinding("key.wailatedump", Keyboard.KEY_NUMPAD1),
|
||||
//new KeyBinding("key.wailatedump", Keyboard.KEY_NUMPAD1),
|
||||
}, new boolean[]{
|
||||
false,
|
||||
false,
|
||||
false
|
||||
//false
|
||||
});
|
||||
|
||||
LanguageRegistry.instance().addStringLocalization("key.wailaconfig", "[Waila] Config screen");
|
||||
LanguageRegistry.instance().addStringLocalization("key.wailadisplay", "[Waila] Show/Hide");
|
||||
LanguageRegistry.instance().addStringLocalization("key.wailatedump", "[Waila] Dump server TE");
|
||||
//LanguageRegistry.instance().addStringLocalization("key.wailatedump", "[Waila] Dump server TE");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -52,12 +52,13 @@ public class ConfigKeyHandler extends KeyHandler {
|
||||
else if (kb.keyDescription == "key.wailadisplay" && !ConfigHandler.instance().getConfig("waila.showmode")){
|
||||
NEIClientConfig.getSetting("options.inworld tooltips").setBooleanValue(true);
|
||||
}
|
||||
else if (kb.keyDescription == "key.wailatedump"){
|
||||
this.dumpTag(DataAccessor.instance.remoteNbt, 0);
|
||||
}
|
||||
//else if (kb.keyDescription == "key.wailatedump"){
|
||||
// this.dumpTag(DataAccessor.instance.remoteNbt, 0);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
private void dumpTag(NBTTagCompound nbt, int tab){
|
||||
if (nbt == null) return;
|
||||
|
||||
@@ -101,7 +102,7 @@ public class ConfigKeyHandler extends KeyHandler {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
@Override
|
||||
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {
|
||||
if (!tickEnd) return;
|
||||
|
||||
@@ -16,11 +16,6 @@ public class GuiIngameWiki extends BaseWailaScreen {
|
||||
this.widReader.setHeight(this.res.getScaledHeight());
|
||||
|
||||
this.addWidget("wikireader", this.widReader);
|
||||
|
||||
this.widReader.setText("The quick brown fox jumps \n\n\n\n\nover the \nlazy \ndog \nThe \nq\nu\ni\nc\nk\n \nb\nrown \n\n\nf\nox\n \nj\nu\nm\np\ns\n \n\nn\no\nver the\n lazy \ndog \nThe \nquick \nbrown \nfox \njumps\n over the lazy dog The quick brown fox jumps \nover the lazy dog ");
|
||||
for (String s : this.widReader.getTailoredText()){
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,7 +76,7 @@ public class WikiReader extends BaseWidget {
|
||||
}
|
||||
|
||||
public ArrayList<String> getTailoredText(){
|
||||
String[] splittedText = this.text.split("\n");
|
||||
String[] splittedText = this.text.split("\r?\n");
|
||||
ArrayList<String> lines = new ArrayList<String>();
|
||||
for (String s : splittedText){
|
||||
ArrayList<Integer> whiteSpaces = this.getWhiteSpaces(s);
|
||||
|
||||
@@ -23,7 +23,7 @@ public class HUDHandlerWaila implements IHighlightHandler {
|
||||
public List<String> handleTextData(ItemStack itemStack, World world, EntityPlayer player, MovingObjectPosition mop, List<String> currenttip, Layout layout) {
|
||||
|
||||
if (layout == Layout.FOOTER){
|
||||
String modName = mod_Waila.instance.getCanonicalName(itemStack);
|
||||
String modName = mod_Waila.instance.getModName(itemStack);
|
||||
if (modName != null && !modName.equals(""))
|
||||
currenttip.add("\u00a79\u00a7o" + modName);
|
||||
} else if (layout == Layout.HEADER && ConfigHandler.instance().getConfig("waila.showmetadata", false)){
|
||||
|
||||
@@ -17,7 +17,7 @@ public class TooltipHandlerWaila implements IContainerTooltipHandler {
|
||||
|
||||
@Override
|
||||
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, List<String> currenttip) {
|
||||
String canonicalName = waila.getCanonicalName(itemstack);
|
||||
String canonicalName = waila.getModName(itemstack);
|
||||
if (canonicalName != null && !canonicalName.equals(""))
|
||||
currenttip.add("\u00a79\u00a7o" + canonicalName);
|
||||
return currenttip;
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
package mcp.mobius.waila.handlers;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import mcp.mobius.waila.mod_Waila;
|
||||
import mcp.mobius.waila.addons.ExternalModulesHandler;
|
||||
import mcp.mobius.waila.gui.GuiEnchantScreen;
|
||||
import mcp.mobius.waila.gui.GuiIngameWiki;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.forge.IContainerInputHandler;
|
||||
@@ -31,12 +38,41 @@ public class WikiHandler implements IContainerInputHandler {
|
||||
if(keyID == NEIClientConfig.getKeyBinding("showwiki")){
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
GuiIngameWiki wikiScreen = new GuiIngameWiki(mc.currentScreen);
|
||||
|
||||
wikiScreen.widReader.setText(this.getDescriptionString(mod_Waila.instance.getModID(stackover), stackover.getItemName()));
|
||||
|
||||
//Item item = Item.itemsList[stackover.itemID];
|
||||
//String itemCanonical = item.getClass().getCanonicalName();
|
||||
|
||||
//if (item instanceof ItemBlock){
|
||||
// Block block = Block.blocksList[((ItemBlock)item).getBlockID()];
|
||||
// wikiScreen.widReader.setText(this.getDescriptionString(block.getClass().getCanonicalName(), stackover.getItemDamage()));
|
||||
//} else {
|
||||
// wikiScreen.widReader.setText(this.getDescriptionString(itemCanonical, stackover.getItemDamage()));
|
||||
//}
|
||||
mc.displayGuiScreen(wikiScreen);
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getDescriptionString(String modid, String name){
|
||||
if (ExternalModulesHandler.instance().hasDocText(modid, name)){
|
||||
return ExternalModulesHandler.instance().getDocText(modid, name);
|
||||
} else {
|
||||
LinkedHashMap <String, String> entries = ExternalModulesHandler.instance().wikiDescriptions.get(modid);
|
||||
for (String s: entries.keySet()){
|
||||
String regexed = s;
|
||||
regexed = regexed.replace(".", "\\.");
|
||||
regexed = regexed.replace("*", ".*");
|
||||
|
||||
if (name.matches(s))
|
||||
return ExternalModulesHandler.instance().getDocText(modid, s);
|
||||
}
|
||||
return String.format("No description for %s$$%s",modid, name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(GuiContainer gui, int mousex, int mousey,
|
||||
int button) {
|
||||
|
||||
@@ -132,7 +132,7 @@ public class mod_Waila {
|
||||
|
||||
}
|
||||
|
||||
public String getCanonicalName(ItemStack itemstack){
|
||||
public String getModName(ItemStack itemstack){
|
||||
try{
|
||||
String modID = this.itemMap.get(itemstack.itemID);
|
||||
ModContainer mod = CommonUtils.findModContainer(modID);
|
||||
@@ -143,7 +143,16 @@ public class mod_Waila {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getModID(ItemStack itemstack){
|
||||
try{
|
||||
String modID = this.itemMap.get(itemstack.itemID);
|
||||
return modID;
|
||||
} catch (NullPointerException e){
|
||||
//System.out.printf("NPE : %s\n",itemstack.toString());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user