aboutsummaryrefslogtreecommitdiff
path: root/src/guiMainMenu.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2013-02-15 21:13:53 +0200
committerPerttu Ahola <celeron55@gmail.com>2013-05-02 19:43:47 +0300
commit084be3599a5ef0acba7c341bfd14a4e9801423a2 (patch)
tree319535075c0eafd482abd32f5418502aefc17ea9 /src/guiMainMenu.cpp
parentb28734c82cdb88228a12a3cac90f51ab9384b653 (diff)
downloadminetest-084be3599a5ef0acba7c341bfd14a4e9801423a2.tar.gz
minetest-084be3599a5ef0acba7c341bfd14a4e9801423a2.tar.bz2
minetest-084be3599a5ef0acba7c341bfd14a4e9801423a2.zip
Get menu background image from selected game
Diffstat (limited to 'src/guiMainMenu.cpp')
-rw-r--r--src/guiMainMenu.cpp47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp
index d3e3c007a..07efbb62f 100644
--- a/src/guiMainMenu.cpp
+++ b/src/guiMainMenu.cpp
@@ -162,6 +162,8 @@ enum
GUI_ID_SERVERLIST_TOGGLE,
GUI_ID_SERVERLIST_DELETE,
GUI_ID_SERVERLIST_TITLE,
+ GUI_ID_GAME_BUTTON_FIRST = 130,
+ GUI_ID_GAME_BUTTON_MAX = 150,
};
enum
@@ -255,8 +257,12 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
{
core::rect<s32> rect(0, 0, size.X, 40);
rect += v2s32(4, 0);
- Environment->addStaticText(narrow_to_wide(
- "Minetest " VERSION_STRING).c_str(),
+ std::string t = "Minetest " VERSION_STRING;
+ if(m_data->selected_game != ""){
+ t += "/";
+ t += m_data->selected_game;
+ }
+ Environment->addStaticText(narrow_to_wide(t).c_str(),
rect, false, true, this, -1);
}
@@ -900,6 +906,27 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
}
}
+ /* Add game selection buttons */
+
+ video::IVideoDriver* driver = Environment->getVideoDriver();
+ for(size_t i=0; i<m_data->games.size(); i++){
+ const SubgameSpec *spec = &m_data->games[i];
+ v2s32 p(8 + i*(48+8), screensize.Y - (48+8));
+ core::rect<s32> rect(0, 0, 48, 48);
+ rect += p;
+ video::ITexture *bgtexture = NULL;
+ if(spec->menuicon_path != "")
+ bgtexture = driver->getTexture(spec->menuicon_path.c_str());
+ gui::IGUIButton *b = Environment->addButton(rect, this,
+ GUI_ID_GAME_BUTTON_FIRST+i, narrow_to_wide(wrap_rows(spec->id, 4)).c_str());
+ if(bgtexture){
+ b->setImage(bgtexture);
+ b->setText(L"");
+ b->setDrawBorder(false);
+ b->setUseAlphaChannel(true);
+ }
+ }
+
m_is_regenerating = false;
}
@@ -909,7 +936,9 @@ void GUIMainMenu::drawMenu()
if (!skin)
return;
video::IVideoDriver* driver = Environment->getVideoDriver();
-
+
+ /* Draw menu background */
+
/*video::SColor bgcolor(140,0,0,0);
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
@@ -976,6 +1005,8 @@ void GUIMainMenu::drawMenu()
}
}
+ /* Draw UI elements */
+
gui::IGUIElement::draw();
}
@@ -1221,7 +1252,7 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
return true;
}
case GUI_ID_CREATE_WORLD_BUTTON: {
- std::vector<SubgameSpec> games = getAvailableGames();
+ const std::vector<SubgameSpec> &games = m_data->games;
if(games.size() == 0){
wchar_t* text = wgettext("Cannot create world: No games found");
GUIMessageMenu *menu = new GUIMessageMenu(env, parent,
@@ -1308,6 +1339,14 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
}
#endif
}
+ /* Game buttons */
+ int eid = event.GUIEvent.Caller->getID();
+ if(eid >= GUI_ID_GAME_BUTTON_FIRST &&
+ eid <= GUI_ID_GAME_BUTTON_MAX){
+ m_data->selected_game =
+ m_data->games[eid - GUI_ID_GAME_BUTTON_FIRST].id;
+ regenerateGui(m_screensize_old);
+ }
}
if(event.GUIEvent.EventType==gui::EGET_EDITBOX_ENTER)
{