aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/illusions/duckman/menusystem_duckman.cpp77
-rw-r--r--engines/illusions/duckman/menusystem_duckman.h14
-rw-r--r--engines/illusions/menusystem.cpp39
-rw-r--r--engines/illusions/menusystem.h7
4 files changed, 127 insertions, 10 deletions
diff --git a/engines/illusions/duckman/menusystem_duckman.cpp b/engines/illusions/duckman/menusystem_duckman.cpp
index 8a9e1cce47..554be9aac5 100644
--- a/engines/illusions/duckman/menusystem_duckman.cpp
+++ b/engines/illusions/duckman/menusystem_duckman.cpp
@@ -110,12 +110,26 @@ BaseMenu *DuckmanMenuSystem::createOptionsMenu() {
BaseMenu *menu = new BaseMenu(this, 0x00120003, 12, 17, 11, 27, 1);
menu->addText(" GAME OPTIONS @@@@");
menu->addText("--------------------------------------");
- menu->addMenuItem(new MenuItem("SFX Volume @@{~~~~~~~~~~~~|~~~} @@@", new MenuActionReturnChoice(this, 21)));
- menu->addMenuItem(new MenuItem("Music Volume @@@{~~~~~~~~~~~~|~~~} @@@", new MenuActionReturnChoice(this, 21)));
- menu->addMenuItem(new MenuItem("Speech Volume {~~~~~~~~~~~~|~~~} @@@", new MenuActionReturnChoice(this, 21)));
- menu->addMenuItem(new MenuItem("Text Duration @@@{~~~~~~~~~~~~|~~~} @@@", new MenuActionReturnChoice(this, 21)));
- menu->addMenuItem(new MenuItem("Restore Defaults @@", new MenuActionReturnChoice(this, 21)));
- menu->addMenuItem(new MenuItem("Back @@@", new MenuActionLeaveMenu(this)));
+ MenuActionUpdateSlider *action = new MenuActionUpdateSlider(this, menu);
+ MenuItem *menuItem = new MenuItem("SFX Volume @@{~~~~~~~~~~~~|~~~} @@@", action);
+ action->setMenuItem(menuItem);
+ menu->addMenuItem(menuItem);
+
+ action = new MenuActionUpdateSlider(this, menu);
+ menuItem = new MenuItem("Music Volume @@@{~~~~~~~~~~~~|~~~} @@@", action);
+ action->setMenuItem(menuItem);
+ menu->addMenuItem(menuItem);
+
+ action = new MenuActionUpdateSlider(this, menu);
+ menuItem = new MenuItem("Speech Volume {~~~~~~~~~~~~|~~~} @@@", action);
+ action->setMenuItem(menuItem);
+ menu->addMenuItem(menuItem);
+
+ action = new MenuActionUpdateSlider(this, menu);
+ menuItem = new MenuItem("Text Duration @@@{~~~~~~~~~~~~|~~~} @@@", action);
+ action->setMenuItem(menuItem);
+ menu->addMenuItem(menuItem);
+
return menu;
}
@@ -290,4 +304,55 @@ void MenuActionInventoryAddRemove::execute() {
_menuSystem->leaveMenu();
}
+MenuActionUpdateSlider::MenuActionUpdateSlider(BaseMenuSystem *menuSystem, BaseMenu *menu)
+ : BaseMenuAction(menuSystem), menu(menu) {
+ menuItem = NULL;
+}
+
+void MenuActionUpdateSlider::execute() {
+ assert(menuItem);
+ Common::String text = menuItem->getText();
+ Common::Point point = menuItem->getMouseClickPoint();
+ int offset = 0;
+ _menuSystem->calcMenuItemTextPositionAtPoint(point, offset);
+ int newSliderValue = calcNewSliderValue(text, offset);
+
+ debug(0, "item text: %s, (%d, %d), New slider value: %d", text.c_str(), point.x, point.y, newSliderValue);
+
+ menuItem->setText(text);
+ _menuSystem->redrawMenuText(menu);
+ // TODO update slider here set value callback.
+}
+
+int MenuActionUpdateSlider::calcNewSliderValue(Common::String &text, int newOffset) {
+ int newSliderValue = 0;
+ int start = 0;
+ int end = 0;
+ int currentPosition = 0;
+ for(int i = 0; i < text.size(); i++) {
+ switch (text[i]) {
+ case '{' : start = i; break;
+ case '}' : end = i; break;
+ case '|' : currentPosition = i; break;
+ default: break;
+ }
+ }
+
+ if (newOffset >= start && newOffset <= end) {
+ if (newOffset == start) {
+ newSliderValue = 0;
+ } else if (newOffset == end) {
+ newSliderValue = 15;
+ } else {
+ newSliderValue = newOffset - (start + 1);
+ }
+
+ text.setChar('~', currentPosition);
+ text.setChar('|', start + 1 + newSliderValue);
+
+ return newSliderValue;
+ }
+ return currentPosition - start - 1;
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/duckman/menusystem_duckman.h b/engines/illusions/duckman/menusystem_duckman.h
index 2921277630..22bfefa794 100644
--- a/engines/illusions/duckman/menusystem_duckman.h
+++ b/engines/illusions/duckman/menusystem_duckman.h
@@ -83,6 +83,20 @@ protected:
int _choiceIndex;
};
+class MenuActionUpdateSlider : public BaseMenuAction {
+public:
+ MenuActionUpdateSlider(BaseMenuSystem *menuSystem, BaseMenu *baseMenu);
+ void setMenuItem(MenuItem *newMmenuItem) {
+ menuItem = newMmenuItem;
+ }
+
+ virtual void execute();
+protected:
+ MenuItem *menuItem;
+ BaseMenu *menu;
+ int calcNewSliderValue(Common::String &text, int newOffset);
+};
+
} // End of namespace Illusions
#endif // ILLUSIONS_DUCKMAN_MENUSYSTEM_DUCKMAN_H
diff --git a/engines/illusions/menusystem.cpp b/engines/illusions/menusystem.cpp
index e1aacf78ee..fbb52ee862 100644
--- a/engines/illusions/menusystem.cpp
+++ b/engines/illusions/menusystem.cpp
@@ -44,7 +44,8 @@ MenuItem::~MenuItem() {
delete _action;
}
-void MenuItem::executeAction() {
+void MenuItem::executeAction(const Common::Point &point) {
+ _mouseClickPoint = point;
_action->execute();
}
@@ -371,7 +372,7 @@ void BaseMenuSystem::closeMenu() {
}
void BaseMenuSystem::handleClick(uint menuItemIndex, const Common::Point &mousePos) {
- debug(0, "BaseMenuSystem::handleClick() menuItemIndex: %d", menuItemIndex);
+ debug(0, "BaseMenuSystem::handleClick() menuItemIndex: %d click point: (%d, %d)", menuItemIndex, mousePos.x, mousePos.y);
if (menuItemIndex == 0) {
playSoundEffect14();
@@ -379,7 +380,7 @@ void BaseMenuSystem::handleClick(uint menuItemIndex, const Common::Point &mouseP
}
MenuItem *menuItem = _activeMenu->getMenuItem(menuItemIndex - 1);
- menuItem->executeAction();
+ menuItem->executeAction(mousePos);
}
@@ -544,6 +545,38 @@ void BaseMenuSystem::updateTimeOut(bool resetTimeOut) {
}
+void BaseMenuSystem::redrawMenuText(BaseMenu *menu) {
+ _vm->_screenText->removeText();
+ drawMenuText(menu);
+}
+
+bool BaseMenuSystem::calcMenuItemTextPositionAtPoint(Common::Point pt, int &offset) {
+ uint menuItemIndex;
+ if(!calcMenuItemIndexAtPoint(pt, menuItemIndex)) {
+ return false;
+ }
+
+ WRect rect;
+
+ MenuItem *menuItem = _activeMenu->getMenuItem(menuItemIndex - 1);
+ calcMenuItemRect(menuItemIndex, rect);
+ int x = pt.x - rect._topLeft.x;
+ Common::String text = menuItem->getText();
+ FontResource *font = _vm->_dict->findFont(_activeMenu->_fontId);
+
+ uint curX = 0;
+ for (int i=0; i < text.size(); i++) {
+ int16 w = font->getCharInfo(text[i])->_width;
+ if (x >= curX && x <= curX + w) {
+ offset = i;
+ return true;
+ }
+ curX = curX + w;
+ }
+
+ return false;
+}
+
// MenuTextBuilder
MenuTextBuilder::MenuTextBuilder() : _pos(0) {
diff --git a/engines/illusions/menusystem.h b/engines/illusions/menusystem.h
index 0a7f432e99..cc761167a0 100644
--- a/engines/illusions/menusystem.h
+++ b/engines/illusions/menusystem.h
@@ -45,11 +45,14 @@ class MenuItem {
public:
MenuItem(const Common::String text, BaseMenuAction *action);
~MenuItem();
- void executeAction();
+ void executeAction(const Common::Point &point);
const Common::String& getText() const { return _text; }
+ void setText(const Common::String &text) { _text = text; }
+ const Common::Point& getMouseClickPoint() { return _mouseClickPoint; };
protected:
Common::String _text;
BaseMenuAction *_action;
+ Common::Point _mouseClickPoint;
};
class BaseMenu {
@@ -98,12 +101,14 @@ public:
void closeMenu();
void handleClick(uint menuItemIndex, const Common::Point &mousePos);
uint drawMenuText(BaseMenu *menu);
+ void redrawMenuText(BaseMenu *menu);
void update(Control *cursorControl);
void setTimeOutDuration(uint32 duration, uint timeOutMenuChoiceIndex);
void setMenuCallerThreadId(uint32 menuCallerThreadId);
void setMenuChoiceOffsets(MenuChoiceOffsets menuChoiceOffsets, int16 *menuChoiceOffset);
void setSavegameSlotNum(int slotNum);
void setSavegameDescription(Common::String desc);
+ bool calcMenuItemTextPositionAtPoint(Common::Point pt, int &offset);
virtual bool initMenuCursor() = 0;
virtual int getGameState() = 0;
virtual void setGameState(int gameState) = 0;