MORTEVIELLE: Convert menu code to a class

This commit is contained in:
Paul Gilbert 2012-02-13 00:02:03 +11:00 committed by Strangerke
parent 2fb94dfa01
commit c3a63e04ee
10 changed files with 126 additions and 104 deletions

View File

@ -543,9 +543,12 @@ void tmettre() {
show_mouse();
tinke();
pendule();
if (ipers != 0) affper(ipers);
else person();
menu_aff();
if (ipers != 0)
affper(ipers);
else
person();
g_vm->_menu.menu_aff();
if (entre) {
s.mlieu = 17;
tmlieu(17);

View File

@ -38,19 +38,22 @@ namespace Mortevielle {
/* NIVEAU 14*/
void menut(int no, Common::String nom) {
/**
* Setup a menu's contents
*/
void Menu::menut(int no, Common::String nom) {
byte h, l;
Common::String s;
/* debug('menut'); */
h = hi(no);
l = lo(no);
s = nom;
if (! tesok) {
g_vm->quitGame();
}
while (s.size() < 20) s = s + ' ';
while (s.size() < 20)
s = s + ' ';
switch (h) {
case invent :
if (l != 7) {
@ -73,10 +76,13 @@ void menut(int no, Common::String nom) {
}
}
void menu_disable(int no) {
/**
* Disable a menu item
* @param no Hi byte represents menu number, lo byte reprsents item index
*/
void Menu::disableMenuItem(int no) {
byte h, l;
/* debug('menu_disable'); */
h = hi(no);
l = lo(no);
switch (h) {
@ -84,7 +90,8 @@ void menu_disable(int no) {
if (l > 6) {
inv[l].setChar('<', 0);
inv[l].setChar('>', 21);
} else inv[l].setChar('*', 0);
} else
inv[l].setChar('*', 0);
}
break;
case depla :
@ -102,10 +109,13 @@ void menu_disable(int no) {
}
}
void menu_enable(int no) {
/**
* Enable a menu item
* @param no Hi byte represents menu number, lo byte reprsents item index
*/
void Menu::enableMenuItem(int no) {
byte h, l;
/* debug('menu_disable'); */
h = hi(no);
l = lo(no);
switch (h) {
@ -131,19 +141,13 @@ void menu_enable(int no) {
}
}
void menu_aff() {
void Menu::menu_aff() {
int ind_tabl, k, col;
// char c;
int pt, x, y, color, msk,
num_letr;
/* debug('menu_aff'); */
int pt, x, y, color, msk, num_letr;
hide_mouse();
/*if not tesok then
begin
clrscr;
halt;
end;*/
g_vm->_screenSurface.fillRect(7, Common::Rect(0, 0, 639, 10));
col = 28 * res;
if (gd == cga) color = 1;
@ -177,9 +181,10 @@ void menu_aff() {
show_mouse();
}
void draw_menu() {
/* debug('draw_menu'); */
/**
* Show the menu
*/
void Menu::drawMenu() {
menu_aff();
active_menu = true;
msg4 = no_choice;
@ -189,10 +194,9 @@ void draw_menu() {
test0 = false;
}
void invers(int ix) {
void Menu::invers(int ix) {
Common::String s;
/* debug('invers'); */
if (msg4 == no_choice) return;
g_vm->_screenSurface.putxy(don[msg3][1] << 3, succ(void, lo(msg4)) << 3);
switch (msg3) {
@ -235,7 +239,7 @@ void invers(int ix) {
msg4 = no_choice;
}
void util(int x, int y) {
void Menu::util(int x, int y) {
int ymx, dxcar, xmn, xmx, ix;
/* debug('util'); */
@ -258,11 +262,14 @@ void util(int x, int y) {
}
}
void menu_down(int ii) {
/**
* Draw a menu
*/
void Menu::menuDown(int ii) {
int cx, xcc;
int xco, nb_lig;
/* debug('menu_down'); */
/* debug('menuDown'); */
// Make a copy of the current screen surface for later restore
g_vm->_backgroundSurface.copyFrom(g_vm->_screenSurface);
@ -331,8 +338,11 @@ void menu_down(int ii) {
show_mouse();
}
void menu_up(int xx) {
/* debug('menu_up'); */
/**
* Menu is being removed, so restore the previous background area.
*/
void Menu::menuUp(int xx) {
/* debug('menuUp'); */
if (test0) {
charecr(10, succ(byte, don[xx][2]) << 1);
@ -351,14 +361,20 @@ void menu_up(int xx) {
}
}
void erase_menu() {
/* debug('erase_menu'); */
/**
* Erase the menu
*/
void Menu::eraseMenu() {
/* debug('eraseMenu'); */
active_menu = false;
g_vm->setMouseClick(false);
menu_up(msg3);
menuUp(msg3);
}
void mdn() {
/**
* Handle updates to the menu
*/
void Menu::mdn() {
//int x, y, c, a, ix;
int x, y, ix;
bool tes;
@ -389,28 +405,28 @@ void mdn() {
else ix = fichier;
if ((ix != msg3) || (! test0))
if (!((ix == fichier) && ((msg3 == sauve) || (msg3 == charge)))) {
menu_up(msg3);
menu_down(ix);
menuUp(msg3);
menuDown(ix);
msg3 = ix;
msg4 = no_choice;
}
} else { /* Not in the MenuTitle line */
if ((y > 11) && (test0)) util(x, y);
}
} else /* There was a click */
} else { /* There was a click */
if ((msg3 == fichier) && (msg4 != no_choice)) {
// Another menu to be displayed
g_vm->setMouseClick(false);
menu_up(msg3);
menuUp(msg3);
if (lo(msg4) == 1) msg3 = 7;
else msg3 = 8;
menu_down(msg3);
menuDown(msg3);
g_vm->setMouseClick(false);
} else {
// A menu was clicked on
choisi = (test0) && (msg4 != no_choice);
menu_up(msg3);
menuUp(msg3);
msg[4] = msg4;
msg[3] = msg3;
msg3 = no_choice;
@ -418,6 +434,7 @@ void mdn() {
g_vm->setMouseClick(false);
}
}
}
} // End of namespace Mortevielle

View File

@ -32,18 +32,21 @@
namespace Mortevielle {
/* NIVEAU 14*/
extern void menut(int no, Common::String nom);
extern void menu_disable(int no);
extern void menu_enable(int no);
extern void menu_aff();
extern void draw_menu();
extern void invers(int ix);
extern void util(int x, int y);
extern void menu_down(int ii);
extern void menu_up(int xx);
extern void erase_menu();
extern void mdn();
class Menu {
private:
void util(int x, int y);
void invers(int ix);
void menuDown(int ii);
public:
void menut(int no, Common::String nom);
void disableMenuItem(int no);
void enableMenuItem(int no);
void menu_aff();
void drawMenu();
void menuUp(int xx);
void eraseMenu();
void mdn();
};
} // End of namespace Mortevielle
#endif

View File

@ -324,8 +324,8 @@ void modobj(int m) {
deline(m - 501 + c_st41, str_, tay);
strp = delig;
}
menut(invt[8], strp);
menu_disable(invt[8]);
g_vm->_menu.menut(invt[8], strp);
g_vm->_menu.disableMenuItem(invt[8]);
}
void modobj2(int m, bool t1, bool t2) {
@ -341,8 +341,8 @@ void modobj2(int m, bool t1, bool t2) {
deline(m - 501 + c_st41, str_, tay);
strp = delig;
}
menut(invt[8], strp);
menu_disable(invt[8]);
g_vm->_menu.menut(invt[8], strp);
g_vm->_menu.disableMenuItem(invt[8]);
}
@ -445,47 +445,48 @@ void affper(int per) {
int cx;
/* debug('affper'); */
for (cx = 1; cx <= 8; cx ++) menu_disable(disc[cx]);
for (cx = 1; cx <= 8; cx ++)
g_vm->_menu.disableMenuItem(disc[cx]);
clsf10();
if ((per & 128) == 128) {
g_vm->_screenSurface.putxy(560, 24);
g_vm->_screenSurface.writeg("LEO", 4);
menu_enable(disc[1]);
g_vm->_menu.enableMenuItem(disc[1]);
}
if ((per & 64) == 64) {
g_vm->_screenSurface.putxy(560, 32);
g_vm->_screenSurface.writeg("PAT", 4);
menu_enable(disc[2]);
g_vm->_menu.enableMenuItem(disc[2]);
}
if ((per & 32) == 32) {
g_vm->_screenSurface.putxy(560, 40);
g_vm->_screenSurface.writeg("GUY", 4);
menu_enable(disc[3]);
g_vm->_menu.enableMenuItem(disc[3]);
}
if ((per & 16) == 16) {
g_vm->_screenSurface.putxy(560, 48);
g_vm->_screenSurface.writeg("EVA", 4);
menu_enable(disc[4]);
g_vm->_menu.enableMenuItem(disc[4]);
}
if ((per & 8) == 8) {
g_vm->_screenSurface.putxy(560, 56);
g_vm->_screenSurface.writeg("BOB", 4);
menu_enable(disc[5]);
g_vm->_menu.enableMenuItem(disc[5]);
}
if ((per & 4) == 4) {
g_vm->_screenSurface.putxy(560, 64);
g_vm->_screenSurface.writeg("LUC", 4);
menu_enable(disc[6]);
g_vm->_menu.enableMenuItem(disc[6]);
}
if ((per & 2) == 2) {
g_vm->_screenSurface.putxy(560, 72);
g_vm->_screenSurface.writeg("IDA", 4);
menu_enable(disc[7]);
g_vm->_menu.enableMenuItem(disc[7]);
}
if ((per & 1) == 1) {
g_vm->_screenSurface.putxy(560, 80);
g_vm->_screenSurface.writeg("MAX", 4);
menu_enable(disc[8]);
g_vm->_menu.enableMenuItem(disc[8]);
}
ipers = per;
}
@ -526,7 +527,7 @@ void cpl1(int &p) {
if ((h > 17) && (h < 22)) p = 35;
if ((h > 21) && (h < 24)) p = 50;
if ((h >= 0) && (h < 8)) p = 70;
mdn();
g_vm->_menu.mdn();
}
void cpl2(int &p) {
@ -578,7 +579,7 @@ void cpl6(int &p) {
void person() {
/* debug('person'); */
for (int cf = 1; cf <= 8; cf ++)
menu_disable(disc[cf]);
g_vm->_menu.disableMenuItem(disc[cf]);
clsf10();
g_vm->_screenSurface.putxy(560, 30);

View File

@ -104,7 +104,7 @@ void tinke() {
nh = readclock();
if ((nh - mh) > t) {
am = active_menu;
erase_menu();
g_vm->_menu.eraseMenu();
jh = jh + ((nh - mh) / t);
mh = nh;
switch (li) {
@ -165,7 +165,8 @@ void tinke() {
}
}
}
if (am) draw_menu();
if (am)
g_vm->_menu.drawMenu();
}
}
hfb = readclock();
@ -233,11 +234,12 @@ void tmlieu(int mli) {
deline(cx + c_tmlieu, st, tail);
nomp = delig;
while (nomp.size() < 20) nomp = nomp + ' ';
menut(depl[i], nomp);
g_vm->_menu.menut(depl[i], nomp);
i = i + 1;
}
nomp = "* ";
for (cx = 7; cx >= i; cx --) menut(depl[cx], nomp);
for (cx = 7; cx >= i; cx --)
g_vm->_menu.menut(depl[cx], nomp);
}
@ -271,20 +273,11 @@ void mfouen()
int cx;
tmlieu(s.mlieu);
for (cx = 1; cx <= 11; cx ++) menu_enable(men[cx]);
/* menu_enable( scacher);
menu_enable(menup, attacher);
menu_enable(menup, defoncer);
menu_enable(menup, dormir);
menu_enable(menup, entrer);
menu_enable(menup, fermer);
menu_enable(menup, frapper);
menu_enable(menup, manger);
menu_enable(menup, mettre);
menu_enable(menup, ouvrir);
menu_enable(menup, sortir); */
menut(sonder, g_vm->getString(S_PROBE));
menut(soulever, g_vm->getString(S_RAISE));
for (cx = 1; cx <= 11; cx ++)
g_vm->_menu.enableMenuItem(men[cx]);
g_vm->_menu.menut(sonder, g_vm->getString(S_PROBE));
g_vm->_menu.menut(soulever, g_vm->getString(S_RAISE));
}
void atf3f8(int &key) {
@ -382,13 +375,13 @@ void modinv() {
r = (ord(s.sjer[cx]) + 400);
deline(r - 501 + c_st41, nom, tay);
nomp = delig;
menut(invt[cy], nomp);
menu_enable(invt[cx]);
g_vm->_menu.menut(invt[cy], nomp);
g_vm->_menu.enableMenuItem(invt[cx]);
}
if (cy < 6)
for (cx = cy + 1; cx <= 6; cx ++) {
menut(invt[cx], " ");
menu_disable(invt[cx]);
g_vm->_menu.menut(invt[cx], " ");
g_vm->_menu.disableMenuItem(invt[cx]);
}
}
@ -425,16 +418,16 @@ void mfoudi() {
int cx;
for (cx = 1; cx <= 7; cx ++)
menu_disable(depl[cx]);
g_vm->_menu.disableMenuItem(depl[cx]);
for (cx = 1; cx <= 11; cx ++)
menu_disable(men[cx]);
g_vm->_menu.disableMenuItem(men[cx]);
menut(sonder, g_vm->getString(S_SUITE));
menut(soulever, g_vm->getString(S_STOP));
g_vm->_menu.menut(sonder, g_vm->getString(S_SUITE));
g_vm->_menu.menut(soulever, g_vm->getString(S_STOP));
}
void mennor() {
menu_up(msg[3]);
g_vm->_menu.menuUp(msg[3]);
}
void premtet() {
@ -553,7 +546,8 @@ void quelquun()
{
int haz, cx;
if (imen) erase_menu();
if (imen)
g_vm->_menu.eraseMenu();
finfouil();
crep = 997;
L1:
@ -591,7 +585,8 @@ L1:
affrep();
}
}
if (imen) draw_menu();
if (imen)
g_vm->_menu.drawMenu();
}
void tsuiv() {

View File

@ -553,7 +553,7 @@ void MortevielleEngine::handleAction() {
oo = false;
ctrm = 0;
if (! iesc) {
draw_menu();
g_vm->_menu.drawMenu();
imen = true;
temps = 0;
key = 0;
@ -562,7 +562,7 @@ void MortevielleEngine::handleAction() {
_inMainGameLoop = true;
do {
mdn();
g_vm->_menu.mdn();
tinke();
mov_mouse(funct, inkey);
CHECK_QUIT;
@ -570,7 +570,7 @@ void MortevielleEngine::handleAction() {
} while (!((choisi) || (temps > lim) || (funct) || (anyone)));
_inMainGameLoop = false;
erase_menu();
g_vm->_menu.eraseMenu();
imen = false;
if ((inkey == '\1') || (inkey == '\3') || (inkey == '\5') || (inkey == '\7') || (inkey == '\11')) {
change_gd((uint)pred(int, ord(inkey)) >> 1);

View File

@ -33,6 +33,7 @@
#include "common/error.h"
#include "graphics/surface.h"
#include "mortevielle/graphics.h"
#include "mortevielle/menu.h"
#include "mortevielle/saveload.h"
#include "mortevielle/sound.h"
@ -100,6 +101,7 @@ public:
Common::RandomSource _randomSource;
SoundManager _soundManager;
SavegameManager _savegameManager;
Menu _menu;
bool _quitGame; // Quit game flag. Originally called 'arret'
bool _endGame; // End game flag. Originally called 'solu'

View File

@ -114,7 +114,8 @@ void init_menu() {
disc[i] = 0x500 + i;
if (i < 8) depl[i] = 0x200 + i;
invt[i] = 0x100 + i;
if (i > 6) menu_disable(invt[i]);
if (i > 6)
g_vm->_menu.disableMenuItem(invt[i]);
}
msg3 = no_choice;
msg4 = no_choice;

View File

@ -54,7 +54,7 @@ void change_gd(int ngd) {
maff = 68;
afdes(0);
repon(2, crep);
menu_aff();
g_vm->_menu.menu_aff();
}
/**

View File

@ -278,7 +278,7 @@ char get_ch() {
*/
void s_sauv(int Gd, int y, int dy) {
// Note: May no longer be necessary, since the backgorund restore code
// is being handled slightly differently now in the menu_up() method
// is being handled slightly differently now in the menuUp() method
}
void palette(int v1) {