From: Ricardo Cruz Date: Sat, 24 Apr 2004 15:27:38 +0000 (+0000) Subject: Ingo, that code is not buggy! X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=04591e0701ed667fa06eb947801484374fb9874e;p=supertux.git 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 ;-) SVN-Revision: 685 --- diff --git a/src/menu.cpp b/src/menu.cpp index 9eec207b3..49c28b759 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -223,6 +223,7 @@ Menu::Menu() 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 @@ Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* m { 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)); } diff --git a/src/menu.h b/src/menu.h index 44cd83f40..7855de7d9 100644 --- a/src/menu.h +++ b/src/menu.h @@ -139,6 +139,7 @@ private: int pos_x; int pos_y; bool has_backitem; + int last_id; /** input event for the menu (up, down, left, right, etc.) */ MenuAction menuaction;