Skip to content

Commit a25e6bf

Browse files
committed
main menu when leaving load menu
1 parent b1a022a commit a25e6bf

File tree

4 files changed

+56
-41
lines changed

4 files changed

+56
-41
lines changed

src/game.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ void Config::reset(void)
272272
key_move_right.sym = SDLK_d;
273273
key_move_up.sym = SDLK_w;
274274
key_quit.sym = SDLK_q;
275-
key_quit.mod = KMOD_SHIFT;
276275
key_save.sym = SDLK_F1;
277276
key_screenshot.sym = SDLK_F10;
278277
key_console.sym = SDLK_BACKQUOTE;
@@ -501,7 +500,7 @@ void Game::state_change(uint8_t new_state, const std::string &why)
501500
TRACE_AND_INDENT();
502501

503502
//
504-
// Actions for the new state
503+
// Cleanup actions for the new state
505504
//
506505
switch (new_state) {
507506
case STATE_MAIN_MENU :
@@ -520,6 +519,21 @@ void Game::state_change(uint8_t new_state, const std::string &why)
520519
wid_main_menu_destroy(g);
521520
wid_quit_destroy(g);
522521
wid_save_destroy(g);
522+
break;
523+
case STATE_KEYBOARD_MENU :
524+
case STATE_LOAD_MENU :
525+
case STATE_SAVE_MENU :
526+
case STATE_QUIT_MENU : break;
527+
}
528+
529+
//
530+
// Enter the new state
531+
//
532+
switch (new_state) {
533+
case STATE_MAIN_MENU : wid_main_menu_select(g); break;
534+
535+
case STATE_QUITTING : break;
536+
case STATE_PLAYING :
523537
if (old_state == STATE_MAIN_MENU) {
524538
wid_leftbar_init(g);
525539
wid_rightbar_init(g);

src/game_load.hpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ std::array< bool, UI_WID_SAVE_SLOTS > slot_valid;
3232

3333
std::istream &operator>>(std::istream &in, Bits< SDL_Keysym & > my)
3434
{
35-
TRACE_AND_INDENT();
35+
TRACE_NO_INDENT();
3636
in >> bits(my.t.scancode);
3737
in >> bits(my.t.sym);
3838
in >> bits(my.t.mod);
@@ -42,7 +42,7 @@ std::istream &operator>>(std::istream &in, Bits< SDL_Keysym & > my)
4242

4343
std::istream &operator>>(std::istream &in, Bits< Config & > my)
4444
{
45-
TRACE_AND_INDENT();
45+
TRACE_NO_INDENT();
4646

4747
in >> bits(my.t.version);
4848
LOG("Read config: version = [%s]", my.t.version.c_str());
@@ -199,7 +199,7 @@ std::istream &operator>>(std::istream &in, Bits< Config & > my)
199199

200200
std::istream &operator>>(std::istream &in, Bits< class Game & > my)
201201
{
202-
TRACE_AND_INDENT();
202+
TRACE_NO_INDENT();
203203
in >> bits(my.t.version);
204204
in >> bits(my.t.serialized_size);
205205

@@ -237,7 +237,7 @@ std::istream &operator>>(std::istream &in, Bits< class Game & > my)
237237
// ios::ate, open at end
238238
std::vector< char > read_file(const std::string filename)
239239
{
240-
TRACE_AND_INDENT();
240+
TRACE_NO_INDENT();
241241
std::ifstream ifs(filename, std::ios::in | std::ios::binary | std::ios::ate);
242242
if (ifs.is_open()) {
243243
ifs.unsetf(std::ios::skipws);
@@ -255,7 +255,7 @@ std::vector< char > read_file(const std::string filename)
255255

256256
static std::vector< char > read_lzo_file(const std::string filename, lzo_uint *uncompressed_sz, uint32_t *cs)
257257
{
258-
TRACE_AND_INDENT();
258+
TRACE_NO_INDENT();
259259
std::ifstream ifs(filename, std::ios::in | std::ios::binary | std::ios::ate);
260260
if (ifs.is_open()) {
261261
// tellg is not ideal, look into <filesystem> post mojave
@@ -281,7 +281,7 @@ static std::vector< char > read_lzo_file(const std::string filename, lzo_uint *u
281281

282282
uint32_t csum(char *mem, uint32_t len)
283283
{
284-
TRACE_AND_INDENT();
284+
TRACE_NO_INDENT();
285285
uint32_t ret = 0;
286286
while (len--) {
287287
ret <<= 1;
@@ -293,7 +293,7 @@ uint32_t csum(char *mem, uint32_t len)
293293

294294
bool Game::load(std::string file_to_load, class Game &target)
295295
{
296-
TRACE_AND_INDENT();
296+
TRACE_NO_INDENT();
297297
game_load_error = "";
298298

299299
//
@@ -362,7 +362,7 @@ bool Game::load(std::string file_to_load, class Game &target)
362362

363363
std::string Game::load_config(void)
364364
{
365-
TRACE_AND_INDENT();
365+
TRACE_NO_INDENT();
366366
game_load_error = "";
367367

368368
auto filename = saved_dir + "config";
@@ -376,7 +376,7 @@ std::string Game::load_config(void)
376376

377377
void Game::load(void)
378378
{
379-
TRACE_AND_INDENT();
379+
TRACE_NO_INDENT();
380380
LOG("-");
381381
CON("INF: Loading %s", save_file.c_str());
382382
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
@@ -396,7 +396,7 @@ void Game::load(void)
396396

397397
void Game::load(int slot)
398398
{
399-
TRACE_AND_INDENT();
399+
TRACE_NO_INDENT();
400400
if (slot < 0) {
401401
return;
402402
}
@@ -441,7 +441,7 @@ void Game::load(int slot)
441441

442442
void Game::load_snapshot(void)
443443
{
444-
TRACE_AND_INDENT();
444+
TRACE_NO_INDENT();
445445
game->fini();
446446

447447
auto this_save_file = saved_dir + "saved-snapshot";
@@ -467,7 +467,7 @@ void Game::load_snapshot(void)
467467

468468
void wid_load_destroy(Gamep g)
469469
{
470-
TRACE_AND_INDENT();
470+
TRACE_NO_INDENT();
471471
if (wid_load) {
472472
delete wid_load;
473473
wid_load = nullptr;
@@ -477,7 +477,7 @@ void wid_load_destroy(Gamep g)
477477

478478
static bool wid_load_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
479479
{
480-
TRACE_AND_INDENT();
480+
TRACE_NO_INDENT();
481481

482482
if (sdlk_eq(*key, game->config.key_console)) {
483483
return false;
@@ -516,7 +516,7 @@ static bool wid_load_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
516516
case 'B' :
517517
case SDLK_ESCAPE :
518518
{
519-
TRACE_AND_INDENT();
519+
TRACE_NO_INDENT();
520520
CON("INF: Load game cancelled");
521521
wid_load_destroy(game);
522522
return true;
@@ -531,7 +531,7 @@ static bool wid_load_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
531531

532532
static bool wid_load_key_down(Gamep g, Widp w, const struct SDL_Keysym *key)
533533
{
534-
TRACE_AND_INDENT();
534+
TRACE_NO_INDENT();
535535

536536
if (sdlk_eq(*key, game->config.key_console)) {
537537
return false;
@@ -542,7 +542,7 @@ static bool wid_load_key_down(Gamep g, Widp w, const struct SDL_Keysym *key)
542542

543543
static bool wid_load_mouse_up(Gamep g, Widp w, int x, int y, uint32_t button)
544544
{
545-
TRACE_AND_INDENT();
545+
TRACE_NO_INDENT();
546546
auto slot = wid_get_int_context(w);
547547
game->load(slot);
548548
wid_load_destroy(game);
@@ -551,23 +551,23 @@ static bool wid_load_mouse_up(Gamep g, Widp w, int x, int y, uint32_t button)
551551

552552
static bool wid_load_saved_snapshot(Gamep g, Widp w, int x, int y, uint32_t button)
553553
{
554-
TRACE_AND_INDENT();
554+
TRACE_NO_INDENT();
555555
game->load_snapshot();
556556
wid_load_destroy(game);
557557
return true;
558558
}
559559

560560
static bool wid_load_cancel(Gamep g, Widp w, int x, int y, uint32_t button)
561561
{
562-
TRACE_AND_INDENT();
562+
TRACE_NO_INDENT();
563563
wid_load_destroy(game);
564564
return true;
565565
}
566566

567567
void Game::load_select(void)
568568
{
569+
CON("INF: Load menu");
569570
TRACE_AND_INDENT();
570-
CON("INF: Loading a saved game");
571571

572572
if (wid_load) {
573573
return;
@@ -585,7 +585,7 @@ void Game::load_select(void)
585585
wid_set_on_key_down(game, wid_load->wid_popup_container, wid_load_key_down);
586586

587587
{
588-
TRACE_AND_INDENT();
588+
TRACE_NO_INDENT();
589589
auto p = wid_load->wid_text_area->wid_text_area;
590590
auto w = wid_new_square_button(game, p, "back");
591591

src/game_save.hpp

+18-17
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int GAME_SAVE_MARKER_CONFIG = 987654;
2424

2525
std::ostream &operator<<(std::ostream &out, Bits< const SDL_Keysym & > const my)
2626
{
27-
TRACE_AND_INDENT();
27+
TRACE_NO_INDENT();
2828
out << bits(my.t.scancode);
2929
out << bits(my.t.sym);
3030
out << bits(my.t.mod);
@@ -34,7 +34,7 @@ std::ostream &operator<<(std::ostream &out, Bits< const SDL_Keysym & > const my)
3434

3535
std::ostream &operator<<(std::ostream &out, Bits< const Config & > const my)
3636
{
37-
TRACE_AND_INDENT();
37+
TRACE_NO_INDENT();
3838
out << bits(my.t.version);
3939
uint32_t serialized_size = sizeof(Config);
4040
out << bits(serialized_size);
@@ -90,7 +90,7 @@ std::ostream &operator<<(std::ostream &out, Bits< const Config & > const my)
9090

9191
std::ostream &operator<<(std::ostream &out, Bits< const class Game & > const my)
9292
{
93-
TRACE_AND_INDENT();
93+
TRACE_NO_INDENT();
9494
uint32_t serialized_size = (uint32_t) (sizeof(Game));
9595
out << bits(my.t.version);
9696
out << bits(serialized_size);
@@ -111,7 +111,7 @@ std::ostream &operator<<(std::ostream &out, Bits< const class Game & > const my)
111111

112112
bool Game::save(std::string file_to_save)
113113
{
114-
TRACE_AND_INDENT();
114+
TRACE_NO_INDENT();
115115
std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
116116

117117
const class Game &c = *this;
@@ -212,7 +212,7 @@ bool Game::save(std::string file_to_save)
212212

213213
void Game::save(void)
214214
{
215-
TRACE_AND_INDENT();
215+
TRACE_NO_INDENT();
216216
LOG("-");
217217
CON("INF: Saving %s", save_file.c_str());
218218
LOG("| | | | | | | | | | | | | | | | | | | | | | | | | | |");
@@ -228,7 +228,7 @@ void Game::save(void)
228228

229229
void Game::save(int slot)
230230
{
231-
TRACE_AND_INDENT();
231+
TRACE_NO_INDENT();
232232
if (slot < 0) {
233233
return;
234234
}
@@ -258,7 +258,7 @@ void Game::save_snapshot(void)
258258
{
259259
CON("Autosaving...");
260260

261-
TRACE_AND_INDENT();
261+
TRACE_NO_INDENT();
262262

263263
auto this_save_file = saved_dir + "saved-snapshot";
264264

@@ -279,7 +279,7 @@ void Game::save_snapshot(void)
279279

280280
void Game::save_config(void)
281281
{
282-
TRACE_AND_INDENT();
282+
TRACE_NO_INDENT();
283283
auto filename = saved_dir + "config";
284284
std::ofstream out(filename, std::ios::binary);
285285
if (! out) {
@@ -293,7 +293,7 @@ void Game::save_config(void)
293293

294294
void wid_save_destroy(Gamep g)
295295
{
296-
TRACE_AND_INDENT();
296+
TRACE_NO_INDENT();
297297
if (wid_save) {
298298
delete wid_save;
299299
wid_save = nullptr;
@@ -303,7 +303,7 @@ void wid_save_destroy(Gamep g)
303303

304304
static bool wid_save_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
305305
{
306-
TRACE_AND_INDENT();
306+
TRACE_NO_INDENT();
307307

308308
if (sdlk_eq(*key, game->config.key_console)) {
309309
return false;
@@ -316,7 +316,7 @@ static bool wid_save_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
316316
switch (key->sym) {
317317
default :
318318
{
319-
TRACE_AND_INDENT();
319+
TRACE_NO_INDENT();
320320
auto c = wid_event_to_char(key);
321321
switch (c) {
322322
case '0' :
@@ -330,7 +330,7 @@ static bool wid_save_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
330330
case '8' :
331331
case '9' :
332332
{
333-
TRACE_AND_INDENT();
333+
TRACE_NO_INDENT();
334334
int slot = c - '0';
335335
game->save(slot);
336336
wid_save_destroy(game);
@@ -340,7 +340,7 @@ static bool wid_save_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
340340
case 'B' :
341341
case SDLK_ESCAPE :
342342
{
343-
TRACE_AND_INDENT();
343+
TRACE_NO_INDENT();
344344
CON("INF: Save game cancelled");
345345
wid_save_destroy(game);
346346
return true;
@@ -355,7 +355,7 @@ static bool wid_save_key_up(Gamep g, Widp w, const struct SDL_Keysym *key)
355355

356356
static bool wid_save_key_down(Gamep g, Widp w, const struct SDL_Keysym *key)
357357
{
358-
TRACE_AND_INDENT();
358+
TRACE_NO_INDENT();
359359

360360
if (sdlk_eq(*key, game->config.key_console)) {
361361
return false;
@@ -366,7 +366,7 @@ static bool wid_save_key_down(Gamep g, Widp w, const struct SDL_Keysym *key)
366366

367367
static bool wid_save_mouse_up(Gamep g, Widp w, int x, int y, uint32_t button)
368368
{
369-
TRACE_AND_INDENT();
369+
TRACE_NO_INDENT();
370370
auto slot = wid_get_int_context(w);
371371
game->save(slot);
372372
wid_save_destroy(game);
@@ -375,13 +375,14 @@ static bool wid_save_mouse_up(Gamep g, Widp w, int x, int y, uint32_t button)
375375

376376
static bool wid_save_cancel(Gamep g, Widp w, int x, int y, uint32_t button)
377377
{
378-
TRACE_AND_INDENT();
378+
TRACE_NO_INDENT();
379379
wid_save_destroy(game);
380380
return true;
381381
}
382382

383383
void Game::save_select(void)
384384
{
385+
CON("INF: Save menu");
385386
TRACE_AND_INDENT();
386387

387388
if (wid_save) {
@@ -398,7 +399,7 @@ void Game::save_select(void)
398399
wid_set_on_key_down(game, wid_save->wid_popup_container, wid_save_key_down);
399400

400401
{
401-
TRACE_AND_INDENT();
402+
TRACE_NO_INDENT();
402403
auto p = wid_save->wid_text_area->wid_text_area;
403404
auto w = wid_new_square_button(game, p, "back");
404405

src/sdl_events.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ static void __attribute__((noinline)) sdl_event_mousemotion(Gamep g, SDL_Keysym
185185
last_mx = mx;
186186
last_my = my;
187187

188-
LOG("SDL: Mouse: Moved to @%d,%d (rel %d,%d) state %d (actually at %d,%d)", event->motion.x, event->motion.y,
189-
event->motion.xrel, event->motion.yrel, sdl.mouse_down, mx, my);
188+
DBG2("SDL: Mouse: Moved to @%d,%d (rel %d,%d) state %d (actually at %d,%d)", event->motion.x, event->motion.y,
189+
event->motion.xrel, event->motion.yrel, sdl.mouse_down, mx, my);
190190

191191
wid_mouse_visible = 1;
192192
sdl.mouse_tick++;

0 commit comments

Comments
 (0)