Skip to content

Commit

Permalink
Converted the slider fields to use the new select field
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatyas committed Mar 30, 2024
1 parent 17be6c9 commit 05092b8
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 345 deletions.
5 changes: 3 additions & 2 deletions src/common/ui/MI_SelectField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,10 @@ void MI_SelectFieldDyn<T>::updateOutput() const


template<typename T>
void MI_SelectFieldDyn<T>::add(std::string name, T value, bool hidden, bool goodRandom, short iconOverride)
void MI_SelectFieldDyn<T>::add(std::string name, T value, bool hidden, bool goodRandom)
{
size_t new_idx = m_items.size();
m_items.emplace_back(std::move(name), std::move(value), hidden, iconOverride);
m_items.emplace_back(std::move(name), std::move(value), hidden, -1);
m_index = 0;

if (goodRandom)
Expand Down Expand Up @@ -797,3 +797,4 @@ bool MI_SelectFieldDyn<T>::moveRandom()

// Actual typed classes
template class MI_SelectFieldDyn<bool>;
template class MI_SelectFieldDyn<short>;
2 changes: 1 addition & 1 deletion src/common/ui/MI_SelectField.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class MI_SelectFieldDyn : public UI_Control {
//! Sets the currently selected item
bool setCurrentIndex(size_t index);
//! Adds an item to the list
void add(std::string name, T value, bool hidden = false, bool goodRandom = true, short iconOverride = -1);
void add(std::string name, T value, bool hidden = false, bool goodRandom = true);
//! Removes all items
void clear();
//! Hides the items containing the specified value
Expand Down
52 changes: 27 additions & 25 deletions src/common/ui/MI_SliderField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ extern CResourceManager* rm;
* MI_SliderField Class
**************************************/

MI_SliderField::MI_SliderField(gfxSprite * nspr, gfxSprite * nsprSlider, short x, short y, const char * name, short width, short indent1, short indent2) :
MI_SelectField(nspr, x, y, name, width, indent1)
MI_SliderField::MI_SliderField(gfxSprite * nspr, gfxSprite * nsprSlider, short x, short y, const char * name, short width, short indent1, short indent2)
: MI_SelectFieldDyn<short>(nspr, x, y, name, width, indent1)
{
iIndent2 = indent2;
sprSlider = nsprSlider;
m_indent2 = indent2;
m_sprSlider = nsprSlider;

SetPosition(x, y);
}
Expand All @@ -24,59 +24,61 @@ MI_SliderField::~MI_SliderField()

void MI_SliderField::SetPosition(short x, short y)
{
MI_SelectField::SetPosition(x, y);
miModifyImageLeft->SetPosition(ix + iIndent - 26, iy + 4);
miModifyImageRight->SetPosition(ix + iWidth - 16, iy + 4);
MI_SelectFieldDyn<short>::SetPosition(x, y);
miModifyImageLeft->SetPosition(ix + m_indent - 26, iy + 4);
miModifyImageRight->SetPosition(ix + m_width - 16, iy + 4);
}

void MI_SliderField::Draw()
{
if (!fShow)
return;

spr->draw(ix, iy, 0, (fSelected ? 32 : 0) + iAdjustmentY, iIndent - 16, 32);
spr->draw(ix + iIndent - 16, iy, 0, (fSelected ? 96 : 64), 32, 32);
spr->draw(ix + iIndent + 16, iy, 528 - iWidth + iIndent, (fSelected ? 32 : 0) + iAdjustmentY, iWidth - iIndent - 16, 32);
m_spr->draw(ix, iy, 0, (fSelected ? 32 : 0) + m_adjustmentY, m_indent - 16, 32);
m_spr->draw(ix + m_indent - 16, iy, 0, (fSelected ? 96 : 64), 32, 32);
m_spr->draw(ix + m_indent + 16, iy, 528 - m_width + m_indent, (fSelected ? 32 : 0) + m_adjustmentY, m_width - m_indent - 16, 32);

rm->menu_font_large.drawChopRight(ix + 16, iy + 5, iIndent - 8, szName.c_str());
rm->menu_font_large.drawChopRight(ix + 16, iy + 5, m_indent - 8, m_name.c_str());

if (!items.empty()) {
rm->menu_font_large.drawChopRight(ix + iIndent2 + 16, iy + 5, iWidth - iIndent2 - 24, (*current)->sName.c_str());
if (!m_items.empty()) {
rm->menu_font_large.drawChopRight(ix + m_indent2 + 16, iy + 5, m_width - m_indent2 - 24, currentItem().name.c_str());
}

short iSpacing = (iIndent2 - iIndent - 20) / ((short)items.size() - 1);
short iSpacing = (m_indent2 - m_indent - 20) / ((short)m_items.size() - 1);
short iSpot = 0;

for (unsigned int index = 0; index < items.size(); index++) {
if (index < items.size() - 1)
sprSlider->draw(ix + iIndent + iSpot + 16, iy + 10, 0, 0, iSpacing, 13);
for (unsigned int index = 0; index < m_items.size(); index++) {
if (index < m_items.size() - 1)
m_sprSlider->draw(ix + m_indent + iSpot + 16, iy + 10, 0, 0, iSpacing, 13);
else
sprSlider->draw(ix + iIndent + iSpot + 16, iy + 10, 164, 0, 4, 13);
m_sprSlider->draw(ix + m_indent + iSpot + 16, iy + 10, 164, 0, 4, 13);

iSpot += iSpacing;
}

sprSlider->draw(ix + iIndent + (iIndex * iSpacing) + 14, iy + 8, 168, 0, 8, 16);
m_sprSlider->draw(ix + m_indent + (m_index * iSpacing) + 14, iy + 8, 168, 0, 8, 16);

if (current != items.begin() || !fNoWrap)
const bool drawLeft = m_index > 0;
if (m_wraps || drawLeft)
miModifyImageLeft->Draw();

if (current != --items.end() || !fNoWrap)
const bool drawRight = (m_index + 1) < m_items.size();
if (m_wraps || drawRight)
miModifyImageRight->Draw();
}

MenuCodeEnum MI_SliderField::SendInput(CPlayerInput * playerInput)
{
for (int iPlayer = 0; iPlayer < 4; iPlayer++) {
if (playerInput->outputControls[iPlayer].menu_scrollfast.fPressed) {
if (iIndex == 0)
while (MoveNext());
if (m_index == 0)
while (moveNext());
else
while (MovePrev());
while (movePrev());

return mcItemChangedCode;
}
}

return MI_SelectField::SendInput(playerInput);
return MI_SelectFieldDyn<short>::SendInput(playerInput);
}
20 changes: 7 additions & 13 deletions src/common/ui/MI_SliderField.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
#ifndef UI_SLIDER_FIELD_H
#define UI_SLIDER_FIELD_H
#pragma once

#include "ui/MI_SelectField.h"

class MI_SliderField : public MI_SelectField
{
public:

class MI_SliderField : public MI_SelectFieldDyn<short> {
public:
MI_SliderField(gfxSprite * nspr, gfxSprite * nsprSlider, short x, short y, const char * name, short width, short indent1, short indent2);
virtual ~MI_SliderField();

void SetPosition(short x, short y);

//Draws every frame
virtual void Draw();
void Draw() override;
//Sends player input to control on every frame
MenuCodeEnum SendInput(CPlayerInput * playerInput);
MenuCodeEnum SendInput(CPlayerInput * playerInput) override;

protected:

gfxSprite * sprSlider;
short iIndent2;

gfxSprite* m_sprSlider;
short m_indent2;
};

#endif // UI_SLIDER_FIELD_H
Loading

0 comments on commit 05092b8

Please sign in to comment.