XEEN: Implement cmdChooseNumeric script opcode

This commit is contained in:
Paul Gilbert 2015-03-04 08:49:05 -05:00
parent 15d375bc44
commit 652a662315
4 changed files with 113 additions and 4 deletions

View File

@ -201,5 +201,79 @@ int NumericInput::execute(int maxLength, int maxWidth) {
return 0;
}
/*------------------------------------------------------------------------*/
int Choose123::show(XeenEngine *vm, int numOptions) {
assert(numOptions <= 3);
Choose123 *dlg = new Choose123(vm);
int result = dlg->execute(numOptions);
delete dlg;
return result;
}
int Choose123::execute(int numOptions) {
EventsManager &events = *_vm->_events;
Interface &intf = *_vm->_interface;
Screen &screen = *_vm->_screen;
Town &town = *_vm->_town;
Mode oldMode = _vm->_mode;
_vm->_mode = MODE_DIALOG_123;
loadButtons(numOptions);
_iconSprites.draw(screen, 7, Common::Point(232, 74));
drawButtons(&screen);
screen._windows[34].update();
int result = -1;
while (result == -1) {
do {
events.updateGameCounter();
int delay;
if (town.isActive()) {
town.drawTownAnim(true);
delay = 3;
} else {
intf.draw3d(true);
delay = 1;
}
events.wait(delay, true);
if (_vm->shouldQuit())
return 0;
} while (!_buttonValue);
switch (_buttonValue) {
case Common::KEYCODE_ESCAPE:
result = 0;
break;
case Common::KEYCODE_1:
case Common::KEYCODE_2:
case Common::KEYCODE_3: {
int v = _buttonValue - Common::KEYCODE_1 + 1;
if (v <= numOptions)
result = v;
break;
}
default:
break;
}
}
_vm->_mode = oldMode;
intf.mainIconsPrint();
}
void Choose123::loadButtons(int numOptions) {
_iconSprites.load("choose.icn");
if (numOptions >= 1)
addButton(Common::Rect(235, 75, 259, 95), Common::KEYCODE_1, &_iconSprites);
if (numOptions >= 2)
addButton(Common::Rect(260, 75, 284, 95), Common::KEYCODE_2, &_iconSprites);
if (numOptions >= 3)
addButton(Common::Rect(286, 75, 311, 95), Common::KEYCODE_3, &_iconSprites);
}
} // End of namespace Xeen

View File

@ -64,6 +64,20 @@ public:
static int show(XeenEngine *vm, int window, int maxLength, int maxWidth);
};
class Choose123 : public ButtonContainer {
private:
XeenEngine *_vm;
SpriteResource _iconSprites;
Choose123(XeenEngine *vm) : ButtonContainer(), _vm(vm) {}
int execute(int numOptions);
void loadButtons(int numOptions);
public:
static int show(XeenEngine *vm, int numOptions);
};
} // End of namespace Xeen
#endif /* XEEN_DIALOGS_STRING_INPUT_H */

View File

@ -954,7 +954,20 @@ void Scripts::cmdConfirmWord(Common::Array<byte> &params) {
cmdNoAction(params);
}
void Scripts::cmdDamage(Common::Array<byte> &params) { error("TODO"); }
void Scripts::cmdDamage(Common::Array<byte> &params) {
Combat &combat = *_vm->_combat;
Interface &intf = *_vm->_interface;
if (!_redrawDone) {
intf.draw3d(true);
_redrawDone = true;
}
int damage = (params[1] << 8) | params[0];
combat.giveCharDamage(damage, (DamageType)params[2], _charIndex);
cmdNoAction(params);
}
/**
* Jump if a random number matches a given value
@ -1164,7 +1177,6 @@ void Scripts::cmdSelRndChar(Common::Array<byte> &params) {
void Scripts::cmdGiveEnchanted(Common::Array<byte> &params) {
Party &party = *_vm->_party;
bool isDarkCc = _vm->_files->_isDarkCc;
if (params[0] >= 35) {
if (params[0] < 49) {
@ -1257,12 +1269,20 @@ void Scripts::cmdCheckProtection(Common::Array<byte> &params) {
cmdExit(params);
}
/**
* Given a number of options, and a list of line numbers associated with
* those options, jumps to whichever line for the option the user selects
*/
void Scripts::cmdChooseNumeric(Common::Array<byte> &params) {
error("TODO");
int choice = Choose123::show(_vm, params[0]);
if (choice) {
_lineNum = params[choice] - 1;
}
cmdNoAction(params);
}
void Scripts::cmdDisplayBottomTwoLines(Common::Array<byte> &params) {
Interface &intf = *_vm->_interface;
Map &map = *_vm->_map;
Window &w = _vm->_screen->_windows[12];

View File

@ -88,6 +88,7 @@ enum Mode {
MODE_9 = 9,
MODE_CHARACTER_INFO = 10,
MODE_12 = 12,
MODE_DIALOG_123 = 13,
MODE_17 = 17,
MODE_86 = 86
};