From e6daf212bd0acbeb3c42f86b230a16c495cfa931 Mon Sep 17 00:00:00 2001 From: DRayX7 Date: Thu, 21 May 2009 08:56:23 +0000 Subject: [PATCH] * Added a button to game prompts to make a game a favorite. * Game prompt now displays how many times a game has been played. (cap of 255 will be fixed) * Added buton on main window to view only favorited games. (Known Bug: If this button is pressed with no favorite games, the loader will crash) --- source/filelist.h | 6 ++ source/language.c | 7 +- source/language.h | 3 +- source/libwiigui/gui_gamebrowser.cpp | 15 +++ source/libwiigui/gui_gamebrowser.h | 3 +- source/menu.cpp | 148 ++++++++++++++++++++------- 6 files changed, 140 insertions(+), 42 deletions(-) diff --git a/source/filelist.h b/source/filelist.h index 5ea05ce2..6be30dea 100644 --- a/source/filelist.h +++ b/source/filelist.h @@ -247,5 +247,11 @@ extern const u32 exit_button_png_size; extern const u8 mp3_stop_png[]; extern const u32 mp3_stop_png_size; + +extern const u8 favorite_png[]; +extern const u32 favorite_png_size; + +extern const u8 not_favorite_png[]; +extern const u32 not_favorite_png_size; #endif diff --git a/source/language.c b/source/language.c index 579189a6..15edf11a 100644 --- a/source/language.c +++ b/source/language.c @@ -153,7 +153,8 @@ snprintf(LANGUAGE.Partition, sizeof(LANGUAGE.Partition), "Partition"); snprintf(LANGUAGE.Password, sizeof(LANGUAGE.Password), "Password"); snprintf(LANGUAGE.PasswordChanged, sizeof(LANGUAGE.PasswordChanged), "Password Changed"); snprintf(LANGUAGE.Passwordhasbeenchanged, sizeof(LANGUAGE.Passwordhasbeenchanged), "Password has been changed"); -snprintf(LANGUAGE.Passwordchange, sizeof(LANGUAGE.Passwordchange), "Password change"); +snprintf(LANGUAGE.Passwordchange, sizeof(LANGUAGE.Passwordchange), "Password change"); +snprintf(LANGUAGE.Plays, sizeof(LANGUAGE.Plays), "Play Count"); snprintf(LANGUAGE.PowerofftheWii, sizeof(LANGUAGE.PowerofftheWii), "Power off the Wii"); snprintf(LANGUAGE.Prev, sizeof(LANGUAGE.Prev), "Prev"); snprintf(LANGUAGE.PromptsButtons, sizeof(LANGUAGE.PromptsButtons), "Prompts Buttons"); @@ -745,6 +746,10 @@ void language_set(char *name, char *val) strcopy(LANGUAGE.Passwordchange, val, sizeof(LANGUAGE.Passwordchange)); return; } + if (strcmp(name, "Plays") == 0) { + strcopy(LANGUAGE.Plays, val, sizeof(LANGUAGE.Plays)); + return; + } if (strcmp(name, "PowerofftheWii") == 0) { strcopy(LANGUAGE.PowerofftheWii, val, sizeof(LANGUAGE.PowerofftheWii)); return; diff --git a/source/language.h b/source/language.h index 17d30ece..aaa4759c 100644 --- a/source/language.h +++ b/source/language.h @@ -139,7 +139,8 @@ struct LANGUAGE char PasswordChanged[50]; char Passwordhasbeenchanged[80]; char Passwordchange[50]; - char PowerofftheWii[50]; + char PowerofftheWii[50]; + char Plays[20]; char Prev[50]; char PromptsButtons[50]; char ReloadSD[50]; diff --git a/source/libwiigui/gui_gamebrowser.cpp b/source/libwiigui/gui_gamebrowser.cpp index b95ce11c..5e6361b1 100644 --- a/source/libwiigui/gui_gamebrowser.cpp +++ b/source/libwiigui/gui_gamebrowser.cpp @@ -635,4 +635,19 @@ void GuiGameBrowser::Update(GuiTrigger * t) if(updateCB) updateCB(this); +} + +void GuiGameBrowser::Reload(struct discHdr * l, int count) +{ + LOCK(this); + gameList = l; + gameCnt = count; + if (gameCnt == 0) gameCnt = 1; + scrollbaron = (gameCnt > THEME.pagesize) ? 1 : 0; + pagesize = (gameCnt > THEME.pagesize) ? THEME.pagesize : gameCnt; + selectedItem = 0; + listOffset = 0; + + for(int i=0; iResetState(); } diff --git a/source/libwiigui/gui_gamebrowser.h b/source/libwiigui/gui_gamebrowser.h index 5b588a85..fc5546af 100644 --- a/source/libwiigui/gui_gamebrowser.h +++ b/source/libwiigui/gui_gamebrowser.h @@ -41,7 +41,8 @@ class GuiGameBrowser : public GuiElement void SetFocus(int f); void Draw(); void Update(GuiTrigger * t); - int GetOffset(); + int GetOffset(); + void Reload(struct discHdr * l, int count); //GuiText * optionVal[PAGESIZE]; protected: int selectedItem; diff --git a/source/menu.cpp b/source/menu.cpp index 364cf1ec..9b4830bf 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -83,6 +83,7 @@ static int datag = 0; int datagB =0; int dataed = -1; int cosa=0,sina=0,offa=0; +u8 dispFave=0; //downloadvariables static char missingFiles[500][12]; //fixed @@ -991,6 +992,8 @@ int GameWindowPrompt() char ID[4]; char IDFull[7]; char gameName[CFG.maxcharacters + 4]; + u8 faveChoice = 0; + u8 playCount = 0; GuiWindow promptWindow(472,320); promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); @@ -1001,6 +1004,11 @@ int GameWindowPrompt() char imgPath[100]; snprintf(imgPath, sizeof(imgPath), "%sbutton_dialogue_box.png", CFG.theme_path); GuiImageData btnOutline(imgPath, button_dialogue_box_png); + + snprintf(imgPath, sizeof(imgPath), "%sfavorite.png", CFG.theme_path); + GuiImageData imgFavorite(imgPath, favorite_png); + snprintf(imgPath, sizeof(imgPath), "%snot_favorite.png", CFG.theme_path); + GuiImageData imgNotFavorite(imgPath, not_favorite_png); snprintf(imgPath, sizeof(imgPath), "%sstartgame_arrow_left.png", CFG.theme_path); GuiImageData imgLeft(imgPath, startgame_arrow_left_png); @@ -1062,7 +1070,12 @@ int GameWindowPrompt() diskImg2.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); diskImg2.SetPosition(0, -20); diskImg2.SetAngle(angle); - diskImg2.SetBeta(180); + diskImg2.SetBeta(180); + + char PlayCnt[25] = ""; + GuiText playcntTxt(PlayCnt, 18, (GXColor){THEME.info_r, THEME.info_g, THEME.info_b, 255}); + playcntTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); + playcntTxt.SetPosition(-115,45); GuiButton btn1(160, 160); btn1.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); @@ -1115,6 +1128,17 @@ int GameWindowPrompt() btn3.SetSoundClick(&btnClick); btn3.SetTrigger(&trigA); btn3.SetEffectGrow(); + + GuiImage btnFavoriteImg; + btnFavoriteImg.SetWidescreen(CFG.widescreen); + GuiButton btnFavorite(imgFavorite.GetWidth(), imgFavorite.GetHeight()); + btnFavorite.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); + btnFavorite.SetPosition(-125, -60); + btnFavorite.SetImage(&btnFavoriteImg); + btnFavorite.SetSoundOver(&btnSoundOver); + btnFavorite.SetSoundClick(&btnClick); + btnFavorite.SetTrigger(&trigA); + btnFavorite.SetEffectGrow(); GuiImage btnLeftImg(&imgLeft); GuiButton btnLeft(imgLeft.GetWidth(), imgLeft.GetHeight()); @@ -1140,11 +1164,13 @@ int GameWindowPrompt() promptWindow.Append(&dialogBoxImg); promptWindow.Append(&nameBtn); - promptWindow.Append(&sizeTxt); + promptWindow.Append(&sizeTxt); + promptWindow.Append(&playcntTxt); // promptWindow.Append(&btn1); // move down at last apended promptWindow.Append(&btn2); promptWindow.Append(&btnLeft); - promptWindow.Append(&btnRight); + promptWindow.Append(&btnRight); + promptWindow.Append(&btnFavorite); //check if unlocked if (CFG.godmode == 1) @@ -1269,6 +1295,19 @@ int GameWindowPrompt() diskImg.SetImage(diskCover); sizeTxt.SetText(sizeText); nameTxt.SetText(gameName); + + struct Game_NUM* game_num = CFG_get_game_num(header->id); + if (game_num) { + playCount = game_num->count; + faveChoice = game_num->favorite; + } else { + playCount = 0; + faveChoice = 0; + } + sprintf(PlayCnt,"%s: %i",LANGUAGE.Plays, playCount); + playcntTxt.SetText(PlayCnt); + btnFavoriteImg.SetImage(faveChoice ? &imgFavorite : &imgNotFavorite); + char* pch; pch=strrchr((gameName),'_'); @@ -1340,6 +1379,22 @@ int GameWindowPrompt() choice = 3; promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); } + + else if(btnFavorite.GetState() == STATE_CLICKED){//switch favorite + if(isSdInserted() == 1) { + faveChoice = !faveChoice; + btnFavoriteImg.SetImage(faveChoice ? &imgFavorite : &imgNotFavorite); + extern u8 favorite; + struct Game_NUM* game_num = CFG_get_game_num(header->id); + if (game_num) { + favorite = game_num->favorite; + } + favorite = faveChoice; + CFG_save_game_num(header->id); + } + btnFavorite.ResetState(); + } + // this next part is long because nobody could agree on what the left/right buttons should do else if((btnRight.GetState() == STATE_CLICKED) && (Settings.xflip == no)){//next game promptWindow.SetEffect(EFFECT_SLIDE_RIGHT | EFFECT_SLIDE_OUT, 50); @@ -2324,26 +2379,24 @@ s32 __Menu_GetEntries(void) /* Get header list */ ret = WBFS_GetHeaders(buffer, cnt, sizeof(struct discHdr)); - if (ret < 0) - goto err; + if (ret < 0) { + if(buffer) free(buffer); + return ret; + } - /////////////show favorites only/////////////////////// - if (Settings.sort==fave){ + /* Filters */ + if (Settings.sort==fave || dispFave) { u32 cnt2 = 0; for (u32 i = 0; i < cnt; i++) { - header = &buffer[i]; - u8 favorite = 0; - struct Game_NUM* game_num = CFG_get_game_num(header->id); - if (game_num) - { - favorite = game_num->favorite;} - if (favorite==1) - - - //if (get_block(header) < CFG.parentalcontrol) - { + header = &buffer[i]; + u8 favorite = 0; + struct Game_NUM* game_num = CFG_get_game_num(header->id); + if (game_num) { + favorite = game_num->favorite; + } + if (favorite==1) { buffer2 = (discHdr *) realloc(buffer2, (cnt2+1) * sizeof(struct discHdr)); if (!buffer2) { @@ -2359,12 +2412,8 @@ s32 __Menu_GetEntries(void) buffer = buffer2; buffer2 = NULL; cnt = cnt2; - //if (cnt==0){Settings.sort=all;__Menu_GetEntries();} - - qsort(buffer, cnt, sizeof(struct discHdr), __Menu_EntryCmp); } - - else { + if (CFG.parentalcontrol && !CFG.godmode) { u32 cnt2 = 0; @@ -2388,34 +2437,28 @@ s32 __Menu_GetEntries(void) buffer = buffer2; buffer2 = NULL; cnt = cnt2; - }if (Settings.sort==all){qsort(buffer, cnt, sizeof(struct discHdr), __Menu_EntryCmp);} - else //if (Settings.sort==pcount) - {qsort(buffer, cnt, sizeof(struct discHdr), __Menu_EntryCmpCount);} + } + + if (Settings.sort==pcount) { + qsort(buffer, cnt, sizeof(struct discHdr), __Menu_EntryCmpCount); + } + else { + qsort(buffer, cnt, sizeof(struct discHdr), __Menu_EntryCmp); } - - - /* Sort entries */ - //qsort(buffer, cnt, sizeof(struct discHdr), __Menu_EntryCmp); /* Free memory */ if (gameList) free(gameList); /* Set values */ - gameList = buffer; + gameList = buffer; + buffer = NULL; gameCnt = cnt; /* Reset variables */ gameSelected = gameStart = 0; return 0; - -err: - /* Free memory */ - if (buffer) - free(buffer); - - return ret; } /**************************************************************************** @@ -2826,6 +2869,11 @@ static int MenuDiscList() GuiImageData batteryRed(imgPath, battery_red_png); snprintf(imgPath, sizeof(imgPath), "%sbattery_bar.png", CFG.theme_path); GuiImageData batteryBar(imgPath, battery_bar_png); + + snprintf(imgPath, sizeof(imgPath), "%sfavorite.png", CFG.theme_path); + GuiImageData imgFavoriteOn(imgPath, favorite_png); + snprintf(imgPath, sizeof(imgPath), "%snot_favorite.png", CFG.theme_path); + GuiImageData imgFavoriteOff(imgPath, not_favorite_png); GuiTrigger trigA; trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); @@ -2945,6 +2993,17 @@ static int MenuDiscList() wiiBtn.SetSoundOver(&btnSoundOver); wiiBtn.SetSoundClick(&btnClick); wiiBtn.SetTrigger(&trigA); + + GuiImage favoriteBtnImg(dispFave ? &imgFavoriteOn : &imgFavoriteOff);; + favoriteBtnImg.SetWidescreen(CFG.widescreen); + GuiButton favoriteBtn(imgFavoriteOn.GetWidth(), imgFavoriteOn.GetHeight()); + favoriteBtn.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); + favoriteBtn.SetPosition(-90, 105); + favoriteBtn.SetImage(&favoriteBtnImg); + favoriteBtn.SetSoundOver(&btnSoundOver); + favoriteBtn.SetSoundClick(&btnClick); + favoriteBtn.SetTrigger(&trigA); + favoriteBtn.SetEffectGrow(); //Downloading Covers GuiTooltip DownloadBtnTT(LANGUAGE.ClicktoDownloadCovers); @@ -2996,7 +3055,8 @@ static int MenuDiscList() w.Append(&installBtn); w.Append(&homeBtn); w.Append(&settingsBtn); - w.Append(&DownloadBtn); + w.Append(&DownloadBtn); + w.Append(&favoriteBtn); if((Settings.hddinfo == hr12)||(Settings.hddinfo == hr24)) { @@ -3200,6 +3260,16 @@ static int MenuDiscList() } + else if(favoriteBtn.GetState() == STATE_CLICKED) + { + dispFave = !dispFave; + __Menu_GetEntries(); + gameBrowser.Reload(gameList, gameCnt); + sprintf(GamesCnt,"%s: %i",LANGUAGE.Games, gameCnt); + gamecntTxt.SetText(GamesCnt); + favoriteBtnImg.SetImage(dispFave ? &imgFavoriteOn : &imgFavoriteOff); + favoriteBtn.ResetState(); + } //Get selected game under cursor int selectimg;//, promptnumber;