From 527246bbff2939ca2186dc15a0b06cf648e0edd5 Mon Sep 17 00:00:00 2001 From: Vamist Date: Wed, 2 Dec 2020 20:53:12 +0000 Subject: [PATCH] Moved CharacterHandler to a different file to temp fix rebuild --- CoreScripts/Character/BlobCharacter.as | 120 ++++++++++++++++++++++++- CoreScripts/Rules/CharacterHandler.as | 1 + 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/CoreScripts/Character/BlobCharacter.as b/CoreScripts/Character/BlobCharacter.as index f8fc822..2d29f8b 100644 --- a/CoreScripts/Character/BlobCharacter.as +++ b/CoreScripts/Character/BlobCharacter.as @@ -1,4 +1,122 @@ -#include "CharacterCore" +//#include "CharacterCore" + + +mixin class Character +{ + dictionary ResponseMap = dictionary(); + + // Maybe you want this character to have a custom font + string PreferedFont = "Menu"; + // Custom character name + string CharacterName = ""; + + // Text that is currently on the screen + string CurrentRenderText = ""; + // The whole text that is being written to ^ + string CurrentText = ""; + // How fast should we write (needs changing) + int WriteSpeed = 1; + // Are we done writing? + bool FinishedWriting = false; + + void SetName(string name) + { + CharacterName = name; + } + + void AddResponse(string eventName, string text) + { + ResponseMap.set(eventName, text); + } + + string getResponse(string eventName) + { + string text = ""; + ResponseMap.get(eventName, text); + return text; + } + + void GetResponse(string eventName, string &out text) + { + ResponseMap.get(eventName, text); + } + + void SetCurrentResponse(string eventName, int textSpeed = 1) + { + FinishedWriting = false; + CurrentText = getResponse(eventName); + WriteSpeed = textSpeed; + } + + void SetPreferedFont(string name) + { + PreferedFont = name; + } + + const string getName() + { + return CharacterName; + } + + void UpdateText() + { + if (getGameTime() % WriteSpeed == 0) + { + string char = CurrentText.substr(CurrentRenderText.length, 1); + + // Grab the full token so users dont see a part of it when reading + if (char == '$') + { + for (int a = CurrentRenderText.length + 1; a < CurrentText.length; a++) + { + string currentchar = CurrentText.substr(a, 1); + char += currentchar; + + if (currentchar == "$") + { + // Add in the next char so adding a token doesnt waste a text update + char += CurrentText.substr(a + 1, 1); + break; + } + } + } + else if (char != ' ') // TODO -> Set custom audio and sort out what we are doing with audio + { + Sound::Play("Archer_blip" + (XORRandom(1) == 0 ? "_2" : "")); + } + + CurrentRenderText += char; + + if (CurrentRenderText.length == CurrentText.length) + FinishedWriting = true; + } + } + + // TODO -> Sort this junk out, clear our sHeight and sWidth n stuff + void RenderBox() + { + GUI::SetFont(PreferedFont); + int sHeight = getDriver().getScreenHeight(); + int sWidth = getDriver().getScreenWidth(); + + int leftX = sWidth / 6; + int topY = sHeight - (sHeight / 2.5); + int hardValue = 100; + GUI::DrawFramedPane(Vec2f(leftX, topY), Vec2f(leftX + hardValue, topY + hardValue)); + + leftX += hardValue; + GUI::DrawRectangle(Vec2f(leftX, topY), Vec2f(leftX + hardValue + 500, topY + hardValue), SColor(150,0,0,0)); + GUI::DrawText(CurrentRenderText, Vec2f(leftX + 25, topY + 10), Vec2f(leftX + hardValue + 475, topY + hardValue), SColor(255, 255, 255, 255), false, false, false); + } +} + + +// Chat box used for global chat +// Not in use yet, will finish later on +class GlobalCharacter : Character +{ + +} class BlobCharacter : Character { diff --git a/CoreScripts/Rules/CharacterHandler.as b/CoreScripts/Rules/CharacterHandler.as index 54f32b6..fc3a11d 100644 --- a/CoreScripts/Rules/CharacterHandler.as +++ b/CoreScripts/Rules/CharacterHandler.as @@ -21,6 +21,7 @@ void onRestart(CRules@ this) void onReload(CRules@ this) { + print("hi"); if (Handler !is null) Handler.Clear(); -- knotmirror 0.0.1