* New interface. * This breaks a lot of things. It is not feature-equivalent. It probably doesn't compile under windows and doesn't work on PSP. * Damage is not resolved any more. This will have to be fixed. * Blockers can't be ordered any more. This will have to be fixed. * A lot of new art is included.
137 lines
2.9 KiB
C++
137 lines
2.9 KiB
C++
#include "../include/OptionItem.h"
|
|
#include "../include/GameApp.h"
|
|
#include <JGE.h>
|
|
#include "../include/GameOptions.h"
|
|
#include "../include/Translate.h"
|
|
|
|
OptionItem::OptionItem(string _id, string _displayValue, int _maxValue, int _increment):JGuiObject(0){
|
|
id = _id;
|
|
maxValue = _maxValue;
|
|
increment = _increment;
|
|
displayValue = _(_displayValue);
|
|
value = options[id].number;
|
|
hasFocus = 0;
|
|
x = 0;
|
|
y = 0;
|
|
}
|
|
|
|
void OptionItem::setData(){
|
|
options[id] = GameOption(value);
|
|
}
|
|
|
|
void OptionItem::Render(){
|
|
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
|
|
if (hasFocus){
|
|
mFont->SetColor(ARGB(255,255,255,0));
|
|
}else{
|
|
mFont->SetColor(ARGB(255,255,255,255));
|
|
}
|
|
JRenderer * renderer = JRenderer::GetInstance();
|
|
renderer->FillRoundRect(x-5,y-2,SCREEN_WIDTH -x - 5,20,2,ARGB(150,50,50,50));
|
|
mFont->DrawString(displayValue.c_str(),x,y);
|
|
char buf[512];
|
|
if (maxValue == 1){
|
|
if (value){
|
|
sprintf(buf, _("Yes").c_str());
|
|
}else{
|
|
sprintf(buf,_("No").c_str());
|
|
}
|
|
}else{
|
|
sprintf(buf, "%i", value);
|
|
}
|
|
mFont->DrawString(buf,SCREEN_WIDTH -10 ,y,JGETEXT_RIGHT);
|
|
}
|
|
|
|
void OptionItem::Update(float dt){
|
|
JGE * mEngine = JGE::GetInstance();
|
|
if (hasFocus){
|
|
if (mEngine->GetButtonClick(PSP_CTRL_CIRCLE)) updateValue();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void OptionItem::Entering(){
|
|
hasFocus = true;
|
|
}
|
|
bool OptionItem::Leaving(){
|
|
hasFocus = false;
|
|
return true;
|
|
}
|
|
|
|
|
|
OptionsList::OptionsList(){
|
|
nbitems = 0;
|
|
current = -1;
|
|
}
|
|
OptionsList::~OptionsList(){
|
|
for (int i = 0 ; i < nbitems; i++){
|
|
SAFE_DELETE(options[i]);
|
|
}
|
|
}
|
|
|
|
void OptionsList::Add(OptionItem * item){
|
|
if (nbitems < 20){
|
|
options[nbitems] = item;
|
|
item->x = 10;
|
|
item->y = 20 + 30*nbitems;
|
|
nbitems++;
|
|
if (current < 0){
|
|
current = 0;
|
|
options[0]->Entering();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
void OptionsList::Render(){
|
|
if (!nbitems){
|
|
JLBFont * mFont = GameApp::CommonRes->GetJLBFont("graphics/f3");
|
|
mFont->DrawString("NO OPTIONS AVAILABLE",SCREEN_WIDTH/2, 5, JGETEXT_RIGHT);
|
|
}
|
|
for (int i = 0 ; i < nbitems; i++){
|
|
options[i]->Render();
|
|
}
|
|
}
|
|
|
|
void OptionsList::save(){
|
|
for (int i = 0; i < nbitems; i++){
|
|
options[i]->setData();
|
|
}
|
|
::options.save();
|
|
}
|
|
|
|
void OptionsList::Update(float dt){
|
|
JGE * mEngine = JGE::GetInstance();
|
|
if (mEngine->GetButtonClick(PSP_CTRL_UP))
|
|
{
|
|
if (current > 0){
|
|
options[current]->Leaving();
|
|
current--;
|
|
options[current]->Entering();
|
|
}
|
|
}
|
|
else if (mEngine->GetButtonClick(PSP_CTRL_DOWN))
|
|
{
|
|
if (current < nbitems -1){
|
|
options[current]->Leaving();
|
|
current++;
|
|
options[current]->Entering();
|
|
}
|
|
}
|
|
for (int i = 0 ; i < nbitems; i++){
|
|
options[i]->Update(dt);
|
|
}
|
|
}
|
|
|
|
ostream& OptionItem::toString(ostream& out) const
|
|
{
|
|
return out << "OptionItem ::: displayValue : " << displayValue
|
|
<< " ; id : " << id
|
|
<< " ; value : " << value
|
|
<< " ; hasFocus : " << hasFocus
|
|
<< " ; maxValue : " << maxValue
|
|
<< " ; increment : " << increment
|
|
<< " ; x,y : " << x << "," << y;
|
|
}
|