stupid menu bullshit

This commit is contained in:
Andrei "Akari" Alexeyev 2017-02-12 05:43:52 +02:00
parent c1bf52ab0b
commit f2485d5cb8
13 changed files with 181 additions and 152 deletions

View file

@ -53,6 +53,7 @@ set(SRCs
menu/savereplay.c
menu/difficulty.c
menu/charselect.c
menu/common.c
stages/stage1.c
stages/stage2.c
stages/stage2_events.c

146
src/menu/common.c Normal file
View file

@ -0,0 +1,146 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
*/
#include "global.h"
#include "menu.h"
#include "savereplay.h"
#include "difficulty.h"
#include "charselect.h"
#include "ending.h"
#include "credits.h"
void start_game(void *arg) {
MenuData m;
init_player(&global.plr);
troll:
create_difficulty_menu(&m);
if(difficulty_menu_loop(&m) == -1)
return;
create_char_menu(&m);
if(char_menu_loop(&m) == -1)
goto troll;
global.replay_stage = NULL;
replay_init(&global.replay);
int chr = global.plr.cha;
int sht = global.plr.shot;
troll2:
if(arg)
((StageInfo*)arg)->loop();
else {
int i;
for(i = 0; stages[i].loop; ++i)
stages[i].loop();
}
if(global.game_over == GAMEOVER_RESTART) {
init_player(&global.plr);
replay_destroy(&global.replay);
replay_init(&global.replay);
global.game_over = 0;
init_player(&global.plr);
global.plr.cha = chr;
global.plr.shot = sht;
goto troll2;
}
if(global.replay_stage) {
switch(tconfig.intval[SAVE_RPY]) {
case 0: break;
case 1: {
save_rpy(NULL);
break;
}
case 2: {
MenuData m;
create_saverpy_menu(&m);
saverpy_menu_loop(&m);
break;
}
}
global.replay_stage = NULL;
}
if(global.game_over == GAMEOVER_WIN && !arg) {
start_bgm("bgm_ending");
ending_loop();
start_bgm("bgm_credits");
credits_loop();
}
start_bgm("bgm_menu");
replay_destroy(&global.replay);
global.game_over = 0;
}
void draw_menu_selector(float x, float y, float w, float h, float t) {
Texture *bg = get_tex("part/smoke");
glPushMatrix();
glTranslatef(x, y, 0);
glScalef(w / bg->w, h / bg->h, 1);
glRotatef(t*2,0,0,1);
glColor4f(0,0,0,0.5);
draw_texture_p(0,0,bg);
glPopMatrix();
}
void draw_menu_title(MenuData *m, char *title) {
glColor4f(1, 1, 1, 1);
draw_text(AL_Right, (stringwidth(title, _fonts.mainmenu) + 10) * (1.0-menu_fade(m)), 30, title, _fonts.mainmenu);
}
void draw_menu_list(MenuData *m, float x, float y, void (*draw)(void*, int, int)) {
glPushMatrix();
float offset = ((((m->ecount+5) * 20) > SCREEN_H)? min(0, SCREEN_H * 0.7 - y - m->drawdata[2]) : 0);
glTranslatef(x, y + offset, 0);
draw_menu_selector(m->drawdata[0], m->drawdata[2], m->drawdata[1], 34, m->frames);
int i;
for(i = 0; i < m->ecount; i++) {
MenuEntry *e = &(m->entries[i]);
e->drawdata += 0.2 * (10*(i == m->cursor) - e->drawdata);
float p = offset + 20*i;
if(p < -y-10 || p > SCREEN_H+10)
continue;
float a = e->drawdata * 0.1;
float o = (p < 0? 1-p/(-y-10) : 1);
if(e->action == NULL)
glColor4f(0.5, 0.5, 0.5, 0.5*o);
else {
float ia = 1-a;
glColor4f(0.9 + ia * 0.1, 0.6 + ia * 0.4, 0.2 + ia * 0.8, (0.7 + 0.3 * a)*o);
}
if(draw && i < m->ecount-1)
draw(e, i, m->ecount);
else if(e->name)
draw_text(AL_Left, 20 - e->drawdata, 20*i, e->name, _fonts.standard);
}
glPopMatrix();
}
void animate_menu_list(MenuData *m) {
MenuEntry *s = m->entries + m->cursor;
int w = stringwidth(s->name, _fonts.standard);
m->drawdata[0] += (10 + w/2.0 - m->drawdata[0])/10.0;
m->drawdata[1] += (w*2 - m->drawdata[1])/10.0;
m->drawdata[2] += (20*m->cursor - m->drawdata[2])/10.0;
}

19
src/menu/common.h Normal file
View file

@ -0,0 +1,19 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
*/
#ifndef MENUCOMMON_H
#define MENUCOMMON_H
#include "menu.h"
void start_game(void *arg);
void draw_menu_selector(float x, float y, float w, float h, float t);
void draw_menu_title(MenuData *m, char *title);
void draw_menu_list(MenuData *m, float x, float y, void (*draw)(void*, int, int));
void animate_menu_list(MenuData *m);
#endif

View file

@ -6,6 +6,7 @@
*/
#include "menu.h"
#include "common.h"
#include "ingamemenu.h"
#include "global.h"
#include "stage.h"
@ -55,10 +56,10 @@ void draw_ingame_menu(MenuData *menu) {
glPushMatrix();
glTranslatef(VIEWPORT_W/2, VIEWPORT_H/4, 0);
draw_menu_selector(0, menu->drawdata[0], menu->drawdata[1]/45.0, 0.25, menu->frames);
draw_menu_selector(0, menu->drawdata[0], menu->drawdata[1]*2, 41, menu->frames);
menu->drawdata[0] += (menu->cursor*35 - menu->drawdata[0])/7.0;
menu->drawdata[1] += (strlen(menu->entries[menu->cursor].name)*5 - menu->drawdata[1])/10.0;
menu->drawdata[1] += (stringwidth(menu->entries[menu->cursor].name, _fonts.standard) - menu->drawdata[1])/10.0;
if(menu->context) {
float s = 0.3 + 0.2 * sin(menu->frames/10.0);

View file

@ -8,8 +8,7 @@
#include "mainmenu.h"
#include "menu.h"
#include "difficulty.h"
#include "charselect.h"
#include "common.h"
#include "options.h"
#include "stageselect.h"
#include "replayview.h"
@ -17,82 +16,8 @@
#include "global.h"
#include "stage.h"
#include "ending.h"
#include "credits.h"
#include "paths/native.h"
void start_story(void *arg) {
MenuData m;
init_player(&global.plr);
troll:
create_difficulty_menu(&m);
if(difficulty_menu_loop(&m) == -1)
return;
create_char_menu(&m);
if(char_menu_loop(&m) == -1)
goto troll;
global.replay_stage = NULL;
replay_init(&global.replay);
int chr = global.plr.cha;
int sht = global.plr.shot;
troll2:
if(arg)
((StageInfo*)arg)->loop();
else {
int i;
for(i = 0; stages[i].loop; ++i)
stages[i].loop();
}
if(global.game_over == GAMEOVER_RESTART) {
init_player(&global.plr);
replay_destroy(&global.replay);
replay_init(&global.replay);
global.game_over = 0;
init_player(&global.plr);
global.plr.cha = chr;
global.plr.shot = sht;
goto troll2;
}
if(global.replay_stage) {
switch(tconfig.intval[SAVE_RPY]) {
case 0: break;
case 1: {
save_rpy(NULL);
break;
}
case 2: {
MenuData m;
create_saverpy_menu(&m);
saverpy_menu_loop(&m);
break;
}
}
global.replay_stage = NULL;
}
if(global.game_over == GAMEOVER_WIN && !arg) {
start_bgm("bgm_ending");
ending_loop();
start_bgm("bgm_credits");
credits_loop();
}
start_bgm("bgm_menu");
replay_destroy(&global.replay);
global.game_over = 0;
}
void enter_options(void *arg) {
MenuData m;
create_options_menu(&m);
@ -114,7 +39,7 @@ void enter_replayview(void *arg) {
void create_main_menu(MenuData *m) {
create_menu(m);
add_menu_entry(m, "Start Story", start_story, NULL);
add_menu_entry(m, "Start Story", start_game, NULL);
add_menu_entry(m, "Start Extra", NULL, NULL);
#ifdef DEBUG
add_menu_entry(m, "Select Stage", enter_stagemenu, NULL);

View file

@ -11,12 +11,8 @@
#include "menu.h"
void create_main_menu(MenuData *m);
void draw_main_menu_bg(MenuData *m);
void draw_main_menu(MenuData *m);
void main_menu_loop(MenuData *m);
void start_story(void*);
#endif

View file

@ -166,18 +166,3 @@ int menu_loop(MenuData *menu, void (*input)(MenuData*), void (*draw)(MenuData*),
return menu->selected;
}
void draw_menu_selector(float x, float y, float w, float h, float t) {
Texture *bg = get_tex("part/smoke");
glPushMatrix();
glTranslatef(x, y, 0);
glScalef(w, h, 1);
glRotatef(t*2,0,0,1);
glColor4f(0,0,0,0.5);
draw_texture_p(0,0,bg);
glPopMatrix();
}
void draw_menu_title(MenuData *m, char *title) {
draw_text(AL_Right, (stringwidth(title, _fonts.mainmenu) + 10) * (1.0-menu_fade(m)), 30, title, _fonts.mainmenu);
}

View file

@ -93,9 +93,6 @@ int menu_loop(MenuData *menu, void (*input)(MenuData*), void (*draw)(MenuData*),
float menu_fade(MenuData *menu);
void draw_menu_selector(float x, float y, float w, float h, float t);
void draw_menu_title(MenuData *m, char *title);
void menu_event(EventType type, int state, void *arg);
#endif

View file

@ -8,6 +8,7 @@
#include <stdio.h>
#include "menu.h"
#include "common.h"
#include "options.h"
#include "global.h"
#include "video.h"
@ -651,10 +652,10 @@ void draw_options_menu(MenuData *menu) {
glPushMatrix();
glTranslatef(100, 100, 0);
draw_menu_selector(menu->drawdata[0], menu->drawdata[2], menu->drawdata[1]/100.0, 0.2, menu->frames);
draw_menu_selector(menu->drawdata[0], menu->drawdata[2], menu->drawdata[1], 34, menu->frames);
menu->drawdata[0] += ((SCREEN_W/2 - 100) - menu->drawdata[0])/10.0;
menu->drawdata[1] += ((SCREEN_W - 200) - menu->drawdata[1])/10.0;
menu->drawdata[1] += ((SCREEN_W - 200) * 1.75 - menu->drawdata[1])/10.0;
menu->drawdata[2] += (20*menu->cursor - menu->drawdata[2])/10.0;
int i, caption_drawn = 2;

View file

@ -16,7 +16,7 @@
#include "paths/native.h"
#include "plrmodes.h"
#include "video.h"
#include "stageselect.h"
#include "common.h"
struct ReplayviewItemContext;
typedef struct ReplayviewItemContext ReplayviewItemContext;
@ -251,7 +251,7 @@ static void replayview_draw(MenuData *m) {
draw_menu_title(m, "Replays");
m->drawdata[0] = SCREEN_W/2 - 100;
m->drawdata[1] = (SCREEN_W - 200)*0.85;
m->drawdata[1] = (SCREEN_W - 200)*1.75;
m->drawdata[2] += (20*m->cursor - m->drawdata[2])/10.0;
draw_menu_list(m, 100, 100, replayview_drawitem);
@ -266,7 +266,6 @@ static void replayview_draw(MenuData *m) {
replayview_draw_stagemenu(sm);
}
}
}
int replayview_cmp(const void *a, const void *b) {

View file

@ -12,6 +12,7 @@
#include "global.h"
#include "replay.h"
#include "plrmodes.h"
#include "common.h"
void save_rpy(void *a) {
Replay *rpy = &global.replay;
@ -51,7 +52,7 @@ void draw_saverpy_menu(MenuData *m) {
draw_options_menu_bg(m);
draw_menu_selector(SCREEN_W/2 + 100 * m->drawdata[0] - 50, SCREEN_H/2, 1, 0.5, m->frames);
draw_menu_selector(SCREEN_W/2 + 100 * m->drawdata[0] - 50, SCREEN_H/2, 163, 81, m->frames);
glPushMatrix();
glColor4f(1, 1, 1, 1);

View file

@ -11,7 +11,7 @@
#include "options.h"
#include "stage.h"
#include "stageselect.h"
#include "mainmenu.h"
#include "common.h"
void create_stage_menu(MenuData *m) {
char title[STGMENU_MAX_TITLE_LENGTH];
@ -22,58 +22,17 @@ void create_stage_menu(MenuData *m) {
for(i = 0; stages[i].loop; ++i) if(!stages[i].hidden) {
snprintf(title, STGMENU_MAX_TITLE_LENGTH, "%s", stages[i].title);
add_menu_entry(m, title, start_story, &(stages[i]));
add_menu_entry(m, title, start_game, stages+i);
}
add_menu_separator(m);
add_menu_entry(m, "Back", (MenuAction)kill_menu, m);
}
void draw_menu_list(MenuData *m, float x, float y, void (*draw)(void*, int, int)) {
glPushMatrix();
float offset = ((((m->ecount+5) * 20) > SCREEN_H)? min(0, SCREEN_H * 0.7 - y - m->drawdata[2]) : 0);
glTranslatef(x, y + offset, 0);
draw_menu_selector(m->drawdata[0], m->drawdata[2], m->drawdata[1]/100.0, 0.2, m->frames);
int i;
for(i = 0; i < m->ecount; i++) {
MenuEntry *e = &(m->entries[i]);
e->drawdata += 0.2 * (10*(i == m->cursor) - e->drawdata);
float p = offset + 20*i;
if(p < -y-10 || p > SCREEN_H+10)
continue;
float a = e->drawdata * 0.1;
float o = (p < 0? 1-p/(-y-10) : 1);
if(e->action == NULL)
glColor4f(0.5, 0.5, 0.5, 0.5*o);
else {
float ia = 1-a;
glColor4f(0.9 + ia * 0.1, 0.6 + ia * 0.4, 0.2 + ia * 0.8, (0.7 + 0.3 * a)*o);
}
if(draw && i < m->ecount-1)
draw(e, i, m->ecount);
else if(e->name)
draw_text(AL_Left, 20 - e->drawdata, 20*i, e->name, _fonts.standard);
}
glPopMatrix();
}
void draw_stage_menu(MenuData *m) {
MenuEntry *s = &(m->entries[m->cursor]);
draw_options_menu_bg(m);
draw_menu_title(m, "Stage Select");
m->drawdata[0] += (stringwidth(s->name, _fonts.mainmenu)/2.0 - s->drawdata*1.5 - m->drawdata[0])/10.0;
m->drawdata[1] += (stringwidth(s->name, _fonts.mainmenu) - m->drawdata[1])/10.0;
m->drawdata[2] += (20*m->cursor - m->drawdata[2])/10.0;
animate_menu_list(m);
draw_menu_list(m, 100, 100, NULL);
}

View file

@ -12,7 +12,6 @@
#define STGMENU_MAX_TITLE_LENGTH 128
void create_stage_menu(MenuData *m);
void draw_menu_list(MenuData *m, float x, float y, void (*draw)(void *, int, int));
int stage_menu_loop(MenuData *m);
#endif