mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 18:30:27 -04:00
Links work, basic navigation is in place.
This commit is contained in:
parent
61f2eb268d
commit
d49bb94e56
4
src/main/resources/assets/opencomputers/doc/adapter.md
Normal file
4
src/main/resources/assets/opencomputers/doc/adapter.md
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Adapter
|
||||||
|

|
||||||
|
|
||||||
|
The Adapter is at the core of most of OpenComputers' mod integration.
|
@ -4,7 +4,7 @@ This is some test text for the subset of Markdown supported by the planned ingam
|
|||||||

|

|
||||||
*This* is *italic* text, ~~strikethrough~~ maybe abc-ter **some** text **in bold**. Is _this underlined_? Oh, no, _it's also italic!_ Well, this [a link](blah).
|
*This* is *italic* text, ~~strikethrough~~ maybe abc-ter **some** text **in bold**. Is _this underlined_? Oh, no, _it's also italic!_ Well, this [a link](blah).
|
||||||

|

|
||||||
## Smaller headline [also with *link* but this __one__ longer](huehue)
|
## Smaller headline [also with *link* but this __one__ longer](adapter.md)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package li.cil.oc.client.gui
|
package li.cil.oc.client.gui
|
||||||
|
|
||||||
|
import java.io.InputStream
|
||||||
import java.util
|
import java.util
|
||||||
|
|
||||||
import com.google.common.base.Charsets
|
import com.google.common.base.Charsets
|
||||||
@ -14,6 +15,7 @@ import net.minecraft.util.ResourceLocation
|
|||||||
import org.lwjgl.input.Mouse
|
import org.lwjgl.input.Mouse
|
||||||
|
|
||||||
import scala.collection.convert.WrapAsJava._
|
import scala.collection.convert.WrapAsJava._
|
||||||
|
import scala.collection.mutable
|
||||||
import scala.io.Source
|
import scala.io.Source
|
||||||
|
|
||||||
class Manual extends GuiScreen {
|
class Manual extends GuiScreen {
|
||||||
@ -24,6 +26,8 @@ class Manual extends GuiScreen {
|
|||||||
var offset = 0
|
var offset = 0
|
||||||
var document = Iterable.empty[PseudoMarkdown.Segment]
|
var document = Iterable.empty[PseudoMarkdown.Segment]
|
||||||
var documentHeight = 0
|
var documentHeight = 0
|
||||||
|
var history = mutable.Stack("index.md")
|
||||||
|
var hoveredLink = None: Option[String]
|
||||||
final val documentMaxWidth = 230
|
final val documentMaxWidth = 230
|
||||||
final val documentMaxHeight = 176
|
final val documentMaxHeight = 176
|
||||||
final val scrollPosX = 244
|
final val scrollPosX = 244
|
||||||
@ -34,10 +38,43 @@ class Manual extends GuiScreen {
|
|||||||
|
|
||||||
protected var scrollButton: ImageButton = _
|
protected var scrollButton: ImageButton = _
|
||||||
|
|
||||||
def loadPage(location: ResourceLocation): Iterator[String] = {
|
def loadPage(path: String): Iterator[String] = {
|
||||||
val resource = Minecraft.getMinecraft.getResourceManager.getResource(location)
|
val location = new ResourceLocation(Settings.resourceDomain, if (path.startsWith("/")) path else "doc/" + path)
|
||||||
val is = resource.getInputStream
|
var is: InputStream = null
|
||||||
Source.fromInputStream(is)(Charsets.UTF_8).getLines()
|
try {
|
||||||
|
val resource = Minecraft.getMinecraft.getResourceManager.getResource(location)
|
||||||
|
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
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
case t: Throwable =>
|
||||||
|
Iterator(s"Failed loading page '$path':") ++ t.toString.lines
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Option(is).foreach(_.close())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def refreshPage(): Unit = {
|
||||||
|
document = PseudoMarkdown.parse(loadPage(history.top))
|
||||||
|
documentHeight = PseudoMarkdown.height(document, documentMaxWidth, fontRendererObj)
|
||||||
|
scrollTo(offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
def pushPage(path: String): Unit = {
|
||||||
|
history.push(path)
|
||||||
|
scrollTo(0)
|
||||||
|
refreshPage()
|
||||||
|
}
|
||||||
|
|
||||||
|
def popPage(): Unit = {
|
||||||
|
if (history.size > 1) {
|
||||||
|
history.pop()
|
||||||
|
scrollTo(0)
|
||||||
|
refreshPage()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def doesGuiPauseGame = false
|
override def doesGuiPauseGame = false
|
||||||
@ -53,9 +90,7 @@ class Manual extends GuiScreen {
|
|||||||
guiTop = midY - guiSize.getScaledHeight / 2
|
guiTop = midY - guiSize.getScaledHeight / 2
|
||||||
xSize = guiSize.getScaledWidth
|
xSize = guiSize.getScaledWidth
|
||||||
ySize = guiSize.getScaledHeight
|
ySize = guiSize.getScaledHeight
|
||||||
offset = 0
|
refreshPage()
|
||||||
document = PseudoMarkdown.parse(loadPage(new ResourceLocation(Settings.resourceDomain, "doc/index.md")))
|
|
||||||
documentHeight = PseudoMarkdown.height(document, documentMaxWidth, fontRendererObj)
|
|
||||||
|
|
||||||
scrollButton = new ImageButton(1, guiLeft + scrollPosX, guiTop + scrollPosY, 6, 13, Textures.guiButtonScroll)
|
scrollButton = new ImageButton(1, guiLeft + scrollPosX, guiTop + scrollPosY, 6, 13, Textures.guiButtonScroll)
|
||||||
add(buttonList, scrollButton)
|
add(buttonList, scrollButton)
|
||||||
@ -68,10 +103,12 @@ class Manual extends GuiScreen {
|
|||||||
super.drawScreen(mouseX, mouseY, dt)
|
super.drawScreen(mouseX, mouseY, dt)
|
||||||
|
|
||||||
PseudoMarkdown.render(document, guiLeft + 8, guiTop + 8, documentMaxWidth, documentMaxHeight, offset, fontRendererObj, mouseX, mouseY) match {
|
PseudoMarkdown.render(document, guiLeft + 8, guiTop + 8, documentMaxWidth, documentMaxHeight, offset, fontRendererObj, mouseX, mouseY) match {
|
||||||
case Some(segment) => segment.tooltip match {
|
case Some(segment) =>
|
||||||
case Some(text) if text.nonEmpty => drawHoveringText(seqAsJavaList(text.lines.toSeq), mouseX, mouseY, fontRendererObj)
|
segment.tooltip match {
|
||||||
case _ =>
|
case Some(text) if text.nonEmpty => drawHoveringText(seqAsJavaList(text.lines.toSeq), mouseX, mouseY, fontRendererObj)
|
||||||
}
|
case _ =>
|
||||||
|
}
|
||||||
|
hoveredLink = segment.link
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,6 +121,19 @@ class Manual extends GuiScreen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def mouseClicked(mouseX: Int, mouseY: Int, button: Int): Unit = {
|
||||||
|
super.mouseClicked(mouseX, mouseY, button)
|
||||||
|
|
||||||
|
if (button == 0) {
|
||||||
|
// Left click, did we hit a link?
|
||||||
|
hoveredLink.foreach(link => pushPage(link))
|
||||||
|
}
|
||||||
|
else if (button == 1) {
|
||||||
|
// Right mouseclick = back.
|
||||||
|
popPage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private def scrollUp() = scrollTo(offset - PseudoMarkdown.lineHeight(fontRendererObj) * 3)
|
private def scrollUp() = scrollTo(offset - PseudoMarkdown.lineHeight(fontRendererObj) * 3)
|
||||||
|
|
||||||
private def scrollDown() = scrollTo(offset + PseudoMarkdown.lineHeight(fontRendererObj) * 3)
|
private def scrollDown() = scrollTo(offset + PseudoMarkdown.lineHeight(fontRendererObj) * 3)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user