From 39aaed5577eff940876ce50bdbe0a3640c6142c5 Mon Sep 17 00:00:00 2001
From: JappaWakka <jjlspeelman@outlook.com>
Date: Tue, 19 Oct 2021 23:55:26 +0200
Subject: [PATCH] Made <system.token(str_tokenname)> and
 <system.button(str_buttonname)> constructs

---
 P3D/Dialogues/TextBox.vb                      | 14 ----
 P3D/HelperClasses/Localization.vb             | 65 -------------------
 .../V2/ScriptConstructs/DoSystem.vb           | 64 ++++++++++++++++++
 3 files changed, 64 insertions(+), 79 deletions(-)

diff --git a/P3D/Dialogues/TextBox.vb b/P3D/Dialogues/TextBox.vb
index 7aa745a13..c822a0e17 100644
--- a/P3D/Dialogues/TextBox.vb
+++ b/P3D/Dialogues/TextBox.vb
@@ -99,20 +99,6 @@
     End Sub
 
     Private Sub FormatText()
-        Dim tokenSearchBuffer As String() = Me.Text.Split(CChar("<token."))
-        Dim tokenEndIdx As Integer = 0
-        Dim validToken As String = ""
-        Dim token As Token = Nothing
-        For Each possibleToken As String In tokenSearchBuffer
-            tokenEndIdx = possibleToken.IndexOf(">")
-            If Not tokenEndIdx = -1 Then
-                validToken = possibleToken.Substring(0, tokenEndIdx)
-                If Localization.LocalizationTokens.ContainsKey(validToken) = True Then
-                    Me.Text = Me.Text.Replace("<token." & validToken & ">", Localization.GetString(validToken, validToken))
-                End If
-            End If
-        Next
-
         Me.Text = Me.Text.Replace("<playername>", Core.Player.Name)
         Me.Text = Me.Text.Replace("<player.name>", Core.Player.Name)
 
diff --git a/P3D/HelperClasses/Localization.vb b/P3D/HelperClasses/Localization.vb
index 56fa69010..c52cb5312 100644
--- a/P3D/HelperClasses/Localization.vb
+++ b/P3D/HelperClasses/Localization.vb
@@ -116,71 +116,6 @@
                     result = result.Replace("<rivalname>", Core.Player.RivalName)
                     result = result.Replace("<player.name>", Core.Player.RivalName)
                 End If
-
-                Dim tokenSearchBuffer As String() = result.Split("<button.")
-                Dim tokenEndIdx As Integer = 0
-                Dim validToken As String = ""
-                For Each possibleToken As String In tokenSearchBuffer
-                    tokenEndIdx = possibleToken.IndexOf(">")
-                    If Not tokenEndIdx = -1 Then
-                        Dim key As Keys
-                        validToken = possibleToken.Substring(0, tokenEndIdx)
-                        Select Case validToken.ToLower()
-                            Case "moveforward"
-                                key = KeyBindings.ForwardMoveKey
-                            Case "moveleft"
-                                key = KeyBindings.LeftMoveKey
-                            Case "movebackward"
-                                key = KeyBindings.BackwardMoveKey
-                            Case "moveright"
-                                key = KeyBindings.RightMoveKey
-                            Case "openmenu"
-                                key = KeyBindings.OpenInventoryKey
-                            Case "chat"
-                                key = KeyBindings.ChatKey
-                            Case "special", "phone"
-                                key = KeyBindings.SpecialKey
-                            Case "muteaudio"
-                                key = KeyBindings.MuteAudioKey
-                            Case "cameraleft"
-                                key = KeyBindings.LeftKey
-                            Case "cameraright"
-                                key = KeyBindings.RightKey
-                            Case "cameraup"
-                                key = KeyBindings.UpKey
-                            Case "cameradown"
-                                key = KeyBindings.DownKey
-                            Case "cameralock"
-                                key = KeyBindings.CameraLockKey
-                            Case "guicontrol"
-                                key = KeyBindings.GUIControlKey
-                            Case "screenshot"
-                                key = KeyBindings.ScreenshotKey
-                            Case "debugcontrol"
-                                key = KeyBindings.DebugKey
-                            Case "perspectiveswitch"
-                                key = KeyBindings.PerspectiveSwitchKey
-                            Case "fullscreen"
-                                key = KeyBindings.FullScreenKey
-                            Case "enter1"
-                                key = KeyBindings.EnterKey1
-                            Case "enter2"
-                                key = KeyBindings.EnterKey2
-                            Case "back1"
-                                key = KeyBindings.BackKey1
-                            Case "back2"
-                                key = KeyBindings.BackKey2
-                            Case "escape", "esc"
-                                key = KeyBindings.EscapeKey
-                            Case "onlinestatus"
-                                key = KeyBindings.OnlineStatusKey
-                            Case "lighting"
-                                key = KeyBindings.LightKey
-                        End Select
-                        result = result.Replace("<button." & validToken & ">", KeyBindings.GetKeyName(key))
-                    End If
-                Next
-
                 Return result
             End If
         Else
