confirmation menu

This commit is contained in:
Tropicananass 2016-05-11 17:23:53 +02:00
parent 097c3f9ec2
commit 269fa59870
5 changed files with 89 additions and 20 deletions

BIN
bin/hex

Binary file not shown.

View File

@ -9,6 +9,7 @@
#include "affichage_menu.h"
#include "affichage_plateau.h"
#include "action_plateau.h"
#include "menu.h"
#include "sub_menu.h"
#include "sauvegarde.h"
@ -135,7 +136,7 @@ int menu_save (plateau_t p)
}
vec2 c = m->cur;
m->cur.x = 1;
m->cur.x = 1;
m->cur.y = 1;
Affiche_entry (m, 0);
m->cur = c;
}
@ -152,7 +153,7 @@ int menu_save (plateau_t p)
}
vec2 c = m->cur;
m->cur.x = 1;
m->cur.x = 1;
m->cur.y = 1;
Affiche_entry (m, 0);
m->cur = c;
}
@ -163,7 +164,7 @@ int menu_save (plateau_t p)
entries [2] [cur] = '_';
vec2 c = m->cur;
m->cur.x = 1;
m->cur.x = 1;
m->cur.y = 1;
Affiche_entry (m, 0);
m->cur = c;
}
@ -178,23 +179,34 @@ int menu_save (plateau_t p)
end = true;
char** liste;
int nb = listeSauvegarde (&liste);
entries [2] [cur] = '\0';
for (int i = 0; i < nb && end; ++i)
if (!strcmp (entries [2], liste [i]))
{
strcpy (entries [2], "existe déjà");
cur = 1;
vec2 c = m->cur;
m->cur.x = 1;
m->cur.x = 1;
m->cur.y = 1;
Affiche_entry (m, 0);
m->cur = c;
end = 0;
}
free_liste (liste, nb);
if (end)
if (end || confirmation (p->window, NULL, "Écraser", entries [2]) == M_UP)
{
entries [2] [cur] = '\0';
sauvegarde (entries [2], p->hist, p->ia);
end = true;
}
else
{
if (cur != 8)
{
entries [2] [cur] = '_';
entries [2] [cur + 1] = '\0';
}
m->cur.x = 1;
m->cur.y = 1;
Affiche_menu(m);
}
}
break;
@ -204,7 +216,7 @@ int menu_save (plateau_t p)
cur = 8;
vec2 c = m->cur;
m->cur.x = 1;
m->cur.x = 1;
m->cur.y = 1;
Affiche_entry (m, 0);
m->cur = c;
break;
@ -215,7 +227,7 @@ int menu_save (plateau_t p)
cur = 8;
vec2 c = m->cur;
m->cur.x = 1;
m->cur.x = 1;
m->cur.y = 1;
Affiche_entry (m, 0);
m->cur = c;
break;
@ -303,7 +315,7 @@ int menu_en_jeu_part1 (plateau_t p)
retour = M_DOWN;
else
retour = evenement_menu(p->window, m, event, 0);
if (retour == M_UP || retour == M_RIGHT)
if (retour == M_UP || retour == M_RIGHT || retour == M7_UP)
{
if (resize.x == p->window->w && resize.y == p->window->h)
SDL_BlitSurface (save, NULL, p->window, NULL);
@ -339,7 +351,11 @@ int menu_en_jeu_part1 (plateau_t p)
end = true;
break;
case M7_UP :
if (confirmation (p->window, NULL, "Annuler le ", "dernier coup") == M_UP)
annuler (p);
m->cur.x = 1;
m->cur.y = 1;
Affiche_menu(m);
break;
}
}

View File

@ -200,6 +200,8 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
end = true;
break;
case M_MID :
if (confirmation (window, scroll, "supprimer", entries [2]) == M_UP)
{
supprimer (entries [2]);
free_liste (liste, nb_sav);
nb_sav = listeSauvegarde(&liste);
@ -211,6 +213,11 @@ int menu_charger (SDL_Surface* window, scrolling_t scroll, char** file)
nb_sav = 1;
}
cur = 0;
sprintf (entries [2], "%s", liste[cur]);
}
m->cur.x = 1;
m->cur.y = 1;
Affiche_menu(m);
break;
}
}

View File

@ -15,6 +15,50 @@
#define VOL(x) x * MIX_MAX_VOLUME / 100
int confirmation (SDL_Surface* window, scrolling_t scroll, char* ask1, char* ask2)
{
char* entries [5] = {"?", " OUI ", "?", " NON ", "?"};
if (ask1 != NULL)
entries [0] = ask1;
if (ask2 != NULL)
entries [2] = ask2;
menu_t m = init_menu (window, entries);
Affiche_menu(m);
int retour;
bool end = false;
while (!end)
{
SDL_Event event;
if (scroll == NULL)
SDL_WaitEvent (&event);
else
event = scroll_msg (window, scroll);
if (event.type == SDL_QUIT || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE))
retour = M_DOWN;
else
retour = evenement_menu(window, m, event, 1);
if ((event.type == SDL_VIDEORESIZE || (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_f)) && scroll != NULL)
scroll = resize_scroll(window, scroll);
switch (retour)
{
case M_UP:
end = true;
break;
case M_LEFT :
break;
case M_RIGHT :
break;
case M_DOWN :
end = true;
break;
case M_MID :
break;
}
}
free_menu(m);
return retour;
}
int menu_music (SDL_Surface* window, scrolling_t scroll)
{
bool en_jeu = Mix_PlayingMusic();

View File

@ -12,6 +12,8 @@
#include "globals.h"
#include "scrolling.h"
int confirmation (SDL_Surface* window, scrolling_t scroll, char* ask1, char* ask2);
int menu_music (SDL_Surface* window, scrolling_t scroll);
int menu_son (SDL_Surface* window, scrolling_t scroll);