diff --git a/data/translations/text.dat b/data/translations/text.dat index 945651b71..3399e8028 100644 --- a/data/translations/text.dat +++ b/data/translations/text.dat @@ -52,6 +52,8 @@ eng=CONTROL TYPE eng=MUSIC [STR__PAULS_TEST__SFX] eng=SFX +[STR__PAULS_TEST__EXIT] +eng=EXIT diff --git a/source/gui/gbutton.cpp b/source/gui/gbutton.cpp index 5fa8285eb..6714cebf4 100644 --- a/source/gui/gbutton.cpp +++ b/source/gui/gbutton.cpp @@ -45,13 +45,14 @@ Vars ---- */ + /*---------------------------------------------------------------------- Function: Purpose: Params: Returns: ---------------------------------------------------------------------- */ -void CGUIButton::setButtonTarget(int *_target) +void CGUIToggleButton::setButtonTarget(int *_target) { m_target=_target; } @@ -63,7 +64,44 @@ void CGUIButton::setButtonTarget(int *_target) Params: Returns: ---------------------------------------------------------------------- */ -void CGUIButton::setButtonData(int *_data) +void CGUIToggleButton::think(int _frames) +{ + ASSERT(getTarget()); + + CGUIObject::think(_frames); + if(isSelected()) + { + int pad; + + pad=PadGetRepeat(0); + if(pad&PAD_CROSS) + { + int *target; + target=getTarget(); + if(*target==true) + { + *target=false; + } + else + { + *target=true; + } + } + } +} + + + + + + +/*---------------------------------------------------------------------- + Function: + Purpose: + Params: + Returns: + ---------------------------------------------------------------------- */ +void CGUICycleButton::setButtonData(int *_data) { m_data=_data; } @@ -75,12 +113,12 @@ void CGUIButton::setButtonData(int *_data) Params: Returns: ---------------------------------------------------------------------- */ -void CGUIButton::think(int _frames) +void CGUICycleButton::think(int _frames) { - ASSERT(m_target); - ASSERT(m_data); + ASSERT(getTarget()); + ASSERT(getData()); - CGUIObject::think(_frames); + CGUIToggleButton::think(_frames); if(isSelected()) { int pad; @@ -88,29 +126,31 @@ void CGUIButton::think(int _frames) pad=PadGetRepeat(0); if(pad&PAD_CROSS) { + int *target; int *data; int tmp; - data=m_data; - tmp=*data; + target=getTarget(); + data=getData(); do { tmp=*data; - data++; - if(*m_target==tmp) + if(*target==*data) { break; } + data++; } while(tmp<*data); if(tmp>*data) { - data=m_data; + data=getData(); } - *m_target=*data; + *target=*data; } } } + /*=========================================================================== end */ \ No newline at end of file diff --git a/source/gui/gbutton.h b/source/gui/gbutton.h index 6c9201921..cc4f8e11f 100644 --- a/source/gui/gbutton.h +++ b/source/gui/gbutton.h @@ -34,22 +34,40 @@ Structure defintions -------------------- */ -class CGUIButton : public CGUIObject +class CGUIToggleButton : public CGUIObject { public: virtual void setButtonTarget(int *_target); + + virtual void think(int _frames); + + +protected: + int *getTarget() {return m_target;} + virtual int isSelectable() {return true;} + + +private: + int *m_target; + +}; + + +class CGUICycleButton : public CGUIToggleButton +{ +public: virtual void setButtonData(int *_data); virtual void think(int _frames); protected: - virtual int isSelectable() {return true;} + int *getData() {return m_data;} private: - int *m_target; int *m_data; + }; diff --git a/source/gui/greadout.h b/source/gui/greadout.h index f3666ea5e..96f3cdac6 100644 --- a/source/gui/greadout.h +++ b/source/gui/greadout.h @@ -44,7 +44,7 @@ public: } TextReadoutData; - virtual void init(CGUIObject *_parent,GUIId _id); + virtual void init(CGUIObject *_parent,GUIId _id=noId); virtual void setReadoutTarget(int *_target); virtual void setReadoutData(TextReadoutData *_data); @@ -77,7 +77,7 @@ public: } SpriteReadoutData; - virtual void init(CGUIObject *_parent,GUIId _id); + virtual void init(CGUIObject *_parent,GUIId _id=noId); virtual void shutdown(); virtual void setReadoutTarget(int *_target); diff --git a/source/gui/gtextbox.h b/source/gui/gtextbox.h index 5e7ac9e85..b09c9e898 100644 --- a/source/gui/gtextbox.h +++ b/source/gui/gtextbox.h @@ -37,7 +37,7 @@ class CGUITextBox : public CGUIObjectWithFont { public: - virtual void init(CGUIObject *_parent,GUIId _id); + virtual void init(CGUIObject *_parent,GUIId _id=noId); virtual void setText(unsigned int _textId); diff --git a/source/gui/gui.h b/source/gui/gui.h index 4ccb02506..d0d5ea845 100644 --- a/source/gui/gui.h +++ b/source/gui/gui.h @@ -33,6 +33,7 @@ class CGUIObject { public: typedef int GUIId; + static const GUIId noId=-1; typedef enum { @@ -50,7 +51,7 @@ public: }; - virtual void init(CGUIObject *_parent,GUIId _id); + virtual void init(CGUIObject *_parent,GUIId _id=noId); virtual void shutdown(); void setObjectX(int _x) {m_x=_x;recalc();} @@ -115,7 +116,7 @@ private: class CGUIObjectWithFont : public CGUIObject { public: - virtual void init(CGUIObject *_parent,GUIId _id); + virtual void init(CGUIObject *_parent,GUIId _id=noId); virtual void shutdown(); virtual void setFlags(GUI_FLAGS _flags); diff --git a/source/paul/paul.cpp b/source/paul/paul.cpp index 27a97f54c..e7ecd9a22 100644 --- a/source/paul/paul.cpp +++ b/source/paul/paul.cpp @@ -112,23 +112,19 @@ int h=40; CGUITextReadout::TextReadoutData onOffTextReadouts[]= { - { 0, STR__ON, }, - { 1, STR__OFF, }, - { 0, 0, }, + { false, STR__ON, }, + { true, STR__OFF, }, + { 0, 0, }, }; CGUISpriteReadout::SpriteReadoutData onOffSpriteReadouts[]= { - { 0, FRM__CROSS, }, - { 1, FRM__TICK, }, - { 0, 0, }, + { false, FRM__CROSS, }, + { true, FRM__TICK, }, + { 0, 0, }, }; -int onOffValues[]= -{ - 0,1, - 0, -}; -int musicStatus=0; -int sfxStatus=0; +int musicStatus=false; +int sfxStatus=false; +int readyToExit=false; @@ -139,99 +135,59 @@ void CPaulScene::init() { CGUIGroupFrame *fr; CGUITextBox *tb; - CGUIButton *bu; + CGUIToggleButton *tg; CGUITextReadout *tr; CGUISpriteReadout *sr; s_fontBank.initialise(&standardFont); baseGUIObject=new ("Uber GUI object") CGUIControlFrame(); - baseGUIObject->init(NULL,1); + baseGUIObject->init(NULL); baseGUIObject->setObjectXYWH(32,32,512-64,256-64); fr=new ("frame") CGUIGroupFrame(); - fr->init(baseGUIObject,2); + fr->init(baseGUIObject); fr->setObjectXYWH(10,10,448-20,30); tb=new ("textbox") CGUITextBox(); - tb->init(fr,20); + tb->init(fr); tb->setObjectXYWH(0,0,300,30); tb->setText(STR__PAULS_TEST__MUSIC); - bu=new ("button") CGUIButton(); - bu->init(fr,21); -// bu->setObjectXYWH(0,0,0,0); - bu->setButtonTarget(&musicStatus); - bu->setButtonData(onOffValues); + tg=new ("togglebutton") CGUIToggleButton(); + tg->init(fr); + tg->setButtonTarget(&musicStatus); tr=new ("textreadout") CGUITextReadout(); - tr->init(fr,22); + tr->init(fr); tr->setObjectXYWH(300,0,128,30); tr->setReadoutTarget(&musicStatus); tr->setReadoutData(onOffTextReadouts); fr=new ("frame") CGUIGroupFrame(); - fr->init(baseGUIObject,3); + fr->init(baseGUIObject); fr->setObjectXYWH(10,50,448-20,30); tb=new ("textbox") CGUITextBox(); - tb->init(fr,30); + tb->init(fr); tb->setObjectXYWH(0,0,300,30); tb->setText(STR__PAULS_TEST__SFX); - bu=new ("button") CGUIButton(); - bu->init(fr,31); -// bu->setObjectXYWH(0,0,0,0); - bu->setButtonTarget(&sfxStatus); - bu->setButtonData(onOffValues); + tg=new ("togglebutton") CGUIToggleButton(); + tg->init(fr); + tg->setButtonTarget(&sfxStatus); sr=new ("spritereadout") CGUISpriteReadout(); - sr->init(fr,32); + sr->init(fr); sr->setObjectXYWH(300,0,128,30); sr->setReadoutTarget(&sfxStatus); sr->setReadoutData(onOffSpriteReadouts); - - fr=new ("frame") CGUIGroupFrame(); - fr->init(baseGUIObject,3); - fr->setObjectXYWH(10,90,448-20,30); + fr->init(baseGUIObject); + fr->setObjectXYWH(10,155,448-20,30); tb=new ("textbox") CGUITextBox(); - tb->init(fr,30); - tb->setObjectXYWH(0,0,300,30); - tb->setText(STR__PAULS_TEST__SFX); - bu=new ("button") CGUIButton(); - bu->init(fr,31); -// bu->setObjectXYWH(0,0,0,0); - bu->setButtonTarget(&sfxStatus); - bu->setButtonData(onOffValues); - sr=new ("spritereadout") CGUISpriteReadout(); - sr->init(fr,32); - sr->setObjectXYWH(300,0,128,30); - sr->setReadoutTarget(&sfxStatus); - sr->setReadoutData(onOffSpriteReadouts); - + tb->init(fr); + tb->setObjectXYWH(0,0,428,30); + tb->setText(STR__PAULS_TEST__EXIT); + tg=new ("togglebutton") CGUIToggleButton(); + tg->init(fr); + tg->setButtonTarget(&readyToExit); - -/* - tb=new ("textbox") CGUITextBox(); - tb->init(baseGUIObject,1); - tb->setObjectXYWH(10,10,400,25); - tb->setText(STR__PAULS_TEST_STRING_1); - - fr=new ("frame") CGUIGroupFrame(); - fr->init(baseGUIObject,2); - fr->setObjectXYWH(10,40,400,25); - tb=new ("textbox") CGUITextBox(); - tb->init(fr,20); - tb->setObjectXYWH(50,1,300,22); - tb->setText(STR__PAULS_TEST_STRING_1); - bu=new ("button") CGUIButton(); - bu->init(fr,21); - bu->setObjectXYWH(50,1,10,10); - bu->setButtonTarget(&testValue); - bu->setButtonData(testButtonData); - - tr=new ("textreadout") CGUITextReadout(); - tr->init(baseGUIObject,3); - tr->setObjectXYWH(10,70,400,25); - tr->setReadoutTarget(&testValue); - tr->setReadoutData(testReadoutData); -*/ // Heh.. this'll actually work =) // baseGUIObject->shutdown(); @@ -275,8 +231,9 @@ void CPaulScene::render() y+=charHeight; } } - - baseGUIObject->render(); + + if(baseGUIObject) + baseGUIObject->render(); } @@ -288,14 +245,16 @@ void CPaulScene::render() ---------------------------------------------------------------------- */ void CPaulScene::think(int _frames) { - /* - CGUITextBox *tb; - tb=(CGUITextBox *)guiGetItem(1); - tb->setObjectWH(w,h); - tb->setText(str); - */ - - baseGUIObject->think(_frames); + if(readyToExit) + { + baseGUIObject->shutdown(); + delete baseGUIObject; + baseGUIObject=NULL; + readyToExit=0; + } + + if(baseGUIObject) + baseGUIObject->think(_frames); }