taisei/src/menu/mainmenu.c

236 lines
5.9 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
2017-09-12 03:28:15 +02:00
* Copyright (c) 2011-2017, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2017, Andrei Alexeyev <akari@alienslab.net>.
*/
#include "mainmenu.h"
#include "menu.h"
2017-02-12 04:43:52 +01:00
#include "common.h"
#include "options.h"
#include "stageselect.h"
2012-07-16 19:26:41 +02:00
#include "replayview.h"
2012-08-07 05:28:41 +02:00
#include "savereplay.h"
2017-02-12 05:30:25 +01:00
#include "spellpractice.h"
2017-09-11 21:09:30 +02:00
#include "stagepractice.h"
#include "difficultyselect.h"
#include "global.h"
#include "video.h"
#include "stage.h"
2017-09-18 10:49:06 +02:00
#include "version.h"
void enter_options(MenuData *menu, void *arg) {
MenuData m;
create_options_menu(&m);
menu_loop(&m);
}
void enter_stagemenu(MenuData *menu, void *arg) {
MenuData m;
create_stage_menu(&m);
menu_loop(&m);
}
void enter_replayview(MenuData *menu, void *arg) {
2012-07-16 19:26:41 +02:00
MenuData m;
create_replayview_menu(&m);
menu_loop(&m);
2012-07-16 19:26:41 +02:00
}
2017-02-12 05:30:25 +01:00
void enter_spellpractice(MenuData *menu, void *arg) {
MenuData m;
create_spell_menu(&m);
menu_loop(&m);
2017-02-12 05:30:25 +01:00
}
2017-09-11 21:09:30 +02:00
void enter_stagepractice(MenuData *menu, void *arg) {
MenuData m;
do {
create_difficulty_menu(&m);
if(menu_loop(&m) < 0) {
return;
}
create_stgpract_menu(&m, global.diff);
menu_loop(&m);
} while(m.selected < 0 || m.selected == m.ecount - 1);
}
2017-02-12 05:30:25 +01:00
static MenuEntry *spell_practice_entry;
2017-09-11 21:09:30 +02:00
static MenuEntry *stage_practice_entry;
2017-02-12 05:30:25 +01:00
2017-09-11 21:09:30 +02:00
void main_menu_update_practice_menus(void) {
spell_practice_entry->action = NULL;
stage_practice_entry->action = NULL;
2017-02-12 05:30:25 +01:00
2017-09-11 21:09:30 +02:00
for(StageInfo *stg = stages; stg->procs && (!spell_practice_entry->action || !stage_practice_entry->action); ++stg) {
2017-02-12 05:30:25 +01:00
if(stg->type == STAGE_SPELL) {
StageProgress *p = stage_get_progress_from_info(stg, D_Any, false);
2017-09-11 21:09:30 +02:00
2017-02-12 05:30:25 +01:00
if(p && p->unlocked) {
2017-09-11 21:09:30 +02:00
spell_practice_entry->action = enter_spellpractice;
}
} else if(stg->type == STAGE_STORY) {
for(Difficulty d = D_Easy; d <= D_Lunatic; ++d) {
StageProgress *p = stage_get_progress_from_info(stg, d, false);
if(p && p->unlocked) {
stage_practice_entry->action = enter_stagepractice;
}
2017-02-12 05:30:25 +01:00
}
}
}
}
void begin_main_menu(MenuData *m) {
2017-10-02 04:34:51 +02:00
start_bgm("menu");
}
void create_main_menu(MenuData *m) {
create_menu(m);
m->draw = draw_main_menu;
m->begin = begin_main_menu;
2017-02-12 04:43:52 +01:00
add_menu_entry(m, "Start Story", start_game, NULL);
2011-06-24 12:35:03 +02:00
add_menu_entry(m, "Start Extra", NULL, NULL);
2017-09-11 21:09:30 +02:00
add_menu_entry(m, "Stage Practice", enter_stagepractice, NULL);
2017-02-12 05:30:25 +01:00
add_menu_entry(m, "Spell Practice", enter_spellpractice, NULL);
#ifdef DEBUG
2012-07-14 10:49:58 +02:00
add_menu_entry(m, "Select Stage", enter_stagemenu, NULL);
#endif
2012-07-16 19:26:41 +02:00
add_menu_entry(m, "Replays", enter_replayview, NULL);
add_menu_entry(m, "Options", enter_options, NULL);
add_menu_entry(m, "Quit", menu_commonaction_close, NULL)->transition = TransFadeBlack;;
2017-09-11 21:09:30 +02:00
stage_practice_entry = m->entries + 2;
spell_practice_entry = m->entries + 3;
main_menu_update_practice_menus();
2017-02-12 05:30:25 +01:00
}
2011-06-24 12:35:03 +02:00
void draw_main_menu_bg(MenuData* menu) {
glColor4f(1,1,1,1);
2017-03-04 22:51:23 +01:00
//draw_texture(SCREEN_W/2, SCREEN_H/2, "mainmenu/mainmenubgbg");
//glColor4f(1,1,1,0.95 + 0.05*sin(menu->frames/100.0));
draw_texture(SCREEN_W/2, SCREEN_H/2, "mainmenu/mainmenubg");
2011-06-24 12:35:03 +02:00
glColor4f(1,1,1,1);
2012-08-03 19:58:21 +02:00
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2011-06-24 12:35:03 +02:00
}
void draw_main_menu(MenuData *menu) {
draw_main_menu_bg(menu);
2017-03-04 11:32:59 +01:00
draw_texture(150.5, 100, "mainmenu/logo");
glPushMatrix();
2017-09-11 21:09:30 +02:00
glTranslatef(0, SCREEN_H-270, 0);
Texture *bg = get_tex("part/smoke");
glPushMatrix();
glTranslatef(50 + menu->drawdata[1]/2, menu->drawdata[2], 0); // 135
glScalef(menu->drawdata[1]/100.0, 0.5, 1);
glRotatef(menu->frames*2,0,0,1);
glColor4f(0,0,0,0.5);
draw_texture_p(0,0,bg);
glPopMatrix();
int i;
menu->drawdata[1] += (stringwidth(menu->entries[menu->cursor].name, _fonts.mainmenu) - menu->drawdata[1])/10.0;
menu->drawdata[2] += (35*menu->cursor - menu->drawdata[2])/10.0;
for(i = 0; i < menu->ecount; i++) {
float s = 5*sin(menu->frames/80.0 + 20*i);
menu->entries[i].drawdata += 0.2 * ((i == menu->cursor) - menu->entries[i].drawdata);
if(menu->entries[i].action == NULL) {
2017-03-04 22:51:23 +01:00
glColor4f(0.2,0.3,0.5,0.7);
} else {
//glColor4f(1,1,1,0.7);
float a = 1 - menu->entries[i].drawdata;
glColor4f(1, 0.7 + a, 0.4 + a, 0.7);
}
draw_text(AL_Left, 50 + s, 35*i, menu->entries[i].name, _fonts.mainmenu);
}
glPopMatrix();
2017-03-04 22:51:23 +01:00
glColor4f(1,1,1,1);
for(int i = 0; i < 50; i++) { // who needs persistent state for a particle system?
int period = 900;
int t = menu->frames+100*i + 30*sin(35*i);
int cycle = t/period;
float posx = SCREEN_W+300+100*sin(100345*i)+200*sin(1003*i+13537*cycle)-(0.6+0.01*sin(35*i))*(t%period);
float posy = 50+ 50*sin(503*i+14677*cycle)+0.8*(t%period);
float rx = sin(56*i+2147*cycle);
float ry = sin(913*i+137*cycle);
float rz = sin(1303*i+89631*cycle);
float r = sqrt(rx*rx+ry*ry+rz*rz);
if(!r) {
continue;
}
2017-03-04 22:51:23 +01:00
rx /= r;
ry /= r;
rz /= r;
2017-03-04 22:51:23 +01:00
if(posx > SCREEN_W+20 || posy < -20 || posy > SCREEN_H+20)
continue;
glDisable(GL_CULL_FACE);
glPushMatrix();
glTranslatef(posx,posy,0);
glScalef(0.2,0.2,0.2);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glRotatef(2*(t%period),rx,ry,rz);
draw_texture(0,0,"part/petal");
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_CULL_FACE);
glPopMatrix();
}
char version[32];
snprintf(version, sizeof(version), "v%s", TAISEI_VERSION);
draw_text(AL_Right,SCREEN_W-5,SCREEN_H-10,version,_fonts.small);
}
void draw_loading_screen(void) {
preload_resource(RES_TEXTURE, "loading", RESF_PERMANENT);
set_ortho();
draw_texture(SCREEN_W/2, SCREEN_H/2, "loading");
2017-09-18 10:49:06 +02:00
draw_text(AL_Right,SCREEN_W-5,SCREEN_H-10,TAISEI_VERSION,_fonts.small);
SDL_GL_SwapWindow(video.window);
}
void menu_preload(void) {
difficulty_preload();
preload_resources(RES_TEXTURE, RESF_PERMANENT,
"mainmenu/mainmenubg",
"mainmenu/logo",
"part/smoke",
"part/petal",
"dialog/marisa",
"dialog/youmu",
"charselect_arrow",
NULL);
preload_resources(RES_SFX, RESF_PERMANENT | RESF_OPTIONAL,
"generic_shot",
"shot_special1",
"hit",
NULL);
preload_resources(RES_BGM, RESF_PERMANENT | RESF_OPTIONAL,
2017-10-02 04:34:51 +02:00
"menu",
NULL);
}