[Add] Preliminary main menu.

This commit is contained in:
Allanis 2013-03-20 22:29:07 +00:00
parent 14af8c7e74
commit b183286fdb
5 changed files with 63 additions and 13 deletions

1
TODO
View File

@ -2,7 +2,6 @@ Vital:
-- Missions -- Missions
-- Save -- Save
-- Allow multiple ships in storage. -- Allow multiple ships in storage.
-- Main Menu.
-- Player faction system. -- Player faction system.
Major: Major:

View File

@ -26,6 +26,7 @@
#include "sound.h" #include "sound.h"
#include "spfx.h" #include "spfx.h"
#include "economy.h" #include "economy.h"
#include "menu.h"
#include "music.h" #include "music.h"
#define XML_START_ID "Start" #define XML_START_ID "Start"
@ -160,8 +161,7 @@ int main(int argc, char** argv) {
fleet_load(); fleet_load();
space_load(); space_load();
// Create new player. TODO: Start menu. menu_main();
player_new();
gtime = SDL_GetTicks(); // Init the time. gtime = SDL_GetTicks(); // Init the time.
@ -193,9 +193,12 @@ int main(int argc, char** argv) {
fps_control(); // Who doesn't love FPS control? fps_control(); // Who doesn't love FPS control?
toolkit_update(); // Simulate key repetition. toolkit_update(); // Simulate key repetition.
if(!paused && !toolkit) update_space(); // Update the game.
if(!menu_isOpen(MENU_MAIN)) {
if(!paused && !toolkit) update_space(); // Update the game.
render_space(); render_space();
}
if(toolkit) toolkit_render(); if(toolkit) toolkit_render();
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();

View File

@ -10,6 +10,9 @@
#include "player.h" #include "player.h"
#include "menu.h" #include "menu.h"
#define MAIN_WIDTH 120
#define MAIN_HEIGHT 250
#define MENU_WIDTH 120 #define MENU_WIDTH 120
#define MENU_HEIGHT 200 #define MENU_HEIGHT 200
@ -25,15 +28,13 @@
#define BUTTON_WIDTH 80 #define BUTTON_WIDTH 80
#define BUTTON_HEIGHT 30 #define BUTTON_HEIGHT 30
#define MENU_SMALL (1<<0)
#define MENU_INFO (1<<1)
#define MENU_DEATH (1<<2)
#define menu_isOpen(f) (menu_open & (f))
#define menu_Open(f) (menu_open |= (f)) #define menu_Open(f) (menu_open |= (f))
#define menu_Close(f) (menu_open ^= (f)) #define menu_Close(f) (menu_open ^= (f))
static int menu_open = 0; int menu_open = 0;
static void menu_main_close(void);
static void menu_main_new(char* str);
static void menu_small_close(char* str); static void menu_small_close(char* str);
static void edit_options(void); static void edit_options(void);
static void exit_game(void); static void exit_game(void);
@ -42,10 +43,50 @@ static void info_outfits_menu(char* str);
static void info_outfits_menu_close(char* str); static void info_outfits_menu_close(char* str);
static void menu_death_respawn(char* str); static void menu_death_respawn(char* str);
void menu_main(void) {
unsigned int bwid, wid;
// Create background image window.
bwid = window_create("BG", -1, -1, gl_screen.w, gl_screen.h);
window_addRect(bwid, 0, 0, gl_screen.w, gl_screen.h, "rctBG", &cBlack, 0);
// Create menu window.
wid = window_create("Main Menu", -1, -1, MAIN_WIDTH, MAIN_HEIGHT);
window_addButton(wid, 20, 20 + (BUTTON_HEIGHT+20)*3,
BUTTON_WIDTH, BUTTON_HEIGHT,
"btnLoad", "Load Game", NULL);
window_addButton(wid, 20, 20 + (BUTTON_HEIGHT+20)*2,
BUTTON_WIDTH, BUTTON_HEIGHT,
"btnNew", "New Game", menu_main_new);
window_addButton(wid, 20, 20 + (BUTTON_HEIGHT+20),
BUTTON_WIDTH, BUTTON_HEIGHT,
"btnOptions", "Options", (void(*)(char*)) edit_options);
window_addButton(wid, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
"btnExit", "Exit", (void(*)(char*)) exit_game);
menu_Open(MENU_MAIN);
}
static void menu_main_close(void) {
window_destroy(window_get("Main Menu"));
window_destroy(window_get("BG"));
menu_Close(MENU_MAIN);
}
static void menu_main_new(char* str) {
(void)str;
menu_main_close();
player_new();
}
// Ze ingame menu. // Ze ingame menu.
// Small ingame menu. // Small ingame menu.
void menu_small(void) { void menu_small(void) {
if(menu_isOpen(MENU_SMALL) || menu_isOpen(MENU_DEATH)) if(menu_isOpen(MENU_MAIN) ||
menu_isOpen(MENU_SMALL) ||
menu_isOpen(MENU_DEATH))
return; // It's already open.. return; // It's already open..
pause(); pause();

View File

@ -1,7 +1,14 @@
#pragma once #pragma once
void menu_small(void); #define MENU_MAIN (1<<0)
#define MENU_SMALL (1<<1)
#define MENU_INFO (1<<2)
#define MENU_DEATH (1<<3)
#define menu_isOpen(f) (menu_open & (f))
extern int menu_open;
void menu_main(void);
void menu_small(void);
void menu_info(void); void menu_info(void);
void menu_deah(void); void menu_deah(void);

View File

@ -46,7 +46,7 @@ void window_modifyText(const unsigned int wid, char* name, char* newstring);
void window_modifyImage(const unsigned int wid, char* name, glTexture* image); void window_modifyImage(const unsigned int wid, char* name, glTexture* image);
// Get! // Get!
glTexture window_getImage(const unsigned int wid, char* name); glTexture* window_getImage(const unsigned int wid, char* name);
// Get the window by name. // Get the window by name.
int window_exists(const char* wdwname); int window_exists(const char* wdwname);