**Changes

*Modified EFFECT_GOROUND so that it takes a center of rotation, angles work properly, and things don't move back.
*Updated the gui_gamecarousel files so that they are functional, shouldn't have any more code dumps, and use the EFFECT_GOROUND.
*The carousel button doesn't do anything anymore (since GOROUND was changed so much)

**Notes
*The easiest way test the carousel is to change guiGameGrid to guiGameCarousel in source/menu.cpp.
*If you compile with no modifications, the only noticeable difference is that the carousel button does nothing.

**Known Bugs in gui_gamecarousel
*The images dont line up horizontally (when shifting left they go too far left, and the same for shifting right). I think there is a rounding bug somewhere in GOROUND (I already fixed several).
*Cant hold down left and right to scroll yet
*Launching a game only works if the pointer is over two boxes
*If an image is growing when the carousel is turned, that button disapears
*If an image is grown when the carousel is turned, it wont shrink back
This commit is contained in:
DRayX7 2009-05-28 01:46:05 +00:00
parent 94a8ccc7c1
commit aaa2a3f25f
5 changed files with 163 additions and 177 deletions

View File

@ -344,7 +344,9 @@ class GuiElement
//!\param startdegree Degree where to start circling
//!\param anglespeedset Set the speed of Angle rotating make 1 for same speed as Circlespeed
//! or 0.5 for half the speed of the circlingspeed. Turn Anglecircling off by 0 to this param.
void SetEffect(int e, int speed, int circles, int r, int startdegree, f32 anglespeedset);
//!\param center_x x co-ordinate of the center of circle.
//!\param center_y y co-ordinate of the center of circle.
void SetEffect(int e, int speed, int circles, int r, int startdegree, f32 anglespeedset, int center_x, int center_y);
//!Sets an effect to be enabled on wiimote cursor over
//!\param e Effect to enable
//!\param a Amount of the effect (usage varies on effect)
@ -420,6 +422,8 @@ class GuiElement
int xmax; //!< Element's max X offset allowed
int xoffsetDyn; //!< Element X offset, dynamic (added to xoffset value for animation effects)
int yoffsetDyn; //!< Element Y offset, dynamic (added to yoffset value for animation effects)
int temp_xoffset; //!< Element Temp X offset
int temp_yoffset; //!< Element Temp Y offset
f32 degree; //!< Degree where to start for EFFECT_GOROUND enter it in ° like 60°
f32 frequency; //!< Speed for EFFECT_GOROUND || can also be negative for other direction
int Radius; //!< The radius in which the Element goes round for EFFECT_GOROUND

View File

