[Fix] Pause is handled on opening a window, but for safety it is best to handle pause on menu open.
-- Forgot the menu files too..
This commit is contained in:
parent
100c605d6b
commit
19570b0f6a
62
src/menu.c
Normal file
62
src/menu.c
Normal file
@ -0,0 +1,62 @@
|
||||
#include <string.h>
|
||||
#include "SDL.h"
|
||||
|
||||
#include "toolkit.h"
|
||||
#include "log.h"
|
||||
#include "main.h"
|
||||
#include "pause.h"
|
||||
#include "menu.h"
|
||||
|
||||
#define MENU_WIDTH 120
|
||||
#define MENU_HEIGHT 200
|
||||
|
||||
#define BUTTON_WIDTH 80
|
||||
#define BUTTON_HEIGHT 30
|
||||
|
||||
static int menu_open = 0;
|
||||
|
||||
static void menu_small_close(char* str);
|
||||
static void edit_options(void);
|
||||
static void exit_game(void);
|
||||
|
||||
// Small ingame menu.
|
||||
void menu_small(void) {
|
||||
if(menu_open) return; // It's already open..
|
||||
|
||||
unsigned int wid;
|
||||
|
||||
wid = window_create("Menu", -1, -1, MENU_WIDTH, MENU_HEIGHT);
|
||||
|
||||
window_addButton(wid, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||
"btnExit", "Exit", (void(*)(char*))exit_game);
|
||||
window_addButton(wid, 20, 20 + BUTTON_HEIGHT + 20,
|
||||
BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||
"btnOptions", "Options", (void(*)(char*))edit_options);
|
||||
window_addButton(wid, 20, 20 + BUTTON_HEIGHT*2 + 20*2,
|
||||
BUTTON_WIDTH, BUTTON_HEIGHT,
|
||||
"btnResume", "Resume", menu_small_close);
|
||||
|
||||
pause();
|
||||
menu_open = 1;
|
||||
}
|
||||
|
||||
void menu_small_close(char* str) {
|
||||
if(strcmp(str, "btnResume")==0)
|
||||
window_destroy(window_get("Menu"));
|
||||
|
||||
unpause();
|
||||
menu_open = 0;
|
||||
}
|
||||
|
||||
// Edit the options.
|
||||
static void edit_options(void) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// Exit the game.
|
||||
static void exit_game(void) {
|
||||
SDL_Event quit;
|
||||
quit.type = SDL_QUIT;
|
||||
SDL_PushEvent(&quit);
|
||||
}
|
||||
|
4
src/menu.h
Normal file
4
src/menu.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma one
|
||||
|
||||
void menu_small(void);
|
||||
|
Loading…
Reference in New Issue
Block a user