diff --git a/src/main/java/li/cil/oc/api/Manual.java b/src/main/java/li/cil/oc/api/Manual.java index 655a1bc08..ed13e305b 100644 --- a/src/main/java/li/cil/oc/api/Manual.java +++ b/src/main/java/li/cil/oc/api/Manual.java @@ -26,11 +26,12 @@ public class Manual { * usually be one, for your main index page. * * @param renderer the renderer used to render the icon on your tab. + * @param tooltip the unlocalized tooltip of the tab, or null. * @param path the path to the page to open when the tab is clicked. */ - public static void addTab(TabIconRenderer renderer, String path) { + public static void addTab(TabIconRenderer renderer, String tooltip, String path) { if (API.manual != null) - API.manual.addTab(renderer, path); + API.manual.addTab(renderer, tooltip, path); } /** diff --git a/src/main/java/li/cil/oc/api/detail/ManualAPI.java b/src/main/java/li/cil/oc/api/detail/ManualAPI.java index b626c3ddd..3e469dc4f 100644 --- a/src/main/java/li/cil/oc/api/detail/ManualAPI.java +++ b/src/main/java/li/cil/oc/api/detail/ManualAPI.java @@ -17,9 +17,10 @@ public interface ManualAPI { * usually be one, for your main index page. * * @param renderer the renderer used to render the icon on your tab. + * @param tooltip the unlocalized tooltip of the tab, or null. * @param path the path to the page to open when the tab is clicked. */ - void addTab(TabIconRenderer renderer, String path); + void addTab(TabIconRenderer renderer, String tooltip, String path); /** * Register a path provider. diff --git a/src/main/java/li/cil/oc/api/manual/TabIconRenderer.java b/src/main/java/li/cil/oc/api/manual/TabIconRenderer.java index 8a0225e27..45b3a329f 100644 --- a/src/main/java/li/cil/oc/api/manual/TabIconRenderer.java +++ b/src/main/java/li/cil/oc/api/manual/TabIconRenderer.java @@ -1,5 +1,8 @@ package li.cil.oc.api.manual; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + /** * Allows defining a renderer for a manual tab. *

@@ -18,5 +21,6 @@ public interface TabIconRenderer { * This should render something in a 16x16 area. The OpenGL state has been * adjusted so that drawing starts at (0,0,0), and should go to (16,16,0). */ + @SideOnly(Side.CLIENT) void render(); } diff --git a/src/main/java/li/cil/oc/api/prefab/ItemStackTabIconRenderer.java b/src/main/java/li/cil/oc/api/prefab/ItemStackTabIconRenderer.java index 6281fd588..db8d43be4 100644 --- a/src/main/java/li/cil/oc/api/prefab/ItemStackTabIconRenderer.java +++ b/src/main/java/li/cil/oc/api/prefab/ItemStackTabIconRenderer.java @@ -1,5 +1,7 @@ package li.cil.oc.api.prefab; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import li.cil.oc.api.manual.TabIconRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.OpenGlHelper; @@ -20,6 +22,7 @@ public class ItemStackTabIconRenderer implements TabIconRenderer { this.stack = stack; } + @SideOnly(Side.CLIENT) @Override public void render() { GL11.glEnable(GL12.GL_RESCALE_NORMAL); diff --git a/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java b/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java index bfb06562b..0a382814b 100644 --- a/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java +++ b/src/main/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java @@ -1,5 +1,7 @@ package li.cil.oc.api.prefab; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import li.cil.oc.api.manual.TabIconRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; @@ -17,6 +19,7 @@ public class TextureTabIconRenderer implements TabIconRenderer { } @Override + @SideOnly(Side.CLIENT) public void render() { Minecraft.getMinecraft().getTextureManager().bindTexture(location); final Tessellator t = Tessellator.instance; diff --git a/src/main/resources/assets/opencomputers/lang/de_DE.lang b/src/main/resources/assets/opencomputers/lang/de_DE.lang index ba449824e..bb1ab2800 100644 --- a/src/main/resources/assets/opencomputers/lang/de_DE.lang +++ b/src/main/resources/assets/opencomputers/lang/de_DE.lang @@ -183,6 +183,8 @@ oc:gui.Error.NoCPU=Im Computer ist kein Hauptprozessor (CPU) installiert. oc:gui.Error.NoEnergy=Nicht genug Energie. oc:gui.Error.NoRAM=Im Computer ist kein RAM installiert. oc:gui.Error.OutOfMemory=Nicht genug Arbeitsspeicher. +oc:gui.Manual.Blocks=Blöcke +oc:gui.Manual.Items=Gegenstände oc:gui.Raid.Warning=§4Eine Platte einzufügen löscht sie.[nl] Eine Platte zu entfernen löscht das Raid. oc:gui.Robot.Power=Energie oc:gui.Robot.TurnOff=Ausschalten diff --git a/src/main/resources/assets/opencomputers/lang/en_US.lang b/src/main/resources/assets/opencomputers/lang/en_US.lang index 3da044bb7..44665ed9a 100644 --- a/src/main/resources/assets/opencomputers/lang/en_US.lang +++ b/src/main/resources/assets/opencomputers/lang/en_US.lang @@ -183,6 +183,8 @@ oc:gui.Error.NoCPU=No CPU is installed in the computer. oc:gui.Error.NoEnergy=Not enough energy. oc:gui.Error.NoRAM=No RAM is installed in the computer. oc:gui.Error.OutOfMemory=Out of memory. +oc:gui.Manual.Blocks=Blocks +oc:gui.Manual.Items=Items oc:gui.Raid.Warning=§4Adding a disk wipes it.[nl] Removing a disk wipes the raid. oc:gui.Robot.Power=Energy oc:gui.Robot.TurnOff=Turn off diff --git a/src/main/scala/li/cil/oc/client/Manual.scala b/src/main/scala/li/cil/oc/client/Manual.scala index 1c8c6e38f..247f68fde 100644 --- a/src/main/scala/li/cil/oc/client/Manual.scala +++ b/src/main/scala/li/cil/oc/client/Manual.scala @@ -24,7 +24,7 @@ object Manual extends ManualAPI { class History(val path: String, var offset: Int = 0) - class Tab(val renderer: TabIconRenderer, val path: String) + class Tab(val renderer: TabIconRenderer, val tooltip: Option[String], val path: String) val tabs = mutable.Buffer.empty[Tab] @@ -36,8 +36,8 @@ object Manual extends ManualAPI { reset() - override def addTab(renderer: TabIconRenderer, path: String): Unit = { - tabs += new Tab(renderer, path) + override def addTab(renderer: TabIconRenderer, tooltip: String, path: String): Unit = { + tabs += new Tab(renderer, Option(tooltip), path) } override def addProvider(provider: PathProvider): Unit = { diff --git a/src/main/scala/li/cil/oc/client/gui/Manual.scala b/src/main/scala/li/cil/oc/client/gui/Manual.scala index 8125c7aae..91cfab3bc 100644 --- a/src/main/scala/li/cil/oc/client/gui/Manual.scala +++ b/src/main/scala/li/cil/oc/client/gui/Manual.scala @@ -5,8 +5,8 @@ import java.util import li.cil.oc.Localization import li.cil.oc.api -import li.cil.oc.client.Manual import li.cil.oc.client.Textures +import li.cil.oc.client.{Manual => ManualAPI} import li.cil.oc.util.PseudoMarkdown import net.minecraft.client.Minecraft import net.minecraft.client.gui.Gui @@ -43,7 +43,7 @@ class Manual extends GuiScreen { private def canScroll = maxOffset > 0 - def offset = Manual.history.top.offset + def offset = ManualAPI.history.top.offset def maxOffset = documentHeight - documentMaxHeight @@ -58,21 +58,21 @@ class Manual extends GuiScreen { } def refreshPage(): Unit = { - document = PseudoMarkdown.parse(api.Manual.contentFor(Manual.history.top.path)) + document = PseudoMarkdown.parse(api.Manual.contentFor(ManualAPI.history.top.path)) documentHeight = PseudoMarkdown.height(document, documentMaxWidth, fontRendererObj) scrollTo(offset) } def pushPage(path: String): Unit = { - if (path != Manual.history.top.path) { - Manual.history.push(new Manual.History(path)) + if (path != ManualAPI.history.top.path) { + ManualAPI.history.push(new ManualAPI.History(path)) refreshPage() } } def popPage(): Unit = { - if (Manual.history.size > 1) { - Manual.history.pop() + if (ManualAPI.history.size > 1) { + ManualAPI.history.pop() refreshPage() } else { @@ -83,8 +83,8 @@ class Manual extends GuiScreen { override def doesGuiPauseGame = false override def actionPerformed(button: GuiButton): Unit = { - if (button.id >= 0 && button.id < Manual.tabs.length) { - api.Manual.navigate(Manual.tabs(button.id).path) + if (button.id >= 0 && button.id < ManualAPI.tabs.length) { + api.Manual.navigate(ManualAPI.tabs(button.id).path) } } @@ -103,7 +103,7 @@ class Manual extends GuiScreen { scrollButton = new ImageButton(-1, guiLeft + scrollPosX, guiTop + scrollPosY, 6, 13, Textures.guiButtonScroll) add(buttonList, scrollButton) - for ((tab, i) <- Manual.tabs.zipWithIndex if i < 7) { + for ((tab, i) <- ManualAPI.tabs.zipWithIndex if i < 7) { val x = guiLeft + tabPosX val y = guiTop + tabPosY + i * (tabHeight - 1) add(buttonList, new ImageButton(i, x, y, tabWidth, tabHeight, Textures.guiManualTab)) @@ -121,7 +121,7 @@ class Manual extends GuiScreen { super.drawScreen(mouseX, mouseY, dt) - for ((tab, i) <- Manual.tabs.zipWithIndex if i < 7) { + for ((tab, i) <- ManualAPI.tabs.zipWithIndex if i < 7) { val x = guiLeft + tabPosX val y = guiTop + tabPosY + i * (tabHeight - 1) GL11.glPushMatrix() @@ -133,12 +133,20 @@ class Manual extends GuiScreen { PseudoMarkdown.render(document, guiLeft + 8, guiTop + 8, documentMaxWidth, documentMaxHeight, offset, fontRendererObj, mouseX, mouseY) match { case Some(segment) => segment.tooltip match { - case Some(text) if text.nonEmpty => drawHoveringText(seqAsJavaList(text.lines.toSeq), mouseX, mouseY, fontRendererObj) + case Some(text) if text.nonEmpty => drawHoveringText(seqAsJavaList(Localization.localizeImmediately(text).lines.toSeq), mouseX, mouseY, fontRendererObj) case _ => } hoveredLink = segment.link case _ => hoveredLink = None } + + for ((tab, i) <- ManualAPI.tabs.zipWithIndex if i < 7) { + val x = guiLeft + tabPosX + val y = guiTop + tabPosY + i * (tabHeight - 1) + if (mouseX > x && mouseX < x + tabWidth && mouseY > y && mouseY < y + tabHeight) tab.tooltip.foreach(text => { + drawHoveringText(seqAsJavaList(Localization.localizeImmediately(text).lines.toSeq), mouseX, mouseY, fontRendererObj) + }) + } } override protected def mouseMovedOrUp(mouseX: Int, mouseY: Int, button: Int) { @@ -159,7 +167,7 @@ class Manual extends GuiScreen { // Left click, did we hit a link? hoveredLink.foreach(link => { if (link.startsWith("http://") || link.startsWith("https://")) handleUrl(link) - else pushPage(Manual.makeRelative(link, Manual.history.top.path)) + else pushPage(ManualAPI.makeRelative(link, ManualAPI.history.top.path)) }) } else if (button == 1) { @@ -204,7 +212,7 @@ class Manual extends GuiScreen { private def scrollDown() = scrollTo(offset + PseudoMarkdown.lineHeight(fontRendererObj) * 3) private def scrollTo(row: Int): Unit = { - Manual.history.top.offset = math.max(0, math.min(maxOffset, row)) + ManualAPI.history.top.offset = math.max(0, math.min(maxOffset, row)) val yMin = guiTop + scrollPosY if (maxOffset > 0) { scrollButton.yPosition = yMin + (scrollHeight - 13) * offset / maxOffset diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala index d181f46e4..0c48a2385 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala @@ -200,8 +200,8 @@ object ModOpenComputers extends ModProxy { api.Manual.addProvider(DefinitionPathProvider) api.Manual.addProvider(new ResourceContentProvider(Settings.resourceDomain)) - api.Manual.addTab(new ItemStackTabIconRenderer(api.Items.get("case1").createItemStack(1)), "doc/%LANGUAGE%/block/index.md") - api.Manual.addTab(new ItemStackTabIconRenderer(api.Items.get("chip1").createItemStack(1)), "doc/%LANGUAGE%/item/index.md") + api.Manual.addTab(new ItemStackTabIconRenderer(api.Items.get("case1").createItemStack(1)), "oc:gui.Manual.Blocks", "doc/%LANGUAGE%/block/index.md") + api.Manual.addTab(new ItemStackTabIconRenderer(api.Items.get("chip1").createItemStack(1)), "oc:gui.Manual.Items", "doc/%LANGUAGE%/item/index.md") } private def blacklistHost(host: Class[_], itemNames: String*) { @@ -231,8 +231,8 @@ object ModOpenComputers extends ModProxy { private def checkBlacklisted(info: ItemInfo): String = if (info == null || Blacklist.contains(info.name)) null - else if (info.block != null) "block/" + info.name + ".md" - else "item/" + info.name + ".md" + else if (info.block != null) "doc/%LANGUAGE%/block/" + info.name + ".md" + else "doc/%LANGUAGE%/item/" + info.name + ".md" } }