@ -431,7 +431,7 @@ int GuiElement::GetEffect()
return effects;
}
void GuiElement::SetEffect(int eff, int speed, int circles, int r, int startdegree, f32 anglespeedset) {
void GuiElement::SetEffect(int eff, int speed, int circles, int r, int startdegree, f32 anglespeedset, int center_x, int center_y) {
if(eff & EFFECT_GOROUND) {
xoffsetDyn = 0; //!position of circle in x
@ -439,8 +439,10 @@ void GuiElement::SetEffect(int eff, int speed, int circles, int r, int startdegr
Radius = r; //!Radius of the circle
degree = startdegree*PI/180; //!for example -90 (°) to start at top of circle
circleamount = circles; //!circleamoutn in degrees for example 360 for 1 circle
angleDyn = 0.0; //!this is used by the code to calc the angle
angleDyn = 0.0f; //!this is used by the code to calc the angle
anglespeed = anglespeedset; //!This is anglespeed depending on circle speed 1 is same speed and 0.5 half speed
temp_xoffset = center_x; //!position of center in x
temp_yoffset = center_y; //!position of center in y
}
effects |= eff;
effectAmount = speed; //!Circlespeed
@ -596,40 +598,22 @@ void GuiElement::UpdateEffects()
if(effects & EFFECT_GOROUND) {
//!< check out gui.h for info
if(abs(frequency) < PI*circleamount/180) {
xoffset = temp_xoffset;
yoffset = temp_yoffset;
angleDyn = (frequency+degree) * 180/PI * anglespeed;
frequency += effectAmount*0.001;
if(fabs(frequency) < PI*((f32) circleamount)/180.0f) {
angleDyn = ((frequency+degree) * 180.0f/PI + 90.0f) * anglespeed;
frequency += effectAmount*0.001f;
xoffsetDyn = (int)(Radius*cos(frequency+degree));
yoffsetDyn = (int)(Radius*sin(frequency+degree));
} else {
//Angle go back to start value (has to be 0.0001 when near 0 but not 0 so that the if state goes through)
//value 0.0001 isnt noticeable that's why i chose it.
angleDyn = degree* 180/PI * anglespeed +0.0001;
//Reset Angle to 0
//angleDyn = 0.0001;
//fly back to the middle tolerance to 0 is +- 10pixel
if(xoffsetDyn < -10)
xoffsetDyn += abs(effectAmount)*0.1;
else if(xoffsetDyn > 10)
xoffsetDyn -= abs(effectAmount)*0.1;
else xoffsetDyn = 0;
if(yoffsetDyn < -10)
yoffsetDyn += abs(effectAmount)*0.1;
else if(yoffsetDyn > 10)
yoffsetDyn -= abs(effectAmount)*0.1;
else yoffsetDyn = 0;
if(xoffsetDyn == 0 && yoffsetDyn == 0) {
effects = 0;
frequency = 0;
Radius = 0;
}
xoffset += xoffsetDyn;
yoffset += yoffsetDyn;
}
}

View File

@ -61,11 +61,10 @@ GuiGameCarousel::GuiGameCarousel(int w, int h, struct discHdr * l, int gameCnt,
btnLeftImg = new GuiImage(imgLeft);
btnLeft = new GuiButton(imgLeft->GetWidth(), imgLeft->GetHeight());
btnLeft->SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
btnLeft->SetPosition(20, -30);
btnLeft->SetPosition(20, -100);
btnLeft->SetParent(this);
btnLeft->SetImage(btnLeftImg);
btnLeft->SetSoundOver(btnSoundOver);
btnLeft->SetSoundClick(btnSoundClick);
btnLeft->SetTrigger(trigA);
btnLeft->SetTrigger(trigL);
btnLeft->SetTrigger(trigMinus);
@ -75,10 +74,9 @@ GuiGameCarousel::GuiGameCarousel(int w, int h, struct discHdr * l, int gameCnt,
btnRight = new GuiButton(imgRight->GetWidth(), imgRight->GetHeight());
btnRight->SetParent(this);
btnRight->SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE);
btnRight->SetPosition(-20, -30);
btnRight->SetPosition(-20, -100);
btnRight->SetImage(btnRightImg);
btnRight->SetSoundOver(btnSoundOver);
btnRight->SetSoundClick(btnSoundClick);
btnRight->SetTrigger(trigA);
btnRight->SetTrigger(trigR);
btnRight->SetTrigger(trigPlus);
@ -88,6 +86,11 @@ GuiGameCarousel::GuiGameCarousel(int w, int h, struct discHdr * l, int gameCnt,
game = new GuiButton * [pagesize];
coverImg = new GuiImage * [pagesize];
cover = new GuiImageData * [pagesize];
bob = new int[7];
for(int i=0; i<7; i++) {
bob[i]=i;
}
char ID[4];
char IDfull[7];
@ -116,22 +119,15 @@ GuiGameCarousel::GuiGameCarousel(int w, int h, struct discHdr * l, int gameCnt,
coverImg[i] = new GuiImage(cover[i]);
coverImg[i]->SetScale(0.8);
coverImg[i]->SetWidescreen(CFG.widescreen);
coverImg[i]->SetAngle(-30+(i*10));
coverImg[i]->SetPosition(-20,0);
game[i] = new GuiButton(122,244);
game[i]->SetParent(this);
game[i]->SetAlignment(ALIGN_CENTRE,ALIGN_MIDDLE);
game[i]->SetPosition(0,740);
game[i]->SetImage(coverImg[i]);
if (i==0)game[i]->SetPosition(-290,20);
if (i==1)game[i]->SetPosition(-200,-45);
if (i==2)game[i]->SetPosition(-100,-85);
if (i==3)game[i]->SetPosition(0,-100);
if (i==4)game[i]->SetPosition(100,-80);
if (i==5)game[i]->SetPosition(200,-40);
if (i==6)game[i]->SetPosition(290,20);
game[i]->SetRumble(false);
game[i]->SetTrigger(trigA);
game[i]->SetSoundClick(btnSoundClick);
game[i]->SetEffectGrow();
game[i]->SetEffect(EFFECT_GOROUND, -50, 49, 780, 298+7*i, 1, 0, 740);
}
}
@ -158,7 +154,10 @@ GuiGameCarousel::~GuiGameCarousel()
delete cover[i];
}
delete [] gameIndex;
delete [] bob;
delete [] game;
delete [] coverImg;
delete [] cover;
}
@ -256,7 +255,7 @@ void GuiGameCarousel::Draw()
for(int i=0; i<pagesize; i++) {
if(next >= 0) {
game[i]->Draw();
game[bob[i]]->Draw();
next = this->FindMenuItem(next, 1);
} else break;
}
@ -273,6 +272,12 @@ void GuiGameCarousel::Update(GuiTrigger * t)
if(state == STATE_DISABLED || !t)
return;
if(game[0]->GetEffect() == 0) {
for(int i=0; i<7; i++) {
game[i]->SetEffectGrow();
}
}
btnRight->Update(t);
btnLeft->Update(t);
@ -308,43 +313,64 @@ void GuiGameCarousel::Update(GuiTrigger * t)
}
}
// pad/joystick navigation
// navigation
if(!focus)
return; // skip navigation
if ((t->Right() || btnRight->GetState() == STATE_CLICKED)) {
if (firstPic<0)
firstPic=6;
if (t->Left() || btnLeft->GetState() == STATE_CLICKED) {
changed++;
if (changed > (gameCnt-1))
changed=0;
int bob[7];
firstPic++;
if (firstPic>6)
firstPic=0;
for (int i=0; i<7; i++) {
bob[i] = (firstPic+i < 7) ? firstPic+i : firstPic+i-7;
}
for(int i=0; i<20; i++) {
int index = (changed+7 < gameCnt) ? changed+7 : changed+7-gameCnt;
struct discHdr *header = &gameList[index];
snprintf (ID,sizeof(ID),"%c%c%c", header->id[0], header->id[1], header->id[2]);
snprintf (IDfull,sizeof(IDfull),"%c%c%c%c%c%c", header->id[0], header->id[1], header->id[2],header->id[3], header->id[4], header->id[5]);
delete cover[bob[6]];
snprintf(imgPath, sizeof(imgPath), "%s%s.png", CFG.covers_path, IDfull); //Load full id image
cover[bob[6]] = new GuiImageData(imgPath,0);
if (!cover[bob[6]]->GetImage()) {
delete cover[bob[6]];
snprintf(imgPath, sizeof(imgPath), "%s%s.png", CFG.covers_path, ID); //Load short id image
cover[bob[6]] = new GuiImageData(imgPath, 0);
if (!cover[bob[6]]->GetImage()) {
delete cover[bob[6]];
snprintf(imgPath, sizeof(imgPath), "%snoimage.png", CFG.covers_path); //Load no image
cover[bob[6]] = new GuiImageData(imgPath, nocover_png);
}
}
delete coverImg[bob[6]];
coverImg[bob[6]] = new GuiImage(cover[bob[6]]);
coverImg[bob[6]]->SetScale(0.8);
coverImg[bob[6]]->SetWidescreen(CFG.widescreen);
game[bob[6]]->SetImage(coverImg[bob[6]]);
game[bob[1]]->SetPosition((-200-(4.5*i)),(-45+(3.25*i)));
coverImg[bob[1]]->SetAngle(-20-(i/2));
for (int i=0; i<7; i++) {
game[bob[i]]->SetEffect(EFFECT_GOROUND, -50, 7, 780, 256+7*i, 1, 0, 740);
}
game[bob[2]]->SetPosition((-100-(5*i)),(-85+(2*i)));
coverImg[bob[2]]->SetAngle(-10-(i/2));
btnLeft->ResetState();
}
game[bob[3]]->SetPosition((0-(5*i)),(-100+(0.75*i)));
coverImg[bob[3]]->SetAngle(0-(i/2));
else if(t->Right() || btnRight->GetState() == STATE_CLICKED) {
changed--;
if (changed<0)
changed=(gameCnt-1);
firstPic--;
if (firstPic<0)
firstPic=6;
game[bob[4]]->SetPosition((100-(5*i)),(-80-(1*i)));
coverImg[bob[4]]->SetAngle(10-(i/2));
for(int i=0; i<7; i++) {
bob[i] = (firstPic+i < 7) ? firstPic+i : firstPic+i-7;
}
game[bob[5]]->SetPosition((200-(4.5*i)),(-40-(2*i)));
coverImg[bob[5]]->SetAngle(20-(i/2));
game[bob[6]]->SetPosition((290-(4.5*i)),(20-(3*i)));
coverImg[bob[6]]->SetAngle(30-(i/2));
if (i==1) {
struct discHdr *header = &gameList[changed];
snprintf (ID,sizeof(ID),"%c%c%c", header->id[0], header->id[1], header->id[2]);
snprintf (IDfull,sizeof(IDfull),"%c%c%c%c%c%c", header->id[0], header->id[1], header->id[2],header->id[3], header->id[4], header->id[5]);
@ -366,86 +392,12 @@ void GuiGameCarousel::Update(GuiTrigger * t)
coverImg[bob[0]]->SetScale(0.8);
coverImg[bob[0]]->SetWidescreen(CFG.widescreen);
game[bob[0]]->SetImage(coverImg[bob[0]]);
}
game[bob[0]]->SetPosition((380-(4.5*i)),(80-(3*i)));
coverImg[bob[0]]->SetAngle(40-(i/2));
usleep(speed/25);
for(int j=0; j<pagesize; j++) {
game[bob[6-j]]->Draw();
}
}
firstPic++;
btnRight->ResetState();
}
else if((t->Left() || btnLeft->GetState() == STATE_CLICKED)) {
if (firstPic<0)
firstPic=6;
changed--;
if (changed<0)
changed=(gameCnt-1);
int bob[7];
for(int i=0; i<7; i++) {
bob[i] = (firstPic+i < 7) ? firstPic+i : firstPic+i-7;
game[bob[i]]->SetEffect(EFFECT_GOROUND, 50, 7, 780, 242+7*i, 1, 0, 740);
}
for(int i=0; i<20; i++) {
game[bob[0]]->SetPosition((-290+(4.5*i)),(20-(3.25*i)));
coverImg[bob[0]]->SetAngle(-30+(i/2));
game[bob[1]]->SetPosition((-200+(5*i)),(-45-(2*i)));
coverImg[bob[1]]->SetAngle(-20+(i/2));
game[bob[2]]->SetPosition((-100+(5*i)),(-85-(.75*i)));
coverImg[bob[2]]->SetAngle(-10+(i/2));
game[bob[3]]->SetPosition((0+(5*i)),(-100+(1*i)));
coverImg[bob[3]]->SetAngle(0+(i/2));
game[bob[4]]->SetPosition((100+(5*i)),(-80+(2*i)));
coverImg[bob[4]]->SetAngle(10+(i/2));
game[bob[5]]->SetPosition((200+(4.5*i)),(-40+(3*i)));
coverImg[bob[5]]->SetAngle(20+(i/2));
if (i==1) {
struct discHdr *header = &gameList[changed];
snprintf (ID,sizeof(ID),"%c%c%c", header->id[0], header->id[1], header->id[2]);
snprintf (IDfull,sizeof(IDfull),"%c%c%c%c%c%c", header->id[0], header->id[1], header->id[2],header->id[3], header->id[4], header->id[5]);
delete cover[bob[6]];
snprintf(imgPath, sizeof(imgPath), "%s%s.png", CFG.covers_path, IDfull); //Load full id image
cover[bob[6]] = new GuiImageData(imgPath,0);
if (!cover[bob[6]]->GetImage()) {
delete cover[bob[6]];
snprintf(imgPath, sizeof(imgPath), "%s%s.png", CFG.covers_path, ID); //Load short id image
cover[bob[6]] = new GuiImageData(imgPath, 0);
if (!cover[bob[6]]->GetImage()) {
delete cover[bob[6]];
snprintf(imgPath, sizeof(imgPath), "%snoimage.png", CFG.covers_path); //Load no image
cover[bob[6]] = new GuiImageData(imgPath, nocover_png);
}
}
delete coverImg[bob[6]];
coverImg[bob[6]] = new GuiImage(cover[bob[6]]);
coverImg[bob[6]]->SetScale(0.8);
coverImg[bob[6]]->SetWidescreen(CFG.widescreen);
game[bob[6]]->SetImage(coverImg[bob[6]]);
}
game[bob[6]]->SetPosition((-380+(4.5*i)),(80-(3*i)));
coverImg[bob[6]]->SetAngle(-40+(i/2));
usleep(speed/25);
for(int j=0; j<pagesize; j++) {
game[bob[6-j]]->Draw();
}
}
firstPic--;
btnLeft->ResetState();
btnRight->ResetState();
}
if(updateCB)
@ -462,4 +414,47 @@ void GuiGameCarousel::Reload(struct discHdr * l, int count)
selectedItem = 0;
listOffset = 0;
firstPic = 0;
for(int i=0; i<7; i++) {
bob[i]=i;
}
char ID[4];
char IDfull[7];
char imgPath[100];
for(int i=0; i < pagesize; i++) {
struct discHdr *header = &gameList[i];
snprintf (ID,sizeof(ID),"%c%c%c", header->id[0], header->id[1], header->id[2]);
snprintf (IDfull,sizeof(IDfull),"%c%c%c%c%c%c", header->id[0], header->id[1], header->id[2],header->id[3], header->id[4], header->id[5]);
snprintf(imgPath, sizeof(imgPath), "%s%s.png", CFG.covers_path, IDfull);
//Load full id image
cover[i] = new GuiImageData(imgPath,0);
if (!cover[i]->GetImage()) {
delete cover[i];
snprintf(imgPath, sizeof(imgPath), "%s%s.png", CFG.covers_path, ID);
//Load short id image
cover[i] = new GuiImageData(imgPath, 0);
if (!cover[i]->GetImage()) {
delete cover[i];
snprintf(imgPath, sizeof(imgPath), "%snoimage.png", CFG.covers_path);
//Load no image
cover[i] = new GuiImageData(imgPath, nocover_png);
}
}
coverImg[i] = new GuiImage(cover[i]);
coverImg[i]->SetScale(0.8);
coverImg[i]->SetWidescreen(CFG.widescreen);
game[i] = new GuiButton(122,244);
game[i]->SetParent(this);
game[i]->SetAlignment(ALIGN_CENTRE,ALIGN_MIDDLE);
game[i]->SetPosition(0,740);
game[i]->SetImage(coverImg[i]);
game[i]->SetRumble(false);
game[i]->SetTrigger(trigA);
game[i]->SetSoundClick(btnSoundClick);
game[i]->SetEffect(EFFECT_GOROUND, -50, 49, 780, 305+7*i, 1, 0, 740);
}
}

View File

@ -32,6 +32,8 @@ class GuiGameCarousel : public GuiElement
int gameCnt;
int * gameIndex;
int * bob;
GuiButton ** game;
GuiText ** gameTxt;

View File

@ -32,6 +32,7 @@
#include "libwbfs/libwbfs.h"
#include "sys.h"
#include "libwiigui/gui_gamegrid.h"
#include "libwiigui/gui_gamecarousel.h"
#include "patchcode.h"
#include "wpad.h"
#include "cfg.h"