Added memory to manual (well, made it remember where you were when closing it with escape).

More documentation fixes.
This commit is contained in:
Florian Nücke 2015-04-09 13:17:12 +02:00
parent 33af3d6734
commit c6bf4d156b
17 changed files with 48 additions and 29 deletions

View File

@ -1,5 +1,5 @@
# Acid # 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). 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).

View File

@ -1,5 +1,5 @@
# Arithmetic Logic Unit # 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). Used for crafting most things pushing numbers, such as [CPUs](cpu1.md) and [graphics cards](gpu1.md).

View File

@ -1,5 +1,5 @@
# Arrow Keys # 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. At the risk of repeating myself: it's a button sink. Because the button economy has seen some serious inflation in recent years.

View File

@ -1,5 +1,5 @@
# Button Group # 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. Because you *always* have too many buttons lying around somewhere. Don't lie. We all shift-click that button recipe time and again.

View File

@ -1,5 +1,5 @@
# Card # 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. Common crafting material for most, if not all card components in OpenComputers.

View File

@ -1,5 +1,5 @@
# Microchips # 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. 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.

View File

@ -1,5 +1,5 @@
# Circuit Board # 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). Intermediary crafting item made from [raw circuit boards](rawCircuitBoard.md) and used to make [printed circuit boards](printedCircuitBoard.md).

View File

@ -1,5 +1,5 @@
# Control Unit # 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). Higher tier crafting material used in more advanced circuitry, such as [CPUs](cpu1.md).

View File

@ -1,5 +1,5 @@
# Cutting Wire # 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. 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.

View File

@ -1,5 +1,5 @@
# Disc # 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). Basic crafting component used in crafting storage media such as [floppies](floppy.md) and [hard drives](hdd1.md).

View File

@ -1,5 +1,5 @@
# Interweb # 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). 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).

View File

@ -1,5 +1,5 @@
# Numeric Keypad # 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... 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...

View File

@ -1,5 +1,5 @@
# Printed Circuit Board # 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). 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).

View File

@ -1,5 +1,5 @@
# Raw Circuit Board # 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). Intermediary crafting material, used for crafting [circuit boards](circuitBoard.md) (or [printed circuit boards](printedCircuitBoard.md), depending on the recipe set you use).

View File

@ -1,5 +1,5 @@
# Transistor # 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. 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.

View File

