Skip to content

Commit

Permalink
Added character voice page
Browse files Browse the repository at this point in the history
  • Loading branch information
PringlesGang committed Nov 13, 2024
1 parent 44d2382 commit 1429654
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ set(Impacto_Src
src/ui/widgets/cclcc/optionsentry.cpp
src/ui/widgets/cclcc/optionsbinarybutton.cpp
src/ui/widgets/cclcc/optionsslider.cpp
src/ui/widgets/cclcc/optionsvoiceslider.cpp
src/ui/widgets/cclcc/saveentrybutton.cpp
src/ui/widgets/cclcc/sysmenubutton.cpp
src/ui/widgets/cclcc/tipsentrybutton.cpp
Expand Down Expand Up @@ -560,6 +561,7 @@ set(Impacto_Header
src/ui/widgets/cclcc/optionsentry.h
src/ui/widgets/cclcc/optionsbinarybutton.h
src/ui/widgets/cclcc/optionsslider.h
src/ui/widgets/cclcc/optionsvoiceslider.h

src/renderer/3d/camera.h
src/renderer/3d/model.h
Expand Down
4 changes: 2 additions & 2 deletions profiles/cclcc/hud/optionsmenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ root.OptionsMenu = {
SliderTrackSprite = "OptionsSliderTrack",
SliderTrackOffset = { X = 664, Y = 2 },
VoiceSliderTrackSprite = "OptionsVoiceSliderTrack",
VoiceSliderOffset = { X = 111, Y = 56 },
VoiceSliderOffset = { X = 110, Y = 55 },
BinaryBoxSprite = "OptionsBinaryBox",
BinaryBoxOffset = { X = 812, Y = 2 },
SliderSpeed = 1.0,
Expand Down Expand Up @@ -207,7 +207,7 @@ for i = 0, 25 do
root.Sprites["OptionsPortrait" .. i] = {
Sheet = "ConfigEx",
Bounds = {
X = 768 + (width + 1) * i,
X = 768 + (width + 1) * (i // 2),
Y = ((i % 2 == 0) and {2256} or {2357})[1],
Width = width,
Height = width
Expand Down
46 changes: 42 additions & 4 deletions src/games/cclcc/optionsmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../../vm/interface/input.h"
#include "../../ui/widgets/cclcc/optionsbinarybutton.h"
#include "../../ui/widgets/cclcc/optionsslider.h"
#include "../../ui/widgets/cclcc/optionsvoiceslider.h"

namespace Impacto {
namespace UI {
Expand Down Expand Up @@ -70,12 +71,47 @@ OptionsMenu::OptionsMenu() {
Pages.push_back(SoundPage);

VoicePage = new Group(this);
for (int i = 0; i < 12; i++) {
constexpr int columns = 3;
constexpr int entries = 12;
for (int i = 0; i < entries; i++) {
glm::vec2 pos = VoicePosition;
pos += VoiceEntriesOffset * glm::vec2(i % 3, i / 3);
pos += VoiceEntriesOffset * glm::vec2(i % columns, i / columns);

VoicePage->Add(new Label(NametagSprites[i], pos), FDIR_RIGHT);
Widget* widget = new OptionsVoiceSlider(
VoiceSliderTrackSprite, NametagSprites[i], PortraitSprites[2 * i],
PortraitSprites[2 * i + 1], pos, highlightTint, SliderSpeed);
VoicePage->Add(widget, FDIR_RIGHT);
}

// Loop separately to overwrite the direction set at initial adding
// First entry won't set anything; skip
for (int i = 1; i < entries; i++) {
Widget* const widget = VoicePage->Children.at(i);

if (i % columns != 0) { // Not on first column
Widget* const leftWidget = VoicePage->Children.at(i - 1);
widget->SetFocus(leftWidget, FDIR_LEFT);
leftWidget->SetFocus(widget, FDIR_RIGHT);

if (i % columns == columns - 1) { // On last column
Widget* const rowStart = VoicePage->Children.at(i - columns + 1);
widget->SetFocus(rowStart, FDIR_RIGHT);
rowStart->SetFocus(widget, FDIR_LEFT);
}
}
if (i >= columns) { // Not on first row
Widget* const upWidget = VoicePage->Children.at(i - columns);
widget->SetFocus(upWidget, FDIR_UP);
upWidget->SetFocus(widget, FDIR_DOWN);

if (i >= entries - columns) { // On last layer
Widget* const columnStart = VoicePage->Children.at(i % columns);
widget->SetFocus(columnStart, FDIR_DOWN);
columnStart->SetFocus(widget, FDIR_UP);
}
}
}

Pages.push_back(VoicePage);

CurrentPage = 0;
Expand Down Expand Up @@ -163,7 +199,9 @@ void OptionsMenu::Render() {

Renderer->DrawSprite(PoleAnimation.CurrentSprite(), PagePanelPosition, col);

Renderer->DrawSprite(GuideSprite, GuidePosition, col);
const Sprite& guideSprite =
CurrentPage == 3 ? VoiceGuideSprite : GuideSprite;
Renderer->DrawSprite(guideSprite, GuidePosition, col);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/widgets/cclcc/optionsslider.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class OptionsSlider : public OptionsEntry {
void Render() override;
void Update(float dt) override;

private:
protected:
const Sprite& BoxSprite;

float Progress = 0.0f;
Expand Down
48 changes: 48 additions & 0 deletions src/ui/widgets/cclcc/optionsvoiceslider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "optionsvoiceslider.h"

#include "../../../profile/games/cclcc/optionsmenu.h"
#include "../../../renderer/renderer.h"
#include "../../../vm/interface/input.h"

using namespace Impacto::Profile::CCLCC::OptionsMenu;
using namespace Impacto::Vm::Interface;

namespace Impacto {
namespace UI {
namespace Widgets {
namespace CCLCC {

OptionsVoiceSlider::OptionsVoiceSlider(const Sprite& box, const Sprite& label,
const Sprite& portrait,
const Sprite& mutedPortrait,
glm::vec2 pos, glm::vec4 highlightTint,
float sliderSpeed)
: OptionsSlider(box, label, pos, highlightTint, sliderSpeed),
Portrait(portrait),
MutedPortrait(mutedPortrait) {}

void OptionsVoiceSlider::Render() {
HighlightTint.a = Tint.a;

Renderer->DrawSprite(Muted ? MutedPortrait : Portrait, Bounds.GetPos(), Tint);
Renderer->DrawSprite(LabelSprite, Bounds.GetPos() + NametagOffset,
Selected ? Tint : glm::vec4(0.0f, 0.0f, 0.0f, Tint.a));

RectF highlightBounds(
Bounds.X + VoiceSliderOffset.x, Bounds.Y + VoiceSliderOffset.y,
Progress * BoxSprite.ScaledWidth(), BoxSprite.ScaledHeight());
Renderer->DrawRect(highlightBounds, HighlightTint);
Renderer->DrawSprite(BoxSprite, Bounds.GetPos() + VoiceSliderOffset, Tint);
}

void OptionsVoiceSlider::UpdateInput() {
OptionsEntry::UpdateInput();
if (!Selected) return;

Muted ^= (bool)(PADinputButtonWentDown & PAD1Y);
}

} // namespace CCLCC
} // namespace Widgets
} // namespace UI
} // namespace Impacto
29 changes: 29 additions & 0 deletions src/ui/widgets/cclcc/optionsvoiceslider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "./optionsslider.h"
#include "../../../spritesheet.h"

namespace Impacto {
namespace UI {
namespace Widgets {
namespace CCLCC {

class OptionsVoiceSlider : public OptionsSlider {
public:
OptionsVoiceSlider(const Sprite& box, const Sprite& label,
const Sprite& portrait, const Sprite& mutedPortrait,
glm::vec2 pos, glm::vec4 highlightTint, float sliderSpeed);
void Render() override;
void UpdateInput() override;

private:
const Sprite& Portrait;
const Sprite& MutedPortrait;

bool Muted = false;
};

} // namespace CCLCC
} // namespace Widgets
} // namespace UI
} // namespace Impacto

0 comments on commit 1429654

Please sign in to comment.