taisei/src/menu/mainmenu.c

244 lines
6 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
2018-01-04 18:14:31 +01:00
* Copyright (c) 2011-2018, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2018, Andrei Alexeyev <akari@alienslab.net>.
*/
#include "taisei.h"
#include "mainmenu.h"
#include "menu.h"
#include "submenus.h"
2017-02-12 04:43:52 +01:00
#include "common.h"
2012-08-07 05:28:41 +02:00
#include "savereplay.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"
#include "plrmodes.h"
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;
}
global.diff = progress.game_settings.difficulty;
2017-09-11 21:09:30 +02:00
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
}
}
}
}
2017-12-26 12:07:40 +01:00
static void begin_main_menu(MenuData *m) {
2017-10-02 04:34:51 +02:00
start_bgm("menu");
}
2017-12-26 12:07:40 +01:00
static void update_main_menu(MenuData *menu);
void create_main_menu(MenuData *m) {
create_menu(m);
m->draw = draw_main_menu;
2017-12-26 12:07:40 +01:00
m->logic = update_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) {
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
2018-07-23 19:07:59 +02:00
r_color4(1, 1, 1, 1);
fill_screen("menu/mainmenubg");
2011-06-24 12:35:03 +02:00
}
2017-12-26 12:07:40 +01:00
static void update_main_menu(MenuData *menu) {
menu->drawdata[1] += (text_width(get_font("big"), menu->entries[menu->cursor].name, 0) - menu->drawdata[1])/10.0;
2017-12-26 12:07:40 +01:00
menu->drawdata[2] += (35*menu->cursor - menu->drawdata[2])/10.0;
for(int i = 0; i < menu->ecount; i++) {
menu->entries[i].drawdata += 0.2 * ((i == menu->cursor) - menu->entries[i].drawdata);
}
}
2011-06-24 12:35:03 +02:00
void draw_main_menu(MenuData *menu) {
draw_main_menu_bg(menu);
draw_sprite(150.5, 100, "menu/logo");
r_mat_push();
r_mat_translate(0, SCREEN_H-270, 0);
draw_menu_selector(50 + menu->drawdata[1]/2, menu->drawdata[2], 1.5 * menu->drawdata[1], 64, menu->frames);
r_shader("text_default");
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
2018-07-23 19:07:59 +02:00
float o = 0.7;
2017-12-26 12:07:40 +01:00
for(int i = 0; i < menu->ecount; i++) {
float s = 5*sin(menu->frames/80.0 + 20*i);
if(menu->entries[i].action == NULL) {
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
2018-07-23 19:07:59 +02:00
r_color4(0.2 * o, 0.3 * o, 0.5 * o, o);
} else {
float a = 1 - menu->entries[i].drawdata;
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
2018-07-23 19:07:59 +02:00
r_color4(o, min(1, 0.7 + a) * o, min(1, 0.4 + a) * o, o);
}
text_draw(menu->entries[i].name, &(TextParams) {
.pos = { 50 + s, 35*i },
.font = "big",
// .shader = "text_example",
// .custom = time_get()
});
}
r_mat_pop();
bool cullcap_saved = r_capability_current(RCAP_CULL_FACE);
r_disable(RCAP_CULL_FACE);
Premultiplied alpha (#133) * WIP premultiplied alpha * WIP color API rework (doesn't build yet; lots of things left to convert) * convert everything remaining to new Color api except stage*_event.c files * convert the stages to new Color api. builds & runs now; still many rendering errors * fix the bullet shader for premultiplied alpha * fix masterspark, graphs and stage 1 fog clouds * fix marisa_b and most of spellcards * Add deprecation warnings for BLEND_ADD and PFLAG_DRAWADD * fix a segfault in stage 6 undo accidental earlier change * fix text_hud.frag.glsl * fix scuttle bg and remaining stage3 BLEND_ADDs * fix marisa laser opacity * hacky fix for myon The old implementation relied on alpha being stored inside p->color. In premul alpha this doesn’t work and functions like color_set_opacity can’t solve this i think. So I tried messing around with it until it looked somewhat similar. * fix marisa_b stars * remove color_set_opacity i overlooked * more plrmode blending changes * fixup additive blending in stage 1 * various premultiplied alpha fixups for bosses and enemies * stage 2 premul alpha fixups * stage 4 premul alpha fixups * stage 5 premul alpha fixups * stage 6 premul alpha fixups * make lasers also use the PMA blend mode * remove PFLAG_DRAWADD and PFLAG_DRAWSUB * fix remaining PMA issues in menus * lame extraspell bg workaround * fix item alpha * make marisaA lasers look somewhat like in master * fix marisaA bomb background fadeout * fixup various r_color4 calls * fix myon * remove dead code * fix use of BLEND_ADD in player death effect * fix myon shot trails (broken on master as well) * fix myon shot fade-in * extend the sprite shaders custom parameter to a vec4 * fix youmuB stuff and make it look somewhat better. the code looks even worse though.
2018-07-23 19:07:59 +02:00
r_color4(1, 1, 1, 0);
r_shader("sprite_default");
2017-03-04 22:51:23 +01:00
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;
r_mat_push();
r_mat_translate(posx,posy,0);
r_mat_scale(0.2,0.2,0.2);
r_mat_rotate_deg(2*(t%period),rx,ry,rz);
draw_sprite_batched(0,0,"part/petal");
r_mat_pop();
2017-03-04 22:51:23 +01:00
}
r_shader("text_default");
r_capability(RCAP_CULL_FACE, cullcap_saved);
char version[32];
snprintf(version, sizeof(version), "v%s", TAISEI_VERSION);
text_draw(TAISEI_VERSION, &(TextParams) {
.align = ALIGN_RIGHT,
.pos = { SCREEN_W-5, SCREEN_H-10 },
.font = "small",
});
2018-07-25 00:33:01 +02:00
r_shader_standard();
}
void draw_loading_screen(void) {
preload_resource(RES_TEXTURE, "loading", RESF_PERMANENT);
set_ortho(SCREEN_W, SCREEN_H);
fill_screen("loading");
/*
text_draw(TAISEI_VERSION, &(TextParams) {
.align = ALIGN_RIGHT,
.pos = { SCREEN_W-5, SCREEN_H-10 },
.font = "small",
.shader = "text_default",
});
*/
video_swap_buffers();
}
void menu_preload(void) {
difficulty_preload();
preload_resources(RES_FONT, RESF_PERMANENT,
"big",
"small",
NULL);
preload_resources(RES_TEXTURE, RESF_PERMANENT,
"menu/mainmenubg",
NULL);
preload_resources(RES_SPRITE, RESF_PERMANENT,
"part/smoke",
"part/petal",
"menu/logo",
"menu/arrow",
"star",
NULL);
preload_resources(RES_SHADER_PROGRAM, RESF_PERMANENT,
"sprite_circleclipped_indicator",
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);
for(int i = 0; i < NUM_CHARACTERS; ++i) {
preload_resource(RES_SPRITE, plrchar_get(i)->dialog_sprite_name, RESF_PERMANENT);
}
}