Skip to content

Commit

Permalink
Merge pull request #294 from eriktorbjorn/tinsel-scrollwheel
Browse files Browse the repository at this point in the history
TINSEL: Add scrollwheel support to save/load and inventory
  • Loading branch information
David Turner committed Dec 3, 2012
2 parents 997386d + 220fb66 commit 2509b64
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 38 deletions.
126 changes: 89 additions & 37 deletions engines/tinsel/dialogs.cpp
Expand Up @@ -4861,50 +4861,101 @@ static void InvDragEnd() {
g_Xchange = g_Ychange = 0; // Probably no need, but does no harm!
}

static void MenuPageDown() {
static bool MenuDown(int lines) {
if (cd.box == loadBox || cd.box == saveBox) {
if (cd.extraBase < MAX_SAVED_FILES-NUM_RGROUP_BOXES) {
FirstFile(cd.extraBase+(NUM_RGROUP_BOXES - 1));
if (cd.extraBase < MAX_SAVED_FILES - NUM_RGROUP_BOXES) {
FirstFile(cd.extraBase + lines);
AddBoxes(true);
cd.selBox = NUM_RGROUP_BOXES - 1;
Select(cd.selBox, true);
return true;
}
} else if (cd.box == hopperBox1) {
if (cd.extraBase < g_numScenes - NUM_RGROUP_BOXES) {
FirstScene(cd.extraBase + (NUM_RGROUP_BOXES - 1));
FirstScene(cd.extraBase + lines);
AddBoxes(true);
if (cd.selBox)
cd.selBox = NUM_RGROUP_BOXES - 1;
Select(cd.selBox, true);
return true;
}
} else if (cd.box == hopperBox2) {
if (cd.extraBase < g_numEntries - NUM_RGROUP_BOXES) {
FirstEntry(cd.extraBase+(NUM_RGROUP_BOXES - 1));
FirstEntry(cd.extraBase + lines);
AddBoxes(true);
if (cd.selBox)
cd.selBox = NUM_RGROUP_BOXES - 1;
Select(cd.selBox, true);
return true;
}
}
return false;
}

static void MenuPageUp() {
static bool MenuUp(int lines) {
if (cd.extraBase > 0) {
if (cd.box == loadBox || cd.box == saveBox)
FirstFile(cd.extraBase-(NUM_RGROUP_BOXES - 1));
FirstFile(cd.extraBase - lines);
else if (cd.box == hopperBox1)
FirstScene(cd.extraBase-(NUM_RGROUP_BOXES - 1));
FirstScene(cd.extraBase - lines);
else if (cd.box == hopperBox2)
FirstEntry(cd.extraBase-(NUM_RGROUP_BOXES - 1));
FirstEntry(cd.extraBase - lines);
else
return;
return false;

AddBoxes(true);
return true;
}
return false;
}

static void MenuRollDown() {
if (MenuDown(1)) {
if (cd.selBox > 0)
cd.selBox--;
Select(cd.selBox, true);
}
}

static void MenuRollUp() {
if (MenuUp(1)) {
if (cd.selBox < NUM_RGROUP_BOXES - 1)
cd.selBox++;
Select(cd.selBox, true);
}
}

static void MenuPageDown() {
if (MenuDown(NUM_RGROUP_BOXES - 1)) {
cd.selBox = NUM_RGROUP_BOXES - 1;
Select(cd.selBox, true);
}
}

static void MenuPageUp() {
if (MenuUp(NUM_RGROUP_BOXES - 1)) {
cd.selBox = 0;
Select(cd.selBox, true);
}
}

static void InventoryDown() {
// This code is a copy of the IB_SLIDE_DOWN case in InvWalkTo
// TODO: So share this duplicate code
if (g_InvD[g_ino].NoofVicons == 1)
if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems)
g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons;
for (int i = 1; i < g_InvD[g_ino].NoofVicons; i++) {
if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems)
g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons;
}
g_ItemsChanged = true;
}

static void InventoryUp() {
// This code is a copy of the I_SLIDE_UP case in InvWalkTo
// TODO: So share this duplicate code
if (g_InvD[g_ino].NoofVicons == 1)
g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons;
for (int i = 1; i < g_InvD[g_ino].NoofVicons; i++)
g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons;
if (g_InvD[g_ino].FirstDisp < 0)
g_InvD[g_ino].FirstDisp = 0;
g_ItemsChanged = true;
}

/**************************************************************************/
/************** Incoming events - further processing **********************/
/**************************************************************************/
Expand Down Expand Up @@ -5402,16 +5453,7 @@ extern void EventToInventory(PLR_EVENT pEvent, const Common::Point &coOrds) {
// Only act if load or save screen
MenuPageDown();
} else {
// This code is a copy of the IB_SLIDE_DOWN case in InvWalkTo
// TODO: So share this duplicate code
if (g_InvD[g_ino].NoofVicons == 1)
if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems)
g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons;
for (int i = 1; i < g_InvD[g_ino].NoofVicons; i++) {
if (g_InvD[g_ino].FirstDisp + g_InvD[g_ino].NoofHicons*g_InvD[g_ino].NoofVicons < g_InvD[g_ino].NoofItems)
g_InvD[g_ino].FirstDisp += g_InvD[g_ino].NoofHicons;
}
g_ItemsChanged = true;
InventoryDown();
}
break;

