*Fixed some bugs in the game browser and game carousel

*Added a few new files for later use
This commit is contained in:
DRayX7 2009-06-08 16:26:04 +00:00
parent 6cf6de3e70
commit c257e1d378
4 changed files with 162 additions and 55 deletions

101
source/gameobjects.cpp Normal file
View File

@ -0,0 +1,101 @@
/****************************************************************************
* gameobjects.cpp
*
* class definition
***************************************************************************/
#include "libwiigui/gui_gamebrowser.h"
#include "libwiigui/gui_gamegrid.h"
#include "libwiigui/gui_gamecarousel.h"
/**
* Constructor for the GameObjects class.
*/
GameObjects::GameObjects(int obj)
{
gameBroswer = new GuiGameBrowser(/* Params */);
gameGrid = new GuiGameGrid(/* Params */);
gameCarousel = new GuiGameCarousel(/* Params */);
active = obj;
}
/**
* Destructor for the GuiGameCarousel class.
*/
GameObjects::~GameObjects()
{
delete gameBrowser;
delete gameGrid;
delete gameCarousel;
}
/**
* Functions to set and get teh active object.
*/
void GameObjects::SetActive(int obj)
{
active = obj;
}
int GameObjects::GetActive()
{
return active;
}
/**
* Reload Functions.
*/
void GameObjects::ReloadAll(struct discHdr * l, int count)
{
gameBrowser->Reload(l, count);
gameGrid->Reload(l, count);
gameCarousel->Reload(l, count);
}
void GameObjects::Reload(int obj, struct discHdr * l, int count)
{
if(obj == LIST) gameBrowser->Reload(l, count);
else if(obj == GRID) gameGrid->Reload(l, count);
else if(obj == CAROUSEL) gameCarousel->Reload(l, count);
}
void GameObjects::Reload(struct discHdr * l, int count)
{
Reload(active, l, count);
}
/**
* Functions to get pointers to the various objects.
*/
void * GameObjects::Ptr(int obj)
{
if(obj == LIST) return gameBrowser;
else if(obj == GRID) return gameGrid;
else if(obj == CAROUSEL) return gameCarousel;
else return NULL;
}
void * GameObjects::Ptr()
{
return Ptr(active);
}
/**
* Functions to set focus.
*/
void GameObjects::SetFocus(int obj, int f)
{
if(obj == LIST) gameBrowser->SetFocus(f);
else if(obj == GRID) gameGrid->SetFocus(f);
else if(obj == CAROUSEL) gameCarousel->SetFocus(f);
}
void GameObjects::SetFocus(int f)
{
SetFocus(active, f);
}
void GameObjects::SetFocus()
{
SetFocus(active, 1);
}

25
source/gameobjects.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef _GAMEOBJECTS_H_
#define _GAMEOBJECTS_H_
class GameObjects
{
public:
GameObjects(int obj);
~GameObjects();
void SetActive(int obj);
int GetActive();
void ReloadAll(struct discHdr * l, int count);
void Reload(int obj, struct discHdr * l, int count);
void Reload(struct discHdr * l, int count);
void * Ptr(int obj);
void * Ptr();
void SetFocus(int obj, int f);
void SetFocus(int f);
void SetFocus();
protected:
GuiGameBrowser * gameBrowser;
GuiGameGrid * gameGrid;
GuiGameCarousel * gameCarousel;
int active;
};
#endif

View File