@ -22,6 +22,24 @@ import scala.collection.convert.WrapAsJava._
import scala.collection.mutable import scala.collection.mutable
import scala.io.Source 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 { class Manual extends GuiScreen {
final val documentMaxWidth = 230 final val documentMaxWidth = 230
final val documentMaxHeight = 176 final val documentMaxHeight = 176
@ -29,22 +47,21 @@ class Manual extends GuiScreen {
final val scrollPosY = 6 final val scrollPosY = 6
final val scrollWidth = 6 final val scrollWidth = 6
final val scrollHeight = 180 final val scrollHeight = 180
final val languageKey = "%LANGUAGE%"
var guiLeft = 0 var guiLeft = 0
var guiTop = 0 var guiTop = 0
var xSize = 0 var xSize = 0
var ySize = 0 var ySize = 0
var offset = 0
var isDragging = false var isDragging = false
var document = Iterable.empty[PseudoMarkdown.Segment] var document = Iterable.empty[PseudoMarkdown.Segment]
var documentHeight = 0 var documentHeight = 0
var history = mutable.Stack(s"doc/$languageKey/index.md")
var hoveredLink = None: Option[String] var hoveredLink = None: Option[String]
protected var scrollButton: ImageButton = _ protected var scrollButton: ImageButton = _
private def canScroll = maxOffset > 0 private def canScroll = maxOffset > 0
def offset = Manual.history.top.offset
def maxOffset = documentHeight - documentMaxHeight def maxOffset = documentHeight - documentMaxHeight
def add[T](list: util.List[T], value: Any) = list.add(value.asInstanceOf[T]) 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] = { def loadPage(path: String, localized: Boolean = false, seen: List[String] = List.empty): Iterator[String] = {
val language = FMLCommonHandler.instance.getCurrentLanguage 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) if (seen.contains(resolvedPath)) return Iterator("Redirection loop: ") ++ seen.iterator ++ Iterator(path)
val location = new ResourceLocation(Settings.resourceDomain, resolvedPath) val location = new ResourceLocation(Settings.resourceDomain, resolvedPath)
var is: InputStream = null var is: InputStream = null
@ -77,7 +94,7 @@ class Manual extends GuiScreen {
} }
catch { catch {
case e: FileNotFoundException if !localized && language != "en_US" => 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 => case t: Throwable =>
Iterator(s"Failed loading page '$path':") ++ t.toString.lines Iterator(s"Failed loading page '$path':") ++ t.toString.lines
} }
@ -87,24 +104,22 @@ class Manual extends GuiScreen {
} }
def refreshPage(): Unit = { def refreshPage(): Unit = {
document = PseudoMarkdown.parse(loadPage(history.top)) document = PseudoMarkdown.parse(loadPage(Manual.history.top.path))
documentHeight = PseudoMarkdown.height(document, documentMaxWidth, fontRendererObj) documentHeight = PseudoMarkdown.height(document, documentMaxWidth, fontRendererObj)
scrollTo(offset) scrollTo(offset)
} }
def pushPage(path: String): Unit = { def pushPage(path: String): Unit = {
val resolvedPath = resolveLink(path, history.top) val resolvedPath = resolveLink(path, Manual.history.top.path)
if (resolvedPath != history.top) { if (resolvedPath != Manual.history.top.path) {
history.push(resolvedPath) Manual.history.push(new Manual.History(resolvedPath))
scrollTo(0)
refreshPage() refreshPage()
} }
} }
def popPage(): Unit = { def popPage(): Unit = {
if (history.size > 1) { if (Manual.history.size > 1) {
history.pop() Manual.history.pop()
scrollTo(0)
refreshPage() refreshPage()
} }
else { else {
@ -215,7 +230,7 @@ class Manual extends GuiScreen {
private def scrollDown() = scrollTo(offset + PseudoMarkdown.lineHeight(fontRendererObj) * 3) private def scrollDown() = scrollTo(offset + PseudoMarkdown.lineHeight(fontRendererObj) * 3)
private def scrollTo(row: Int): Unit = { 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 val yMin = guiTop + scrollPosY
if (maxOffset > 0) { if (maxOffset > 0) {
scrollButton.yPosition = yMin + (scrollHeight - 13) * offset / maxOffset scrollButton.yPosition = yMin + (scrollHeight - 13) * offset / maxOffset

View File

@ -15,6 +15,9 @@ import net.minecraft.world.World
class Manual(val parent: Delegator) extends Delegate { class Manual(val parent: Delegator) extends Delegate {
override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = { override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = {
if (world.isRemote) { if (world.isRemote) {
if (player.isSneaking) {
gui.Manual.reset()
}
player.openGui(OpenComputers, GuiType.Manual.id, world, 0, 0, 0) player.openGui(OpenComputers, GuiType.Manual.id, world, 0, 0, 0)
} }
super.onItemRightClick(stack, world, player) 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) player.openGui(OpenComputers, GuiType.Manual.id, world, 0, 0, 0)
Minecraft.getMinecraft.currentScreen match { Minecraft.getMinecraft.currentScreen match {
case manual: gui.Manual => case manual: gui.Manual =>
gui.Manual.reset()
val descriptor = api.Items.get(new ItemStack(block)) val descriptor = api.Items.get(new ItemStack(block))
manual.pushPage("block/" + descriptor.name + ".md") manual.pushPage("block/" + descriptor.name + ".md")
case _ => case _ =>