Open page of clicked blocks. Redirects, e.g. for blocks with tiers.

This commit is contained in:
Florian Nücke 2015-04-08 13:56:48 +02:00
parent 38a6b626e9
commit e44b65b986
9 changed files with 42 additions and 5 deletions

View File

@ -1,4 +1,4 @@
# Headline with more lines [with link](huehue) and *some* more
# Headline with more lines [with link](redirect1.md) and *some* more
This is some test text for the subset of Markdown supported by the planned ingame documentation system for OpenComputers.
![This is a tooltip...](../../textures/gui/printer_ink.png)

View File

@ -0,0 +1 @@
#redirect redirect2.md

View File

@ -0,0 +1 @@
#REDIRECT redirect1.md

View File

@ -0,0 +1,4 @@
# Screen
![Screen](oredict:oc:screen1)
Screens! Magic! Stuff.

View File

@ -0,0 +1 @@
#REDIRECT screen1.md

View File

@ -0,0 +1 @@
#REDIRECT screen1.md

View File

@ -38,7 +38,8 @@ class Manual extends GuiScreen {
protected var scrollButton: ImageButton = _
def loadPage(path: String): Iterator[String] = {
def loadPage(path: String, seen: List[String] = List.empty): Iterator[String] = {
if (seen.contains(path)) return Iterator("Redirection loop: ") ++ seen.iterator ++ Iterator(path)
val location = new ResourceLocation(Settings.resourceDomain, if (path.startsWith("/")) path else "doc/" + path)
var is: InputStream = null
try {
@ -46,7 +47,11 @@ class Manual extends GuiScreen {
is = resource.getInputStream
// Force resolving immediately via toArray, otherwise we return a read
// iterator on a closed input stream (because of the finally).
Source.fromInputStream(is)(Charsets.UTF_8).getLines().toArray.iterator
val lines = Source.fromInputStream(is)(Charsets.UTF_8).getLines().toArray
lines.headOption match {
case Some(line) if line.toLowerCase.startsWith("#redirect ") => loadPage(line.substring("#redirect ".length), seen :+ path)
case _ => lines.iterator
}
}
catch {
case t: Throwable =>

View File

@ -1,14 +1,39 @@
package li.cil.oc.common.item
import li.cil.oc.OpenComputers
import li.cil.oc.api
import li.cil.oc.client.gui
import li.cil.oc.common.GuiType
import li.cil.oc.common.block.SimpleBlock
import li.cil.oc.util.BlockPosition
import li.cil.oc.util.ExtendedWorld._
import net.minecraft.client.Minecraft
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.world.World
class Manual(val parent: Delegator) extends Delegate {
override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer): ItemStack = {
player.openGui(OpenComputers, GuiType.Manual.id, world, 0, 0, 0)
if (world.isRemote) {
player.openGui(OpenComputers, GuiType.Manual.id, world, 0, 0, 0)
}
super.onItemRightClick(stack, world, player)
}
override def onItemUse(stack: ItemStack, player: EntityPlayer, position: BlockPosition, side: Int, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
val world = player.getEntityWorld
world.getBlock(position) match {
case block: SimpleBlock =>
if (world.isRemote) {
player.openGui(OpenComputers, GuiType.Manual.id, world, 0, 0, 0)
Minecraft.getMinecraft.currentScreen match {
case manual: gui.Manual =>
manual.pushPage(api.Items.get(new ItemStack(block)).name + ".md")
case _ =>
}
}
true
case _ => super.onItemUse(stack, player, position, side, hitX, hitY, hitZ)
}
}
}

View File

@ -27,7 +27,6 @@ import scala.collection.convert.WrapAsScala._
import scala.collection.mutable
import scala.util.matching.Regex
/**
* Primitive Markdown parser, only supports a very small subset. Used for
* parsing documentation into segments, to be displayed in a GUI somewhere.