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.scrollMin = res->readUint16BE();
data.cdef = res->readUint16BE();
data.refcon = (ControlType)id; id++;
res->readUint32BE();
data.refcon = (ControlAction)res->readUint32BE();//(ControlType)id; id++;
data.type = (ControlType)id; id++;
data.titleLength = res->readByte();
if (data.titleLength) {
data.title = new char[data.titleLength + 1];
res->read(data.title, data.titleLength);
data.title[data.titleLength] = '\0';
}
if (data.refcon != kControlExitBox)
if (data.type != kControlExitBox)
data.border = commandsBorder;
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();
for (; it != _controlData->end(); ++it) {
CommandButton button = *it;
if (button.getData().refcon != kControlExitBox)
if (button.getData().type != kControlExitBox)
button.draw(*_controlsWindow->getSurface());
}
}
@ -816,7 +816,7 @@ void Gui::updateExit(ObjID obj) {
{
ControlData data;
data.titleLength = 0;
data.objref = obj;
data.refcon = (ControlAction)obj; // Objects can be exits (actions)
Common::Point pos = _engine->getObjExitPosition(obj);
pos.x = border.leftOffset;
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);
_draggedObj.id = 0;
}
@ -1102,7 +1101,7 @@ bool Gui::processEvent(Common::Event &event) {
bool Gui::processCommandEvents(WindowClick click, Common::Event &event) {
if (event.type == Common::EVENT_LBUTTONUP) {
if (_engine->needsClickToContinue()) {
_engine->activateCommand(kControlClickToContinue);
_engine->activateCommand(kClickToContinue);
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->refreshReady();
_engine->preparedToRun();
@ -1240,11 +1239,21 @@ void Gui::processCursorTick() {
void Gui::handleSingleClick(Common::Point pos) {
debug("Single Click");
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) {
debug("Double Click");
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 */

View file

@ -111,7 +111,7 @@ struct WindowData {
bool updateScroll;
};
enum ControlType {
enum ControlType { // HACK, should correspond exactly with the types of controls (sliders etc)
kControlExitBox = 0,
kControlExamine = 1,
kControlOpen = 2,
@ -124,6 +124,26 @@ enum ControlType {
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 {
Common::Rect bounds;
uint16 scrollValue;
@ -131,8 +151,8 @@ struct ControlData {
uint16 scrollMax;
uint16 scrollMin;
uint16 cdef;
ObjID objref;
ControlType refcon; // If exits window, then the obj id. Otherwise, the control type
ControlAction refcon;
ControlType type;
uint8 titleLength;
char* title;
uint16 border;
@ -362,7 +382,7 @@ public:
private:
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];
}

View file

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

View file

@ -71,6 +71,27 @@ enum {
kClickToContinueTextID = 0x84,
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 {
kMCVID = 1,
@ -162,7 +183,7 @@ public:
void requestQuit();
void requestUnpause();
void selectControl(ControlAction action);
void activateCommand(ControlType id);
void activateCommand(ControlAction id);
void refreshReady();
void preparedToRun();
void gameChanged();

View file

@ -353,7 +353,8 @@ bool ScriptEngine::runFunc(EngineFrame *frame) {
opbaCRAN(state, frame);
break;
case 0xbb: //fork
opbbFORK(state, frame);
if (opbbFORK(state, frame))
return true;
break;
case 0xbc: //call
if (opbcCALL(state, frame, script))
@ -902,14 +903,20 @@ void ScriptEngine::opbaCRAN(EngineState * state, EngineFrame * frame) {
frame->saves[i].rank = 0;
}
void ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) {
bool ScriptEngine::opbbFORK(EngineState * state, EngineFrame * frame) {
EngineFrame newframe;
newframe.action = (ControlAction)state->pop();
newframe.src = state->pop();
newframe.dest = state->pop();
newframe.x = 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) {
@ -1071,7 +1078,7 @@ void ScriptEngine::opd5DLOG(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) {

View file

@ -31,24 +31,6 @@ namespace MacVenture {
class Container;
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 int16 word;
@ -239,7 +221,7 @@ private:
void opb8CLOW(EngineState *state, EngineFrame *frame); //cancel low priority
void opb9CHI(EngineState *state, EngineFrame *frame); //cancel high priority
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
void opbdFOOB(EngineState *state, EngineFrame *frame); //focus object
void opbeSWOB(EngineState *state, EngineFrame *frame); //swap objects