Skip to content

Commit

Permalink
Merge pull request #70 from PringlesGang/cclcc-wait-icon
Browse files Browse the repository at this point in the history
C;CLCC wait icon
  • Loading branch information
KKhanhH authored Oct 11, 2024
2 parents e006a4e + 42524be commit d42532e
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 99 deletions.
2 changes: 1 addition & 1 deletion profiles/cclcc/dialogue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ root.Dialogue = {
WaitIconCurrentType = WaitIconType.SpriteAnimFixed,
WaitIconSpriteAnim = "WaitIconSpriteAnim",
WaitIconAnimationDuration = 0.7,
WaitIconOffset = { X = 1624, Y = 955 },
WaitIconOffset = { X = 1595, Y = 895 },
WaitIconFixedSpriteId = 6,
AutoIconCurrentType = AutoIconType.SpriteAnimFixed,
AutoIconSpriteAnim = "AutoIconSpriteAnim",
Expand Down
1 change: 1 addition & 0 deletions profiles/common/scriptvars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ root.ScriptVars = {
SF_TITLEMODE=1240,
SF_TITLEEND=1241,
SF_UIHIDDEN=1244,
SF_SHOWWAITICON=1251,
SF_LOADING=1264,
SF_SYSMENUDISABLE=1286,
SF_SYSTEMMENUDISABLE=1221, -- i don't know SYS and SYSTEM exists
Expand Down
198 changes: 125 additions & 73 deletions src/hud/waiticondisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "waiticondisplay.h"

#include "../profile/dialogue.h"
#include "../renderer/renderer.h"
#include "../profile/dialogue.h"
#include "../profile/scriptvars.h"
#include "../profile/games/chlcc/dialoguebox.h"

#include "../animation.h"

namespace Impacto {
namespace WaitIconDisplay {

Expand All @@ -15,87 +18,136 @@ using namespace Impacto::Profile::Dialogue;
using namespace Impacto::Profile::CHLCC;

void Init() {
if (WaitIconCurrentType == +WaitIconType::SpriteAnim) {
SpriteAnim = WaitIconSpriteAnim.Instantiate();
SpriteAnim.LoopMode = ALM_Loop;
SpriteAnim.StartIn();
} else if (WaitIconCurrentType == +WaitIconType::SpriteAnimFixed) {
SpriteAnim = WaitIconSpriteAnim.Instantiate();
SpriteAnim.LoopMode = ALM_Stop;
FixedSpriteAnim = static_cast<FixedSpriteAnimation&>(SpriteAnim);
FixedSpriteAnim.Def->FixSpriteId = WaitIconFixedSpriteId;
FixedSpriteAnim.StartIn();
} else {
SimpleAnim.DurationIn = WaitIconAnimationDuration;
SimpleAnim.LoopMode = ALM_Loop;
SimpleAnim.StartIn();
if (WaitIconCurrentType == +WaitIconType::None) return;

switch (WaitIconCurrentType) {
case WaitIconType::SpriteAnim:
SpriteAnim = WaitIconSpriteAnim.Instantiate();
SpriteAnim.LoopMode = ALM_Loop;
SpriteAnim.StartIn();
break;
case WaitIconType::SpriteAnimFixed:
SpriteAnim = WaitIconSpriteAnim.Instantiate();
SpriteAnim.LoopMode = ALM_Stop;
FixedSpriteAnim = static_cast<FixedSpriteAnimation&>(SpriteAnim);
FixedSpriteAnim.Def->FixSpriteId = WaitIconFixedSpriteId;
break;
default:
SimpleAnim.DurationIn = WaitIconAnimationDuration;
SimpleAnim.LoopMode = ALM_Loop;
SimpleAnim.StartIn();
break;
}
}

void Update(float dt) {
if (WaitIconCurrentType == +WaitIconType::SpriteAnim) {
SpriteAnim.Update(dt);
} else if (WaitIconCurrentType == +WaitIconType::SpriteAnimFixed) {
FixedSpriteAnim.Update(dt);
} else {
SimpleAnim.Update(dt);
switch (WaitIconCurrentType) {
case WaitIconType::None:
return;

case WaitIconType::SpriteAnim: {
bool showWaitIcon = GetFlag(Profile::ScriptVars::SF_SHOWWAITICON);
if (showWaitIcon && SpriteAnim.IsOut())
SpriteAnim.StartIn();
else if (!showWaitIcon && SpriteAnim.IsIn())
SpriteAnim.StartOut();

SpriteAnim.Update(dt);
break;
}

case WaitIconType::SpriteAnimFixed: {
bool showWaitIcon = GetFlag(Profile::ScriptVars::SF_SHOWWAITICON);
if (showWaitIcon && FixedSpriteAnim.IsOut())
FixedSpriteAnim.StartIn();
else if (!showWaitIcon && FixedSpriteAnim.IsIn())
FixedSpriteAnim.StartOut();

FixedSpriteAnim.Update(dt);
break;
}

default:
SimpleAnim.Update(dt);
break;
}
}

static void RenderSpriteAnim(glm::vec2 pos, glm::vec4 opacityTint,
DialoguePageMode mode) {
if (FixedSpriteAnim.IsOut()) return;

glm::vec2 offset = WaitIconOffset;

if (DialogueBoxCurrentType == +DialogueBoxType::CHLCC) {
// To deal with multiple DialogueBox
opacityTint = glm::vec4(1.0f, 1.0f, 1.0f, opacityTint.a);

// Erin DialogueBox
if (mode == DPM_REV)
offset = Impacto::Profile::CHLCC::DialogueBox::REVWaitIconOffset;
}

Renderer->DrawSprite(SpriteAnim.CurrentSprite(), pos + offset, opacityTint);
}

static void RenderSpriteAnimFixed(glm::vec4 opacityTint) {
if (FixedSpriteAnim.Progress == 0.0f) return;

Renderer->DrawSprite(FixedSpriteAnim.CurrentSprite(),
glm::vec2(WaitIconOffset.x, WaitIconOffset.y),
opacityTint);
}

static void RenderRotateZ(glm::vec2 pos, glm::vec4 opacityTint) {
if (!GetFlag(Profile::ScriptVars::SF_SHOWWAITICON)) return;

// TODO: MO6TW only for now
glm::vec3 euler(SimpleAnim.Progress * 2.0f * M_PI, 0, 0.6f);
glm::quat quat;
eulerZYXToQuat(&euler, &quat);

glm::vec2 vanishingPoint(
(pos.x + WaitIconOffset.x) + (WaitIconSprite.ScaledWidth() / 2.0f),
(pos.y + WaitIconOffset.y) + (WaitIconSprite.ScaledHeight() / 2.0f));

Renderer->DrawSprite3DRotated(
WaitIconSprite,
glm::vec2(pos.x + WaitIconOffset.x, pos.y + WaitIconOffset.y), 1.0f,
vanishingPoint, true, quat, opacityTint);
}

static void RenderFixed(glm::vec4 opacityTint) {
if (!GetFlag(Profile::ScriptVars::SF_SHOWWAITICON)) return;

Renderer->DrawSprite(WaitIconSprite, WaitIconOffset, opacityTint);
}

void Render(glm::vec2 pos, glm::vec4 opacityTint, DialoguePageMode mode) {
if (WaitIconCurrentType == +WaitIconType::SpriteAnim) {
if (DialogueBoxCurrentType == +DialogueBoxType::CHLCC) {
// To deal with multiple DialogueBox
glm::vec4 col = glm::vec4(1.0f, 1.0f, 1.0f, opacityTint.a);
// Erin DialogueBox
if (mode == DPM_REV) {
Renderer->DrawSprite(
SpriteAnim.CurrentSprite(),
glm::vec2(
pos.x +
Impacto::Profile::CHLCC::DialogueBox::REVWaitIconOffset.x,
pos.y +
Impacto::Profile::CHLCC::DialogueBox::REVWaitIconOffset.y),
col);

} else {
Renderer->DrawSprite(
SpriteAnim.CurrentSprite(),
glm::vec2(pos.x + WaitIconOffset.x, pos.y + WaitIconOffset.y), col);
}
} else {
switch (WaitIconCurrentType) {
case WaitIconType::None:
return;
case WaitIconType::SpriteAnim:
RenderSpriteAnim(pos, opacityTint, mode);
return;
case WaitIconType::SpriteAnimFixed:
RenderSpriteAnimFixed(opacityTint);
return;
case WaitIconType::RotateZ:
RenderRotateZ(pos, opacityTint);
return;
case WaitIconType::Fixed:
RenderFixed(opacityTint);
return;
default:
if (!GetFlag(Profile::ScriptVars::SF_SHOWWAITICON)) return;

Renderer->DrawSprite(
SpriteAnim.CurrentSprite(),
WaitIconSprite,
glm::vec2(pos.x + WaitIconOffset.x, pos.y + WaitIconOffset.y),
opacityTint);
}
} else if (WaitIconCurrentType == +WaitIconType::SpriteAnimFixed) {
Renderer->DrawSprite(
FixedSpriteAnim.CurrentSprite(),
glm::vec2(WaitIconOffset.x - 50, WaitIconOffset.y - 50), opacityTint);
} else if (WaitIconCurrentType == +WaitIconType::RotateZ) {
// TODO: MO6TW only for now
glm::vec3 euler(SimpleAnim.Progress * 2.0f * M_PI, 0, 0.6f);
glm::quat quat;
eulerZYXToQuat(&euler, &quat);

glm::vec2 vanishingPoint(
(pos.x + WaitIconOffset.x) + (WaitIconSprite.ScaledWidth() / 2.0f),
(pos.y + WaitIconOffset.y) + (WaitIconSprite.ScaledHeight() / 2.0f));

Renderer->DrawSprite3DRotated(
WaitIconSprite,
glm::vec2(pos.x + WaitIconOffset.x, pos.y + WaitIconOffset.y), 1.0f,
vanishingPoint, true, quat, opacityTint);
} else if (WaitIconCurrentType == +WaitIconType::None) {
Renderer->DrawSprite(
WaitIconSprite,
glm::vec2(pos.x + WaitIconOffset.x, pos.y + WaitIconOffset.y),
opacityTint, glm::vec2(1.0f));
} else {
Renderer->DrawSprite(
WaitIconSprite,
glm::vec2(pos.x + WaitIconOffset.x, pos.y + WaitIconOffset.y),
opacityTint, glm::vec2(1.0f), SimpleAnim.Progress * 2.0f * (float)M_PI);
opacityTint, glm::vec2(1.0f),
SimpleAnim.Progress * 2.0f * (float)M_PI);
return;
}
}

Expand Down
36 changes: 22 additions & 14 deletions src/profile/dialogue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,30 @@ void Configure() {
TryGetMemberFloat("TipsLineSpacing", TipsLineSpacing);
TryGetMemberInt("TipsColorIndex", TipsColorIndex);

int WaitIconCurrentTypeInt;
if (!TryGetMemberInt("WaitIconCurrentType", WaitIconCurrentTypeInt))
WaitIconCurrentTypeInt = +WaitIconDisplay::WaitIconType::None;
WaitIconCurrentType = WaitIconDisplay::WaitIconType::_from_integral_unchecked(
EnsureGetMemberInt("WaitIconCurrentType"));
if (WaitIconCurrentType == +WaitIconDisplay::WaitIconType::SpriteAnim) {
WaitIconSpriteAnim = EnsureGetMemberAnimation("WaitIconSpriteAnim");
} else if (WaitIconCurrentType ==
+WaitIconDisplay::WaitIconType::SpriteAnimFixed) {
WaitIconSpriteAnim = EnsureGetMemberAnimation("WaitIconSpriteAnim");
WaitIconFixedSpriteId = EnsureGetMemberInt("WaitIconFixedSpriteId");
} else if (WaitIconCurrentType == +WaitIconDisplay::WaitIconType::None) {
WaitIconSprite = EnsureGetMemberSprite("WaitIconSprite");
} else {
WaitIconSprite = EnsureGetMemberSprite("WaitIconSprite");
WaitIconAnimationDuration =
EnsureGetMemberFloat("WaitIconAnimationDuration");
WaitIconCurrentTypeInt);
if (WaitIconCurrentType != +WaitIconDisplay::WaitIconType::None) {
switch (WaitIconCurrentType) {
case WaitIconDisplay::WaitIconType::SpriteAnim:
WaitIconSpriteAnim = EnsureGetMemberAnimation("WaitIconSpriteAnim");
break;
case WaitIconDisplay::WaitIconType::SpriteAnimFixed:
WaitIconSpriteAnim = EnsureGetMemberAnimation("WaitIconSpriteAnim");
WaitIconFixedSpriteId = EnsureGetMemberInt("WaitIconFixedSpriteId");
break;
case WaitIconDisplay::WaitIconType::Fixed:
WaitIconSprite = EnsureGetMemberSprite("WaitIconSprite");
break;
default:
WaitIconSprite = EnsureGetMemberSprite("WaitIconSprite");
WaitIconAnimationDuration =
EnsureGetMemberFloat("WaitIconAnimationDuration");
}
WaitIconOffset = EnsureGetMemberVec2("WaitIconOffset");
}
WaitIconOffset = EnsureGetMemberVec2("WaitIconOffset");

int AutoIconCurrentTypeInt;
if (!TryGetMemberInt("AutoIconCurrentType", AutoIconCurrentTypeInt))
Expand Down
1 change: 1 addition & 0 deletions src/scriptvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ V(SF_MESREAD)
V(SF_TITLEMODE)
V(SF_TITLEEND)
V(SF_UIHIDDEN)
V(SF_SHOWWAITICON)
V(SF_LOADING)
V(SF_SYSMENUDISABLE)
V(SF_SYSTEMMENUDISABLE)
Expand Down
10 changes: 10 additions & 0 deletions src/spriteanimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
namespace Impacto {

bool SpriteAnimation::Exists() { return Def != 0; }

Sprite SpriteAnimation::CurrentSprite() {
int frame = (int)(Progress * (float)Def->FrameCount);

if (frame >= Def->FrameCount)
frame = Def->FrameCount - 1;
else if (frame < 0)
frame = 0;

return Def->Frames[frame];
}

void FixedSpriteAnimation::StartInImpl(bool reset) {
if (reset) Progress = GetFixedSpriteProgress();
}

void FixedSpriteAnimation::StartOutImpl(bool reset) {
if (reset) Progress = GetFixedSpriteProgress();
}

void FixedSpriteAnimation::UpdateImpl(float dt) {
float fixedSpriteProgress = GetFixedSpriteProgress();
int animationRequest = Direction;
Expand Down Expand Up @@ -58,6 +64,7 @@ void FixedSpriteAnimation::UpdateImpl(float dt) {
State = AS_Playing;
}
}

Sprite FixedSpriteAnimation::CurrentSprite() {
int frame;
float fixedSpriteProgress = GetFixedSpriteProgress();
Expand All @@ -78,11 +85,13 @@ Sprite FixedSpriteAnimation::CurrentSprite() {

return Def->Frames[frame];
}

float FixedSpriteAnimation::GetFixedSpriteProgress() const {
/* Converse because in- and out directions are reversed
between spritesheet and implementation */
return 1.0f - (float)Def->FixSpriteId / Def->FrameCount;
}

SpriteAnimation SpriteAnimationDef::Instantiate() {
SpriteAnimation result;
result.Def = this;
Expand All @@ -95,4 +104,5 @@ SpriteAnimation SpriteAnimationDef::Instantiate() {

return result;
}

} // namespace Impacto
9 changes: 4 additions & 5 deletions src/spriteanimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace Impacto {

class SpriteAnimationDef;
class FixedSpriteAnimationDef;

struct SpriteAnimation : public Animation {
SpriteAnimationDef* Def = 0;
Expand Down Expand Up @@ -34,10 +33,10 @@ struct SpriteAnimation : public Animation {
(with 1 being fully in).
*/
struct FixedSpriteAnimation : public SpriteAnimation {
void StartInImpl(bool reset);
void StartOutImpl(bool reset);
void UpdateImpl(float dt);
Sprite CurrentSprite();
void StartInImpl(bool reset) override;
void StartOutImpl(bool reset) override;
void UpdateImpl(float dt) override;
Sprite CurrentSprite() override;
float GetFixedSpriteProgress() const;
};

Expand Down
10 changes: 4 additions & 6 deletions src/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,12 +721,10 @@ void DialoguePage::Render() {
}

// Wait icon
if (Typewriter.Progress == 1.0f && Glyphs.size() > 0) {
WaitIconDisplay::Render(
glm::vec2(Glyphs.back().DestRect.X + Glyphs.back().DestRect.Width,
Glyphs.back().DestRect.Y),
col, Mode);
}
const RectF& lastGlyphDest =
Glyphs.empty() ? RectF() : Glyphs.back().DestRect;
glm::vec2 waitIconPos(lastGlyphDest.X + lastGlyphDest.Width, lastGlyphDest.Y);
WaitIconDisplay::Render(waitIconPos, col, Mode);

AutoIconDisplay::Render(col);
SkipIconDisplay::Render(col);
Expand Down
Loading

0 comments on commit d42532e

Please sign in to comment.