@ -300,14 +300,15 @@ void GuiGameBrowser::Draw()
break; break;
} }
if(scrollbaron == 1) { if(scrollbaron == 1) {
scrollbarImg->Draw(); scrollbarImg->Draw();
arrowUpBtn->Draw(); arrowUpBtn->Draw();
arrowDownBtn->Draw(); arrowDownBtn->Draw();
scrollbarBoxBtn->Draw(); scrollbarBoxBtn->Draw();
} }
this->UpdateEffects(); this->UpdateEffects();
} }
void GuiGameBrowser::UpdateListEntries() void GuiGameBrowser::UpdateListEntries()
{ {
int next = listOffset; int next = listOffset;
@ -344,17 +345,17 @@ void GuiGameBrowser::Update(GuiTrigger * t)
int next, prev; int next, prev;
int old_listOffset = listOffset; int old_listOffset = listOffset;
static int position2; static int position2;
// scrolldelay affects how fast the list scrolls // scrolldelay affects how fast the list scrolls
// when the arrows are clicked // when the arrows are clicked
float scrolldelay = 3.5; float scrolldelay = 3.5;
if (scrollbaron == 1) { if (scrollbaron == 1) {
// update the location of the scroll box based on the position in the option list // update the location of the scroll box based on the position in the option list
arrowUpBtn->Update(t); arrowUpBtn->Update(t);
arrowDownBtn->Update(t); arrowDownBtn->Update(t);
scrollbarBoxBtn->Update(t); scrollbarBoxBtn->Update(t);
} }
next = listOffset; next = listOffset;
@ -384,16 +385,14 @@ void GuiGameBrowser::Update(GuiTrigger * t)
} }
} }
// pad/joystick navigation // pad and joystick navigation
if(!focus) if(!focus || !gameCnt)
return; // skip navigation return; // skip navigation
if (scrollbaron == 1) if (scrollbaron == 1)
{ {
if (t->Down() || if (t->Down() || arrowDownBtn->GetState() == STATE_CLICKED || arrowDownBtn->GetState() == STATE_HELD) //down
arrowDownBtn->GetState() == STATE_CLICKED ||
arrowDownBtn->GetState() == STATE_HELD)
{ {
next = this->FindMenuItem(gameIndex[selectedItem], 1); next = this->FindMenuItem(gameIndex[selectedItem], 1);
@ -404,7 +403,6 @@ void GuiGameBrowser::Update(GuiTrigger * t)
{ {
// move list down by 1 // move list down by 1
listOffset = this->FindMenuItem(listOffset, 1); listOffset = this->FindMenuItem(listOffset, 1);
// UpdateEntries();
} }
else if(game[selectedItem+1]->IsVisible()) else if(game[selectedItem+1]->IsVisible())
{ {
@ -415,13 +413,10 @@ void GuiGameBrowser::Update(GuiTrigger * t)
scrollbarBoxBtn->Draw(); scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay); usleep(10000 * scrolldelay);
} }
if (buttonshold != WPAD_BUTTON_A){ if (!(ButtonsHold() & WPAD_BUTTON_A))
arrowDownBtn->ResetState(); arrowDownBtn->ResetState();
}
} }
else if(t->Up() || else if(t->Up() || arrowUpBtn->GetState() == STATE_CLICKED || arrowUpBtn->GetState() == STATE_HELD) //up
arrowUpBtn->GetState() == STATE_CLICKED || ////////////////////////////////////////////up
arrowUpBtn->GetState() == STATE_HELD)
{ {
prev = this->FindMenuItem(gameIndex[selectedItem], -1); prev = this->FindMenuItem(gameIndex[selectedItem], -1);
@ -441,21 +436,17 @@ void GuiGameBrowser::Update(GuiTrigger * t)
scrollbarBoxBtn->Draw(); scrollbarBoxBtn->Draw();
usleep(10000 * scrolldelay); usleep(10000 * scrolldelay);
} }
if (buttonshold != WPAD_BUTTON_A){ if (!(ButtonsHold() & WPAD_BUTTON_A))
arrowUpBtn->ResetState(); arrowUpBtn->ResetState();
}
} }
int position1 = 0; int position1 = t->wpad.ir.y;
position1 = t->wpad.ir.y;
if (position2 == 0 && position1 > 0) if (position2 == 0 && position1 > 0)
{ {
position2 = position1; position2 = position1;
} }
if (buttonshold == WPAD_BUTTON_B && position1 > 0) if ((buttonshold & WPAD_BUTTON_B) && position1 > 0)
{ {
scrollbarBoxBtn->ScrollIsOn(1); scrollbarBoxBtn->ScrollIsOn(1);
if (position2 > position1) if (position2 > position1)
@ -469,7 +460,6 @@ void GuiGameBrowser::Update(GuiTrigger * t)
{ {
// move list up by 1 // move list up by 1
listOffset = prev; listOffset = prev;
// UpdateEntries();
} }
else else
{ {
@ -491,7 +481,6 @@ void GuiGameBrowser::Update(GuiTrigger * t)
{ {
// move list down by 1 // move list down by 1
listOffset = this->FindMenuItem(listOffset, 1); listOffset = this->FindMenuItem(listOffset, 1);
// UpdateEntries();
} }
else if(game[selectedItem+1]->IsVisible()) else if(game[selectedItem+1]->IsVisible())
{ {
@ -505,54 +494,46 @@ void GuiGameBrowser::Update(GuiTrigger * t)
} }
} }
else if(buttonshold != WPAD_BUTTON_B) else if(!(buttonshold & WPAD_BUTTON_B))
{ {
scrollbarBoxBtn->ScrollIsOn(0); scrollbarBoxBtn->ScrollIsOn(0);
position2 = 0; position2 = 0;
} }
if(scrollbarBoxBtn->GetState() == STATE_HELD &&/////////////////////allow dragging of scrollbar box if(scrollbarBoxBtn->GetState() == STATE_HELD && scrollbarBoxBtn->GetStateChan() == t->chan && t->wpad.ir.valid && gameCnt > pagesize)
scrollbarBoxBtn->GetStateChan() == t->chan &&
t->wpad.ir.valid && gameCnt > pagesize)
{ {
// allow dragging of scrollbar box
scrollbarBoxBtn->SetPosition(width/2-18+7,0); scrollbarBoxBtn->SetPosition(width/2-18+7,0);
//int position = t->wpad.ir.y - 50 - scrollbarBoxBtn->GetTop();
int position = t->wpad.ir.y - 32 - scrollbarBoxBtn->GetTop(); int position = t->wpad.ir.y - 32 - scrollbarBoxBtn->GetTop();
//listOffset = (position * gameCnt)/237 - selectedItem;
listOffset = (position * gameCnt)/(25.2 * pagesize) - selectedItem; listOffset = (position * gameCnt)/(25.2 * pagesize) - selectedItem;
// UpdateEntries();
if(listOffset <= 0) if(listOffset <= 0)
{ {
listOffset = 0; listOffset = 0;
// UpdateEntries();
selectedItem = 0; selectedItem = 0;
} }
else if(listOffset+pagesize >= gameCnt) else if(listOffset+pagesize >= gameCnt)
{ {
listOffset = gameCnt - pagesize; listOffset = gameCnt - pagesize;
// UpdateEntries();
selectedItem = pagesize-1; selectedItem = pagesize-1;
} }
} }
//int positionbar = 237*(listOffset + selectedItem) / gameCnt;
int positionbar = (25.2 * pagesize)*(listOffset + selectedItem) / gameCnt; int positionbar = (25.2 * pagesize)*(listOffset + selectedItem) / gameCnt;
if(positionbar > (24 * pagesize))//if(positionbar > 216) if(positionbar > (24 * pagesize))
positionbar = (24 * pagesize);//positionbar = 216; positionbar = (24 * pagesize);
scrollbarBoxBtn->SetPosition(width/2-18+7, positionbar+8); scrollbarBoxBtn->SetPosition(width/2-18+7, positionbar+8);
if(t->Right())/////////////////////////////////////////////////////skip pagesize # of games if right is pressed if(t->Right()) //skip pagesize # of games if right is pressed
{ {
if(listOffset < gameCnt && gameCnt > pagesize) if(listOffset < gameCnt && gameCnt > pagesize)
{ {
listOffset =listOffset+ pagesize; listOffset =listOffset+ pagesize;
if(listOffset+pagesize >= gameCnt) if(listOffset+pagesize >= gameCnt)
listOffset = gameCnt-pagesize; listOffset = gameCnt-pagesize;
// UpdateEntries();
} }
} }
else if(t->Left()) else if(t->Left())
@ -562,14 +543,13 @@ void GuiGameBrowser::Update(GuiTrigger * t)
listOffset =listOffset- pagesize; listOffset =listOffset- pagesize;
if(listOffset < 0) if(listOffset < 0)
listOffset = 0; listOffset = 0;
// UpdateEntries();
} }
} }
} }
else else
{ {
if(t->Down())/////////////////////////////////////////////////////if there isn't a scrollbar and down is pressed if(t->Down()) //if there isn't a scrollbar and down is pressed
{ {
next = this->FindMenuItem(gameIndex[selectedItem], 1); next = this->FindMenuItem(gameIndex[selectedItem], 1);
@ -588,7 +568,7 @@ void GuiGameBrowser::Update(GuiTrigger * t)
} }
} }
} }
else if(t->Up())///////////////////////////////////////////////////up else if(t->Up()) //up
{ {
prev = this->FindMenuItem(gameIndex[selectedItem], -1); prev = this->FindMenuItem(gameIndex[selectedItem], -1);
@ -607,7 +587,8 @@ void GuiGameBrowser::Update(GuiTrigger * t)
} }
} }
} }
} }
if(old_listOffset != listOffset) if(old_listOffset != listOffset)
UpdateListEntries(); UpdateListEntries();

View File

@ -219,15 +219,15 @@ int GuiGameCarousel::GetOffset()
int GuiGameCarousel::GetClickedOption() int GuiGameCarousel::GetClickedOption()
{ {
int found = -1; int found = -1;
if (clickedItem>-1){ if (clickedItem>=0 && clickedItem<=pagesize){
if (game[bob[clickedItem+1]]->GetState()==STATE_SELECTED){ if (game[bob[(clickedItem+1) % pagesize]]->GetState()==STATE_SELECTED){
found= (clickedItem+listOffset+1) % gameCnt; found = (clickedItem+listOffset+1) % gameCnt;
game[bob[clickedItem+1]]->SetState(STATE_SELECTED); game[bob[(clickedItem+1) % pagesize]]->SetState(STATE_SELECTED);
game[bob[clickedItem]]->SetState(STATE_SELECTED);} game[bob[clickedItem]]->SetState(STATE_SELECTED);
else { } else {
game[bob[clickedItem]]->SetState(STATE_SELECTED); game[bob[clickedItem]]->SetState(STATE_SELECTED);
found= (clickedItem+listOffset) % gameCnt;} found= (clickedItem+listOffset) % gameCnt;}
clickedItem=-1; clickedItem=-1;
} }
return found; return found;
} }