2011-06-14 19:53:19 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* libwiigui
|
|
|
|
*
|
|
|
|
* gui_customoptionbrowser.cpp
|
|
|
|
*
|
|
|
|
* GUI class definitions
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
#include "../wpad.h"
|
|
|
|
#include "../main.h"
|
|
|
|
#include "../gecko.h"
|
|
|
|
#include "../settings/CSettings.h"
|
|
|
|
#include "gui_optionbrowser.h"
|
|
|
|
#include "themes/CTheme.h"
|
|
|
|
#include "utils/tools.h"
|
|
|
|
#include "menu.h"
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
#define GAMESELECTSIZE 30
|
2011-06-14 19:53:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
GuiOptionBrowser * Constructor for the GuiOptionBrowser class.
|
|
|
|
*/
|
|
|
|
GuiOptionBrowser::GuiOptionBrowser(int w, int h, OptionList * l, const char * custombg)
|
2011-07-26 00:28:22 +02:00
|
|
|
: scrollBar(h-10)
|
2011-06-14 19:53:19 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
width = w;
|
|
|
|
height = h;
|
|
|
|
options = l;
|
|
|
|
selectable = true;
|
|
|
|
selectedItem = 0;
|
2011-09-24 01:49:18 +02:00
|
|
|
oldSelectedItem = -1;
|
2011-07-26 00:28:22 +02:00
|
|
|
coL2 = 50;
|
|
|
|
listOffset = 0;
|
|
|
|
|
|
|
|
trigA = new GuiTrigger;
|
|
|
|
trigA->SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
|
|
|
|
|
|
|
bgOptions = Resources::GetImageData(custombg);
|
|
|
|
|
|
|
|
bgOptionsImg = new GuiImage(bgOptions);
|
|
|
|
bgOptionsImg->SetParent(this);
|
|
|
|
bgOptionsImg->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
|
|
|
|
bgOptionsEntry = Resources::GetImageData("bg_options_entry.png");
|
|
|
|
|
|
|
|
scrollBar.SetParent(this);
|
|
|
|
scrollBar.SetAlignment(thAlign("right - options browser scrollbar align hor"), thAlign("top - options browser scrollbar align ver"));
|
|
|
|
scrollBar.SetPosition(thInt("0 - options browser scrollbar pos x"), thInt("5 - options browser scrollbar pos y"));
|
|
|
|
scrollBar.listChanged.connect(this, &GuiOptionBrowser::onListChange);
|
|
|
|
|
2011-09-24 01:49:18 +02:00
|
|
|
optionBtn.resize(PAGESIZE);
|
|
|
|
optionBg.resize(PAGESIZE);
|
|
|
|
optionTxt.resize(PAGESIZE);
|
|
|
|
optionVal.resize(PAGESIZE);
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
for (int i = 0; i < PAGESIZE; i++)
|
|
|
|
{
|
|
|
|
optionTxt[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color"));
|
|
|
|
optionTxt[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
optionTxt[i]->SetPosition(24, 0);
|
|
|
|
optionTxt[i]->SetMaxWidth(bgOptionsImg->GetWidth()-scrollBar.GetWidth()-40, DOTTED);
|
|
|
|
|
|
|
|
optionBg[i] = new GuiImage(bgOptionsEntry);
|
|
|
|
|
|
|
|
optionVal[i] = new GuiText((wchar_t *) NULL, 20, thColor("r=0 g=0 b=0 a=255 - settings text color"));
|
|
|
|
optionVal[i]->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
|
|
|
|
optionBtn[i] = new GuiButton(width - scrollBar.GetWidth(), GAMESELECTSIZE);
|
|
|
|
optionBtn[i]->SetParent(this);
|
|
|
|
optionBtn[i]->SetLabel(optionTxt[i], 0);
|
|
|
|
optionBtn[i]->SetLabel(optionVal[i], 1);
|
|
|
|
optionBtn[i]->SetImageOver(optionBg[i]);
|
|
|
|
optionBtn[i]->SetPosition(10, GAMESELECTSIZE * i + 4);
|
|
|
|
optionBtn[i]->SetRumble(false);
|
|
|
|
optionBtn[i]->SetTrigger(trigA);
|
|
|
|
optionBtn[i]->SetSoundClick(btnSoundClick);
|
|
|
|
}
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor for the GuiOptionBrowser class.
|
|
|
|
*/
|
|
|
|
GuiOptionBrowser::~GuiOptionBrowser()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
delete bgOptionsImg;
|
|
|
|
delete bgOptions;
|
|
|
|
delete bgOptionsEntry;
|
|
|
|
|
|
|
|
delete trigA;
|
|
|
|
|
|
|
|
for (int i = 0; i < PAGESIZE; i++)
|
|
|
|
{
|
|
|
|
delete optionTxt[i];
|
|
|
|
delete optionVal[i];
|
|
|
|
delete optionBg[i];
|
|
|
|
delete optionBtn[i];
|
|
|
|
}
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiOptionBrowser::ResetState()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if (state != STATE_DISABLED)
|
|
|
|
{
|
|
|
|
state = STATE_DEFAULT;
|
|
|
|
stateChan = -1;
|
|
|
|
}
|
|
|
|
|
2011-09-24 01:49:18 +02:00
|
|
|
for (u32 i = 0; i < optionBtn.size(); i++)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
optionBtn[i]->ResetState();
|
|
|
|
}
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int GuiOptionBrowser::GetClickedOption()
|
|
|
|
{
|
2011-09-24 01:49:18 +02:00
|
|
|
for (u32 i = 0; i < optionBtn.size(); i++)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
if (optionBtn[i]->GetState() == STATE_CLICKED)
|
|
|
|
{
|
|
|
|
optionBtn[i]->SetState(STATE_SELECTED);
|
2011-09-24 01:49:18 +02:00
|
|
|
return listOffset + i;
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int GuiOptionBrowser::GetSelectedOption()
|
|
|
|
{
|
2011-09-24 01:49:18 +02:00
|
|
|
for (u32 i = 0; i < optionBtn.size(); i++)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
|
|
|
{
|
2011-09-24 01:49:18 +02:00
|
|
|
return listOffset + i;
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiOptionBrowser::SetOffset(int optionnumber)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
listOffset = optionnumber;
|
|
|
|
selectedItem = optionnumber;
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiOptionBrowser::onListChange(int SelItem, int SelInd)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
selectedItem = SelItem;
|
|
|
|
listOffset = SelInd;
|
|
|
|
UpdateListEntries();
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the button on screen
|
|
|
|
*/
|
|
|
|
void GuiOptionBrowser::Draw()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if (!this->IsVisible()) return;
|
2011-06-14 19:53:19 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
bgOptionsImg->Draw();
|
2011-06-14 19:53:19 +02:00
|
|
|
|
2011-09-24 01:49:18 +02:00
|
|
|
for (u32 i = 0; i < optionBtn.size(); i++)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2011-09-24 01:49:18 +02:00
|
|
|
if (listOffset + i < (u32) options->GetLength())
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
optionBtn[i]->Draw();
|
|
|
|
}
|
|
|
|
}
|
2011-06-14 19:53:19 +02:00
|
|
|
|
2011-09-24 01:49:18 +02:00
|
|
|
scrollBar.Draw();
|
2011-06-14 19:53:19 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
this->UpdateEffects();
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiOptionBrowser::UpdateListEntries()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
LOCK(this);
|
2011-09-24 01:49:18 +02:00
|
|
|
if (listOffset < 0)
|
|
|
|
listOffset = 0;
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
int maxNameWidth = 0;
|
2011-09-24 01:49:18 +02:00
|
|
|
for (u32 i = 0; i < optionBtn.size(); i++)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2011-09-24 01:49:18 +02:00
|
|
|
if (listOffset + i < (u32) options->GetLength())
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
if (optionBtn[i]->GetState() == STATE_DISABLED)
|
|
|
|
{
|
|
|
|
optionBtn[i]->SetVisible(true);
|
|
|
|
optionBtn[i]->SetState(STATE_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2011-09-24 01:49:18 +02:00
|
|
|
optionTxt[i]->SetText(options->GetName(listOffset+i));
|
2011-07-26 00:28:22 +02:00
|
|
|
if (maxNameWidth < optionTxt[i]->GetTextWidth()) maxNameWidth = optionTxt[i]->GetTextWidth();
|
2011-09-24 01:49:18 +02:00
|
|
|
optionVal[i]->SetText(options->GetValue(listOffset+i));
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
optionBtn[i]->SetVisible(false);
|
|
|
|
optionBtn[i]->SetState(STATE_DISABLED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coL2 < (24 + maxNameWidth + 16))
|
|
|
|
coL2 = 24 + maxNameWidth + 16;
|
|
|
|
|
2011-09-24 01:49:18 +02:00
|
|
|
for (u32 i = 0; i < optionBtn.size(); i++)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
if (optionBtn[i]->GetState() != STATE_DISABLED)
|
|
|
|
{
|
|
|
|
optionVal[i]->SetPosition(coL2, 0);
|
|
|
|
optionVal[i]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), DOTTED);
|
|
|
|
}
|
|
|
|
}
|
2011-09-24 01:49:18 +02:00
|
|
|
|
|
|
|
oldSelectedItem = -1;
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiOptionBrowser::Update(GuiTrigger * t)
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if (state == STATE_DISABLED || !t) return;
|
|
|
|
|
2011-09-24 01:49:18 +02:00
|
|
|
int listSize = optionBtn.size();
|
2011-07-26 00:28:22 +02:00
|
|
|
static int pressedChan = -1;
|
|
|
|
|
|
|
|
if((t->wpad.btns_d & (WPAD_BUTTON_B | WPAD_BUTTON_DOWN | WPAD_BUTTON_UP | WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT |
|
|
|
|
WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)) ||
|
2015-01-04 21:22:06 +01:00
|
|
|
(t->pad.btns_d & (PAD_BUTTON_UP | PAD_BUTTON_DOWN)) ||
|
|
|
|
(t->wupcdata.btns_d & (WPAD_CLASSIC_BUTTON_B | WPAD_CLASSIC_BUTTON_UP | WPAD_CLASSIC_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_LEFT | WPAD_CLASSIC_BUTTON_RIGHT)))
|
2011-07-26 00:28:22 +02:00
|
|
|
pressedChan = t->chan;
|
|
|
|
|
2011-09-24 01:49:18 +02:00
|
|
|
// update the location of the scroll box based on the position in the option list
|
|
|
|
scrollBar.Update(t);
|
2011-07-26 00:28:22 +02:00
|
|
|
|
2015-01-04 21:22:06 +01:00
|
|
|
if(pressedChan == -1 || (!t->wpad.btns_h && !t->pad.btns_h && !t->wupcdata.btns_h))
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2011-09-24 01:49:18 +02:00
|
|
|
for(int i = 0; i < listSize; i++)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
if (i != selectedItem && optionBtn[i]->GetState() == STATE_SELECTED)
|
|
|
|
{
|
|
|
|
optionBtn[i]->ResetState();
|
|
|
|
}
|
|
|
|
else if (i == selectedItem && optionBtn[i]->GetState() == STATE_DEFAULT)
|
|
|
|
{
|
|
|
|
optionBtn[selectedItem]->SetState(STATE_SELECTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
optionBtn[i]->Update(t);
|
|
|
|
|
|
|
|
if (optionBtn[i]->GetState() == STATE_SELECTED)
|
|
|
|
selectedItem = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-04 21:22:06 +01:00
|
|
|
if(pressedChan == t->chan && !t->wpad.btns_d && !t->wpad.btns_h && !t->wupcdata.btns_d && !t->wupcdata.btns_h)
|
2011-07-26 00:28:22 +02:00
|
|
|
pressedChan = -1;
|
|
|
|
|
2011-09-24 01:49:18 +02:00
|
|
|
if(selectedItem != oldSelectedItem)
|
|
|
|
{
|
|
|
|
if(oldSelectedItem >= 0 && oldSelectedItem < listSize)
|
|
|
|
optionVal[oldSelectedItem]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), DOTTED);
|
|
|
|
if(selectedItem >= 0 && selectedItem < listSize)
|
|
|
|
optionVal[selectedItem]->SetMaxWidth(bgOptionsImg->GetWidth() - (coL2 + scrollBar.GetWidth()+10), SCROLL_HORIZONTAL);
|
|
|
|
|
|
|
|
oldSelectedItem = selectedItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
scrollBar.SetPageSize(listSize);
|
2011-07-26 00:28:22 +02:00
|
|
|
scrollBar.SetSelectedItem(selectedItem);
|
|
|
|
scrollBar.SetSelectedIndex(listOffset);
|
|
|
|
scrollBar.SetEntrieCount(options->GetLength());
|
|
|
|
|
|
|
|
if (options->IsChanged())
|
|
|
|
UpdateListEntries();
|
2011-06-14 19:53:19 +02:00
|
|
|
}
|