mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Implemented gesture for town/hero lists and town/hero selection
This commit is contained in:
@@ -412,7 +412,9 @@ void OptionsTab::CPlayerOptionTooltipBox::genBonusWindow()
|
||||
}
|
||||
|
||||
OptionsTab::SelectedBox::SelectedBox(Point position, PlayerSettings & settings, SelType type)
|
||||
: CIntObject(RCLICK | WHEEL, position), CPlayerSettingsHelper(settings, type)
|
||||
: CIntObject(RCLICK | WHEEL | GESTURE_PANNING, position)
|
||||
, CPlayerSettingsHelper(settings, type)
|
||||
, panningDistanceAccumulated(0)
|
||||
{
|
||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||
|
||||
@@ -444,6 +446,8 @@ void OptionsTab::SelectedBox::clickRight(tribool down, bool previousState)
|
||||
|
||||
void OptionsTab::SelectedBox::wheelScrolled(int distance)
|
||||
{
|
||||
distance = std::clamp(distance, -1, 1);
|
||||
|
||||
switch(CPlayerSettingsHelper::type)
|
||||
{
|
||||
case TOWN:
|
||||
@@ -458,6 +462,38 @@ void OptionsTab::SelectedBox::wheelScrolled(int distance)
|
||||
}
|
||||
}
|
||||
|
||||
void OptionsTab::SelectedBox::panning(bool on)
|
||||
{
|
||||
panningDistanceAccumulated = 0;
|
||||
}
|
||||
|
||||
void OptionsTab::SelectedBox::gesturePanning(const Point & distanceDelta)
|
||||
{
|
||||
// FIXME: currently options tab is completely recreacted from scratch whenever we receive any information from server
|
||||
// because of that, panning event gets interrupted (due to destruction of element)
|
||||
// so, currently, gesture will always move selection only by 1, and then wait for recreation from server info
|
||||
|
||||
int panningDistanceSingle = 48;
|
||||
|
||||
panningDistanceAccumulated += distanceDelta.x;
|
||||
|
||||
if (-panningDistanceAccumulated > panningDistanceSingle )
|
||||
{
|
||||
int scrollAmount = (-panningDistanceAccumulated) / panningDistanceSingle;
|
||||
wheelScrolled(-scrollAmount);
|
||||
panningDistanceAccumulated += scrollAmount * panningDistanceSingle;
|
||||
removeUsedEvents(GESTURE_PANNING);
|
||||
}
|
||||
|
||||
if (panningDistanceAccumulated > panningDistanceSingle )
|
||||
{
|
||||
int scrollAmount = panningDistanceAccumulated / panningDistanceSingle;
|
||||
wheelScrolled(scrollAmount);
|
||||
panningDistanceAccumulated += -scrollAmount * panningDistanceSingle;
|
||||
removeUsedEvents(GESTURE_PANNING);
|
||||
}
|
||||
}
|
||||
|
||||
OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parent)
|
||||
: pi(std::make_unique<PlayerInfo>(SEL->getPlayerInfo(S.color.getNum())))
|
||||
, s(std::make_unique<PlayerSettings>(S))
|
||||
|
||||
Reference in New Issue
Block a user