diff --git a/P3D/World/ActionScript/V2/ScriptConstructs/DoSystem.vb b/P3D/World/ActionScript/V2/ScriptConstructs/DoSystem.vb
index c31ab846a..2aa798b9b 100644
--- a/P3D/World/ActionScript/V2/ScriptConstructs/DoSystem.vb
+++ b/P3D/World/ActionScript/V2/ScriptConstructs/DoSystem.vb
@@ -11,6 +11,70 @@
             Dim argument As String = GetSubClassArgumentPair(subClass).Argument
 
             Select Case command.ToLower()
+                Case "token"
+                    Dim tokenName As String = Localization.GetString(argument)
+                    Return tokenName
+                Case "button"
+                    Dim key As Keys = Nothing
+                    Dim buttonName As String = argument
+                    Select Case buttonName.ToLower()
+                        Case "moveforward"
+                            key = KeyBindings.ForwardMoveKey
+                        Case "moveleft"
+                            key = KeyBindings.LeftMoveKey
+                        Case "movebackward"
+                            key = KeyBindings.BackwardMoveKey
+                        Case "moveright"
+                            key = KeyBindings.RightMoveKey
+                        Case "openmenu"
+                            key = KeyBindings.OpenInventoryKey
+                        Case "chat"
+                            key = KeyBindings.ChatKey
+                        Case "special", "phone"
+                            key = KeyBindings.SpecialKey
+                        Case "muteaudio"
+                            key = KeyBindings.MuteAudioKey
+                        Case "cameraleft"
+                            key = KeyBindings.LeftKey
+                        Case "cameraright"
+                            key = KeyBindings.RightKey
+                        Case "cameraup"
+                            key = KeyBindings.UpKey
+                        Case "cameradown"
+                            key = KeyBindings.DownKey
+                        Case "cameralock"
+                            key = KeyBindings.CameraLockKey
+                        Case "guicontrol"
+                            key = KeyBindings.GUIControlKey
+                        Case "screenshot"
+                            key = KeyBindings.ScreenshotKey
+                        Case "debugcontrol"
+                            key = KeyBindings.DebugKey
+                        Case "perspectiveswitch"
+                            key = KeyBindings.PerspectiveSwitchKey
+                        Case "fullscreen"
+                            key = KeyBindings.FullScreenKey
+                        Case "enter1"
+                            key = KeyBindings.EnterKey1
+                        Case "enter2"
+                            key = KeyBindings.EnterKey2
+                        Case "back1"
+                            key = KeyBindings.BackKey1
+                        Case "back2"
+                            key = KeyBindings.BackKey2
+                        Case "escape", "esc"
+                            key = KeyBindings.EscapeKey
+                        Case "onlinestatus"
+                            key = KeyBindings.OnlineStatusKey
+                        Case "lighting"
+                            key = KeyBindings.LightKey
+                        Case "hidegui"
+                            key = KeyBindings.GUIControlKey
+                    End Select
+                    If key <> Nothing Then
+                        buttonName = KeyBindings.GetKeyName(key)
+                    End If
+                    Return buttonName
                 Case "random"
                     Dim minRange As Integer = 1
                     Dim maxRange As Integer = 2