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

View File

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