basic replayview menu
This commit is contained in:
parent
5308856f1f
commit
4195ea94c4
8 changed files with 140 additions and 35 deletions
|
@ -37,7 +37,8 @@ set(SRCs
|
|||
menu/menu.c
|
||||
menu/mainmenu.c
|
||||
menu/options.c
|
||||
menu/stageselect.c
|
||||
menu/stageselect.c
|
||||
menu/replayview.c
|
||||
menu/ingamemenu.c
|
||||
menu/gameovermenu.c
|
||||
menu/savereplay.c
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "charselect.h"
|
||||
#include "options.h"
|
||||
#include "stageselect.h"
|
||||
#include "replayview.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "stage.h"
|
||||
|
@ -47,32 +48,6 @@ troll:
|
|||
global.game_over = 0;
|
||||
}
|
||||
|
||||
void start_replay(void *arg) {
|
||||
char p[1337];
|
||||
snprintf(p, 1337, "%s/test.%s", get_config_path(), REPLAY_EXTENSION);
|
||||
FILE *fp = fopen(p, "r");
|
||||
printf("%s\n", p);
|
||||
replay_read(&global.replay, fp);
|
||||
fclose(fp);
|
||||
|
||||
StageInfo *s = stage_get(global.replay.stage);
|
||||
|
||||
if(!s) {
|
||||
printf("Invalid stage %d in replay... wtf?!\n", global.replay.stage);
|
||||
return;
|
||||
}
|
||||
|
||||
init_player(&global.plr);
|
||||
|
||||
// XXX: workaround, doesn't even always work. DEBUG THIS.
|
||||
global.fps.show_fps = 0;
|
||||
|
||||
global.replaymode = REPLAY_PLAY;
|
||||
s->loop();
|
||||
global.replaymode = REPLAY_RECORD;
|
||||
global.game_over = 0;
|
||||
}
|
||||
|
||||
void enter_options(void *arg) {
|
||||
MenuData m;
|
||||
create_options_menu(&m);
|
||||
|
@ -85,17 +60,23 @@ void enter_stagemenu(void *arg) {
|
|||
stage_menu_loop(&m);
|
||||
}
|
||||
|
||||
void enter_replayview(void *arg) {
|
||||
MenuData m;
|
||||
create_replayview_menu(&m);
|
||||
replayview_menu_loop(&m);
|
||||
}
|
||||
|
||||
void create_main_menu(MenuData *m) {
|
||||
create_menu(m);
|
||||
|
||||
m->type = MT_Persistent;
|
||||
|
||||
add_menu_entry(m, "Start Story", start_story, NULL);
|
||||
add_menu_entry(m, "Replay (TEST)", start_replay, NULL);
|
||||
add_menu_entry(m, "Start Extra", NULL, NULL);
|
||||
#ifdef DEBUG
|
||||
add_menu_entry(m, "Select Stage", enter_stagemenu, NULL);
|
||||
#endif
|
||||
add_menu_entry(m, "Replays", enter_replayview, NULL);
|
||||
add_menu_entry(m, "Options", enter_options, NULL);
|
||||
add_menu_entry(m, "Quit", quit_menu, m);
|
||||
}
|
||||
|
|
|
@ -10,9 +10,10 @@
|
|||
|
||||
void add_menu_entry(MenuData *menu, char *name, void (*action)(void *), void *arg) {
|
||||
menu->entries = realloc(menu->entries, (++menu->ecount)*sizeof(MenuEntry));
|
||||
menu->entries[menu->ecount-1].name = malloc(strlen(name)+1);
|
||||
menu->entries[menu->ecount-1].name = malloc(strlen(name)+1);
|
||||
strcpy(menu->entries[menu->ecount-1].name, name);
|
||||
menu->entries[menu->ecount-1].action = action;
|
||||
menu->entries[menu->ecount-1].freearg = False;
|
||||
menu->entries[menu->ecount-1].arg = arg;
|
||||
menu->entries[menu->ecount-1].drawdata = 0;
|
||||
}
|
||||
|
@ -28,8 +29,13 @@ void destroy_menu(MenuData *menu) {
|
|||
if(menu->ondestroy)
|
||||
menu->ondestroy(menu);
|
||||
|
||||
for(i = 0; i < menu->ecount; i++)
|
||||
free(menu->entries[i].name);
|
||||
for(i = 0; i < menu->ecount; i++) {
|
||||
MenuEntry *e = &(menu->entries[i]);
|
||||
|
||||
free(e->name);
|
||||
if(e->freearg)
|
||||
free(e->arg);
|
||||
}
|
||||
|
||||
free(menu->entries);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ typedef struct {
|
|||
void (*action)(void* arg);
|
||||
void *arg;
|
||||
float drawdata;
|
||||
int freearg;
|
||||
} MenuEntry;
|
||||
|
||||
typedef enum MenuType { // whether to close on selection or not.
|
||||
|
@ -44,6 +45,7 @@ typedef struct MenuData{
|
|||
|
||||
float drawdata[4];
|
||||
|
||||
char *title;
|
||||
void *context;
|
||||
void (*ondestroy)(void*);
|
||||
} MenuData;
|
||||
|
|
|
@ -342,7 +342,7 @@ void create_options_menu(MenuData *m) {
|
|||
OptionBinding *b;
|
||||
|
||||
create_menu(m);
|
||||
m->type = MT_Persistent;
|
||||
m->type = MT_Transient;
|
||||
m->ondestroy = destroy_options_menu;
|
||||
m->context = NULL;
|
||||
|
||||
|
@ -613,7 +613,7 @@ static void options_key_action(MenuData *menu, int sym) {
|
|||
if(bind->enabled && bind->type == BT_IntValue)
|
||||
bind_setnext(bind);
|
||||
} else if(sym == SDLK_ESCAPE) {
|
||||
menu->quit = 2;
|
||||
menu->quit = 1;
|
||||
}
|
||||
|
||||
menu->cursor = (menu->cursor % menu->ecount) + menu->ecount*(menu->cursor < 0);
|
||||
|
|
95
src/menu/replayview.c
Executable file
95
src/menu/replayview.c
Executable file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* This software is licensed under the terms of the MIT-License
|
||||
* See COPYING for further information.
|
||||
* ---
|
||||
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
|
||||
* Copyright (C) 2012, Alexeyew Andrew <https://github.com/nexAkari>
|
||||
*/
|
||||
|
||||
#include <dirent.h>
|
||||
#include "global.h"
|
||||
#include "menu.h"
|
||||
#include "options.h"
|
||||
#include "mainmenu.h"
|
||||
#include "replayview.h"
|
||||
#include "paths/native.h"
|
||||
|
||||
void backtomain(void*);
|
||||
|
||||
void start_replay(void *arg) {
|
||||
replay_load(&global.replay, (char*)arg);
|
||||
StageInfo *s = stage_get(global.replay.stage);
|
||||
|
||||
if(!s) {
|
||||
printf("Invalid stage %d in replay... wtf?!\n", global.replay.stage);
|
||||
return;
|
||||
}
|
||||
|
||||
init_player(&global.plr);
|
||||
|
||||
// XXX: workaround, doesn't even always work. DEBUG THIS.
|
||||
global.fps.show_fps = 0;
|
||||
|
||||
global.replaymode = REPLAY_PLAY;
|
||||
s->loop();
|
||||
global.replaymode = REPLAY_RECORD;
|
||||
global.game_over = 0;
|
||||
}
|
||||
|
||||
int strendswith(char *s, char *e) {
|
||||
int ls = strlen(s);
|
||||
int le = strlen(e);
|
||||
|
||||
if(le > ls)
|
||||
return False;
|
||||
|
||||
int i; for(i = ls - 1; i < le; ++i)
|
||||
if(s[i] != e[i])
|
||||
return False;
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
void fill_replayview_menu(MenuData *m) {
|
||||
DIR *dir = opendir(get_replays_path());
|
||||
struct dirent *e;
|
||||
|
||||
if(!dir) {
|
||||
printf("Could't read %s\n", get_replays_path());
|
||||
return;
|
||||
}
|
||||
|
||||
char ext[5];
|
||||
snprintf(ext, 5, ".%s", REPLAY_EXTENSION);
|
||||
|
||||
while((e = readdir(dir))) {
|
||||
if(!strendswith(e->d_name, ext))
|
||||
continue;
|
||||
|
||||
int size = strlen(e->d_name) - strlen(ext);
|
||||
char *s = (char*)malloc(size);
|
||||
strncpy(s, e->d_name, size);
|
||||
s[size] = 0;
|
||||
|
||||
add_menu_entry(m, s, start_replay, s);
|
||||
m->entries[m->ecount-1].freearg = True;
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
void create_replayview_menu(MenuData *m) {
|
||||
create_menu(m);
|
||||
m->type = MT_Transient;
|
||||
m->title = "Replays";
|
||||
|
||||
fill_replayview_menu(m);
|
||||
add_menu_separator(m);
|
||||
add_menu_entry(m, "Back", backtomain, m);
|
||||
}
|
||||
|
||||
void draw_stage_menu(MenuData *m);
|
||||
int replayview_menu_loop(MenuData *m) {
|
||||
return menu_loop(m, NULL, draw_stage_menu);
|
||||
}
|
||||
|
15
src/menu/replayview.h
Executable file
15
src/menu/replayview.h
Executable file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* This software is licensed under the terms of the MIT-License
|
||||
* See COPYING for further information.
|
||||
* ---
|
||||
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
|
||||
* Copyright (C) 2012, Alexeyew Andrew <https://github.com/nexAkari>
|
||||
*/
|
||||
|
||||
#ifndef RPYVIEW_H
|
||||
#define RPYVIEW_H
|
||||
|
||||
void create_replayview_menu(MenuData *m);
|
||||
int replayview_menu_loop(MenuData *m);
|
||||
|
||||
#endif
|
|
@ -20,7 +20,9 @@ void create_stage_menu(MenuData *m) {
|
|||
int i;
|
||||
|
||||
create_menu(m);
|
||||
m->type = MT_Persistent;
|
||||
m->type = MT_Transient;
|
||||
// TODO: I think ALL menus should use the title field, but I don't want to screw with it right now.
|
||||
m->title = "Stage Select";
|
||||
|
||||
for(i = 0; stages[i].loop; ++i) if(!stages[i].hidden) {
|
||||
snprintf(title, STGMENU_MAX_TITLE_LENGTH, "%d. %s", i + 1, stages[i].title);
|
||||
|
@ -33,7 +35,10 @@ void create_stage_menu(MenuData *m) {
|
|||
|
||||
void draw_stage_menu(MenuData *m) {
|
||||
draw_options_menu_bg(m);
|
||||
draw_text(AL_Right, 220*(1-m->fade), 30, "Stage Select", _fonts.mainmenu);
|
||||
|
||||
int w, h;
|
||||
TTF_SizeText(_fonts.mainmenu, m->title, &w, &h);
|
||||
draw_text(AL_Right, (w + 10) * (1-m->fade), 30, m->title, _fonts.mainmenu);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(100, 100, 0);
|
||||
|
|
Loading…
Reference in a new issue