-
Notifications
You must be signed in to change notification settings - Fork 804
/
menu.cpp
193 lines (165 loc) · 4.05 KB
/
menu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/**
* @file mainmenu.cpp
*
* Implementation of functions for interacting with the main menu.
*/
#include <cstdint>
#include "DiabloUI/diabloui.h"
#include "DiabloUI/settingsmenu.h"
#include "engine/demomode.h"
#include "init.h"
#include "movie.h"
#include "options.h"
#include "pfile.h"
#include "storm/storm_net.hpp"
#include "utils/language.h"
namespace devilution {
uint32_t gSaveNumber;
namespace {
_music_id NextTrack()
{
if (gbIsSpawn) {
return TMUSIC_INTRO;
}
switch (sgnMusicTrack) {
case TMUSIC_INTRO:
return TMUSIC_CATACOMBS;
case TMUSIC_CATACOMBS:
return TMUSIC_CAVES;
case TMUSIC_CAVES:
return TMUSIC_HELL;
case TMUSIC_HELL:
return gbIsHellfire ? TMUSIC_NEST : TMUSIC_INTRO;
case TMUSIC_NEST:
return gbIsHellfire ? TMUSIC_CRYPT : TMUSIC_INTRO;
default:
return TMUSIC_INTRO;
}
}
void RefreshMusic()
{
music_start(NextTrack());
}
bool InitMenu(_selhero_selections type)
{
bool success;
if (type == SELHERO_PREVIOUS)
return true;
success = StartGame(type != SELHERO_CONTINUE, type != SELHERO_CONNECT);
if (success)
RefreshMusic();
return success;
}
bool InitSinglePlayerMenu()
{
gbIsMultiplayer = false;
return InitMenu(SELHERO_NEW_DUNGEON);
}
bool InitMultiPlayerMenu()
{
gbIsMultiplayer = true;
return InitMenu(SELHERO_CONNECT);
}
void PlayIntro()
{
music_stop();
if (gbIsHellfire)
play_movie("gendata\\Hellfire.smk", true);
else
play_movie("gendata\\diablo1.smk", true);
RefreshMusic();
}
bool DummyGetHeroInfo(_uiheroinfo * /*pInfo*/)
{
return true;
}
} // namespace
bool mainmenu_select_hero_dialog(GameData *gameData)
{
OptionEntryInt<uint32_t> *pSaveNumberFromOptions = nullptr;
_selhero_selections dlgresult = SELHERO_NEW_DUNGEON;
if (demo::IsRunning()) {
pfile_ui_set_hero_infos(DummyGetHeroInfo);
gbLoadGame = true;
} else if (!gbIsMultiplayer) {
pSaveNumberFromOptions = gbIsHellfire ? &sgOptions.Hellfire.lastSinglePlayerHero : &sgOptions.Diablo.lastSinglePlayerHero;
gSaveNumber = **pSaveNumberFromOptions;
UiSelHeroSingDialog(
pfile_ui_set_hero_infos,
pfile_ui_save_create,
pfile_delete_save,
pfile_ui_set_class_stats,
&dlgresult,
&gSaveNumber,
&gameData->nDifficulty);
gbLoadGame = (dlgresult == SELHERO_CONTINUE);
} else {
pSaveNumberFromOptions = gbIsHellfire ? &sgOptions.Hellfire.lastMultiplayerHero : &sgOptions.Diablo.lastMultiplayerHero;
gSaveNumber = **pSaveNumberFromOptions;
UiSelHeroMultDialog(
pfile_ui_set_hero_infos,
pfile_ui_save_create,
pfile_delete_save,
pfile_ui_set_class_stats,
&dlgresult,
&gSaveNumber);
}
if (dlgresult == SELHERO_PREVIOUS) {
return false;
}
if (pSaveNumberFromOptions != nullptr)
pSaveNumberFromOptions->SetValue(gSaveNumber);
return true;
}
void mainmenu_wait_for_button_sound()
{
SDL_FillRect(DiabloUiSurface(), nullptr, 0x000000);
UiFadeIn();
SDL_Delay(350); // delay to let button pressed sound finish playing
}
void mainmenu_loop()
{
bool done;
RefreshMusic();
done = false;
do {
_mainmenu_selections menu = MAINMENU_NONE;
if (demo::IsRunning())
menu = MAINMENU_SINGLE_PLAYER;
else if (!UiMainMenuDialog(gszProductName, &menu, 30))
app_fatal(_("Unable to display mainmenu"));
switch (menu) {
case MAINMENU_NONE:
break;
case MAINMENU_SINGLE_PLAYER:
if (!InitSinglePlayerMenu())
done = true;
break;
case MAINMENU_MULTIPLAYER:
if (!InitMultiPlayerMenu())
done = true;
break;
case MAINMENU_ATTRACT_MODE:
if (gbIsSpawn && !HaveDiabdat())
done = false;
else if (gbActive)
PlayIntro();
break;
case MAINMENU_SHOW_CREDITS:
UiCreditsDialog();
break;
case MAINMENU_SHOW_SUPPORT:
UiSupportDialog();
break;
case MAINMENU_EXIT_DIABLO:
mainmenu_wait_for_button_sound();
done = true;
break;
case MAINMENU_SETTINGS:
UiSettingsMenu();
break;
}
} while (!done);
music_stop();
}
} // namespace devilution