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
{
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);
}
}
}
+ /* 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;
}
if (!skin)
return;
video::IVideoDriver* driver = Environment->getVideoDriver();
-
+
+ /* Draw menu background */
+
/*video::SColor bgcolor(140,0,0,0);
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
}
}
+ /* Draw UI elements */
+
gui::IGUIElement::draw();
}
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,
}
#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)
{
bool rightreleased;
};
-//Draw the tiled menu background
-void drawMenuBackground(video::IVideoDriver* driver) {
- core::dimension2d<u32> screensize = driver->getScreenSize();
-
- std::string path = getTexturePath("menubg.png");
- if (path[0]) {
- static const video::ITexture *bgtexture =
- driver->getTexture(path.c_str());
+void drawMenuBackground(video::IVideoDriver* driver, const SubgameSpec *spec)
+{
+ v2u32 screensize = driver->getScreenSize();
- if (bgtexture) {
- s32 scaledsize = 128;
-
- // The important difference between destsize and screensize is
- // that destsize is rounded to whole scaled pixels.
- // These formulas use component-wise multiplication and division of v2u32.
- v2u32 texturesize = bgtexture->getSize();
- v2u32 sourcesize = texturesize * screensize / scaledsize + v2u32(1,1);
- v2u32 destsize = scaledsize * sourcesize / texturesize;
-
- // Default texture wrapping mode in Irrlicht is ETC_REPEAT.
- driver->draw2DImage(bgtexture,
- core::rect<s32>(0, 0, destsize.X, destsize.Y),
- core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
- NULL, NULL, true);
- }
+ /* Figure out background texture */
+ video::ITexture *texture = NULL;
+ if(spec && spec->menubackground_path != ""){
+ texture = driver->getTexture(spec->menubackground_path.c_str());
}
-}
-//Draw the footer at the bottom of the window
-void drawMenuFooter(video::IVideoDriver* driver, bool clouds) {
- core::dimension2d<u32> screensize = driver->getScreenSize();
- std::string path = getTexturePath(clouds ?
- "menufooter_clouds.png" : "menufooter.png");
- if (path[0]) {
- static const video::ITexture *footertexture =
- driver->getTexture(path.c_str());
-
- if (footertexture) {
- f32 mult = (((f32)screensize.Width)) /
- ((f32)footertexture->getOriginalSize().Width);
-
- v2s32 footersize(((f32)footertexture->getOriginalSize().Width) * mult,
- ((f32)footertexture->getOriginalSize().Height) * mult);
-
- // Don't draw the footer if there isn't enough room
- s32 free_space = (((s32)screensize.Height)-320)/2;
- if (free_space > footersize.Y) {
- core::rect<s32> rect(0,0,footersize.X,footersize.Y);
- rect += v2s32(screensize.Width/2,screensize.Height-footersize.Y);
- rect -= v2s32(footersize.X/2, 0);
-
- driver->draw2DImage(footertexture, rect,
- core::rect<s32>(core::position2d<s32>(0,0),
- core::dimension2di(footertexture->getSize())),
- NULL, NULL, true);
- }
- }
+ /* If no texture, draw background of solid color */
+ if(!texture){
+ video::SColor color(255,80,58,37);
+ core::rect<s32> rect(0, 0, screensize.X, screensize.Y);
+ driver->draw2DRectangle(color, rect, NULL);
+ return;
}
-}
-
-// Draw the Header over the main menu
-void drawMenuHeader(video::IVideoDriver* driver) {
- core::dimension2d<u32> screensize = driver->getScreenSize();
-
- std::string path = getTexturePath("menuheader.png");
- if (path[0]) {
- static const video::ITexture *splashtexture =
- driver->getTexture(path.c_str());
-
- if(splashtexture) {
- f32 mult = (((f32)screensize.Width / 2)) /
- ((f32)splashtexture->getOriginalSize().Width);
- v2s32 splashsize(((f32)splashtexture->getOriginalSize().Width) * mult,
- ((f32)splashtexture->getOriginalSize().Height) * mult);
-
- // Don't draw the header is there isn't enough room
- s32 free_space = (((s32)screensize.Height)-320)/2;
- if (free_space > splashsize.Y) {
- core::rect<s32> splashrect(0, 0, splashsize.X, splashsize.Y);
- splashrect += v2s32((screensize.Width/2)-(splashsize.X/2),
- ((free_space/2)-splashsize.Y/2)+10);
+ /* Draw background texture */
+ v2u32 sourcesize = texture->getSize();
+ driver->draw2DImage(texture,
+ core::rect<s32>(0, 0, screensize.X, screensize.Y),
+ core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
+ NULL, NULL, true);
+}
- video::SColor bgcolor(255,50,50,50);
+void drawMenuOverlay(video::IVideoDriver* driver, const SubgameSpec *spec)
+{
+ v2u32 screensize = driver->getScreenSize();
- driver->draw2DImage(splashtexture, splashrect,
- core::rect<s32>(core::position2d<s32>(0,0),
- core::dimension2di(splashtexture->getSize())),
- NULL, NULL, true);
- }
- }
+ /* Figure out overlay texture */
+ video::ITexture *texture = NULL;
+ if(spec && spec->menuoverlay_path != ""){
+ texture = driver->getTexture(spec->menuoverlay_path.c_str());
}
-}
-// Draw the Splash over the clouds and under the main menu
-void drawMenuSplash(video::IVideoDriver* driver) {
- core::dimension2d<u32> screensize = driver->getScreenSize();
- std::string path = getTexturePath("menusplash.png");
- if (path[0]) {
- static const video::ITexture *splashtexture =
- driver->getTexture(path.c_str());
+ /* If no texture, draw nothing */
+ if(!texture)
+ return;
- if(splashtexture) {
- core::rect<s32> splashrect(0, 0, screensize.Width, screensize.Height);
-
- video::SColor bgcolor(255,50,50,50);
+ /* Draw overlay texture */
+ v2u32 sourcesize = texture->getSize();
+ driver->draw2DImage(texture,
+ core::rect<s32>(0, 0, screensize.X, screensize.Y),
+ core::rect<s32>(0, 0, sourcesize.X, sourcesize.Y),
+ NULL, NULL, true);
+}
- driver->draw2DImage(splashtexture, splashrect,
- core::rect<s32>(core::position2d<s32>(0,0),
- core::dimension2di(splashtexture->getSize())),
- NULL, NULL, true);
+static const SubgameSpec* getMenuGame(const MainMenuData &menudata)
+{
+ for(size_t i=0; i<menudata.games.size(); i++){
+ if(menudata.games[i].id == menudata.selected_game){
+ return &menudata.games[i];
}
}
+ return NULL;
}
-#endif
+#endif // !SERVER
// These are defined global so that they're not optimized too much.
// Can't change them to volatile.
menudata.selected_tab = g_settings->getS32("selected_mainmenu_tab");
if(g_settings->exists("selected_serverlist"))
menudata.selected_serverlist = g_settings->getS32("selected_serverlist");
+ if(g_settings->exists("selected_mainmenu_game"))
+ menudata.selected_game = g_settings->get("selected_mainmenu_game");
menudata.address = narrow_to_wide(address);
menudata.name = narrow_to_wide(playername);
menudata.port = narrow_to_wide(itos(port));
}
// Copy worldspecs to menu
menudata.worlds = worldspecs;
+ // Get game listing
+ menudata.games = getAvailableGames();
+ // If selected game doesn't exist, take first from list
+ if(findSubgame(menudata.selected_game).id == "" &&
+ !menudata.games.empty()){
+ menudata.selected_game = menudata.games[0].id;
+ }
+ const SubgameSpec *menugame = getMenuGame(menudata);
if(skip_main_menu == false)
{
break;
driver->beginScene(true, true,
video::SColor(255,128,128,128));
- drawMenuBackground(driver);
+ drawMenuBackground(driver, menugame);
guienv->drawAll();
driver->endScene();
// On some computers framerate doesn't seem to be
&g_menumgr, &menudata, g_gamecallback);
menu->allowFocusRemoval(true);
- // Clouds for the main menu
- bool cloud_menu_background = false;
- Clouds *clouds = NULL;
- if (g_settings->getBool("menu_clouds")) {
- cloud_menu_background = true;
- clouds = new Clouds(smgr->getRootSceneNode(),
- smgr, -1, rand(), 100);
- clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
-
- // A camera to see the clouds
- scene::ICameraSceneNode* camera;
- camera = smgr->addCameraSceneNode(0,
- v3f(0,0,0), v3f(0, 60, 100));
- camera->setFarValue(10000);
- }
+ // Always create clouds because they may or may not be
+ // needed based on the game selected
+ Clouds *clouds = new Clouds(smgr->getRootSceneNode(),
+ smgr, -1, rand(), 100);
+ clouds->update(v2f(0, 0), video::SColor(255,200,200,255));
+
+ // A camera to see the clouds
+ scene::ICameraSceneNode* camera;
+ camera = smgr->addCameraSceneNode(0,
+ v3f(0,0,0), v3f(0, 60, 100));
+ camera->setFarValue(10000);
if(error_message != L"")
{
if(menu->getStatus() == true)
break;
+ // Game can be selected in the menu
+ menugame = getMenuGame(menudata);
+ // Clouds for the main menu
+ bool cloud_menu_background = g_settings->getBool("menu_clouds");
+ if(menugame){
+ // If game has regular background and no overlay, don't use clouds
+ if(cloud_menu_background &&
+ menugame->menuoverlay_path.empty() &&
+ !menugame->menubackground_path.empty()){
+ cloud_menu_background = false;
+ }
+ // If game game has overlay and no regular background, always draw clouds
+ else if(menugame->menubackground_path.empty() &&
+ !menugame->menuoverlay_path.empty()){
+ cloud_menu_background = true;
+ }
+ }
+
// Time calc for the clouds
f32 dtime; // in seconds
if (cloud_menu_background) {
clouds->step(dtime*3);
clouds->render();
smgr->drawAll();
- drawMenuSplash(driver);
- drawMenuFooter(driver, true);
- drawMenuHeader(driver);
+ drawMenuOverlay(driver, menugame);
} else {
- drawMenuBackground(driver);
- drawMenuFooter(driver, false);
+ drawMenuBackground(driver, menugame);
}
guienv->drawAll();
infostream<<"Dropping main menu"<<std::endl;
menu->drop();
- if (cloud_menu_background) {
- clouds->drop();
- smgr->clear();
- }
+ clouds->drop();
+ smgr->clear();
}
playername = wide_to_narrow(menudata.name);
// Save settings
g_settings->setS32("selected_mainmenu_tab", menudata.selected_tab);
g_settings->setS32("selected_serverlist", menudata.selected_serverlist);
+ g_settings->set("selected_mainmenu_game", menudata.selected_game);
g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
g_settings->set("smooth_lighting", itos(menudata.smooth_lighting));
g_settings->set("enable_3d_clouds", itos(menudata.clouds_3d));