mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-12 16:57:32 -04:00
Open page of clicked blocks. Redirects, e.g. for blocks with tiers.
This commit is contained in:
parent
38a6b626e9
commit
e44b65b986
@ -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.
|
||||

|
||||
|
1
src/main/resources/assets/opencomputers/doc/redirect1.md
Normal file
1
src/main/resources/assets/opencomputers/doc/redirect1.md
Normal file
@ -0,0 +1 @@
|
||||
#redirect redirect2.md
|
1
src/main/resources/assets/opencomputers/doc/redirect2.md
Normal file
1
src/main/resources/assets/opencomputers/doc/redirect2.md
Normal file
@ -0,0 +1 @@
|
||||
#REDIRECT redirect1.md
|
4
src/main/resources/assets/opencomputers/doc/screen1.md
Normal file
4
src/main/resources/assets/opencomputers/doc/screen1.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Screen
|
||||

|
||||
|
||||
Screens! Magic! Stuff.
|
1
src/main/resources/assets/opencomputers/doc/screen2.md
Normal file
1
src/main/resources/assets/opencomputers/doc/screen2.md
Normal file
@ -0,0 +1 @@
|
||||
#REDIRECT screen1.md
|
1
src/main/resources/assets/opencomputers/doc/screen3.md
Normal file
1
src/main/resources/assets/opencomputers/doc/screen3.md
Normal file
@ -0,0 +1 @@
|
||||
#REDIRECT screen1.md
|
@ -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 =>
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user