mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-22 11:03:58 +00:00
WIP: Modes
Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com> m Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
@@ -92,10 +92,12 @@ std::string_view constexpr kMapStyleKey = "MapStyleKeyV1";
|
||||
std::string_view constexpr kAllow3dKey = "Allow3d";
|
||||
std::string_view constexpr kAllow3dBuildingsKey = "Buildings3d";
|
||||
std::string_view constexpr kAllowAutoZoom = "AutoZoom";
|
||||
std::string_view constexpr kTrafficEnabledKey = "TrafficEnabled";
|
||||
std::string_view constexpr kTransitSchemeEnabledKey = "TransitSchemeEnabled";
|
||||
std::string_view constexpr kIsolinesEnabledKey = "IsolinesEnabled";
|
||||
std::string_view constexpr kOutdoorsEnabledKey = "OutdoorsEnabled";
|
||||
std::string_view constexpr kMapModeKey = "MapMode";
|
||||
std::string_view constexpr kMapModeDefaultContourLinesKey = "MapModeDefaultHasContourLines";
|
||||
std::string_view constexpr kMapModeHikingContourLinesKey = "MapModeHikingHasContourLines";
|
||||
std::string_view constexpr kMapModeCyclingContourLinesKey = "MapModeCyclingHasContourLines";
|
||||
std::string_view constexpr kMapModeDrivingTrafficKey = "MapModeDrivingHasTraffic";
|
||||
std::string_view constexpr kMapModePublicTransportTransitLinesKey = "MapModePublicTransportHasTransitLines";
|
||||
std::string_view constexpr kTrafficSimplifiedColorsKey = "TrafficSimplifiedColors";
|
||||
std::string_view constexpr kLargeFontsSize = "LargeFontsSize";
|
||||
std::string_view constexpr kTranslitMode = "TransliterationMode";
|
||||
@@ -206,26 +208,6 @@ EMyPositionMode Framework::GetMyPositionMode() const
|
||||
return m_drapeEngine ? m_drapeEngine->GetMyPositionMode() : PendingPosition;
|
||||
}
|
||||
|
||||
TrafficManager & Framework::GetTrafficManager()
|
||||
{
|
||||
return m_trafficManager;
|
||||
}
|
||||
|
||||
TransitReadManager & Framework::GetTransitManager()
|
||||
{
|
||||
return m_transitManager;
|
||||
}
|
||||
|
||||
IsolinesManager & Framework::GetIsolinesManager()
|
||||
{
|
||||
return m_isolinesManager;
|
||||
}
|
||||
|
||||
IsolinesManager const & Framework::GetIsolinesManager() const
|
||||
{
|
||||
return m_isolinesManager;
|
||||
}
|
||||
|
||||
void Framework::OnUserPositionChanged(m2::PointD const & position, bool hasPosition)
|
||||
{
|
||||
GetBookmarkManager().MyPositionMark().SetUserPosition(position, hasPosition);
|
||||
@@ -351,10 +333,10 @@ Framework::Framework(FrameworkParams const & params, bool loadMaps)
|
||||
/// @todo Uncomment when we will integrate a traffic provider.
|
||||
// m_trafficManager.SetCurrentDataVersion(m_storage.GetCurrentDataVersion());
|
||||
// m_trafficManager.SetSimplifiedColorScheme(LoadTrafficSimplifiedColors());
|
||||
// m_trafficManager.SetEnabled(LoadTrafficEnabled());
|
||||
|
||||
m_isolinesManager.SetEnabled(LoadIsolinesEnabled());
|
||||
// m_trafficManager.SetEnabled(MapModeHasTraffic());
|
||||
|
||||
m_isolinesManager.SetEnabled(MapModeHasContourLines());
|
||||
|
||||
InitTransliteration();
|
||||
LOG(LDEBUG, ("Transliterators initialized"));
|
||||
|
||||
@@ -1481,8 +1463,8 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::GraphicsContextFactory> contextFac
|
||||
|
||||
auto const isAutozoomEnabled = LoadAutoZoom();
|
||||
|
||||
auto const trafficEnabled = m_trafficManager.IsEnabled();
|
||||
auto const isolinesEnabled = m_isolinesManager.IsEnabled();
|
||||
auto const hasTraffic = MapModeHasTraffic();
|
||||
auto const hasContourLines = MapModeHasContourLines();
|
||||
|
||||
auto const simplifiedTrafficColors = m_trafficManager.HasSimplifiedColorScheme();
|
||||
auto const fontsScaleFactor = LoadLargeFontsSize() ? kLargeFontsScaleFactor : 1.0;
|
||||
@@ -1492,7 +1474,7 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::GraphicsContextFactory> contextFac
|
||||
df::MapDataProvider(std::move(idReadFn), std::move(featureReadFn), std::move(isCountryLoadedByNameFn),
|
||||
std::move(updateCurrentCountryFn)),
|
||||
params.m_hints, params.m_visualScale, fontsScaleFactor, std::move(params.m_widgetsInitInfo),
|
||||
std::move(myPositionModeChangedFn), allow3dBuildings, trafficEnabled, isolinesEnabled,
|
||||
std::move(myPositionModeChangedFn), allow3dBuildings, hasTraffic, hasContourLines,
|
||||
params.m_isChoosePositionMode, params.m_isChoosePositionMode, GetSelectedFeatureTriangles(),
|
||||
m_routingManager.IsRoutingActive() && m_routingManager.IsRoutingFollowing(), isAutozoomEnabled,
|
||||
simplifiedTrafficColors, std::nullopt /* arrow3dCustomDecl */, std::move(overlaysShowStatsFn),
|
||||
@@ -1530,9 +1512,8 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::GraphicsContextFactory> contextFac
|
||||
|
||||
InvalidateUserMarks();
|
||||
|
||||
auto const transitSchemeEnabled = LoadTransitSchemeEnabled();
|
||||
m_transitManager.EnableTransitSchemeMode(transitSchemeEnabled);
|
||||
|
||||
m_transitManager.EnableTransitSchemeMode(MapModeHasTransitLines());
|
||||
|
||||
// Show debug info if it's enabled in the config.
|
||||
bool showDebugInfo;
|
||||
if (!settings::Get(kShowDebugInfo, showDebugInfo))
|
||||
@@ -2462,19 +2443,6 @@ void Framework::SetLargeFontsSize(bool isLargeSize)
|
||||
InvalidateRect(GetCurrentViewport());
|
||||
}
|
||||
|
||||
bool Framework::LoadTrafficEnabled()
|
||||
{
|
||||
bool enabled;
|
||||
if (!settings::Get(kTrafficEnabledKey, enabled))
|
||||
enabled = false;
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void Framework::SaveTrafficEnabled(bool trafficEnabled)
|
||||
{
|
||||
settings::Set(kTrafficEnabledKey, trafficEnabled);
|
||||
}
|
||||
|
||||
bool Framework::LoadTrafficSimplifiedColors()
|
||||
{
|
||||
bool simplified;
|
||||
@@ -2510,43 +2478,223 @@ void Framework::SaveAutoZoom(bool allowAutoZoom)
|
||||
settings::Set(kAllowAutoZoom, allowAutoZoom);
|
||||
}
|
||||
|
||||
bool Framework::LoadTransitSchemeEnabled()
|
||||
MapMode Framework::CurrentMapMode()
|
||||
{
|
||||
bool enabled;
|
||||
if (!settings::Get(kTransitSchemeEnabledKey, enabled))
|
||||
enabled = false;
|
||||
return enabled;
|
||||
string mapModeValue = "Default";
|
||||
UNUSED_VALUE(settings::Get(kMapModeKey, mapModeValue));
|
||||
|
||||
MapMode mapMode = DEFAULT;
|
||||
if (mapModeValue == "Hiking")
|
||||
mapMode = HIKING;
|
||||
else if (mapModeValue == "Cycling")
|
||||
mapMode = CYCLING;
|
||||
else if (mapModeValue == "Driving")
|
||||
mapMode = DRIVING;
|
||||
else if (mapModeValue == "PublicTransport")
|
||||
mapMode = PUBLICTRANSPORT;
|
||||
|
||||
return mapMode;
|
||||
}
|
||||
|
||||
void Framework::SaveTransitSchemeEnabled(bool enabled)
|
||||
void Framework::SwitchToMapMode(MapMode const mapMode)
|
||||
{
|
||||
settings::Set(kTransitSchemeEnabledKey, enabled);
|
||||
MapStyle mapStyle = GetMapStyle();
|
||||
|
||||
string mapModeValue = "Default";
|
||||
switch (mapMode)
|
||||
{
|
||||
case HIKING:
|
||||
mapModeValue = "Hiking";
|
||||
if (MapStyleIsDark(mapStyle))
|
||||
mapStyle = MapStyleHikingDark;
|
||||
else
|
||||
mapStyle = MapStyleHikingLight;
|
||||
break;
|
||||
case CYCLING:
|
||||
mapModeValue = "Cycling";
|
||||
if (MapStyleIsDark(mapStyle))
|
||||
mapStyle = MapStyleCyclingDark;
|
||||
else
|
||||
mapStyle = MapStyleCyclingLight;
|
||||
break;
|
||||
case DRIVING:
|
||||
mapModeValue = "Driving";
|
||||
if (MapStyleIsDark(mapStyle))
|
||||
mapStyle = MapStyleDrivingDark;
|
||||
else
|
||||
mapStyle = MapStyleDrivingLight;
|
||||
break;
|
||||
case PUBLICTRANSPORT:
|
||||
mapModeValue = "PublicTransport";
|
||||
if (MapStyleIsDark(mapStyle))
|
||||
mapStyle = MapStylePublicTransportDark;
|
||||
else
|
||||
mapStyle = MapStylePublicTransportLight;
|
||||
break;
|
||||
default:
|
||||
mapModeValue = "Default";
|
||||
if (MapStyleIsDark(mapStyle))
|
||||
mapStyle = MapStyleDefaultDark;
|
||||
else
|
||||
mapStyle = MapStyleDefaultLight;
|
||||
break;
|
||||
}
|
||||
|
||||
settings::Set(kMapModeKey, mapModeValue);
|
||||
|
||||
SetMapStyle(mapStyle);
|
||||
|
||||
RefreshMapMode();
|
||||
}
|
||||
|
||||
bool Framework::LoadIsolinesEnabled()
|
||||
MapAppearance Framework::CurrentMapAppearance()
|
||||
{
|
||||
bool enabled;
|
||||
if (!settings::Get(kIsolinesEnabledKey, enabled))
|
||||
enabled = false;
|
||||
return enabled;
|
||||
if (MapStyleIsDark(GetMapStyle()))
|
||||
return DARK;
|
||||
|
||||
return LIGHT;
|
||||
}
|
||||
|
||||
void Framework::SaveIsolinesEnabled(bool enabled)
|
||||
void Framework::SwitchToMapAppearance(MapAppearance const mapAppearance)
|
||||
{
|
||||
settings::Set(kIsolinesEnabledKey, enabled);
|
||||
MapStyle mapStyle = GetMapStyle();
|
||||
if (mapAppearance == DARK)
|
||||
mapStyle = GetLightMapStyleVariant(mapStyle);
|
||||
else
|
||||
mapStyle = GetDarkMapStyleVariant(mapStyle);
|
||||
|
||||
SetMapStyle(mapStyle);
|
||||
}
|
||||
|
||||
bool Framework::LoadOutdoorsEnabled()
|
||||
bool Framework::IsUsingVehicleStyle()
|
||||
{
|
||||
bool enabled;
|
||||
if (!settings::Get(kOutdoorsEnabledKey, enabled))
|
||||
enabled = false;
|
||||
return enabled;
|
||||
MapStyle const mapStyle = GetMapStyle();
|
||||
return mapStyle == MapStyleVehicleLight || mapStyle == MapStyleVehicleDark;
|
||||
}
|
||||
|
||||
void Framework::SaveOutdoorsEnabled(bool enabled)
|
||||
void Framework::SwitchToUsingVehicleStyle(bool const shouldUseVehicleStyle)
|
||||
{
|
||||
settings::Set(kOutdoorsEnabledKey, enabled);
|
||||
if (shouldUseVehicleStyle)
|
||||
{
|
||||
if (CurrentMapAppearance() == DARK)
|
||||
SetMapStyle(MapStyleVehicleDark);
|
||||
else
|
||||
SetMapStyle(MapStyleVehicleLight);
|
||||
}
|
||||
else
|
||||
{
|
||||
SwitchToMapMode(CurrentMapMode());
|
||||
}
|
||||
}
|
||||
|
||||
bool Framework::DefaultMapModeHasContourLines()
|
||||
{
|
||||
bool hasContourLines;
|
||||
if (!settings::Get(kMapModeDefaultContourLinesKey, hasContourLines))
|
||||
hasContourLines = false;
|
||||
return hasContourLines;
|
||||
}
|
||||
|
||||
void Framework::DefaultMapModeSetContourLines(bool const hasContourLines)
|
||||
{
|
||||
settings::Set(kMapModeDefaultContourLinesKey, hasContourLines);
|
||||
RefreshMapMode();
|
||||
}
|
||||
|
||||
bool Framework::HikingMapModeHasContourLines()
|
||||
{
|
||||
bool hasContourLines;
|
||||
if (!settings::Get(kMapModeHikingContourLinesKey, hasContourLines))
|
||||
hasContourLines = false;
|
||||
return hasContourLines;
|
||||
}
|
||||
|
||||
void Framework::HikingMapModeSetContourLines(bool const hasContourLines)
|
||||
{
|
||||
settings::Set(kMapModeHikingContourLinesKey, hasContourLines);
|
||||
RefreshMapMode();
|
||||
}
|
||||
|
||||
bool Framework::CyclingMapModeHasContourLines()
|
||||
{
|
||||
bool hasContourLines;
|
||||
if (!settings::Get(kMapModeCyclingContourLinesKey, hasContourLines))
|
||||
hasContourLines = false;
|
||||
return hasContourLines;
|
||||
}
|
||||
|
||||
void Framework::CyclingMapModeSetContourLines(bool const hasContourLines)
|
||||
{
|
||||
settings::Set(kMapModeCyclingContourLinesKey, hasContourLines);
|
||||
RefreshMapMode();
|
||||
}
|
||||
|
||||
bool Framework::DrivingMapModeHasTraffic()
|
||||
{
|
||||
bool hasTraffic;
|
||||
if (!settings::Get(kMapModeDrivingTrafficKey, hasTraffic))
|
||||
hasTraffic = false;
|
||||
return hasTraffic;
|
||||
}
|
||||
|
||||
void Framework::DrivingMapModeSetTraffic(bool const hasTraffic)
|
||||
{
|
||||
settings::Set(kMapModeDrivingTrafficKey, hasTraffic);
|
||||
RefreshMapMode();
|
||||
}
|
||||
|
||||
bool Framework::PublicTransportMapModeHasTransitLines()
|
||||
{
|
||||
bool hasTransitLines;
|
||||
if (!settings::Get(kMapModePublicTransportTransitLinesKey, hasTransitLines))
|
||||
hasTransitLines = false;
|
||||
return hasTransitLines;
|
||||
}
|
||||
|
||||
void Framework::PublicTransportMapModeSetTransitLines(bool const hasTransitLines)
|
||||
{
|
||||
settings::Set(kMapModePublicTransportTransitLinesKey, hasTransitLines);
|
||||
RefreshMapMode();
|
||||
}
|
||||
|
||||
bool Framework::MapModeHasContourLines()
|
||||
{
|
||||
switch (CurrentMapMode())
|
||||
{
|
||||
case DEFAULT:
|
||||
return DefaultMapModeHasContourLines();
|
||||
case HIKING:
|
||||
return HikingMapModeHasContourLines();
|
||||
case CYCLING:
|
||||
return CyclingMapModeHasContourLines();
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Framework::MapModeHasTraffic()
|
||||
{
|
||||
return CurrentMapMode() == DRIVING && DrivingMapModeHasTraffic();
|
||||
}
|
||||
|
||||
bool Framework::MapModeHasTransitLines()
|
||||
{
|
||||
return CurrentMapMode() == PUBLICTRANSPORT && PublicTransportMapModeHasTransitLines();
|
||||
}
|
||||
|
||||
void Framework::RefreshMapMode()
|
||||
{
|
||||
bool const hasContourLines = MapModeHasContourLines();
|
||||
if (m_isolinesManager.IsEnabled() != hasContourLines)
|
||||
m_isolinesManager.SetEnabled(hasContourLines);
|
||||
|
||||
bool const hasTraffic = MapModeHasTraffic();
|
||||
if (m_trafficManager.IsEnabled() != hasTraffic)
|
||||
m_trafficManager.SetEnabled(hasTraffic);
|
||||
|
||||
bool const hasTransitLines = MapModeHasTransitLines();
|
||||
if (m_transitManager.IsTransitSchemeModeEnabled() != hasTransitLines)
|
||||
m_transitManager.EnableTransitSchemeMode(hasTransitLines);
|
||||
}
|
||||
|
||||
void Framework::EnableChoosePositionMode(bool enable, bool enableBounds, m2::PointD const * optionalPosition)
|
||||
@@ -2589,17 +2737,13 @@ bool Framework::ParseDrapeDebugCommand(string const & query)
|
||||
{
|
||||
MapStyle desiredStyle = MapStyleCount;
|
||||
if (query == "?dark" || query == "mapstyle:dark")
|
||||
desiredStyle = MapStyleDefaultDark;
|
||||
desiredStyle = MapStyleDefaultDark; // TODO: Mode
|
||||
else if (query == "?light" || query == "mapstyle:light")
|
||||
desiredStyle = MapStyleDefaultLight;
|
||||
desiredStyle = MapStyleDefaultLight; // TODO: Mode
|
||||
else if (query == "?vlight" || query == "mapstyle:vehicle_light")
|
||||
desiredStyle = MapStyleVehicleLight;
|
||||
else if (query == "?vdark" || query == "mapstyle:vehicle_dark")
|
||||
desiredStyle = MapStyleVehicleDark;
|
||||
else if (query == "?olight" || query == "mapstyle:outdoors_light")
|
||||
desiredStyle = MapStyleOutdoorsLight;
|
||||
else if (query == "?odark" || query == "mapstyle:outdoors_dark")
|
||||
desiredStyle = MapStyleOutdoorsDark;
|
||||
|
||||
if (desiredStyle != MapStyleCount)
|
||||
{
|
||||
@@ -3215,10 +3359,9 @@ void Framework::OnRouteFollow(routing::RouterType type)
|
||||
++scale3d;
|
||||
|
||||
bool const isBicycleRoute = type == RouterType::Bicycle;
|
||||
if ((isPedestrianRoute || isBicycleRoute) && LoadTrafficEnabled())
|
||||
if ((isPedestrianRoute || isBicycleRoute) && MapModeHasTraffic())
|
||||
{
|
||||
m_trafficManager.SetEnabled(false /* enabled */);
|
||||
SaveTrafficEnabled(false /* enabled */);
|
||||
}
|
||||
// TODO. We need to sync two enums VehicleType and RouterType to be able to pass
|
||||
// GetRoutingSettings(type).m_matchRoute to the FollowRoute() instead of |isPedestrianRoute|.
|
||||
@@ -3279,16 +3422,16 @@ void Framework::OnPowerFacilityChanged(power_management::Facility const facility
|
||||
}
|
||||
else if (facility == power_management::Facility::TrafficJams)
|
||||
{
|
||||
auto trafficState = enabled && LoadTrafficEnabled();
|
||||
if (trafficState == GetTrafficManager().IsEnabled())
|
||||
auto trafficState = enabled && MapModeHasTraffic();
|
||||
if (trafficState == m_trafficManager.IsEnabled())
|
||||
return;
|
||||
|
||||
GetTrafficManager().SetEnabled(trafficState);
|
||||
m_trafficManager.SetEnabled(trafficState);
|
||||
}
|
||||
}
|
||||
|
||||
void Framework::OnPowerSchemeChanged(power_management::Scheme const actualScheme)
|
||||
{
|
||||
if (actualScheme == power_management::Scheme::EconomyMaximum && GetTrafficManager().IsEnabled())
|
||||
GetTrafficManager().SetEnabled(false);
|
||||
if (actualScheme == power_management::Scheme::EconomyMaximum && m_trafficManager.IsEnabled())
|
||||
m_trafficManager.SetEnabled(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user