Skip to content

Commit

Permalink
Refactor|libcommon|Menu: Use QVariant for menu::ButtonWidget user data
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jul 23, 2014
1 parent 64c3a05 commit 55cae51
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
3 changes: 3 additions & 0 deletions doomsday/plugins/common/include/hu_lib.h
Expand Up @@ -548,6 +548,9 @@ struct ButtonWidget : public Widget
bool noAltText() const;
ButtonWidget &setNoAltText(bool yes = true);

void setData(QVariant const &d);
QVariant const &data() const;

private:
DENG2_PRIVATE(d)
};
Expand Down
15 changes: 13 additions & 2 deletions doomsday/plugins/common/src/hu_lib.cpp
Expand Up @@ -1297,8 +1297,8 @@ void Page::initialize()

if(CVarToggleWidget *tog = wi->maybeAs<CVarToggleWidget>())
{
dd_bool const activate = (*(char *) wi->data1);
tog->setFlags((activate? FO_SET:FO_CLEAR), MNF_ACTIVE);
//dd_bool const activate = (*(char *) wi->data1);
tog->setFlags((wi->data1? FO_SET:FO_CLEAR), MNF_ACTIVE);
}
if(ListWidget *list = wi->maybeAs<ListWidget>())
{
Expand Down Expand Up @@ -2519,6 +2519,7 @@ DENG2_PIMPL_NOREF(ButtonWidget)
de::String text; ///< Label text.
patchid_t patch; ///< Used when drawing this instead of text, if set.
bool noAltText;
QVariant data;

Instance() : patch(-1), noAltText(false) {}
};
Expand Down Expand Up @@ -2683,6 +2684,16 @@ ButtonWidget &ButtonWidget::setNoAltText(bool yes)
return *this;
}

void ButtonWidget::setData(QVariant const &v)
{
d->data = v;
}

QVariant const &ButtonWidget::data() const
{
return d->data;
}

CVarToggleWidget::CVarToggleWidget(char const *cvarPath)
: ButtonWidget()
, _cvarPath(cvarPath)
Expand Down
28 changes: 14 additions & 14 deletions doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -604,7 +604,7 @@ void Hu_MenuInitMainPage()
btn->_origin.y = y;
btn->setShortcut('n');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"GameType";
btn->setData(String("GameType"));
#if defined(__JDOOM__) && !defined(__JDOOM64__)
btn->setPatch(pNGame);
#else
Expand All @@ -622,7 +622,7 @@ void Hu_MenuInitMainPage()
btn->_origin.y = y;
btn->setShortcut('o');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"Options";
btn->setData(String("Options"));
#if defined(__JDOOM__) && !defined(__JDOOM64__)
btn->setPatch(pOptions);
#else
Expand Down Expand Up @@ -676,7 +676,7 @@ void Hu_MenuInitMainPage()
btn->_origin.y = y;
btn->setShortcut('f');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"Files";
btn->setData(String("Files"));
btn->setText("Game Files");
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
Expand Down Expand Up @@ -874,7 +874,7 @@ void Hu_MenuInitMultiplayerPage()
btn->setShortcut('p');
btn->_pageFontIdx = MENU_FONT1;
btn->setText("Player Setup");
btn->data1 = (void *)"PlayerSetup";
btn->setData(String("PlayerSetup"));
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
page->_widgets << btn;
Expand Down Expand Up @@ -1219,7 +1219,7 @@ void Hu_MenuInitOptionsPage()
ButtonWidget *btn = new ButtonWidget;
btn->setShortcut('c');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"ControlOptions";
btn->setData(String("ControlOptions"));
btn->setText("Controls");
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
Expand All @@ -1230,7 +1230,7 @@ void Hu_MenuInitOptionsPage()
ButtonWidget *btn = new ButtonWidget;
btn->setShortcut('g');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"GameplayOptions";
btn->setData(String("GameplayOptions"));
btn->setText("Gameplay");
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
Expand All @@ -1241,7 +1241,7 @@ void Hu_MenuInitOptionsPage()
ButtonWidget *btn = new ButtonWidget;
btn->setShortcut('s');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"SaveOptions";
btn->setData(String("SaveOptions"));
btn->setText("Game saves");
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
Expand All @@ -1252,7 +1252,7 @@ void Hu_MenuInitOptionsPage()
ButtonWidget *btn = new ButtonWidget;
btn->setShortcut('h');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"HUDOptions";
btn->setData(String("HUDOptions"));
btn->setText("HUD");
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
Expand All @@ -1263,7 +1263,7 @@ void Hu_MenuInitOptionsPage()
ButtonWidget *btn = new ButtonWidget;
btn->setShortcut('a');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"AutomapOptions";
btn->setData(String("AutomapOptions"));
btn->setText("Automap");
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
Expand All @@ -1274,7 +1274,7 @@ void Hu_MenuInitOptionsPage()
ButtonWidget *btn = new ButtonWidget;
btn->setShortcut('w');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"WeaponOptions";
btn->setData(String("WeaponOptions"));
btn->setText("Weapons");
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
Expand All @@ -1286,7 +1286,7 @@ void Hu_MenuInitOptionsPage()
ButtonWidget *btn = new ButtonWidget;
btn->setShortcut('i');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"InventoryOptions";
btn->setData(String("InventoryOptions"));
btn->setText("Inventory");
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
Expand All @@ -1298,7 +1298,7 @@ void Hu_MenuInitOptionsPage()
ButtonWidget *btn = new ButtonWidget;
btn->setShortcut('s');
btn->_pageFontIdx = MENU_FONT1;
btn->data1 = (void *)"SoundOptions";
btn->setData(String("SoundOptions"));
btn->setText("Sound");
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->actions[Widget::MNA_FOCUS ].callback = Hu_MenuDefaultFocusAction;
Expand Down Expand Up @@ -3104,7 +3104,7 @@ void Hu_MenuInitEpisodePage()
else
{
btn->actions[Widget::MNA_ACTIVEOUT].callback = Hu_MenuActionSetActivePage;
btn->data1 = (void *)"Skill";
btn->setData(String("Skill"));
}

btn->actions[Widget::MNA_FOCUS].callback = Hu_MenuFocusEpisode;
Expand Down Expand Up @@ -4247,7 +4247,7 @@ void Hu_MenuActionSetActivePage(Widget *wi, Widget::mn_actionid_t action)
{
DENG2_ASSERT(wi != 0);
if(Widget::MNA_ACTIVEOUT != action) return;
Hu_MenuSetActivePage(Hu_MenuFindPageByName((char *)wi->data1));
Hu_MenuSetActivePage(Hu_MenuFindPageByName(wi->as<ButtonWidget>().data().toString()));
}

void Hu_MenuUpdateColorWidgetColor(Widget *wi, Widget::mn_actionid_t action)
Expand Down

0 comments on commit 55cae51

Please sign in to comment.