Skip to content

Commit

Permalink
Added options slider
Browse files Browse the repository at this point in the history
  • Loading branch information
PringlesGang committed Oct 20, 2024
1 parent 7aa1e26 commit b7a9c3d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ set(Impacto_Src
src/ui/widgets/cc/titlebutton.cpp
src/ui/widgets/cclcc/titlebutton.cpp
src/ui/widgets/cclcc/optionsbinarybutton.cpp
src/ui/widgets/cclcc/optionsslider.cpp
src/ui/widgets/cclcc/saveentrybutton.cpp
src/ui/widgets/cclcc/sysmenubutton.cpp
src/ui/widgets/cclcc/tipsentrybutton.cpp
Expand Down Expand Up @@ -556,6 +557,7 @@ set(Impacto_Header
src/ui/widgets/cc/titlebutton.h
src/ui/widgets/cclcc/titlebutton.h
src/ui/widgets/cclcc/optionsbinarybutton.h
src/ui/widgets/cclcc/optionsslider.h

src/renderer/3d/camera.h
src/renderer/3d/model.h
Expand Down
36 changes: 21 additions & 15 deletions src/games/cclcc/optionsmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "../../profile/scriptinput.h"
#include "../../vm/interface/input.h"
#include "../../ui/widgets/cclcc/optionsbinarybutton.h"
#include "../../ui/widgets/cclcc/optionsslider.h"

namespace Impacto {
namespace UI {
Expand All @@ -26,40 +27,45 @@ OptionsMenu::OptionsMenu() {
PoleAnimation = Profile::CCLCC::OptionsMenu::PoleAnimation.Instantiate();

Pages.reserve(4);
glm::vec2 pos = EntriesStartPosition;

BasicPage = new Group(this);
BasicPage->FocusLock = false;
for (int i = 0; i < 4; i++) {
glm::vec2 pos = EntriesStartPosition;
pos.y += EntriesVerticalOffset * i;

BasicPage->Add(new OptionsBinaryButton(BinaryBoxSprite, OnSprite, OffSprite,
LabelSprites[i], pos),
FDIR_DOWN);

pos.y += EntriesVerticalOffset;
}
Pages.push_back(BasicPage);

pos = EntriesStartPosition;
TextPage = new Group(this);
TextPage->FocusLock = false;
for (int i = 4; i < 7; i++) {
glm::vec2 pos = EntriesStartPosition;
pos.y += EntriesVerticalOffset * (i - 4);

TextPage->Add(new OptionsBinaryButton(BinaryBoxSprite, YesSprite, NoSprite,
LabelSprites[i], pos),
for (int i = 4; i < 6; i++) {
TextPage->Add(new OptionsSlider(SliderTrackSprite, LabelSprites[i], pos),
FDIR_DOWN);

pos.y += EntriesVerticalOffset;
}
TextPage->Add(new OptionsBinaryButton(BinaryBoxSprite, YesSprite, NoSprite,
LabelSprites[6], pos),
FDIR_DOWN);
Pages.push_back(TextPage);

pos = SoundEntriesStartPosition;
SoundPage = new Group(this);
SoundPage->FocusLock = false;
for (int i = 7; i < 15; i++) {
glm::vec2 pos = SoundEntriesStartPosition;
pos.y += SoundEntriesVerticalOffset * (i - 7);

SoundPage->Add(new OptionsBinaryButton(BinaryBoxSprite, YesSprite, NoSprite,
LabelSprites[i], pos),
FDIR_DOWN);
Widget* widget =
(i < 11 || i == 14)
? new OptionsSlider(SliderTrackSprite, LabelSprites[i], pos)
: widget = new OptionsBinaryButton(BinaryBoxSprite, YesSprite,
NoSprite, LabelSprites[i], pos);
SoundPage->Add(widget, FDIR_DOWN);

pos.y += SoundEntriesVerticalOffset;
}
Pages.push_back(SoundPage);

Expand Down
39 changes: 39 additions & 0 deletions src/ui/widgets/cclcc/optionsslider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "optionsslider.h"

#include "../../../profile/games/cclcc/optionsmenu.h"
#include "../../../renderer/renderer.h"

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

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

OptionsSlider::OptionsSlider(const Sprite& box, const Sprite& label,
glm::vec2 pos)
: BoxSprite(box), LabelSprite(label) {
Bounds = RectF(pos.x, pos.y, SliderTrackOffset.x + box.ScaledWidth(),
LabelSprite.ScaledHeight());
}

void OptionsSlider::Render() {
HighlightTint.a = Tint.a;
glm::vec4 black = glm::vec4(0.0f, 0.0f, 0.0f, Tint.a);

Renderer->DrawSprite(LabelSprite, Bounds.GetPos(), black);

RectF highlightBounds(
Bounds.X + SliderTrackOffset.x, Bounds.Y + SliderTrackOffset.y,
Progress * BoxSprite.ScaledWidth(), BoxSprite.ScaledHeight());
Renderer->DrawRect(highlightBounds, HighlightTint);

Renderer->DrawSprite(BoxSprite, Bounds.GetPos() + SliderTrackOffset, Tint);
}

void OptionsSlider::UpdateInput() {}

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

#include "../../widget.h"
#include "../../../spritesheet.h"

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

class OptionsSlider : public Widget {
public:
OptionsSlider(const Sprite& box, const Sprite& label, glm::vec2 pos);

void Render() override;
void UpdateInput() override;

private:
const Sprite& BoxSprite;
const Sprite& LabelSprite;

glm::vec4 HighlightTint = glm::vec4(0.94f, 0.49f, 0.59f, 1.0f);

float Progress = 0.0f;
};

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

0 comments on commit b7a9c3d

Please sign in to comment.