Skip to content

Commit efc9329

Browse files
committedMay 13, 2013
Only use game filter in singleplayer tab; use menu_{background, overlay, header, footer}.png for other tabs
1 parent 2c09e8a commit efc9329

File tree

3 files changed

+74
-51
lines changed

3 files changed

+74
-51
lines changed
 

‎src/guiMainMenu.cpp

+22-31
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,6 @@ enum
166166
GUI_ID_GAME_BUTTON_MAX = 150,
167167
};
168168

169-
enum
170-
{
171-
TAB_SINGLEPLAYER=0,
172-
TAB_MULTIPLAYER,
173-
TAB_ADVANCED,
174-
TAB_SETTINGS,
175-
TAB_CREDITS
176-
};
177-
178169
GUIMainMenu::GUIMainMenu(gui::IGUIEnvironment* env,
179170
gui::IGUIElement* parent, s32 id,
180171
IMenuManager *menumgr,
@@ -258,7 +249,8 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
258249
core::rect<s32> rect(0, 0, size.X, 40);
259250
rect += v2s32(4, 0);
260251
std::string t = "Minetest " VERSION_STRING;
261-
if(m_data->selected_game_name != ""){
252+
if(m_data->selected_game_name != "" &&
253+
m_data->selected_tab == TAB_SINGLEPLAYER){
262254
t += "/";
263255
t += m_data->selected_game_name;
264256
}
@@ -428,6 +420,26 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
428420
delete[] text;
429421
}
430422
changeCtype("C");
423+
424+
/* Add game selection buttons */
425+
video::IVideoDriver* driver = Environment->getVideoDriver();
426+
for(size_t i=0; i<m_data->games.size(); i++){
427+
const SubgameSpec *spec = &m_data->games[i];
428+
v2s32 p(8 + i*(48+8), screensize.Y - (48+8));
429+
core::rect<s32> rect(0, 0, 48, 48);
430+
rect += p;
431+
video::ITexture *bgtexture = NULL;
432+
if(spec->menuicon_path != "")
433+
bgtexture = driver->getTexture(spec->menuicon_path.c_str());
434+
gui::IGUIButton *b = Environment->addButton(rect, this,
435+
GUI_ID_GAME_BUTTON_FIRST+i, narrow_to_wide(wrap_rows(spec->id, 4)).c_str());
436+
if(bgtexture){
437+
b->setImage(bgtexture);
438+
b->setText(L"");
439+
b->setDrawBorder(false);
440+
b->setUseAlphaChannel(true);
441+
}
442+
}
431443
}
432444
else if(m_data->selected_tab == TAB_MULTIPLAYER)
433445
{
@@ -920,27 +932,6 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
920932
}
921933
}
922934

923-
/* Add game selection buttons */
924-
925-
video::IVideoDriver* driver = Environment->getVideoDriver();
926-
for(size_t i=0; i<m_data->games.size(); i++){
927-
const SubgameSpec *spec = &m_data->games[i];
928-
v2s32 p(8 + i*(48+8), screensize.Y - (48+8));
929-
core::rect<s32> rect(0, 0, 48, 48);
930-
rect += p;
931-
video::ITexture *bgtexture = NULL;
932-
if(spec->menuicon_path != "")
933-
bgtexture = driver->getTexture(spec->menuicon_path.c_str());
934-
gui::IGUIButton *b = Environment->addButton(rect, this,
935-
GUI_ID_GAME_BUTTON_FIRST+i, narrow_to_wide(wrap_rows(spec->id, 4)).c_str());
936-
if(bgtexture){
937-
b->setImage(bgtexture);
938-
b->setText(L"");
939-
b->setDrawBorder(false);
940-
b->setUseAlphaChannel(true);
941-
}
942-
}
943-
944935
m_is_regenerating = false;
945936
}
946937

‎src/guiMainMenu.h

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ enum {
3434
SERVERLIST_PUBLIC,
3535
};
3636

