From bf9a41e1d2550f491027684d4668d23472425be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 8 Apr 2015 14:42:41 +0200 Subject: [PATCH] Added support for http links. --- .../assets/opencomputers/lang/de_DE.lang | 1 + .../assets/opencomputers/lang/en_US.lang | 1 + src/main/scala/li/cil/oc/Localization.scala | 2 ++ .../scala/li/cil/oc/client/gui/Manual.scala | 19 ++++++++++++++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/resources/assets/opencomputers/lang/de_DE.lang b/src/main/resources/assets/opencomputers/lang/de_DE.lang index dd4b0eec1..ba449824e 100644 --- a/src/main/resources/assets/opencomputers/lang/de_DE.lang +++ b/src/main/resources/assets/opencomputers/lang/de_DE.lang @@ -171,6 +171,7 @@ oc:gui.Chat.NewVersion=Eine neue Version ist verfügbar: %s oc:gui.Chat.TextureName=§7Texturname ist §a%s§f. oc:gui.Chat.WarningClassTransformer=Es gab §cFehler§f beim Ausführen des Class-Transformers. Bitte melde dies, zusammen mit deiner (vollständigen!) FML §alatest.log§f/§afml-server-latest.log§f Log-Datei, danke! oc:gui.Chat.WarningFingerprint=§cWARNUNG§f - ungültige Signatur! Sollte '§a%s§f' sein, aber war '§e%s§f'. Falls du kein Modder bist und die "deobfuscated"-Version des Mods benutzt, solltest du OpenComputers erneut herunterladen, da die JAR, die du benutzt, vermutlich modifiziert wurde. +oc:gui.Chat.WarningLink=Link konnte nicht geöffnet werden: %s oc:gui.Chat.WarningLuaFallback=Die native Lua-Implementierung ist nicht verfügbar. Computer können ihren Ausführungszustand nicht speichern. Sie werden automatisch neu starten, sobald ein Chunk neu geladen wird. oc:gui.Chat.WarningPower=Es ist keine unterstützte, Strom erzeugende Mod verfügbar. Computer, Bildschirme und alle anderen Komponenten werden §lkeine§f Energie benötigen. Installiere eine der folgenden Mods, um Stromnutzung zu ermöglichen: BuildCraft, Electrical Age, IndustrialCraft2, Mekanism oder Thermal Expansion. Deaktiviere Stromverbrauch in der Konfiguration, um diese Warnung zu unterdrücken. oc:gui.Chat.WarningProjectRed=Die verwendete Version von Project: Red ist nicht mit OpenComputers kompatibel. Aktualisiere bitte deine Version von Project: Red. diff --git a/src/main/resources/assets/opencomputers/lang/en_US.lang b/src/main/resources/assets/opencomputers/lang/en_US.lang index a8ad28c8f..a4b89831d 100644 --- a/src/main/resources/assets/opencomputers/lang/en_US.lang +++ b/src/main/resources/assets/opencomputers/lang/en_US.lang @@ -171,6 +171,7 @@ oc:gui.Chat.NewVersion=A new version is available: %s oc:gui.Chat.TextureName=§7Texture name is §a%s§f. oc:gui.Chat.WarningClassTransformer=There were §cerrors§f running the class transformer. Please report this, together with your (full!) FML §alatest.log§f/§afml-server-latest.log§f logfile, thank you! oc:gui.Chat.WarningFingerprint=§cWARNING§f - fingerprint mismatch! Expected '§a%s§f' but got '§e%s§f'. Unless you are a modder and are running the deobfuscated version of the mod, it is §lstrongly§f recommended to redownload OpenComputers, because the JAR you are using may have been tampered with. +oc:gui.Chat.WarningLink=Could not open link: %s oc:gui.Chat.WarningLuaFallback=Native Lua libraries are not available, computers will not be able to persist their state. They will reboot on chunk reloads. oc:gui.Chat.WarningPower=No supported power providing mod available. Computers, screens and all other components will §lnot§f require energy. Install one of the following mods to enable power: BuildCraft, Electrical Age, IndustrialCraft2, Mekanism or Thermal Expansion. Disable power in the config to suppress this warning. oc:gui.Chat.WarningProjectRed=You are using a version of Project: Red that is incompatible with OpenComputers. Try updating your version of Project: Red. diff --git a/src/main/scala/li/cil/oc/Localization.scala b/src/main/scala/li/cil/oc/Localization.scala index 917eb0a87..26f01224a 100644 --- a/src/main/scala/li/cil/oc/Localization.scala +++ b/src/main/scala/li/cil/oc/Localization.scala @@ -89,6 +89,8 @@ object Localization { def WarningSimpleComponent = new ChatComponentText("§aOpenComputers§f: ").appendSibling(localizeLater("gui.Chat.WarningSimpleComponent")) + def WarningLink(url: String) = new ChatComponentText("§aOpenComputers§f: ").appendSibling(localizeLater("gui.Chat.WarningLink", url)) + def InfoNewVersion(version: String) = new ChatComponentText("§aOpenComputers§f: ").appendSibling(localizeLater("gui.Chat.NewVersion", version)) def TextureName(name: String) = new ChatComponentText("§aOpenComputers§f: ").appendSibling(localizeLater("gui.Chat.TextureName", name)) 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 159202208..3963c444b 100644 --- a/src/main/scala/li/cil/oc/client/gui/Manual.scala +++ b/src/main/scala/li/cil/oc/client/gui/Manual.scala @@ -1,9 +1,11 @@ package li.cil.oc.client.gui import java.io.InputStream +import java.net.URI import java.util import com.google.common.base.Charsets +import li.cil.oc.Localization import li.cil.oc.Settings import li.cil.oc.client.Textures import li.cil.oc.util.PseudoMarkdown @@ -146,7 +148,10 @@ class Manual extends GuiScreen { } else if (button == 0) { // Left click, did we hit a link? - hoveredLink.foreach(link => pushPage(link)) + hoveredLink.foreach(link => { + if (link.startsWith("http://") || link.startsWith("https://")) handleUrl(link) + else pushPage(link) + }) } else if (button == 1) { // Right mouseclick = back. @@ -154,6 +159,18 @@ class Manual extends GuiScreen { } } + private def handleUrl(url: String): Unit = { + // Pretty much copy-paste from GuiChat. + try { + val desktop = Class.forName("java.awt.Desktop") + val instance = desktop.getMethod("getDesktop").invoke(null) + desktop.getMethod("browse", classOf[URI]).invoke(instance, new URI(url)) + } + catch { + case t: Throwable => Minecraft.getMinecraft.thePlayer.addChatMessage(Localization.Chat.WarningLink(t.toString)) + } + } + override protected def mouseClickMove(mouseX: Int, mouseY: Int, lastButtonClicked: Int, timeSinceMouseClick: Long) { super.mouseClickMove(mouseX, mouseY, lastButtonClicked, timeSinceMouseClick) if (isDragging) {