From bfe7779e1e987ec458cb5481fcb8e5b24ad0b0d2 Mon Sep 17 00:00:00 2001 From: Vamist Date: Thu, 3 Dec 2020 23:35:31 +0000 Subject: [PATCH] current messy progress - dear god help me --- CoreScripts/Character/BlobCharacter.as | 20 +++++- CoreScripts/Rules/CharacterHandler.as | 94 +++++++++++++++++++++++--- Maps/KnightShowcase/KnightShowcase.as | 2 +- 3 files changed, 104 insertions(+), 12 deletions(-) diff --git a/CoreScripts/Character/BlobCharacter.as b/CoreScripts/Character/BlobCharacter.as index 2d29f8b..3287721 100644 --- a/CoreScripts/Character/BlobCharacter.as +++ b/CoreScripts/Character/BlobCharacter.as @@ -113,14 +113,17 @@ mixin class Character // Chat box used for global chat // Not in use yet, will finish later on -class GlobalCharacter : Character +/*class GlobalCharacter : Character { -} +}*/ class BlobCharacter : Character { CBlob@ OwnerBlob; + + Vertex[] PortraitVertex; + BlobCharacter(CBlob@ owner, string name) { @OwnerBlob = owner; @@ -129,13 +132,24 @@ class BlobCharacter : Character void TempCharacterBind() { + return; int sHeight = getDriver().getScreenHeight(); int sWidth = getDriver().getScreenWidth(); int leftX = sWidth / 6; int topY = sHeight - (sHeight / 2.5); int hardValue = 100; - GUI::DrawIcon("GetiTest.png", 0, Vec2f(12,12), Vec2f(leftX + 5,topY + 5), 3.8f, SColor(150, 255, 255, 255)); + + PortraitVertex.clear(); + + PortraitVertex.push_back(Vertex(leftX, topY, 0, 0, 0, color_white)); // top left + PortraitVertex.push_back(Vertex(leftX + hardValue, topY, 0, 1, 0, color_white)); // top right + PortraitVertex.push_back(Vertex(leftX + hardValue, topY + hardValue, 0, 1, 1, color_white)); // bot right + PortraitVertex.push_back(Vertex(leftX, topY + hardValue, 0, 0, 1, color_white)); // bot left + + Render::SetTransformScreenspace(); + Render::SetAlphaBlend(true); + Render::RawQuads("GetiTest.png", PortraitVertex); } } diff --git a/CoreScripts/Rules/CharacterHandler.as b/CoreScripts/Rules/CharacterHandler.as index fc3a11d..a64fedf 100644 --- a/CoreScripts/Rules/CharacterHandler.as +++ b/CoreScripts/Rules/CharacterHandler.as @@ -2,6 +2,9 @@ BlobCharacterHandler@ Handler; +Vertex[] PortraitVertex; +int id = 0; + // In localhost, this executes before CMap onInit does void onInit(CRules@ this) { @@ -9,6 +12,8 @@ void onInit(CRules@ this) // The blob network ID will need to be sent as well. this.addCommandID("character_bound"); onRestart(this); + + id = Render::addScript(Render::layer_posthud, "CharacterHandler.as", "newRender", 10.0f); } void onRestart(CRules@ this) @@ -21,7 +26,8 @@ void onRestart(CRules@ this) void onReload(CRules@ this) { - print("hi"); + Render::RemoveScript(id); + if (Handler !is null) Handler.Clear(); @@ -42,22 +48,39 @@ void onReload(CRules@ this) if (char is null) continue; - Handler.AddCharacter(char); + Handler.AddCharacter(BlobCharacter(char)); } // End + + id = Render::addScript(Render::layer_posthud, "CharacterHandler.as", "newRender", 10.0f); } -void onTick(CRules@ this) +void SetUp() { - if (Handler !is null) - Handler.onTick(); + CBlob@ local = getLocalPlayerBlob(); + if (local !is null && !Texture::exists("owohead")) + { + CSpriteLayer@ layer = local.getSprite().getSpriteLayer("head"); + if (layer is null) + { + print("hi"); + return; + } + + ImageData@ data = Texture::dataFromSpriteLayer(null); + + if (data !is null) + Texture::createFromData("owohead", data); + } } -void onRender(CRules@ this) +void onTick(CRules@ this) { + SetUp(); + if (Handler !is null) - Handler.onRender(); + Handler.onTick(); } void onCommand(CRules@ this, u8 cmd, CBitStream@ params) @@ -75,4 +98,59 @@ void onCommand(CRules@ this, u8 cmd, CBitStream@ params) Handler.AddCharacter(blob); } -} \ No newline at end of file +} + +// onRender but also useful for character portait stuff +void newRender(int id) +{ + if (Handler !is null) + Handler.onRender(); + + CBlob@ local = getLocalPlayerBlob(); + + if (local is null || local.getSprite() is null) + return; + + + s32 index = local.get_s32("head index"); + s32 team = local.get_s32("head team"); + string texture_file = local.get_string("head texture"); + + + int sHeight = getDriver().getScreenHeight(); + int sWidth = getDriver().getScreenWidth(); + + int leftX = sWidth / 6; + int topY = sHeight - (sHeight / 2.5); + int hardValue = 100; + + int something = 0.035; + int pos = 0.035 * index; + + PortraitVertex.clear(); + PortraitVertex.push_back(Vertex(leftX, topY, 0, 0, 0, color_white)); // top left + PortraitVertex.push_back(Vertex(leftX + hardValue, topY, 0, 1, 0, color_white)); // top right + PortraitVertex.push_back(Vertex(leftX + hardValue, topY + hardValue, 0, 1, 1, color_white)); // bot right + PortraitVertex.push_back(Vertex(leftX, topY + hardValue, 0, 0, 1, color_white)); // bot left + + Render::SetTransformScreenspace(); + Render::SetAlphaBlend(true); + Render::RawQuads("GetiTest.png", PortraitVertex); + + PortraitVertex.clear(); + + PortraitVertex.push_back(Vertex(leftX, topY, 0, 0, 0, color_white)); // top left + PortraitVertex.push_back(Vertex(leftX + hardValue, topY, 0, 1, 0, color_white)); // top right + PortraitVertex.push_back(Vertex(leftX + hardValue, topY + hardValue, 0, 1, 1, color_white)); // bot right + PortraitVertex.push_back(Vertex(leftX, topY + hardValue, 0, 0, 1, color_white)); // bot left + + Render::SetTransformScreenspace(); + Render::SetAlphaBlend(true); + Render::RawQuads("owohead", PortraitVertex); +} + +/// First task + +// -> get blob frame +// -> find a way to calc what part of the frame we are using +// -> display one of the 3 indexs \ No newline at end of file diff --git a/Maps/KnightShowcase/KnightShowcase.as b/Maps/KnightShowcase/KnightShowcase.as index 620b0a2..2e12c64 100644 --- a/Maps/KnightShowcase/KnightShowcase.as +++ b/Maps/KnightShowcase/KnightShowcase.as @@ -28,4 +28,4 @@ void onTick(CMap@ map) { //SpawnInCharacter("archer", 0, Vec2f(538, 560), "archer"); } -} \ No newline at end of file +} -- knotmirror 0.0.1