From f8425a32caf06a7728ab6ba6df0eacee6f7237a4 Mon Sep 17 00:00:00 2001 From: dgengin Date: Sun, 26 Jun 2016 03:01:52 -0700 Subject: [PATCH] - add actions to support changing volume and gamma using keyboard - fix getKeyCode error - add wsad keyboard shortcuts for directional arrows to gamefiles for Android --- gamefiles/towners/adria/panel.json | 4 +- gamefiles/towners/drunk/panel.json | 4 +- gamefiles/towners/gillian/panel.json | 4 +- gamefiles/towners/healer/panel.json | 4 +- gamefiles/towners/smith/panel.json | 4 +- gamefiles/towners/strytell/panel.json | 4 +- gamefiles/towners/townboy/panel.json | 4 +- gamefiles/towners/twnf/panel.json | 4 +- gamefiles/ui/level/charPanelQuests.json | 4 +- gamefiles/ui/level/gameMenu2.json | 188 ++++++++++++++++++++---- gamefiles/ui/level/gameMenuCommon.json | 4 +- gamefiles/ui/mainMenu.json | 4 +- gamefiles/ui/settings.json | 4 +- gamefiles/ui/singlePlayer/select.json | 4 +- src/Actions/ActDrawable.h | 98 ++++++++++++ src/Actions/ActFocus.h | 28 ++++ src/Game.h | 26 ++-- src/Parser/ParseAction.cpp | 24 +++ src/Parser/ParseUtils.cpp | 6 +- 19 files changed, 352 insertions(+), 70 deletions(-) diff --git a/gamefiles/towners/adria/panel.json b/gamefiles/towners/adria/panel.json index 01eb5e72..394d7d66 100755 --- a/gamefiles/towners/adria/panel.json +++ b/gamefiles/towners/adria/panel.json @@ -13,11 +13,11 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { - "key": "down", + "key": ["down", "s"], "action": "focus.moveDown" } ], diff --git a/gamefiles/towners/drunk/panel.json b/gamefiles/towners/drunk/panel.json index 3671bf5d..d14c3ac3 100755 --- a/gamefiles/towners/drunk/panel.json +++ b/gamefiles/towners/drunk/panel.json @@ -13,11 +13,11 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { - "key": "down", + "key": ["down", "s"], "action": "focus.moveDown" } ], diff --git a/gamefiles/towners/gillian/panel.json b/gamefiles/towners/gillian/panel.json index 0e7198b8..0e28af9b 100755 --- a/gamefiles/towners/gillian/panel.json +++ b/gamefiles/towners/gillian/panel.json @@ -13,11 +13,11 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { - "key": "down", + "key": ["down", "s"], "action": "focus.moveDown" } ], diff --git a/gamefiles/towners/healer/panel.json b/gamefiles/towners/healer/panel.json index c453af71..cb52200e 100755 --- a/gamefiles/towners/healer/panel.json +++ b/gamefiles/towners/healer/panel.json @@ -13,11 +13,11 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { - "key": "down", + "key": ["down", "s"], "action": "focus.moveDown" } ], diff --git a/gamefiles/towners/smith/panel.json b/gamefiles/towners/smith/panel.json index ced23bfe..9b1261f9 100755 --- a/gamefiles/towners/smith/panel.json +++ b/gamefiles/towners/smith/panel.json @@ -13,11 +13,11 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { - "key": "down", + "key": ["down", "s"], "action": "focus.moveDown" } ], diff --git a/gamefiles/towners/strytell/panel.json b/gamefiles/towners/strytell/panel.json index ca323b07..d92e3883 100755 --- a/gamefiles/towners/strytell/panel.json +++ b/gamefiles/towners/strytell/panel.json @@ -13,11 +13,11 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { - "key": "down", + "key": ["down", "s"], "action": "focus.moveDown" } ], diff --git a/gamefiles/towners/townboy/panel.json b/gamefiles/towners/townboy/panel.json index db794f5c..025dbd08 100755 --- a/gamefiles/towners/townboy/panel.json +++ b/gamefiles/towners/townboy/panel.json @@ -13,11 +13,11 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { - "key": "down", + "key": ["down", "s"], "action": "focus.moveDown" } ], diff --git a/gamefiles/towners/twnf/panel.json b/gamefiles/towners/twnf/panel.json index bf1f1bcf..a89eea9a 100755 --- a/gamefiles/towners/twnf/panel.json +++ b/gamefiles/towners/twnf/panel.json @@ -13,11 +13,11 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { - "key": "down", + "key": ["down", "s"], "action": "focus.moveDown" } ], diff --git a/gamefiles/ui/level/charPanelQuests.json b/gamefiles/ui/level/charPanelQuests.json index 5b561436..f6ff4952 100755 --- a/gamefiles/ui/level/charPanelQuests.json +++ b/gamefiles/ui/level/charPanelQuests.json @@ -18,7 +18,7 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { @@ -27,7 +27,7 @@ "action": "focus.moveUp" }, { - "key": ["down", "tab"], + "key": ["down", "s", "tab"], "action": "focus.moveDown" }, { diff --git a/gamefiles/ui/level/gameMenu2.json b/gamefiles/ui/level/gameMenu2.json index bd2d6fb8..6794e92d 100755 --- a/gamefiles/ui/level/gameMenu2.json +++ b/gamefiles/ui/level/gameMenu2.json @@ -1,5 +1,95 @@ { - "action": { "name": "resource.add", "id": "gameMenu2" }, + "action": [ + { "name": "resource.add", "id": "gameMenu2" }, + { + "name": "action.set", + "id": "updateAudioProgressBar", + "action": [ + { "name": "drawable.resizeToPositionX", "id": "progressBar1", "idToPosition": "option1", "offset": 14 }, + { "name": "game.setProperty", "property": "musicVolume", "value": "|progressBar1|size.x|", "propRange": [0, 100], "valueRange": [14, 270] }, + { + "name": "if.equal", + "param1": "|game|musicVolume|", + "param2": 0, + "then": { "name": "audio.stop", "id": "main" }, + "else": { "name": "audio.play", "id": "main" } + } + ] + }, + { + "name": "action.set", + "id": "updateSoundProgressBar", + "action": [ + { "name": "drawable.resizeToPositionX", "id": "progressBar2", "idToPosition": "option2", "offset": 14 }, + { "name": "game.setProperty", "property": "soundVolume", "value": "|progressBar2|size.x|", "propRange": [0, 100], "valueRange": [14, 270] } + ] + }, + { + "name": "action.set", + "id": "updateGammaProgressBar", + "action": { "name": "drawable.resizeToPositionX", "id": "progressBar3", "idToPosition": "option3", "offset": 14 } + } + ], + "action": [ + { + "name": "action.set", + "id": "updateAudioUpKeyboardShortcut", + "action": [ + { "name": "drawable.moveStepX", "id": "option1", "idAnchorTo": "progressBar1", "range": 283, "steps": 17, "stepOffset": 1 }, + "updateAudioProgressBar" + ] + }, + { + "name": "action.set", + "id": "updateAudioDownKeyboardShortcut", + "action": [ + { "name": "drawable.moveStepX", "id": "option1", "idAnchorTo": "progressBar1", "range": 283, "steps": 17, "stepOffset": -1 }, + "updateAudioProgressBar" + ] + }, + { + "name": "action.set", + "id": "updateSoundUpKeyboardShortcut", + "action": [ + { "name": "drawable.moveStepX", "id": "option2", "idAnchorTo": "progressBar2", "range": 283, "steps": 17, "stepOffset": 1 }, + "updateSoundProgressBar" + ] + }, + { + "name": "action.set", + "id": "updateSoundDownKeyboardShortcut", + "action": [ + { "name": "drawable.moveStepX", "id": "option2", "idAnchorTo": "progressBar2", "range": 283, "steps": 17, "stepOffset": -1 }, + "updateSoundProgressBar" + ] + }, + { + "name": "action.set", + "id": "updateGammaUpKeyboardShortcut", + "action": [ + { "name": "drawable.moveStepX", "id": "option3", "idAnchorTo": "progressBar3", "range": 283, "steps": 15, "stepOffset": 1 }, + "updateGammaProgressBar" + ] + }, + { + "name": "action.set", + "id": "updateGammaDownKeyboardShortcut", + "action": [ + { "name": "drawable.moveStepX", "id": "option3", "idAnchorTo": "progressBar3", "range": 283, "steps": 15, "stepOffset": -1 }, + "updateGammaProgressBar" + ] + } + ], + "keyboard": [ + { + "key": ["a", "left"], + "action": "updateAudioDownKeyboardShortcut" + }, + { + "key": ["d", "right"], + "action": "updateAudioUpKeyboardShortcut" + } + ], "texture": [ { "id": "optbar", @@ -80,19 +170,13 @@ "textureRect": [283, 28], "position": [263, 121], "anchor": "none", + "sound": "titlemov", "onClick": [ + { "name": "button.click", "id": "music", "playSound": false }, { "name": "drawable.centerOnMouseX", "id": "option1", "idAnchorTo": "progressBar1", "range": 283, "steps": 17 }, - { "name": "drawable.resizeToPositionX", "id": "progressBar1", "idToPosition": "option1", "offset": 14 }, - { "name": "game.setProperty", "property": "musicVolume", "value": "|progressBar1|size.x|", "propRange": [0, 100], "valueRange": [14, 270] }, - { - "name": "if.equal", - "param1": "|game|musicVolume|", - "param2": 0, - "then": { "name": "audio.stop", "id": "main" }, - "else": { "name": "audio.play", "id": "main" } - } + "updateAudioProgressBar" ], - "onClickDrag": { "name": "button.click", "id": "btnOption1" } + "onClickDrag": { "name": "button.click", "id": "btnOption1", "playSound": false } }, { "id": "btnOption2", @@ -100,12 +184,13 @@ "textureRect": [283, 28], "position": [263, 166], "anchor": "none", + "sound": "titlemov", "onClick": [ + { "name": "button.click", "id": "sound", "playSound": false }, { "name": "drawable.centerOnMouseX", "id": "option2", "idAnchorTo": "progressBar2", "range": 283, "steps": 17 }, - { "name": "drawable.resizeToPositionX", "id": "progressBar2", "idToPosition": "option2", "offset": 14 }, - { "name": "game.setProperty", "property": "soundVolume", "value": "|progressBar2|size.x|", "propRange": [0, 100], "valueRange": [14, 270] } + "updateSoundProgressBar" ], - "onClickDrag": { "name": "button.click", "id": "btnOption2" } + "onClickDrag": { "name": "button.click", "id": "btnOption2", "playSound": false } }, { "id": "btnOption3", @@ -113,53 +198,100 @@ "textureRect": [283, 28], "position": [263, 211], "anchor": "none", + "sound": "titlemov", "onClick": [ + { "name": "button.click", "id": "gamma", "playSound": false }, { "name": "drawable.centerOnMouseX", "id": "option3", "idAnchorTo": "progressBar3", "range": 283, "steps": 15 }, - { "name": "drawable.resizeToPositionX", "id": "progressBar3", "idToPosition": "option3", "offset": 14 } + "updateGammaProgressBar" ], - "onClickDrag": { "name": "button.click", "id": "btnOption3" } + "onClickDrag": { "name": "button.click", "id": "btnOption3", "playSound": false } }, { "id": "music", "bitmapFont": "bigtgold", "sound": "titlemov", "focus": true, - "focusSound": "titlemov", + "focusOnClick": false, "text": "Music", "position": [75, 116], "anchor": "none", - "onFocus": [ + "onClick": [ "anchorLeftPentagram", - { "name": "drawable.anchor", "id": "pent2", "idAnchor": "optbar1", "anchor": "right" } - ] + { "name": "drawable.anchor", "id": "pent2", "idAnchor": "optbar1", "anchor": "right" }, + { "name": "loadJson", + "json": { + "keyboard": [ + { + "key": ["a", "left"], + "action": "updateAudioDownKeyboardShortcut" + }, + { + "key": ["d", "right"], + "action": "updateAudioUpKeyboardShortcut" + } + ] + } + } + ], + "onFocus": { "name": "button.click", "id": "music" } }, { "id": "sound", "bitmapFont": "bigtgold", "sound": "titlemov", "focus": true, - "focusSound": "titlemov", + "focusOnClick": false, "text": "Sound", "position": [75, 161], "anchor": "none", - "onFocus": [ + "onClick": [ "anchorLeftPentagram", - { "name": "drawable.anchor", "id": "pent2", "idAnchor": "optbar2", "anchor": "right" } - ] + { "name": "drawable.anchor", "id": "pent2", "idAnchor": "optbar2", "anchor": "right" }, + { "name": "loadJson", + "json": { + "keyboard": [ + { + "key": ["a", "left"], + "action": "updateSoundDownKeyboardShortcut" + }, + { + "key": ["d", "right"], + "action": "updateSoundUpKeyboardShortcut" + } + ] + } + } + ], + "onFocus": { "name": "button.click", "id": "sound" } }, { "id": "gamma", "bitmapFont": "bigtgold", "sound": "titlemov", "focus": true, - "focusSound": "titlemov", + "focusOnClick": false, "text": "Gamma", "position": [75, 206], "anchor": "none", - "onFocus": [ + "onClick": [ "anchorLeftPentagram", - { "name": "drawable.anchor", "id": "pent2", "idAnchor": "optbar3", "anchor": "right" } - ] + { "name": "drawable.anchor", "id": "pent2", "idAnchor": "optbar3", "anchor": "right" }, + { "name": "loadJson", + "json": { + "keyboard": [ + { + "key": ["a", "left"], + "action": "updateGammaDownKeyboardShortcut" + }, + { + "key": ["d", "right"], + "action": "updateGammaUpKeyboardShortcut" + } + ] + } + } + ], + "onFocus": { "name": "button.click", "id": "gamma" } }, { "id": "colorCycling", diff --git a/gamefiles/ui/level/gameMenuCommon.json b/gamefiles/ui/level/gameMenuCommon.json index 77d3b7fc..31780801 100755 --- a/gamefiles/ui/level/gameMenuCommon.json +++ b/gamefiles/ui/level/gameMenuCommon.json @@ -19,7 +19,7 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { @@ -28,7 +28,7 @@ "action": "focus.moveUp" }, { - "key": ["down", "tab"], + "key": ["down", "s", "tab"], "action": "focus.moveDown" }, { diff --git a/gamefiles/ui/mainMenu.json b/gamefiles/ui/mainMenu.json index b137ee81..e74b6ea0 100755 --- a/gamefiles/ui/mainMenu.json +++ b/gamefiles/ui/mainMenu.json @@ -15,7 +15,7 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { @@ -24,7 +24,7 @@ "action": "focus.moveUp" }, { - "key": ["down", "tab"], + "key": ["down", "s", "tab"], "action": "focus.moveDown" }, { diff --git a/gamefiles/ui/settings.json b/gamefiles/ui/settings.json index db25ddc3..5ef4ac53 100755 --- a/gamefiles/ui/settings.json +++ b/gamefiles/ui/settings.json @@ -19,7 +19,7 @@ "action": "focus.click" }, { - "key": "up", + "key": ["up", "w"], "action": "focus.moveUp" }, { @@ -28,7 +28,7 @@ "action": "focus.moveUp" }, { - "key": ["down", "tab"], + "key": ["down", "s", "tab"], "action": "focus.moveDown" }, { diff --git a/gamefiles/ui/singlePlayer/select.json b/gamefiles/ui/singlePlayer/select.json index 5d21e79b..df9be71d 100755 --- a/gamefiles/ui/singlePlayer/select.json +++ b/gamefiles/ui/singlePlayer/select.json @@ -228,7 +228,7 @@ "json": { "keyboard": [ { - "key": "up", + "key": ["up", "w"], "action": [ "focus.moveUp", "saveMenu.moveScrollbar" @@ -243,7 +243,7 @@ ] }, { - "key": ["down", "tab"], + "key": ["down", "s", "tab"], "action": [ "focus.moveDown", "saveMenu.moveScrollbar" diff --git a/src/Actions/ActDrawable.h b/src/Actions/ActDrawable.h index c2702a49..a8f9bf1e 100755 --- a/src/Actions/ActDrawable.h +++ b/src/Actions/ActDrawable.h @@ -420,6 +420,104 @@ class ActDrawableMoveY : public Action } }; +class ActDrawableMoveStepX : public Action +{ +private: + std::string id; + std::string idAnchorTo; + unsigned range; + Variable steps; + int stepOffset; + +public: + ActDrawableMoveStepX(const std::string& id_, const std::string& idAnchorTo_, + unsigned range_, const Variable& steps_, int stepOffset_) + : id(id_), idAnchorTo(idAnchorTo_), range(range_), + steps(steps_), stepOffset(stepOffset_) {} + + virtual bool execute(Game& game) + { + auto item = game.Resources().getResource(id); + auto itemAnchor = game.Resources().getResource(idAnchorTo); + if (item != nullptr && itemAnchor != nullptr) + { + auto itemPos = itemAnchor->DrawPosition(); + auto numSteps = game.getVariable(steps, -1); + if (numSteps > 1) + { + numSteps--; + auto newRange = (float)std::max(0, (int)range - (int)item->Size().x); + auto currSize = item->DrawPosition().x - itemPos.x; + auto currStep = std::round((currSize * numSteps) / newRange); + auto newStep = currStep + (float)stepOffset; + if (newStep < 0) + { + newStep = 0; + } + else if (newStep > numSteps) + { + newStep = numSteps; + } + if (newStep >= 1) + { + itemPos.x += std::round((newStep * newRange) / numSteps); + } + } + item->Position(itemPos); + } + return true; + } +}; + +class ActDrawableMoveStepY : public Action +{ +private: + std::string id; + std::string idAnchorTo; + unsigned range; + Variable steps; + int stepOffset; + +public: + ActDrawableMoveStepY(const std::string& id_, const std::string& idAnchorTo_, + unsigned range_, const Variable& steps_, int stepOffset_) + : id(id_), idAnchorTo(idAnchorTo_), range(range_), + steps(steps_), stepOffset(stepOffset_) {} + + virtual bool execute(Game& game) + { + auto item = game.Resources().getResource(id); + auto itemAnchor = game.Resources().getResource(idAnchorTo); + if (item != nullptr && itemAnchor != nullptr) + { + auto itemPos = itemAnchor->DrawPosition(); + auto numSteps = game.getVariable(steps, -1); + if (numSteps > 1) + { + numSteps--; + auto newRange = (float)std::max(0, (int)range - (int)item->Size().y); + auto currSize = item->DrawPosition().y - itemPos.y; + auto currStep = std::round((currSize * numSteps) / newRange); + auto newStep = currStep + (float)stepOffset; + if (newStep < 0) + { + newStep = 0; + } + else if (newStep > numSteps) + { + newStep = numSteps; + } + if (newStep >= 1) + { + itemPos.y += std::round((newStep * newRange) / numSteps); + } + } + item->Position(itemPos); + } + return true; + } +}; + class ActDrawableResizeOnMouseX : public Action { private: diff --git a/src/Actions/ActFocus.h b/src/Actions/ActFocus.h index ddf8dcd0..f542b3eb 100755 --- a/src/Actions/ActFocus.h +++ b/src/Actions/ActFocus.h @@ -38,3 +38,31 @@ class ActFocusMoveUp : public Action return true; } }; + +class ActFocusSet : public Action +{ +private: + std::string id; + bool focus; + +public: + ActFocusSet(const std::string& id_, bool focus_) : id(id_), focus(focus_) {} + + virtual bool execute(Game& game) + { + auto item = game.Resources().getResource