svn-id: r13457
This commit is contained in:
Torbjörn Andersson 2004-04-04 15:16:05 +00:00
parent 55bbd875db
commit 6d460d2e10
2 changed files with 94 additions and 122 deletions

View File

@ -30,12 +30,7 @@ namespace Sword2 {
int32 Logic::fnAddMenuObject(int32 *params) { int32 Logic::fnAddMenuObject(int32 *params) {
// params: 0 pointer to a MenuObject structure to copy down // params: 0 pointer to a MenuObject structure to copy down
assert(_vm->_totalTemp < TOTAL_engine_pockets); _vm->addMenuObject((MenuObject *) _vm->_memory->intToPtr(params[0]));
// copy the structure to our in-the-engine list
memcpy(&_vm->_tempList[_vm->_totalTemp], _vm->_memory->intToPtr(params[0]), sizeof(MenuObject));
_vm->_totalTemp++;
return IR_CONT; return IR_CONT;
} }
@ -59,160 +54,136 @@ int32 Logic::fnRefreshInventory(int32 *params) {
return IR_CONT; return IR_CONT;
} }
void Sword2Engine::addMenuObject(MenuObject *obj) {
assert(_totalTemp < TOTAL_engine_pockets);
memcpy(&_tempList[_totalTemp], obj, sizeof(MenuObject));
_totalTemp++;
}
/**
* Create and start the inventory (bottom) menu
*/
void Sword2Engine::buildMenu(void) { void Sword2Engine::buildMenu(void) {
// create and start the inventory menu - NOW AT THE BOTTOM OF THE uint32 i, j;
// SCREEN!
uint32 null_pc = 0; // Clear the temporary inventory list, since we are going to build a
uint32 j, k; // new one from scratch.
bool icon_coloured;
uint8 *icon; for (i = 0; i < TOTAL_engine_pockets; i++)
uint8 *head; _tempList[i].icon_resource = 0;
uint32 res = 0;
// reset temp list which will be totally rebuilt
_totalTemp = 0; _totalTemp = 0;
debug(5, "build top menu %d", _totalMasters); // Run the 'build_menu' script in the 'menu_master' object. This will
// register all carried menu objects.
// clear the temp list before building a new temp list in-case list uint32 null_pc = 0;
// gets smaller. check each master char *menuScript = (char *) _resman->openResource(MENU_MASTER_OBJECT);
_logic->runScript(menuScript, menuScript, &null_pc);
for (j = 0; j < TOTAL_engine_pockets; j++)
_tempList[j].icon_resource = 0;
// Call menu builder script which will register all carried menu
// objects. Run the 'build_menu' script in the 'menu_master' object
head = _resman->openResource(MENU_MASTER_OBJECT);
_logic->runScript((char *) head, (char *) head, &null_pc);
_resman->closeResource(MENU_MASTER_OBJECT); _resman->closeResource(MENU_MASTER_OBJECT);
// Create a new master list based on the old master inventory list and
// the new temporary inventory list. The purpose of all this is, as
// far as I can tell, that the new list is ordered in the same way as
// the old list, with new objects added to the end of it.
// Compare new with old. Anything in master thats not in new gets // Compare new with old. Anything in master thats not in new gets
// removed from master - if found in new too, remove from temp // removed from master - if found in new too, remove from temp
if (_totalMasters) { for (i = 0; i < _totalMasters; i++) {
// check each master bool found_in_temp = false;
for (j = 0; j < _totalMasters; j++) { for (j = 0; j < TOTAL_engine_pockets; j++) {
for (k = 0; k < TOTAL_engine_pockets; k++) { if (_masterMenuList[i].icon_resource == _tempList[j].icon_resource) {
res = 0; // We alread know about this object, so kill it
// if master is in temp // in the temporary list.
if (_masterMenuList[j].icon_resource == _tempList[k].icon_resource) { _tempList[j].icon_resource = 0;
// kill it in the temp found_in_temp = true;
_tempList[k].icon_resource = 0; break;
res = 1;
break;
}
}
if (!res) {
// otherwise not in temp so kill in main
_masterMenuList[j].icon_resource = 0;
debug(5, "Killed menu %d", j);
} }
} }
if (!found_in_temp) {
// The object is in the master list, but not in the
// temporary list. The player must have lost the object
// since the last time we checked, so kill it in the
// master list.
_masterMenuList[i].icon_resource = 0;
}
} }
// merge master downwards // Eliminate blank entries from the master list.
_totalMasters = 0; _totalMasters = 0;
//check each master slot for (i = 0; i < TOTAL_engine_pockets; i++) {
if (_masterMenuList[i].icon_resource) {
for (j = 0; j < TOTAL_engine_pockets; j++) { if (i != _totalMasters) {
// not current end - meaning out over the end so move down memcpy(&_masterMenuList[_totalMasters], &_masterMenuList[i], sizeof(MenuObject));
if (_masterMenuList[j].icon_resource && j != _totalMasters) { _masterMenuList[i].icon_resource = 0;
memcpy(&_masterMenuList[_totalMasters++], &_masterMenuList[j], sizeof(MenuObject)); }
// moved down now so kill here
_masterMenuList[j].icon_resource = 0;
} else if (_masterMenuList[j].icon_resource) {
// skip full slots
_totalMasters++; _totalMasters++;
} }
} }
// add those new to menu still in temp but not yet in master to the // Add the new objects - i.e. the ones still in the temporary list but
// end of the master // not yet in the master list - to the end of the master.
// check each master slot for (i = 0; i < TOTAL_engine_pockets; i++) {
if (_tempList[i].icon_resource) {
for (j = 0; j < TOTAL_engine_pockets; j++) { memcpy(&_masterMenuList[_totalMasters++], &_tempList[i], sizeof(MenuObject));
if (_tempList[j].icon_resource) {
// here's a new temp
memcpy(&_masterMenuList[_totalMasters++], &_tempList[j], sizeof(MenuObject));
} }
} }
// init top menu from master list // Initialise the menu from the master list.
for (j = 0; j < 15; j++) { for (i = 0; i < 15; i++) {
if (_masterMenuList[j].icon_resource) { uint32 res = _masterMenuList[i].icon_resource;
// 'res' is now the resource id of the icon uint8 *icon = NULL;
res = _masterMenuList[j].icon_resource;
if (res) {
bool icon_coloured;
if (_examiningMenuIcon) { if (_examiningMenuIcon) {
// WHEN AN ICON HAS BEEN RIGHT-CLICKED FOR // When examining an object, that object is
// 'EXAMINE' - SELECTION COLOURED, THE REST // coloured. The rest are greyed out.
// GREYED OUT icon_coloured = (res == Logic::_scriptVars[OBJECT_HELD]);
// If this is the icon being examined, make
// it coloured. If not, grey this one out.
if (res == Logic::_scriptVars[OBJECT_HELD])
icon_coloured = true;
else
icon_coloured = false;
} else if (Logic::_scriptVars[COMBINE_BASE]) { } else if (Logic::_scriptVars[COMBINE_BASE]) {
// WHEN ONE MENU OBJECT IS BEING USED WITH // When combining two menu object (i.e. using
// ANOTHER - BOTH TO BE COLOURED, THE REST // one on another), both are coloured. The rest
// GREYED OUT // are greyed out.
icon_coloured = (res == Logic::_scriptVars[OBJECT_HELD] || res == Logic::_scriptVars[COMBINE_BASE]);
// if this if either of the icons being
// combined...
if (res == Logic::_scriptVars[OBJECT_HELD] || res == Logic::_scriptVars[COMBINE_BASE])
icon_coloured = true;
else
icon_coloured = false;
} else { } else {
// NORMAL ICON SELECTION - SELECTION GREYED // If an object is selected but we are not yet
// OUT, THE REST COLOURED // doing anything with it, the selected object
// is greyed out. The rest are coloured.
// If this is the selction, grey it out. If icon_coloured = (res != Logic::_scriptVars[OBJECT_HELD]);
// not, make it coloured.
if (res == Logic::_scriptVars[OBJECT_HELD])
icon_coloured = false;
else
icon_coloured = true;
} }
icon = _resman->openResource(_masterMenuList[j].icon_resource) + sizeof(StandardHeader); icon = _resman->openResource(res) + sizeof(StandardHeader);
// The coloured icon is stored directly after the // The coloured icon is stored directly after the
// greyed out one. // greyed out one.
if (icon_coloured) if (icon_coloured)
icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP); icon += (RDMENU_ICONWIDE * RDMENU_ICONDEEP);
_graphics->setMenuIcon(RDMENU_BOTTOM, j, icon);
_resman->closeResource(res);
} else {
// no icon here
_graphics->setMenuIcon(RDMENU_BOTTOM, j, NULL);
debug(5, " NULL for %d", j);
} }
_graphics->setMenuIcon(RDMENU_BOTTOM, i, icon);
if (res)
_resman->closeResource(res);
} }
_graphics->showMenu(RDMENU_BOTTOM); _graphics->showMenu(RDMENU_BOTTOM);
} }
/**
* Build a fresh system (top) menu.
*/
void Sword2Engine::buildSystemMenu(void) { void Sword2Engine::buildSystemMenu(void) {
// start a fresh top system menu
uint8 *icon;
uint32 icon_list[5] = { uint32 icon_list[5] = {
OPTIONS_ICON, OPTIONS_ICON,
QUIT_ICON, QUIT_ICON,
@ -221,11 +192,11 @@ void Sword2Engine::buildSystemMenu(void) {
RESTART_ICON RESTART_ICON
}; };
// build them all high in full colour - when one is clicked on all the // Build them all high in full colour - when one is clicked on all the
// rest will grey out // rest will grey out.
for (int i = 0; i < ARRAYSIZE(icon_list); i++) { for (int i = 0; i < ARRAYSIZE(icon_list); i++) {
icon = _resman->openResource(icon_list[i]) + sizeof(StandardHeader); uint8 *icon = _resman->openResource(icon_list[i]) + sizeof(StandardHeader);
// The only case when an icon is grayed is when the player // The only case when an icon is grayed is when the player
// is dead. Then SAVE is not available. // is dead. Then SAVE is not available.

View File

@ -127,6 +127,12 @@ private:
void pauseGame(void); void pauseGame(void);
void unpauseGame(void); void unpauseGame(void);
MenuObject _tempList[TOTAL_engine_pockets];
uint32 _totalTemp;
MenuObject _masterMenuList[TOTAL_engine_pockets];
uint32 _totalMasters;
public: public:
Sword2Engine(GameDetector *detector, OSystem *syst); Sword2Engine(GameDetector *detector, OSystem *syst);
~Sword2Engine(); ~Sword2Engine();
@ -196,14 +202,9 @@ public:
// Set by fnPassMega() // Set by fnPassMega()
ObjectMega _engineMega; ObjectMega _engineMega;
MenuObject _tempList[TOTAL_engine_pockets];
uint32 _totalTemp;
MenuObject _masterMenuList[TOTAL_engine_pockets];
uint32 _totalMasters;
int menuClick(int menu_items); int menuClick(int menu_items);
void addMenuObject(MenuObject *obj);
void buildMenu(void); void buildMenu(void);
void buildSystemMenu(void); void buildSystemMenu(void);