Permalink
Browse files

MUTATIONOFJB: Implement scroll buttons.

  • Loading branch information...
MiroslavR authored and LubomirR committed Jul 8, 2018
1 parent de60218 commit e650eb74101e1bb7385976b06372b6b5a53d8ffa
Showing with 21 additions and 3 deletions.
  1. +4 −0 engines/mutationofjb/gui.cpp
  2. +13 −1 engines/mutationofjb/inventory.cpp
  3. +4 −2 engines/mutationofjb/inventory.h
@@ -251,6 +251,10 @@ void Gui::onButtonClicked(ButtonWidget *button) {
if (buttonId <= BUTTON_PICKUP) {
const ActionInfo::Action actions[] = {ActionInfo::Walk, ActionInfo::Talk, ActionInfo::Look, ActionInfo::Use, ActionInfo::PickUp};
_game.setCurrentAction(actions[buttonId]);
} else if (buttonId == BUTTON_SCROLL_LEFT) {
_game.getGameData().getInventory().scrollLeft();
} else if (buttonId == BUTTON_SCROLL_RIGHT) {
_game.getGameData().getInventory().scrollRight();
}
}

@@ -81,6 +81,18 @@ void Inventory::renameItem(const Common::String &oldName, const Common::String &
}
}

void Inventory::scrollLeft() {
if (_items.size() > VISIBLE_ITEMS) {
rotateItemsRight(1);
}
}

void Inventory::scrollRight() {
if (_items.size() > VISIBLE_ITEMS) {
rotateItemsLeft(1);
}
}

void Inventory::rotateItemsRight(uint n) {
if (_items.size() < 2) {
return;
@@ -121,7 +133,7 @@ void Inventory::reverseItems(uint from, uint to) {

const uint size = to - from + 1;
for (uint i = 0; i < size / 2; ++i) {
SWAP(_items[i], _items[size - i - 1]);
SWAP(_items[from + i], _items[to - i]);
}
}

@@ -52,12 +52,14 @@ class Inventory {
void removeAllItems();
void renameItem(const Common::String &oldName, const Common::String &newName);

void rotateItemsRight(uint n);
void rotateItemsLeft(uint n);
void scrollLeft();
void scrollRight();

void setObserver(InventoryObserver *observer);

private:
void rotateItemsRight(uint n);
void rotateItemsLeft(uint n);
void reverseItems(uint from, uint to);

Items _items;

0 comments on commit e650eb7

Please sign in to comment.