37+
enum
38+
{
39+
TAB_SINGLEPLAYER=0,
40+
TAB_MULTIPLAYER,
41+
TAB_ADVANCED,
42+
TAB_SETTINGS,
43+
TAB_CREDITS
44+
};
45+
3746
struct MainMenuData
3847
{
3948
// These are in the native format of the gui elements

‎src/main.cpp

+43-20
Original file line numberDiff line numberDiff line change
@@ -663,12 +663,14 @@ class RandomInputHandler : public InputHandler
663663
struct MenuTextures
664664
{
665665
std::string current_gameid;
666+
bool global_textures;
666667
video::ITexture *background;
667668
video::ITexture *overlay;
668669
video::ITexture *header;
669670
video::ITexture *footer;
670671

671672
MenuTextures():
673+
global_textures(false),
672674
background(NULL),
673675
overlay(NULL),
674676
header(NULL),
@@ -678,28 +680,49 @@ struct MenuTextures
678680
static video::ITexture* getMenuTexture(const std::string &tname,
679681
video::IVideoDriver* driver, const SubgameSpec *spec)
680682
{
681-
std::string path;
682-
// eg. minetest_menu_background.png (for texture packs)
683-
std::string pack_tname = spec->id + "_menu_" + tname + ".png";
684-
path = getTexturePath(pack_tname);
685-
if(path != "")
686-
return driver->getTexture(path.c_str());
687-
// eg. games/minetest_game/menu/background.png
688-
path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png");
689-
if(path != "")
690-
return driver->getTexture(path.c_str());
683+
if(spec){
684+
std::string path;
685+
// eg. minetest_menu_background.png (for texture packs)
686+
std::string pack_tname = spec->id + "_menu_" + tname + ".png";
687+
path = getTexturePath(pack_tname);
688+
if(path != "")
689+
return driver->getTexture(path.c_str());
690+
// eg. games/minetest_game/menu/background.png
691+
path = getImagePath(spec->path + DIR_DELIM + "menu" + DIR_DELIM + tname + ".png");
692+
if(path != "")
693+
return driver->getTexture(path.c_str());
694+
} else {
695+
std::string path;
696+
// eg. menu_background.png
697+
std::string pack_tname = "menu_" + tname + ".png";
698+
path = getTexturePath(pack_tname);
699+
if(path != "")
700+
return driver->getTexture(path.c_str());
701+
}
691702
return NULL;
692703
}
693704

694-
void update(video::IVideoDriver* driver, const SubgameSpec *spec)
705+
void update(video::IVideoDriver* driver, const SubgameSpec *spec, int tab)
695706
{
696-
if(spec->id == current_gameid)
697-
return;
698-
current_gameid = spec->id;
699-
background = getMenuTexture("background", driver, spec);
700-
overlay = getMenuTexture("overlay", driver, spec);
701-
header = getMenuTexture("header", driver, spec);
702-
footer = getMenuTexture("footer", driver, spec);
707+
if(tab == TAB_SINGLEPLAYER){
708+
if(spec->id == current_gameid)
709+
return;
710+
current_gameid = spec->id;
711+
global_textures = false;
712+
background = getMenuTexture("background", driver, spec);
713+
overlay = getMenuTexture("overlay", driver, spec);
714+
header = getMenuTexture("header", driver, spec);
715+
footer = getMenuTexture("footer", driver, spec);
716+
} else {
717+
if(global_textures)
718+
return;
719+
current_gameid = "";
720+
global_textures = true;
721+
background = getMenuTexture("background", driver, NULL);
722+
overlay = getMenuTexture("overlay", driver, NULL);
723+
header = getMenuTexture("header", driver, NULL);
724+
footer = getMenuTexture("footer", driver, NULL);
725+
}
703726
}
704727
};
705728

@@ -1778,7 +1801,7 @@ int main(int argc, char *argv[])
17781801
const SubgameSpec *menugame = getMenuGame(menudata);
17791802

17801803
MenuTextures menutextures;
1781-
menutextures.update(driver, menugame);
1804+
menutextures.update(driver, menugame, menudata.selected_tab);
17821805

17831806
if(skip_main_menu == false)
17841807
{
@@ -1839,7 +1862,7 @@ int main(int argc, char *argv[])
18391862

18401863
// Game can be selected in the menu
18411864
menugame = getMenuGame(menudata);
1842-
menutextures.update(driver, menugame);
1865+
menutextures.update(driver, menugame, menu->getTab());
18431866
// Clouds for the main menu
18441867
bool cloud_menu_background = g_settings->getBool("menu_clouds");
18451868
if(menugame){

0 commit comments

Comments
 (0)
Please sign in to comment.