[Super-tux-commit] supertux/src menu.cpp,1.53,1.54 menu.h,1.47,1.48
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-04-24 15:27:47
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23628/src Modified Files: menu.cpp menu.h Log Message: Ingo, that code is not buggy! You can say that it is a bad approuch, but it is not a bug! Besides, I don't think it's a bad approuch. Your code is maybe a better approuch. But in the other hand is buggy, so please let my code be there. Buggy, why, you may ask... Imagine this simple and fictional code: « #define MNID_START 1 menu->additem("Start Game", MNID_START); menu->additem("Options"); if(menu->check() == MNID_START) startgame(); » With your code, when you pressed Options, the game would also start. Have a look at it again and guess why ;-) Index: menu.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.cpp,v retrieving revision 1.53 retrieving revision 1.54 diff -u -d -r1.53 -r1.54 --- menu.cpp 24 Apr 2004 12:11:10 -0000 1.53 +++ menu.cpp 24 Apr 2004 15:27:38 -0000 1.54 @@ -223,6 +223,7 @@ pos_x = screen->w/2; pos_y = screen->h/2; has_backitem = false; + last_id = 0; arrange_left = 0; active_item = 0; effect.init(false); @@ -239,10 +240,13 @@ { if(kind_ == MN_BACK) has_backitem = true; - - if(id == -1) - id = int(item.size()); + if(id == -1 && item.size() == (unsigned)last_id) + { + id = last_id; + last_id++; + } + additem(MenuItem::create(kind_, text_.c_str(), toggle_, menu_, id, int_p)); } Index: menu.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/menu.h,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- menu.h 24 Apr 2004 15:08:21 -0000 1.47 +++ menu.h 24 Apr 2004 15:27:38 -0000 1.48 @@ -139,6 +139,7 @@ int pos_x; int pos_y; bool has_backitem; + int last_id; /** input event for the menu (up, down, left, right, etc.) */ MenuAction menuaction; |