From c6bf4d156bd00a9449900b8d6cbd70b2a40e6895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Thu, 9 Apr 2015 13:17:12 +0200 Subject: [PATCH] Added memory to manual (well, made it remember where you were when closing it with escape). More documentation fixes. --- .../opencomputers/doc/en_US/item/acid.md | 2 +- .../opencomputers/doc/en_US/item/alu.md | 2 +- .../opencomputers/doc/en_US/item/arrowKeys.md | 2 +- .../doc/en_US/item/buttonGroup.md | 2 +- .../opencomputers/doc/en_US/item/card.md | 2 +- .../opencomputers/doc/en_US/item/chip1.md | 2 +- .../doc/en_US/item/circuitBoard.md | 2 +- .../doc/en_US/item/controlUnit.md | 2 +- .../doc/en_US/item/cuttingWire.md | 2 +- .../opencomputers/doc/en_US/item/disk.md | 2 +- .../opencomputers/doc/en_US/item/interweb.md | 2 +- .../opencomputers/doc/en_US/item/numPad.md | 2 +- .../doc/en_US/item/printedCircuitBoard.md | 2 +- .../doc/en_US/item/rawCircuitBoard.md | 2 +- .../doc/en_US/item/transistor.md | 2 +- .../scala/li/cil/oc/client/gui/Manual.scala | 43 +++++++++++++------ .../scala/li/cil/oc/common/item/Manual.scala | 4 ++ 17 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/acid.md b/src/main/resources/assets/opencomputers/doc/en_US/item/acid.md index ac2b03952..eff58cbe5 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/acid.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/acid.md @@ -1,5 +1,5 @@ # Acid -![Reflux?](oredict:oc:acid) +![Reflux?](oredict:oc:materialAcid) You'll probabl only see this item when playing with the hardmod recipe set, in which case you'll need it to etch [circuit boards](circuitBoard.md) to craft [printed circuit boards](printedCircuitBoard.md). diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/alu.md b/src/main/resources/assets/opencomputers/doc/en_US/item/alu.md index 866e3fa48..77a4b3daa 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/alu.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/alu.md @@ -1,5 +1,5 @@ # Arithmetic Logic Unit -![I can into logic!](oredict:oc:alu) +![I can into logic!](oredict:oc:materialALU) Used for crafting most things pushing numbers, such as [CPUs](cpu1.md) and [graphics cards](gpu1.md). diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/arrowKeys.md b/src/main/resources/assets/opencomputers/doc/en_US/item/arrowKeys.md index c893f70cb..2da1b1575 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/arrowKeys.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/arrowKeys.md @@ -1,5 +1,5 @@ # Arrow Keys -![Just be grateful it's not made from arrows.](oredict:oc:arrowKeys) +![Just be grateful it's not made from arrows.](oredict:oc:materialArrowKey) At the risk of repeating myself: it's a button sink. Because the button economy has seen some serious inflation in recent years. diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/buttonGroup.md b/src/main/resources/assets/opencomputers/doc/en_US/item/buttonGroup.md index 6ea0365ca..5d1976afc 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/buttonGroup.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/buttonGroup.md @@ -1,5 +1,5 @@ # Button Group -![Needs more buttons.](oredict:oc:buttonGroup) +![Needs more buttons.](oredict:oc:materialButtonGroup) Because you *always* have too many buttons lying around somewhere. Don't lie. We all shift-click that button recipe time and again. diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/card.md b/src/main/resources/assets/opencomputers/doc/en_US/item/card.md index 41400fb23..2dc2388e4 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/card.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/card.md @@ -1,5 +1,5 @@ # Card -![Can't be read.](oredict:oc:card) +![Can't be read.](oredict:oc:materialCard) Common crafting material for most, if not all card components in OpenComputers. diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/chip1.md b/src/main/resources/assets/opencomputers/doc/en_US/item/chip1.md index 57f30af5a..4f35fc69a 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/chip1.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/chip1.md @@ -1,5 +1,5 @@ # Microchips -![Not the edible ones.](oredict:oc:chip1) +![Not the edible ones.](oredict:oc:circuitChip1) Microchips are the bread and butter of electronic component crafting. They come in different tiers, for the different tier of devices they're used to craft with. diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/circuitBoard.md b/src/main/resources/assets/opencomputers/doc/en_US/item/circuitBoard.md index a95979df3..296274c2a 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/circuitBoard.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/circuitBoard.md @@ -1,5 +1,5 @@ # Circuit Board -![Needs more gold.](oredict:oc:circuitBoard) +![Needs more gold.](oredict:oc:materialCircuitBoard) Intermediary crafting item made from [raw circuit boards](rawCircuitBoard.md) and used to make [printed circuit boards](printedCircuitBoard.md). diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/controlUnit.md b/src/main/resources/assets/opencomputers/doc/en_US/item/controlUnit.md index 23b3e6fbb..63994adfb 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/controlUnit.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/controlUnit.md @@ -1,5 +1,5 @@ # Control Unit -![With built-in cruise control.](oredict:oc:controlUnit) +![With built-in cruise control.](oredict:oc:materialCU) Higher tier crafting material used in more advanced circuitry, such as [CPUs](cpu1.md). diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/cuttingWire.md b/src/main/resources/assets/opencomputers/doc/en_US/item/cuttingWire.md index 10db45b53..045ec42f4 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/cuttingWire.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/cuttingWire.md @@ -1,5 +1,5 @@ # Cutting Wire -![Not a garrote. Honest.](oredict:oc:cuttingWire) +![Not a garrote. Honest.](oredict:oc:materialCuttingWire) You'll usually only encounter this when playing with the hard mode recipe set. In that case, this is used for crafting [raw circuit boards](rawCircuitBoard.md). Very inefficiently. diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/disk.md b/src/main/resources/assets/opencomputers/doc/en_US/item/disk.md index bfb360205..55a6e9c13 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/disk.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/disk.md @@ -1,5 +1,5 @@ # Disc -![World. RIP Terry Pratchett.](oredict:oc:disk) +![World. RIP Terry Pratchett.](oredict:oc:materialDisk) Basic crafting component used in crafting storage media such as [floppies](floppy.md) and [hard drives](hdd1.md). diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/interweb.md b/src/main/resources/assets/opencomputers/doc/en_US/item/interweb.md index 7b29b6f24..91520ca79 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/interweb.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/interweb.md @@ -1,5 +1,5 @@ # Interweb -![A website is a place where there's cobweb.](oredict:oc:interweb) +![A website is a place where there's cobweb.](oredict:oc:materialInterweb) The interweb is a basic component for all things related to long distance communication. It uses the strange mechanics of all things End to allow something along the lines of quantum communication. Used most notably in [internet cards](internetCard.md) and [linked cards](linkedCard.md). diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/numPad.md b/src/main/resources/assets/opencomputers/doc/en_US/item/numPad.md index 612c50da8..303bf606e 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/numPad.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/numPad.md @@ -1,5 +1,5 @@ # Numeric Keypad -![Check for fingerprints.](oredict:oc:numPad) +![Check for fingerprints.](oredict:oc:materialNumPad) The numpad is part of every [keyboard](../block/keyboard.md). I allows you to enter numbers. I'm seriously running out of ideas of what to write here... diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/printedCircuitBoard.md b/src/main/resources/assets/opencomputers/doc/en_US/item/printedCircuitBoard.md index dc8e5be10..fdd266165 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/printedCircuitBoard.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/printedCircuitBoard.md @@ -1,5 +1,5 @@ # Printed Circuit Board -![AKA PCB](oredict:oc:printedCircuitBoard) +![AKA PCB](oredict:oc:materialCircuitBoardPrinted) The printed circuit board is, next to the [transistor](transistor.md), one of the most basic crafting materials in OpenComputers. It is used as a basis for many components, such as [cards](card.md) and a large number of [blocks](../block/index.md). diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/rawCircuitBoard.md b/src/main/resources/assets/opencomputers/doc/en_US/item/rawCircuitBoard.md index d6e6fe8ce..e6fcc56ea 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/rawCircuitBoard.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/rawCircuitBoard.md @@ -1,5 +1,5 @@ # Raw Circuit Board -![Not sushi.](oredict:oc:rawCircuitBoard) +![Not sushi.](oredict:oc:materialCircuitBoardRaw) Intermediary crafting material, used for crafting [circuit boards](circuitBoard.md) (or [printed circuit boards](printedCircuitBoard.md), depending on the recipe set you use). diff --git a/src/main/resources/assets/opencomputers/doc/en_US/item/transistor.md b/src/main/resources/assets/opencomputers/doc/en_US/item/transistor.md index fd188b949..edef8d4b9 100644 --- a/src/main/resources/assets/opencomputers/doc/en_US/item/transistor.md +++ b/src/main/resources/assets/opencomputers/doc/en_US/item/transistor.md @@ -1,5 +1,5 @@ # Transistor -![I think I've used up all my references.](oredict:oc:transistor) +![I think I've used up all my references.](oredict:oc:materialTransistor) The transistor is one of the most basic crafting ingredients in OpenComputers. It is mainly used to craft [microchips](chip1.md) and other electronic goodies. 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 b99db7d6f..48880b542 100644 --- a/src/main/scala/li/cil/oc/client/gui/Manual.scala +++ b/src/main/scala/li/cil/oc/client/gui/Manual.scala @@ -22,6 +22,24 @@ import scala.collection.convert.WrapAsJava._ import scala.collection.mutable import scala.io.Source +object Manual { + final val LanguageKey = "%LANGUAGE%" + + val history = new mutable.Stack[History] + + reset() + + def reset(): Unit = { + history.clear() + history.push(new History(s"doc/$LanguageKey/index.md")) + } + + class History(val path: String) { + var offset = 0 + } + +} + class Manual extends GuiScreen { final val documentMaxWidth = 230 final val documentMaxHeight = 176 @@ -29,22 +47,21 @@ class Manual extends GuiScreen { final val scrollPosY = 6 final val scrollWidth = 6 final val scrollHeight = 180 - final val languageKey = "%LANGUAGE%" var guiLeft = 0 var guiTop = 0 var xSize = 0 var ySize = 0 - var offset = 0 var isDragging = false var document = Iterable.empty[PseudoMarkdown.Segment] var documentHeight = 0 - var history = mutable.Stack(s"doc/$languageKey/index.md") var hoveredLink = None: Option[String] protected var scrollButton: ImageButton = _ private def canScroll = maxOffset > 0 + def offset = Manual.history.top.offset + def maxOffset = documentHeight - documentMaxHeight def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T]) @@ -59,7 +76,7 @@ class Manual extends GuiScreen { def loadPage(path: String, localized: Boolean = false, seen: List[String] = List.empty): Iterator[String] = { val language = FMLCommonHandler.instance.getCurrentLanguage - val resolvedPath = path.replaceAll(languageKey, language) + val resolvedPath = path.replaceAll(Manual.LanguageKey, language) if (seen.contains(resolvedPath)) return Iterator("Redirection loop: ") ++ seen.iterator ++ Iterator(path) val location = new ResourceLocation(Settings.resourceDomain, resolvedPath) var is: InputStream = null @@ -77,7 +94,7 @@ class Manual extends GuiScreen { } catch { case e: FileNotFoundException if !localized && language != "en_US" => - loadPage(path.replaceAll(languageKey, "en_US"), localized = true, seen) + loadPage(path.replaceAll(Manual.LanguageKey, "en_US"), localized = true, seen) case t: Throwable => Iterator(s"Failed loading page '$path':") ++ t.toString.lines } @@ -87,24 +104,22 @@ class Manual extends GuiScreen { } def refreshPage(): Unit = { - document = PseudoMarkdown.parse(loadPage(history.top)) + document = PseudoMarkdown.parse(loadPage(Manual.history.top.path)) documentHeight = PseudoMarkdown.height(document, documentMaxWidth, fontRendererObj) scrollTo(offset) } def pushPage(path: String): Unit = { - val resolvedPath = resolveLink(path, history.top) - if (resolvedPath != history.top) { - history.push(resolvedPath) - scrollTo(0) + val resolvedPath = resolveLink(path, Manual.history.top.path) + if (resolvedPath != Manual.history.top.path) { + Manual.history.push(new Manual.History(resolvedPath)) refreshPage() } } def popPage(): Unit = { - if (history.size > 1) { - history.pop() - scrollTo(0) + if (Manual.history.size > 1) { + Manual.history.pop() refreshPage() } else { @@ -215,7 +230,7 @@ class Manual extends GuiScreen { private def scrollDown() = scrollTo(offset + PseudoMarkdown.lineHeight(fontRendererObj) * 3) private def scrollTo(row: Int): Unit = { - offset = math.max(0, math.min(maxOffset, row)) + Manual.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/common/item/Manual.scala b/src/main/scala/li/cil/oc/common/item/Manual.scala index 079527c38..742dbbf14 100644 --- a/src/main/scala/li/cil/oc/common/item/Manual.scala +++ b/src/main/scala/li/cil/oc/common/item/Manual.scala @@ -15,6 +15,9 @@ import net.minecraft.world.World class Manual(val parent: Delegator) extends Delegate { override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = { if (world.isRemote) { + if (player.isSneaking) { + gui.Manual.reset() + } player.openGui(OpenComputers, GuiType.Manual.id, world, 0, 0, 0) } super.onItemRightClick(stack, world, player) @@ -28,6 +31,7 @@ class Manual(val parent: Delegator) extends Delegate { player.openGui(OpenComputers, GuiType.Manual.id, world, 0, 0, 0) Minecraft.getMinecraft.currentScreen match { case manual: gui.Manual => + gui.Manual.reset() val descriptor = api.Items.get(new ItemStack(block)) manual.pushPage("block/" + descriptor.name + ".md") case _ =>