MACVENTURE: Add double click

This commit is contained in:
Borja Lorente 2016-07-05 13:06:51 +02:00
parent 46a85f02d6
commit b460964284
6 changed files with 86 additions and 49 deletions

View file

@ -521,15 +521,15 @@ bool Gui::loadControls() {
data.scrollMax = res->readUint16BE(); data.scrollMax = res->readUint16BE();
data.scrollMin = res->readUint16BE(); data.scrollMin = res->readUint16BE();
data.cdef = res->readUint16BE(); data.cdef = res->readUint16BE();
data.refcon = (ControlType)id; id++; data.refcon = (ControlAction)res->readUint32BE();//(ControlType)id; id++;
res->readUint32BE(); data.type = (ControlType)id; id++;
data.titleLength = res->readByte(); data.titleLength = res->readByte();
if (data.titleLength) { if (data.titleLength) {
data.title = new char[data.titleLength + 1]; data.title = new char[data.titleLength + 1];
res->read(data.title, data.titleLength); res->read(data.title, data.titleLength);
data.title[data.titleLength] = '\0'; data.title[data.titleLength] = '\0';
} }
if (data.refcon != kControlExitBox) if (data.type != kControlExitBox)
data.border = commandsBorder; data.border = commandsBorder;
Common::Rect bounds(left, top, right, bottom); // For some reason, if I remove this it segfaults Common::Rect bounds(left, top, right, bottom); // For some reason, if I remove this it segfaults
@ -570,7 +570,7 @@ void Gui::drawCommandsWindow() {
Common::Array<CommandButton>::const_iterator it = _controlData->begin(); Common::Array<CommandButton>::const_iterator it = _controlData->begin();
for (; it != _controlData->end(); ++it) { for (; it != _controlData->end(); ++it) {
CommandButton button = *it; CommandButton button = *it;
if (button.getData().refcon != kControlExitBox) if (button.getData().type != kControlExitBox)
button.draw(*_controlsWindow->getSurface()); button.draw(*_controlsWindow->getSurface());
} }
} }
@ -816,7 +816,7 @@ void Gui::updateExit(ObjID obj) {
{ {
ControlData data; ControlData data;
data.titleLength = 0; data.titleLength = 0;
data.objref = obj; data.refcon = (ControlAction)obj; // Objects can be exits (actions)
Common::Point pos = _engine->getObjExitPosition(obj); Common::Point pos = _engine->getObjExitPosition(obj);
pos.x = border.leftOffset; pos.x = border.leftOffset;
pos.y = border.topOffset; pos.y = border.topOffset;
@ -935,7 +935,6 @@ void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleC
} }
_engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick); _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick);
_draggedObj.id = 0; _draggedObj.id = 0;
} }
@ -1102,7 +1101,7 @@ bool Gui::processEvent(Common::Event &event) {
bool Gui::processCommandEvents(WindowClick click, Common::Event &event) { bool Gui::processCommandEvents(WindowClick click, Common::Event &event) {
if (event.type == Common::EVENT_LBUTTONUP) { if (event.type == Common::EVENT_LBUTTONUP) {
if (_engine->needsClickToContinue()) { if (_engine->needsClickToContinue()) {
_engine->activateCommand(kControlClickToContinue); _engine->activateCommand(kClickToContinue);
return true; return true;
} }
@ -1126,7 +1125,7 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) {
} }
_engine->selectControl(_engine->referenceToAction(data.getData().refcon)); _engine->selectControl(data.getData().refcon);
_engine->activateCommand(data.getData().refcon); _engine->activateCommand(data.getData().refcon);
_engine->refreshReady(); _engine->refreshReady();
_engine->preparedToRun(); _engine->preparedToRun();
@ -1240,11 +1239,21 @@ void Gui::processCursorTick() {
void Gui::handleSingleClick(Common::Point pos) { void Gui::handleSingleClick(Common::Point pos) {
debug("Single Click"); debug("Single Click");
handleDragRelease(_draggedObj.pos, false, false); handleDragRelease(_draggedObj.pos, false, false);
// HACK For test, please delete me
//WindowReference destinationWindow = findWindowAtPoint(pos);
//_engine->handleObjectSelect(_draggedObj.id, destinationWindow, false, false);
//_draggedObj.id = 0;
} }
void Gui::handleDoubleClick(Common::Point pos) { void Gui::handleDoubleClick(Common::Point pos) {
debug("Double Click"); debug("Double Click");
handleDragRelease(_draggedObj.pos, false, true); handleDragRelease(_draggedObj.pos, false, true);
// HACK For test, please delete me
//WindowReference destinationWindow = findWindowAtPoint(pos);
//_engine->handleObjectSelect(_draggedObj.id, destinationWindow, false, true);
//_draggedObj.id = 0;
} }
/* Ugly switches */ /* Ugly switches */

View file

@ -111,7 +111,7 @@ struct WindowData {
bool updateScroll; bool updateScroll;
}; };
enum ControlType { enum ControlType { // HACK, should correspond exactly with the types of controls (sliders etc)
kControlExitBox = 0, kControlExitBox = 0,
kControlExamine = 1, kControlExamine = 1,
kControlOpen = 2, kControlOpen = 2,
@ -124,6 +124,26 @@ enum ControlType {
kControlClickToContinue = 9 kControlClickToContinue = 9
}; };
enum ControlAction { // HACK, figure out a way to put it in engine
kNoCommand = 0,
kStartOrResume = 1,
kClose = 2,
kTick = 3,
kActivateObject = 4,
kMoveObject = 5,
kConsume = 6,
kExamine = 7,
kGo = 8,
kHit = 9,
kOpen = 10,
kOperate = 11,
kSpeak = 12,
kBabble = 13,
kTargetName = 14,
kDebugObject = 15,
kClickToContinue = 16
};
struct ControlData { struct ControlData {
Common::Rect bounds; Common::Rect bounds;
uint16 scrollValue; uint16 scrollValue;
@ -131,8 +151,8 @@ struct ControlData {
uint16 scrollMax; uint16 scrollMax;
uint16 scrollMin; uint16 scrollMin;
uint16 cdef; uint16 cdef;
ObjID objref; ControlAction refcon;
ControlType refcon; // If exits window, then the obj id. Otherwise, the control type ControlType type;
uint8 titleLength; uint8 titleLength;
char* title; char* title;
uint16 border; uint16 border;
@ -362,7 +382,7 @@ public:
private: private:
void changeState(CursorInput input) { void changeState(CursorInput input) {
debug("Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]); debug(4, "Change cursor state: [%d] -> [%d]", _state, _transitionTable[_state][input]);
_state = _transitionTable[_state][input]; _state = _transitionTable[_state][input];
} }

View file

@ -177,19 +177,18 @@ void MacVentureEngine::selectControl(ControlAction id) {
_selectedControl = id; _selectedControl = id;
} }
void MacVentureEngine::activateCommand(ControlType id) { void MacVentureEngine::activateCommand(ControlAction id) {
if (id == kControlClickToContinue) { if (id == kClickToContinue) {
_clickToContinue = false; _clickToContinue = false;
_paused = true; _paused = true;
return; return;
} }
ControlAction action = referenceToAction(id); if (id != _activeControl) {
if (action != _activeControl) {
if (_activeControl) if (_activeControl)
_activeControl = kNoCommand; _activeControl = kNoCommand;
_activeControl = action; _activeControl = id;
} }
debug(2, "Activating Command %x... Command %x is active", action, _activeControl); debug(2, "Activating Command %x... Command %x is active", id, _activeControl);
refreshReady(); refreshReady();
} }
@ -267,7 +266,7 @@ bool MacVentureEngine::printTexts() {
gameChanged(); gameChanged();
break; break;
case kTextNewLine: case kTextNewLine:
_gui->printText(Common::String("\n")); _gui->printText(Common::String(""));
gameChanged(); gameChanged();
break; break;
case kTextPlain: case kTextPlain:
@ -314,10 +313,9 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool
if (i >= 0) if (i >= 0)
unselectAll(); unselectAll();
selectObject(objID); selectObject(objID);
if (!_cmdReady) _destObject = objID;
{ _deltaPoint = Common::Point(0, 0);
selectObject(objID); if (!_cmdReady) {
selectControl(kActivateObject); selectControl(kActivateObject);
_activeControl = kActivateObject; _activeControl = kActivateObject;
_cmdReady = true; _cmdReady = true;
@ -340,7 +338,7 @@ void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID
_destObject = newParent; _destObject = newParent;
updateDelta(delta); updateDelta(delta);
selectControl(kOperate); selectControl(kOperate);
activateCommand(kControlOperate); activateCommand(kOperate);
refreshReady(); refreshReady();
preparedToRun(); preparedToRun();
} }

View file

@ -71,6 +71,27 @@ enum {
kClickToContinueTextID = 0x84, kClickToContinueTextID = 0x84,
kStartGameFilenameID = 0x85 kStartGameFilenameID = 0x85
}; };
/*
enum ControlAction {
kNoCommand = 0,
kStartOrResume = 1,
kClose = 2,
kTick = 3,
kActivateObject = 4,
kMoveObject = 5,
kConsume = 6,
kExamine = 7,
kGo = 8,
kHit = 9,
kOpen = 10,
kOperate = 11,
kSpeak = 12,
kBabble = 13,
kTargetName = 14,
kDebugObject = 15,
kClickToContinue = 16
};
*/
enum FilePathID { enum FilePathID {
kMCVID = 1, kMCVID = 1,
@ -162,7 +183,7 @@ public:
void requestQuit(); void requestQuit();
void requestUnpause(); void requestUnpause();
void selectControl(ControlAction action); void selectControl(ControlAction action);
void activateCommand(ControlType id); void activateCommand(ControlAction id);
void refreshReady(); void refreshReady();
void preparedToRun(); void preparedToRun();
void gameChanged(); void gameChanged();

View file

@ -353,7 +353,8 @@ bool ScriptEngine::runFunc(EngineFrame *frame) {
opbaCRAN(state, frame); opbaCRAN(state, frame);
break; break;
case 0xbb: //fork case 0xbb: //fork
opbbFORK(state, frame); if (opbbFORK(state, frame))
return true;
break; break;
case 0xbc: //call case 0xbc: //call
if (opbcCALL(state, frame, script)) if (opbcCALL(state, frame, script))
@ -902,14 +903,20 @@ void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) {
frame->saves[i].rank = 0; frame->saves[i].rank = 0;
} }
void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) { bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) {
EngineFrame newframe; EngineFrame newframe;
newframe.action = (ControlAction)state->pop(); newframe.action = (ControlAction)state->pop();
newframe.src = state->pop(); newframe.src = state->pop();
newframe.dest = state->pop(); newframe.dest = state->pop();
newframe.x = state->pop(); newframe.x = state->pop();
newframe.y = state->pop(); newframe.y = state->pop();
_frames.push_back(newframe); newframe.haltedInFamily = false;
newframe.haltedInFirst = false;
newframe.haltedInSaves = false;
_frames.push_front(newframe);
if (execFrame(true)) {
return true;
}
} }
bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) { bool ScriptEngine::opbcCALL(EngineState * state, EngineFrame * frame, ScriptAsset &script) {
@ -1071,7 +1078,7 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) {
} }
void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) { void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) {
_engine->activateCommand((ControlType)state->pop()); _engine->activateCommand((ControlAction)state->pop());
} }
void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) { void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) {

View file

@ -31,24 +31,6 @@ namespace MacVenture {
class Container; class Container;
class World; class World;
enum ControlAction {
kNoCommand = 0,
kStartOrResume = 1,
kClose = 2,
kTick = 3,
kActivateObject = 4,
kMoveObject = 5,
kConsume = 6,
kExamine = 7,
kGo = 8,
kHit = 9,
kOpen = 10,
kOperate = 11,
kSpeak = 12,
kBabble = 13,
kTargetName = 14,
kDebugObject = 15
};
typedef uint32 ObjID; typedef uint32 ObjID;
typedef int16 word; typedef int16 word;
@ -239,7 +221,7 @@ private:
void opb8CLOW(EngineState *state, EngineFrame *frame); //cancel low priority void opb8CLOW(EngineState *state, EngineFrame *frame); //cancel low priority
void opb9CHI(EngineState *state, EngineFrame *frame); //cancel high priority void opb9CHI(EngineState *state, EngineFrame *frame); //cancel high priority
void opbaCRAN(EngineState *state, EngineFrame *frame); //cancel priority range void opbaCRAN(EngineState *state, EngineFrame *frame); //cancel priority range
void opbbFORK(EngineState *state, EngineFrame *frame); //fork bool opbbFORK(EngineState *state, EngineFrame *frame); //fork
bool opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script); //call bool opbcCALL(EngineState *state, EngineFrame *frame, ScriptAsset &script); //call
void opbdFOOB(EngineState *state, EngineFrame *frame); //focus object void opbdFOOB(EngineState *state, EngineFrame *frame); //focus object
void opbeSWOB(EngineState *state, EngineFrame *frame); //swap objects void opbeSWOB(EngineState *state, EngineFrame *frame); //swap objects