mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-21 21:17:49 +02:00
Added selection of long touch duration
This commit is contained in:
parent
06437cbde6
commit
ffdac314e9
@ -67,6 +67,11 @@
|
|||||||
"vcmi.systemOptions.scalingButton.help" : "{Interface Scaling}\n\nChanges scaling of in-game interface",
|
"vcmi.systemOptions.scalingButton.help" : "{Interface Scaling}\n\nChanges scaling of in-game interface",
|
||||||
"vcmi.systemOptions.scalingMenu.hover" : "Select Interface Scaling",
|
"vcmi.systemOptions.scalingMenu.hover" : "Select Interface Scaling",
|
||||||
"vcmi.systemOptions.scalingMenu.help" : "Change in-game interface scaling.",
|
"vcmi.systemOptions.scalingMenu.help" : "Change in-game interface scaling.",
|
||||||
|
"vcmi.systemOptions.longTouchButton.hover" : "Long Touch Interval: %d ms", // Translation note: "ms" = "milliseconds"
|
||||||
|
"vcmi.systemOptions.longTouchButton.help" : "{Long Touch Interval}\n\nWhen using touchscreen, popup windows will appear after touching screen for specified duration, in milliseconds",
|
||||||
|
"vcmi.systemOptions.longTouchMenu.hover" : "Select Long Touch Interval",
|
||||||
|
"vcmi.systemOptions.longTouchMenu.help" : "Change duration of long touch interval.",
|
||||||
|
"vcmi.systemOptions.longTouchMenu.entry" : "%d milliseconds",
|
||||||
"vcmi.systemOptions.framerateButton.hover" : "Show FPS",
|
"vcmi.systemOptions.framerateButton.hover" : "Show FPS",
|
||||||
"vcmi.systemOptions.framerateButton.help" : "{Show FPS}\n\nToggle the visibility of the Frames Per Second counter in the corner of the game window",
|
"vcmi.systemOptions.framerateButton.help" : "{Show FPS}\n\nToggle the visibility of the Frames Per Second counter in the corner of the game window",
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ InputSourceTouch::InputSourceTouch()
|
|||||||
{
|
{
|
||||||
params.useRelativeMode = settings["general"]["userRelativePointer"].Bool();
|
params.useRelativeMode = settings["general"]["userRelativePointer"].Bool();
|
||||||
params.relativeModeSpeedFactor = settings["general"]["relativePointerSpeedMultiplier"].Float();
|
params.relativeModeSpeedFactor = settings["general"]["relativePointerSpeedMultiplier"].Float();
|
||||||
|
params.longTouchTimeMilliseconds = settings["general"]["longTouchTimeMilliseconds"].Float();
|
||||||
|
|
||||||
if (params.useRelativeMode)
|
if (params.useRelativeMode)
|
||||||
state = TouchState::RELATIVE_MODE;
|
state = TouchState::RELATIVE_MODE;
|
||||||
@ -93,6 +94,9 @@ void InputSourceTouch::handleEventFingerMotion(const SDL_TouchFingerEvent & tfin
|
|||||||
|
|
||||||
void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinger)
|
void InputSourceTouch::handleEventFingerDown(const SDL_TouchFingerEvent & tfinger)
|
||||||
{
|
{
|
||||||
|
// FIXME: better place to update potentially changed settings?
|
||||||
|
params.longTouchTimeMilliseconds = settings["general"]["longTouchTimeMilliseconds"].Float();
|
||||||
|
|
||||||
lastTapTimeTicks = tfinger.timestamp;
|
lastTapTimeTicks = tfinger.timestamp;
|
||||||
|
|
||||||
switch(state)
|
switch(state)
|
||||||
@ -204,7 +208,7 @@ void InputSourceTouch::handleUpdate()
|
|||||||
if ( state == TouchState::TAP_DOWN_SHORT)
|
if ( state == TouchState::TAP_DOWN_SHORT)
|
||||||
{
|
{
|
||||||
uint32_t currentTime = SDL_GetTicks();
|
uint32_t currentTime = SDL_GetTicks();
|
||||||
if (currentTime > lastTapTimeTicks + params.longPressTimeMilliseconds)
|
if (currentTime > lastTapTimeTicks + params.longTouchTimeMilliseconds)
|
||||||
{
|
{
|
||||||
GH.events().dispatchShowPopup(GH.getCursorPosition());
|
GH.events().dispatchShowPopup(GH.getCursorPosition());
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ struct TouchInputParameters
|
|||||||
double relativeModeSpeedFactor = 1.0;
|
double relativeModeSpeedFactor = 1.0;
|
||||||
|
|
||||||
/// tap for period longer than specified here will be qualified as "long tap", triggering corresponding gesture
|
/// tap for period longer than specified here will be qualified as "long tap", triggering corresponding gesture
|
||||||
uint32_t longPressTimeMilliseconds = 750;
|
uint32_t longTouchTimeMilliseconds = 750;
|
||||||
|
|
||||||
/// moving finger for distance larger than specified will be qualified as panning gesture instead of long press
|
/// moving finger for distance larger than specified will be qualified as panning gesture instead of long press
|
||||||
uint32_t panningSensitivityThreshold = 10;
|
uint32_t panningSensitivityThreshold = 10;
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "../../battle/BattleInterface.h"
|
#include "../../battle/BattleInterface.h"
|
||||||
#include "../../gui/CGuiHandler.h"
|
#include "../../gui/CGuiHandler.h"
|
||||||
#include "../../eventsSDL/InputHandler.h"
|
|
||||||
#include "../../../lib/CConfigHandler.h"
|
#include "../../../lib/CConfigHandler.h"
|
||||||
#include "../../../lib/filesystem/ResourceID.h"
|
#include "../../../lib/filesystem/ResourceID.h"
|
||||||
#include "../../../lib/CGeneralTextHandler.h"
|
#include "../../../lib/CGeneralTextHandler.h"
|
||||||
@ -24,8 +23,6 @@ BattleOptionsTab::BattleOptionsTab(BattleInterface * owner)
|
|||||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||||
type |= REDRAW_PARENT;
|
type |= REDRAW_PARENT;
|
||||||
|
|
||||||
//addConditional("touchscreen", GH.input().hasTouchInputDevice());
|
|
||||||
|
|
||||||
const JsonNode config(ResourceID("config/widgets/settings/battleOptionsTab.json"));
|
const JsonNode config(ResourceID("config/widgets/settings/battleOptionsTab.json"));
|
||||||
addCallback("viewGridChanged", [this, owner](bool value)
|
addCallback("viewGridChanged", [this, owner](bool value)
|
||||||
{
|
{
|
||||||
|
@ -8,24 +8,25 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
|
|
||||||
#include "GeneralOptionsTab.h"
|
#include "GeneralOptionsTab.h"
|
||||||
|
|
||||||
#include "../../../lib/CGeneralTextHandler.h"
|
|
||||||
#include "../../../lib/filesystem/ResourceID.h"
|
|
||||||
#include "../../gui/CGuiHandler.h"
|
|
||||||
#include "../../gui/WindowHandler.h"
|
|
||||||
#include "../../widgets/Buttons.h"
|
|
||||||
#include "../../widgets/Slider.h"
|
|
||||||
#include "../../widgets/TextControls.h"
|
|
||||||
#include "../../widgets/Images.h"
|
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
#include "CMusicHandler.h"
|
#include "CMusicHandler.h"
|
||||||
#include "CPlayerInterface.h"
|
#include "CPlayerInterface.h"
|
||||||
#include "windows/GUIClasses.h"
|
|
||||||
#include "CServerHandler.h"
|
#include "CServerHandler.h"
|
||||||
#include "render/IScreenHandler.h"
|
#include "render/IScreenHandler.h"
|
||||||
|
#include "windows/GUIClasses.h"
|
||||||
|
|
||||||
|
#include "../../eventsSDL/InputHandler.h"
|
||||||
|
#include "../../gui/CGuiHandler.h"
|
||||||
|
#include "../../gui/WindowHandler.h"
|
||||||
|
#include "../../widgets/Buttons.h"
|
||||||
|
#include "../../widgets/Images.h"
|
||||||
|
#include "../../widgets/Slider.h"
|
||||||
|
#include "../../widgets/TextControls.h"
|
||||||
|
|
||||||
|
#include "../../../lib/CGeneralTextHandler.h"
|
||||||
|
#include "../../../lib/filesystem/ResourceID.h"
|
||||||
|
|
||||||
static void setIntSetting(std::string group, std::string field, int value)
|
static void setIntSetting(std::string group, std::string field, int value)
|
||||||
{
|
{
|
||||||
@ -52,6 +53,22 @@ static std::string scalingToLabelString( int scaling)
|
|||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string longTouchToEntryString( int duration)
|
||||||
|
{
|
||||||
|
std::string string = CGI->generaltexth->translate("vcmi.systemOptions.longTouchMenu.entry");
|
||||||
|
boost::replace_all(string, "%d", std::to_string(duration));
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string longTouchToLabelString( int duration)
|
||||||
|
{
|
||||||
|
std::string string = CGI->generaltexth->translate("vcmi.systemOptions.longTouchButton.hover");
|
||||||
|
boost::replace_all(string, "%d", std::to_string(duration));
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
static std::string resolutionToEntryString( int w, int h)
|
static std::string resolutionToEntryString( int w, int h)
|
||||||
{
|
{
|
||||||
std::string string = "%wx%h";
|
std::string string = "%wx%h";
|
||||||
@ -79,6 +96,7 @@ GeneralOptionsTab::GeneralOptionsTab()
|
|||||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||||
type |= REDRAW_PARENT;
|
type |= REDRAW_PARENT;
|
||||||
|
|
||||||
|
addConditional("touchscreen", GH.input().hasTouchInputDevice());
|
||||||
#ifdef VCMI_MOBILE
|
#ifdef VCMI_MOBILE
|
||||||
addConditional("mobile", true);
|
addConditional("mobile", true);
|
||||||
addConditional("desktop", false);
|
addConditional("desktop", false);
|
||||||
@ -127,6 +145,10 @@ GeneralOptionsTab::GeneralOptionsTab()
|
|||||||
{
|
{
|
||||||
selectGameScaling();
|
selectGameScaling();
|
||||||
});
|
});
|
||||||
|
addCallback("setLongTouchDuration", [this](int dummyValue)
|
||||||
|
{
|
||||||
|
selectLongTouchDuration();
|
||||||
|
});
|
||||||
addCallback("framerateChanged", [](bool value)
|
addCallback("framerateChanged", [](bool value)
|
||||||
{
|
{
|
||||||
setBoolSetting("video", "showfps", value);
|
setBoolSetting("video", "showfps", value);
|
||||||
@ -150,6 +172,9 @@ GeneralOptionsTab::GeneralOptionsTab()
|
|||||||
std::shared_ptr<CLabel> scalingLabel = widget<CLabel>("scalingLabel");
|
std::shared_ptr<CLabel> scalingLabel = widget<CLabel>("scalingLabel");
|
||||||
scalingLabel->setText(scalingToLabelString(currentResolution["scaling"].Integer()));
|
scalingLabel->setText(scalingToLabelString(currentResolution["scaling"].Integer()));
|
||||||
|
|
||||||
|
std::shared_ptr<CLabel> longTouchLabel = widget<CLabel>("longTouchLabel");
|
||||||
|
longTouchLabel->setText(longTouchToLabelString(settings["general"]["longTouchTimeMilliseconds"].Integer()));
|
||||||
|
|
||||||
std::shared_ptr<CToggleButton> spellbookAnimationCheckbox = widget<CToggleButton>("spellbookAnimationCheckbox");
|
std::shared_ptr<CToggleButton> spellbookAnimationCheckbox = widget<CToggleButton>("spellbookAnimationCheckbox");
|
||||||
spellbookAnimationCheckbox->setSelected(settings["video"]["spellbookAnimation"].Bool());
|
spellbookAnimationCheckbox->setSelected(settings["video"]["spellbookAnimation"].Bool());
|
||||||
|
|
||||||
@ -324,3 +349,48 @@ void GeneralOptionsTab::setGameScaling(int index)
|
|||||||
|
|
||||||
widget<CLabel>("scalingLabel")->setText(scalingToLabelString(scaling));
|
widget<CLabel>("scalingLabel")->setText(scalingToLabelString(scaling));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeneralOptionsTab::selectLongTouchDuration()
|
||||||
|
{
|
||||||
|
longTouchDurations = { 500, 750, 1000, 1250, 1500, 1750, 2000 };
|
||||||
|
|
||||||
|
std::vector<std::string> items;
|
||||||
|
size_t currentIndex = 0;
|
||||||
|
size_t i = 0;
|
||||||
|
for(const auto & it : longTouchDurations)
|
||||||
|
{
|
||||||
|
auto resolutionStr = longTouchToEntryString(it);
|
||||||
|
if(widget<CLabel>("longTouchLabel")->getText() == longTouchToLabelString(it))
|
||||||
|
currentIndex = i;
|
||||||
|
|
||||||
|
items.push_back(std::move(resolutionStr));
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
GH.windows().createAndPushWindow<CObjectListWindow>(
|
||||||
|
items,
|
||||||
|
nullptr,
|
||||||
|
CGI->generaltexth->translate("vcmi.systemOptions.longTouchMenu.hover"),
|
||||||
|
CGI->generaltexth->translate("vcmi.systemOptions.longTouchMenu.help"),
|
||||||
|
[this](int index)
|
||||||
|
{
|
||||||
|
setLongTouchDuration(index);
|
||||||
|
},
|
||||||
|
currentIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GeneralOptionsTab::setLongTouchDuration(int index)
|
||||||
|
{
|
||||||
|
assert(index >= 0 && index < longTouchDurations.size());
|
||||||
|
|
||||||
|
if ( index < 0 || index >= longTouchDurations.size() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
int scaling = longTouchDurations[index];
|
||||||
|
|
||||||
|
Settings longTouchTime = settings.write["general"]["longTouchTimeMilliseconds"];
|
||||||
|
longTouchTime->Float() = scaling;
|
||||||
|
|
||||||
|
widget<CLabel>("longTouchLabel")->setText(longTouchToLabelString(scaling));
|
||||||
|
}
|
||||||
|
@ -20,6 +20,7 @@ private:
|
|||||||
|
|
||||||
std::vector<Point> supportedResolutions;
|
std::vector<Point> supportedResolutions;
|
||||||
std::vector<int> supportedScaling;
|
std::vector<int> supportedScaling;
|
||||||
|
std::vector<int> longTouchDurations;
|
||||||
|
|
||||||
void setFullscreenMode( bool on, bool exclusive);
|
void setFullscreenMode( bool on, bool exclusive);
|
||||||
|
|
||||||
@ -29,6 +30,9 @@ private:
|
|||||||
void selectGameScaling();
|
void selectGameScaling();
|
||||||
void setGameScaling(int index);
|
void setGameScaling(int index);
|
||||||
|
|
||||||
|
void selectLongTouchDuration();
|
||||||
|
void setLongTouchDuration(int index);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GeneralOptionsTab();
|
GeneralOptionsTab();
|
||||||
|
|
||||||
|
@ -21,15 +21,19 @@
|
|||||||
"playerName",
|
"playerName",
|
||||||
"music",
|
"music",
|
||||||
"sound",
|
"sound",
|
||||||
|
"saveRandomMaps",
|
||||||
|
"lastMap",
|
||||||
"language",
|
"language",
|
||||||
"gameDataLanguage",
|
"gameDataLanguage",
|
||||||
"saveRandomMaps",
|
"lastSave",
|
||||||
|
"lastSettingsTab"
|
||||||
|
"lastCampaign",
|
||||||
"saveFrequency",
|
"saveFrequency",
|
||||||
"notifications",
|
"notifications",
|
||||||
"extraDump",
|
"extraDump",
|
||||||
"userRelativePointer",
|
"userRelativePointer",
|
||||||
"relativePointerSpeedMultiplier",
|
"relativePointerSpeedMultiplier",
|
||||||
"lastSettingsTab"
|
"longTouchTimeMilliseconds"
|
||||||
],
|
],
|
||||||
"properties" : {
|
"properties" : {
|
||||||
"playerName" : {
|
"playerName" : {
|
||||||
@ -93,6 +97,10 @@
|
|||||||
"relativePointerSpeedMultiplier" : {
|
"relativePointerSpeedMultiplier" : {
|
||||||
"type" : "number",
|
"type" : "number",
|
||||||
"default" : 1
|
"default" : 1
|
||||||
|
},
|
||||||
|
"longTouchTimeMilliseconds" : {
|
||||||
|
"type" : "number",
|
||||||
|
"default" : 1000
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -102,13 +110,12 @@
|
|||||||
"default" : {},
|
"default" : {},
|
||||||
"required" : [
|
"required" : [
|
||||||
"resolution",
|
"resolution",
|
||||||
"bitsPerPixel",
|
|
||||||
"fullscreen",
|
"fullscreen",
|
||||||
"realFullscreen",
|
"realFullscreen",
|
||||||
"cursor",
|
"cursor",
|
||||||
|
"showIntro",
|
||||||
"spellbookAnimation",
|
"spellbookAnimation",
|
||||||
"driver",
|
"driver",
|
||||||
"showIntro",
|
|
||||||
"displayIndex",
|
"displayIndex",
|
||||||
"showfps",
|
"showfps",
|
||||||
"targetfps"
|
"targetfps"
|
||||||
@ -125,10 +132,6 @@
|
|||||||
},
|
},
|
||||||
"default" : {"width" : 800, "height" : 600, "scaling" : 100 }
|
"default" : {"width" : 800, "height" : 600, "scaling" : 100 }
|
||||||
},
|
},
|
||||||
"bitsPerPixel" : {
|
|
||||||
"type" : "number",
|
|
||||||
"default" : 32
|
|
||||||
},
|
|
||||||
"fullscreen" : {
|
"fullscreen" : {
|
||||||
"type" : "boolean",
|
"type" : "boolean",
|
||||||
"default" : false
|
"default" : false
|
||||||
|
@ -52,6 +52,11 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"text": "core.genrltxt.577"
|
"text": "core.genrltxt.577"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "longTouchLabel",
|
||||||
|
"text": "vcmi.systemOptions.longTouchButton.hover",
|
||||||
|
"created" : "touchscreen"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -95,6 +100,13 @@
|
|||||||
"help": "core.help.364",
|
"help": "core.help.364",
|
||||||
"callback": "spellbookAnimationChanged"
|
"callback": "spellbookAnimationChanged"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "longTouchButton",
|
||||||
|
"type": "buttonGear",
|
||||||
|
"help": "vcmi.systemOptions.longTouchButton",
|
||||||
|
"callback": "setLongTouchDuration",
|
||||||
|
"created" : "touchscreen"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
/////////////////////////////////////// Right section - Audio Settings
|
/////////////////////////////////////// Right section - Audio Settings
|
||||||
|
Loading…
x
Reference in New Issue
Block a user