From 57f0ce0ed462d2b2ee82cb37548cc5bcb37434ef Mon Sep 17 00:00:00 2001 From: giantpune Date: Mon, 13 Jul 2009 11:19:31 +0000 Subject: [PATCH] Added functions/vars to GuiText to allow showing & hiding rows when it is wrapped. new vars are firstLine = 1; numLines = -1; totalLines = 1; totalLines is not changed until the text is set to wrap and Draw() is called 1 time. The other 2 are set with functions. new functions are void GuiText::SetNumLines(int n) void GuiText::SetFirstLine(int n) int GuiText::GetNumLines() int GuiText::GetFirstLine() int GuiText::GetTotalLines() int GuiText::GetLineHeight(int n) These should be self explanatory. GetLineHeight relies on total lines so it needs to be called after the first Draw(); Raised the chars[] to 3000 for the synopsis because people are writing books in there. Used those new fancy functions make the synopsis fit in the info window. Press up/down to scroll the text. Arrows may come later for the buttons. Also put a home buttononlytrigger on the game prompt. moved disable mainWindow to the beginning of the infoprompt to keep from loading images and stuff from the sd at the same time we are reading the xml file. --- Makefile | 2 +- gui.pnproj | 2 +- source/libwiigui/gui.h | 10 +++ source/libwiigui/gui_text.cpp | 74 +++++++++++++++++++-- source/main.cpp | 4 -- source/menu.cpp | 2 + source/prompts/gameinfo.cpp | 117 ++++++++++++++++++++++++++++++---- source/xml/xml.h | 4 +- 8 files changed, 190 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 811f588e..44dc95bf 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80a00 #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project #--------------------------------------------------------------------------------- -LIBS := -ldb -lfat -lpngu -lpng -lm -lz -lwiiuse -lbte -lasnd -logc -lfreetype -ltremor -lmxml +LIBS := -lfat -lpngu -lpng -lm -lz -lwiiuse -lbte -lasnd -logc -lfreetype -ltremor -lmxml #--------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level containing # include and lib diff --git a/gui.pnproj b/gui.pnproj index 58a930fe..fdbd730a 100644 --- a/gui.pnproj +++ b/gui.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/source/libwiigui/gui.h b/source/libwiigui/gui.h index ba68869c..0e53a304 100644 --- a/source/libwiigui/gui.h +++ b/source/libwiigui/gui.h @@ -730,6 +730,12 @@ class GuiText : public GuiElement int GetTextWidth(); // not NULL set horizontal scale to 0.75 //added void SetWidescreen(bool w); + void SetNumLines(int n);//! these two are used to set the first line and numLine + void SetFirstLine(int n); + int GetNumLines();//! these return the line variables for this text + int GetFirstLine(); + int GetLineHeight(int n);//! returns the height of the #n of lines including spacing if wrap mode is on + int GetTotalLines(); //!Constantly called to draw the text void Draw(); protected: @@ -745,6 +751,10 @@ class GuiText : public GuiElement GXColor color; //!< Font color FreeTypeGX *font; short widescreen; //added + //!these are default until the text is drawn + int firstLine; //!these are the first line and the number of lines drawn when the text is wrapped + int numLines;//! default is -1 and it means that all lines are drawn + int totalLines; //!this is the total # of lines when in wrap mode }; //!Display, manage, and manipulate tooltips in the GUI. diff --git a/source/libwiigui/gui_text.cpp b/source/libwiigui/gui_text.cpp index 62117012..c6235d8a 100644 --- a/source/libwiigui/gui_text.cpp +++ b/source/libwiigui/gui_text.cpp @@ -37,6 +37,9 @@ GuiText::GuiText(const char * t, int s, GXColor c) scrollDelay = 0; font = NULL; widescreen = 0; //added + firstLine = 1; + numLines = -1; + totalLines = 1; alignmentHor = ALIGN_CENTRE; alignmentVert = ALIGN_MIDDLE; @@ -62,6 +65,9 @@ GuiText::GuiText(const char * t) scrollDelay = 0; font = NULL; widescreen = 0; //added + firstLine = 1; + numLines = -1; + totalLines = 1; alignmentHor = presetAlignmentHor; alignmentVert = presetAlignmentVert; @@ -82,6 +88,43 @@ GuiText::~GuiText() } } +void GuiText::SetNumLines(int n) +{ + numLines = n; +} + +void GuiText::SetFirstLine(int n) +{ + firstLine = n; +} + +int GuiText::GetNumLines() +{ + return numLines; +} + +int GuiText::GetFirstLine() +{ + return firstLine; +} + +int GuiText::GetTotalLines() +{ + return totalLines; +} + +int GuiText::GetLineHeight(int n) +{ + int newSize = size*this->GetScale(); + int lineheight = newSize + 6; + + if (numLines <0) + return totalLines*lineheight+newSize; + + else return numLines*lineheight+newSize; +} + + void GuiText::SetText(const char * t) { LOCK(this); @@ -289,15 +332,36 @@ void GuiText::Draw() ch++; i++; } - + totalLines = linenum; + if(alignmentVert == ALIGN_MIDDLE) voffset = voffset - (lineheight*linenum)/2 + lineheight/2; - for(i=0; i < linenum; i++) - { - (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[i], c, style); - delete tmptext[i]; + if (numLines <0){ + for(i=0; i < linenum; i++) + { + (font ? font : fontSystem)->drawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[i], c, style); + delete tmptext[i]; + } } + + //put in for txt verticle txt scrolling + else { + int j; + i=0; + for(j=firstLine-1; j < numLines+firstLine-1; j++) + { + if (jdrawText(this->GetLeft(), this->GetTop()+voffset+i*lineheight, tmptext[j], c, style); + i++; + } + for(i=0; i < linenum; i++) + { + delete tmptext[i]; + } + } + + } else if(wrapMode == GuiText::DOTTED) // text dotted { diff --git a/source/main.cpp b/source/main.cpp index db04567a..dd4c11ab 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -33,8 +33,6 @@ #include "wpad.h" #include "fat.h" -#include - /* Constants */ #define CONSOLE_XCOORD 260 #define CONSOLE_YCOORD 115 @@ -120,8 +118,6 @@ main(int argc, char *argv[]) InitVideo(); // Initialise video InitAudio(); // Initialize audio - DEBUG_Init(GDBSTUB_DEVICE_USB, 1);// for debugging - WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); diff --git a/source/menu.cpp b/source/menu.cpp index 7c08ae9d..02df1f6f 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -932,6 +932,8 @@ int MenuDiscList() 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]); choice = showGameInfo(IDfull); gameInfo.ResetState(); + if (choice==2) + homeBtn.SetState(STATE_CLICKED); } if (Settings.gameDisplay==grid){ diff --git a/source/prompts/gameinfo.cpp b/source/prompts/gameinfo.cpp index 680a9379..04fdd341 100644 --- a/source/prompts/gameinfo.cpp +++ b/source/prompts/gameinfo.cpp @@ -15,6 +15,7 @@ #include "wpad.h" #include "fatmounter.h" #include "listfiles.h" +#include "prompts/PromptWindows.h" #include "gameinfo.h" @@ -34,6 +35,9 @@ extern void HaltGui(); ***************************************************************************/ int showGameInfo(char *ID) { + HaltGui();//put this first to try to get rid of the code dump caused by loading this window at the same time as loading images from the SD card + mainWindow->SetState(STATE_DISABLED); + ResumeGui(); //load the xml shit bool databaseopened = true; OpenXMLDatabase(Settings.titlestxt_path, Settings.db_language, Settings.db_JPtoEN, true, false, true); // open file, do not load titles, keep in memory @@ -125,7 +129,7 @@ int showGameInfo(char *ID) GuiWindow txtWindow(350,270); txtWindow.SetAlignment(ALIGN_CENTRE, ALIGN_RIGHT); - txtWindow.SetPosition(85, 50); + txtWindow.SetPosition(95, 55); GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, Settings.sfxvolume); GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, Settings.sfxvolume); @@ -145,7 +149,14 @@ int showGameInfo(char *ID) trigA.SetButtonOnlyTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A); GuiTrigger trigB; trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - + GuiTrigger trigU; + trigU.SetButtonOnlyTrigger(-1, WPAD_BUTTON_UP | WPAD_CLASSIC_BUTTON_UP, PAD_BUTTON_UP); + GuiTrigger trigD; + trigD.SetButtonOnlyTrigger(-1, WPAD_BUTTON_DOWN | WPAD_CLASSIC_BUTTON_DOWN, PAD_BUTTON_DOWN); + GuiTrigger trigH; + trigH.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); + + //buttons for changing between synopsis and other info GuiButton backBtn(0,0); backBtn.SetPosition(-20,-20); backBtn.SetTrigger(&trigB); @@ -156,7 +167,20 @@ int showGameInfo(char *ID) nextBtn.SetTrigger(&trigA); gameinfoWindow.Append(&nextBtn); - char linebuf[1000] = ""; + //buttons for scrolling the synopsis + GuiButton upBtn(0,0); + upBtn.SetPosition(0,0); + upBtn.SetTrigger(&trigU); + + GuiButton dnBtn(0,0); + dnBtn.SetPosition(0,0); + dnBtn.SetTrigger(&trigD); + + GuiButton homeBtn(0,0); + homeBtn.SetPosition(0,0); + homeBtn.SetTrigger(&trigH); + + char linebuf[3000] = ""; char linebuf2[100] = ""; // enable icons for required accessories @@ -577,11 +601,15 @@ int showGameInfo(char *ID) } //synopsis + int pagesize=12; if (strcmp(gameinfo.synopsis,"") != 0) { snprintf(linebuf, sizeof(linebuf), "%s", gameinfo.synopsis); - synopsisTxt = new GuiText(linebuf, 16, (GXColor){0,0,0, 255}); + synopsisTxt = new GuiText(linebuf, 16, (GXColor){0,0,0, 255}); synopsisTxt->SetMaxWidth(350,GuiText::WRAP); synopsisTxt->SetAlignment(ALIGN_LEFT, ALIGN_TOP); synopsisTxt->SetPosition(0,0); + synopsisTxt->SetNumLines(pagesize); + //synopsisTxt->SetFirstLine(12); + dialogBoxImg11 = new GuiImage(&dialogBox1); dialogBoxImg11->SetAlignment(0,3); dialogBoxImg11->SetPosition(-9,0); @@ -604,6 +632,8 @@ int showGameInfo(char *ID) gameinfoWindow2.Append(dialogBoxImg44); txtWindow.Append(synopsisTxt); + txtWindow.Append(&upBtn); + txtWindow.Append(&dnBtn); coverImg2 = new GuiImage(cover); coverImg2->SetWidescreen(CFG.widescreen); coverImg2->SetPosition(15,30); @@ -623,26 +653,43 @@ int showGameInfo(char *ID) gameinfoWindow.SetEffect(EFFECT_SLIDE_LEFT | EFFECT_SLIDE_IN, 100); HaltGui(); - mainWindow->SetState(STATE_DISABLED); + //mainWindow->SetState(STATE_DISABLED); mainWindow->Append(&gameinfoWindow); mainWindow->ChangeFocus(&gameinfoWindow); ResumeGui(); - + while(choice == -1) { + VIDEO_WaitVSync(); + + //u32 buttonshold = ButtonsHold(); if(shutdown == 1) { wiilight(0); Sys_Shutdown(); } - if(reset == 1) + else if(reset == 1) Sys_Reboot(); - if ((backBtn.GetState()==STATE_CLICKED)||(backBtn.GetState()==STATE_HELD)){ - choice=1; + else if ((backBtn.GetState()==STATE_CLICKED)||(backBtn.GetState()==STATE_HELD)){ + if(page==1) + {choice=1; synopsisTxt = NULL; - break; + break;} + else if (page==2) + { + HaltGui(); + //backBtn.SetClickable(true); + gameinfoWindow2.SetVisible(false); + gameinfoWindow.SetVisible(true); + //gameinfoWindow.Append(&backBtn); + //gameinfoWindow.Append(&nextBtn); + //gameinfoWindow.Append(&homeBtn); + mainWindow->Remove(&gameinfoWindow2); + ResumeGui(); + page=1; + } } else if (((nextBtn.GetState()==STATE_CLICKED)||(nextBtn.GetState()==STATE_HELD))&& (strcmp(gameinfo.synopsis,"") != 0)){ @@ -654,8 +701,10 @@ int showGameInfo(char *ID) gameinfoWindow2.SetVisible(true); coverImg->SetPosition(15,30); - backBtn.SetClickable(false); + //backBtn.SetClickable(false); gameinfoWindow2.Append(&nextBtn); + gameinfoWindow2.Append(&backBtn); + gameinfoWindow2.Append(&homeBtn); mainWindow->Append(&gameinfoWindow2); ResumeGui(); page=2; @@ -663,16 +712,60 @@ int showGameInfo(char *ID) else { nextBtn.ResetState(); HaltGui(); - backBtn.SetClickable(true); + //backBtn.SetClickable(true); gameinfoWindow2.SetVisible(false); gameinfoWindow.SetVisible(true); gameinfoWindow.Append(&backBtn); gameinfoWindow.Append(&nextBtn); + gameinfoWindow.Append(&homeBtn); mainWindow->Remove(&gameinfoWindow2); ResumeGui(); page=1; } nextBtn.ResetState(); + + } + else if ((upBtn.GetState()==STATE_CLICKED||upBtn.GetState()==STATE_HELD) && page==2) + { + int l=synopsisTxt->GetFirstLine()>1?synopsisTxt->GetFirstLine()-1:1; + synopsisTxt->SetFirstLine(l); + usleep(60000); + if (!((ButtonsHold() & WPAD_BUTTON_UP)||(ButtonsHold() & PAD_BUTTON_UP))) + upBtn.ResetState(); + } + else if ((dnBtn.GetState()==STATE_CLICKED||dnBtn.GetState()==STATE_HELD) && page==2) + { + int l=0; + if(synopsisTxt->GetTotalLines()>pagesize) + l=synopsisTxt->GetFirstLine()+1; + + if (l>synopsisTxt->GetTotalLines()+1-pagesize) + l=synopsisTxt->GetTotalLines()+1-pagesize; + + synopsisTxt->SetFirstLine(l); + usleep(60000); + if (!((ButtonsHold() & WPAD_BUTTON_DOWN)||(ButtonsHold() & PAD_BUTTON_DOWN))) + dnBtn.ResetState(); + } + //took this out cause it doesnt act right when not called from the main window and I don't feel like fixing it right now + else if (homeBtn.GetState()==STATE_CLICKED) + { + if(page==1) + {choice=2; + synopsisTxt = NULL; + break;} + else if (page==2) + { + HaltGui(); + gameinfoWindow2.SetVisible(false); + gameinfoWindow.SetVisible(true); + //gameinfoWindow.Append(&backBtn); + //gameinfoWindow.Append(&nextBtn); + //gameinfoWindow.Append(&homeBtn); + mainWindow->Remove(&gameinfoWindow2); + ResumeGui(); + page=1; + } } } if (page==1){ diff --git a/source/xml/xml.h b/source/xml/xml.h index 5424d73d..e6a84ac9 100644 --- a/source/xml/xml.h +++ b/source/xml/xml.h @@ -22,9 +22,9 @@ struct gameXMLinfo char version[50]; char region[7]; char title[100]; - char synopsis[2000]; + char synopsis[3000]; char title_EN[100]; - char synopsis_EN[2000]; + char synopsis_EN[3000]; char locales[XML_ELEMMAX+1][3]; int localeCnt; char developer[75];