Expand All @@ -5420,15 +5462,25 @@ extern void EventToInventory(PLR_EVENT pEvent, const Common::Point &coOrds) {
// Only act if load or save screen
MenuPageUp();
} else {
// This code is a copy of the I_SLIDE_UP case in InvWalkTo
// TODO: So share this duplicate code
if (g_InvD[g_ino].NoofVicons == 1)
g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons;
for (int i = 1; i < g_InvD[g_ino].NoofVicons; i++)
g_InvD[g_ino].FirstDisp -= g_InvD[g_ino].NoofHicons;
if (g_InvD[g_ino].FirstDisp < 0)
g_InvD[g_ino].FirstDisp = 0;
g_ItemsChanged = true;
InventoryUp();
}
break;

case PLR_WHEEL_DOWN:
if (g_ino == INV_MENU) {
// Only act if load or save screen
MenuRollDown();
} else {
InventoryDown();
}
break;

case PLR_WHEEL_UP:
if (g_ino == INV_MENU) {
// Only act if load or save screen
MenuRollUp();
} else {
InventoryUp();
}
break;

Expand Down
3 changes: 2 additions & 1 deletion engines/tinsel/events.cpp
Expand Up @@ -389,7 +389,8 @@ void PlayerEvent(PLR_EVENT pEvent, const Common::Point &coOrds) {
"PLR_PROV_WALKTO", "PLR_WALKTO", "PLR_LOOK", "PLR_ACTION", "PLR_ESCAPE",
"PLR_MENU", "PLR_QUIT", "PLR_PGUP", "PLR_PGDN", "PLR_HOME", "PLR_END",
"PLR_DRAG1_START", "PLR_DRAG1_END", "PLR_DRAG2_START", "PLR_DRAG2_END",
"PLR_JUMP", "PLR_NOEVENT"};
"PLR_JUMP", "PLR_NOEVENT", "PLR_SAVE", "PLR_LOAD", "PLR_WHEEL_UP",
"PLR_WHEEL_DOWN"};
debugC(DEBUG_BASIC, kTinselDebugActions, "%s - (%d,%d)",
actionList[pEvent], coOrds.x, coOrds.y);
static uint32 lastRealAction = 0; // FIXME: Avoid non-const global vars
Expand Down
2 changes: 2 additions & 0 deletions engines/tinsel/events.h
Expand Up @@ -65,6 +65,8 @@ enum PLR_EVENT {
PLR_NOEVENT = 16,
PLR_SAVE = 17,
PLR_LOAD = 18,
PLR_WHEEL_UP = 19,
PLR_WHEEL_DOWN = 20,

// Aliases used for DW1 actions
PLR_SLEFT = PLR_WALKTO,
Expand Down
10 changes: 10 additions & 0 deletions engines/tinsel/tinsel.cpp
Expand Up @@ -430,6 +430,14 @@ static void MouseProcess(CORO_PARAM, const void *) {
ProcessButEvent(PLR_DRAG2_END);
break;

case Common::EVENT_WHEELUP:
PlayerEvent(PLR_WHEEL_UP, mousePos);
break;

case Common::EVENT_WHEELDOWN:
PlayerEvent(PLR_WHEEL_DOWN, mousePos);
break;

default:
break;
}
Expand Down Expand Up @@ -1046,6 +1054,8 @@ bool TinselEngine::pollEvent() {
case Common::EVENT_LBUTTONUP:
case Common::EVENT_RBUTTONDOWN:
case Common::EVENT_RBUTTONUP:
case Common::EVENT_WHEELUP:
case Common::EVENT_WHEELDOWN:
// Add button to queue for the mouse process
_mouseButtons.push_back(event.type);
break;
Expand Down

0 comments on commit 2509b64

Please sign in to comment.