diff --git a/Include/DataRefs.h b/Include/DataRefs.h index 70aaa6d..e0232c3 100644 --- a/Include/DataRefs.h +++ b/Include/DataRefs.h @@ -725,7 +725,7 @@ class DataRefs SimTimeCtrlTy rtSTC = STC_SIM_TIME_PLUS_BUFFER; ///< Which sim time to send to RealTraffic? int rtManTOfs = 0; ///< manually configure time offset for requesting historic data RTConnTypeTy rtConnType = RT_CONN_REQU_REPL; ///< Which type of connection to use for RealTraffic data - int rtSetWeather = 0; ///< Set X-Plane's weather based on RealTraffic weather data + int rtSetWeather = 1; ///< Set X-Plane's weather based on RealTraffic weather data? (0-Off, 1-Auto, 2-On) int ffListenPort = 63093; ///< UDP Port to listen to ForeFlight announcing itself, https://www.foreflight.com/connect/spec/ int ffSendPort = 49002; ///< UDP Port to send simulator data to ForeFlight, https://www.foreflight.com/support/network-gps/ int bffUserPlane = 1; // bool Send User plane data? @@ -993,7 +993,7 @@ class DataRefs RTConnTypeTy GetRTConnType () const { return rtConnType; } const std::string& GetRTLicense () const { return sRTLicense; } void SetRTLicense (const std::string& license) { sRTLicense = license; } - bool ShallSetRTWeather() const { return rtSetWeather; } + int GetRTSetWeather() const { return rtSetWeather; } size_t GetFSCEnv() const { return (size_t)fscEnv; } void GetFSCharterCredentials (std::string& user, std::string& pwd) diff --git a/Include/LTWeather.h b/Include/LTWeather.h index ef657ae..e631d59 100644 --- a/Include/LTWeather.h +++ b/Include/LTWeather.h @@ -23,16 +23,23 @@ /// Initialize Weather module, dataRefs bool WeatherInit (); +/// Shutdown Weather module +void WeatherStop (); + +/// Can we, technically, set weather? (X-Plane 12 forward only) +bool WeatherCanSet (); +/// Shall we actuall set the weather as per ability and user's configuration? +bool WeatherShallSet (); + /// Indicate that we are taking control now void WeatherTakeControl (); /// Are we controlling weather? bool WeatherInControl (); -/// Return a human readable string on the weather source, is "LiveTraffic" if WeatherInControl() -std::string WeatherGetSource (); /// Reset weather settings to what they were before X-Plane took over void WeatherReset (); -/// Shutdown Weather module -void WeatherStop (); + +/// Return a human readable string on the weather source, is "LiveTraffic" if WeatherInControl() +std::string WeatherGetSource (); // // MARK: Set X-Plane Weather @@ -105,9 +112,6 @@ struct LTWeather }; -/// Can we set weather? (X-Plane 12 forward only) -bool WeatherCanSet (); - // // MARK: Fetch METAR // diff --git a/Src/DataRefs.cpp b/Src/DataRefs.cpp index be2a557..8cf86d9 100644 --- a/Src/DataRefs.cpp +++ b/Src/DataRefs.cpp @@ -564,7 +564,7 @@ DataRefs::dataRefDefinitionT DATA_REFS_LT[CNT_DATAREFS_LT] = { {"livetraffic/channel/real_traffic/sim_time_ctrl",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true }, {"livetraffic/channel/real_traffic/man_toffset",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true }, {"livetraffic/channel/real_traffic/connect_type",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true }, - {"livetraffic/channel/real_traffic/set_weather",DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true, true }, + {"livetraffic/channel/real_traffic/set_weather",DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true }, {"livetraffic/channel/fore_flight/listen_port", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true }, {"livetraffic/channel/fore_flight/send_port", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true }, {"livetraffic/channel/fore_flight/user_plane", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true }, diff --git a/Src/LTRealTraffic.cpp b/Src/LTRealTraffic.cpp index 105fa64..ed2f311 100644 --- a/Src/LTRealTraffic.cpp +++ b/Src/LTRealTraffic.cpp @@ -555,7 +555,7 @@ bool RealTrafficConnection::ProcessFetchedData () } // If requested to set X-Plane's weather process the detailed weather data - if (WeatherCanSet() && dataRefs.ShallSetRTWeather()) + if (WeatherShallSet()) ProcessWeather (json_object_get_object(pObj, "data")); // Successfully received local pressure information diff --git a/Src/LTWeather.cpp b/Src/LTWeather.cpp index 492c9b3..25bb32a 100644 --- a/Src/LTWeather.cpp +++ b/Src/LTWeather.cpp @@ -653,6 +653,39 @@ bool WeatherInit () return bWeatherCanSet; } +// Shutdown Weather module +void WeatherStop () +{ + WeatherReset(); +} + +// Can we set weather? (X-Plane 12 forward only) +bool WeatherCanSet () +{ + return bWeatherCanSet; +} + +// Shall we actuall set the weather as per ability and user's configuration? +bool WeatherShallSet () +{ + bool bRet = false; + if (WeatherCanSet() && dataRefs.GetRTSetWeather() > 0) // can and want? + bRet = dataRefs.GetRTSetWeather() == 2 || // user always wants + wdr_weather_source.get() == 1; // or real weather is on + + // So should we be off but aren't? + if (!bRet && WeatherInControl()) + { + if (dataRefs.GetRTSetWeather() > 0) { // if user still wants per LiveTraffic's config + weatherOrigSource = -1; // then don't actually touch XP's settings any longer, because the user must have done so already + weatherOrigChangeMode = -1; + } + WeatherReset(); + } + + return bRet; +} + // Indicate that we are taking control now void WeatherTakeControl () { @@ -679,30 +712,6 @@ bool WeatherInControl () return bWeatherControlling; } -/// Return a human readable string on the weather source, is "LiveTraffic" if WeatherInControl() -std::string WeatherGetSource () -{ - // Preset closest to current conditions - static std::array WEATHER_PRESETS = { - "Clear", "VFR Few", "VFR Scattered", "VFR Broken", "VFR Marginal", "IFR Non-precision", "IFR Precision", "Convective", "Large-cell Storms", "Unknown" - }; - int preset = wdr_weather_preset.get(); - if (preset < 0 || preset > 8) preset = 9; // 'Unknown' - - // Weather Source - static std::array WEATHER_SOURCES = { - "X-Plane Preset", "X-Plane Real Weather", "Controlpad", "Plugin", "Unknown" - }; - int source = wdr_weather_source.get(); - if (source < 0 || source > 3) source = 4; - - // Are we in control? Say so! - if (WeatherInControl()) - return std::string("LiveTraffic using RealTraffic data, ") + WEATHER_PRESETS[size_t(preset)]; - else - return std::string(WEATHER_SOURCES[size_t(source)]) + ", " + WEATHER_PRESETS[size_t(preset)]; -} - // Reset weather settings to what they were before X-Plane took over void WeatherReset () { @@ -723,18 +732,29 @@ void WeatherReset () weatherOrigChangeMode = -1; } -// Shutdown Weather module -void WeatherStop () +/// Return a human readable string on the weather source, is "LiveTraffic" if WeatherInControl() +std::string WeatherGetSource () { - WeatherReset(); -} + // Preset closest to current conditions + static std::array WEATHER_PRESETS = { + "Clear", "VFR Few", "VFR Scattered", "VFR Broken", "VFR Marginal", "IFR Non-precision", "IFR Precision", "Convective", "Large-cell Storms", "Unknown" + }; + int preset = wdr_weather_preset.get(); + if (preset < 0 || preset > 8) preset = 9; // 'Unknown' -// Can we set weather? (X-Plane 12 forward only) -bool WeatherCanSet () -{ - return bWeatherCanSet; -} + // Weather Source + static std::array WEATHER_SOURCES = { + "X-Plane Preset", "X-Plane Real Weather", "Controlpad", "Plugin", "Unknown" + }; + int source = wdr_weather_source.get(); + if (source < 0 || source > 3) source = 4; + // Are we in control? Say so! + if (WeatherInControl()) + return std::string("LiveTraffic using RealTraffic data, ") + WEATHER_PRESETS[size_t(preset)]; + else + return std::string(WEATHER_SOURCES[size_t(source)]) + ", " + WEATHER_PRESETS[size_t(preset)]; +} /// Is currently an async operation running to fetch METAR? static std::future futWeather; diff --git a/Src/SettingsUI.cpp b/Src/SettingsUI.cpp index 745660d..aff32b3 100644 --- a/Src/SettingsUI.cpp +++ b/Src/SettingsUI.cpp @@ -586,9 +586,19 @@ void LTSettingsUI::buildInterface() } // Weather - ImGui::FilteredCfgCheckbox("Set Weather from RealTraffic", sFilter, DR_CFG_RT_SET_WEATHER, - "Set X-Plane's weather based on RealTraffic's weather information (also historically)"); - + if (ImGui::FilteredLabel("Set Weather from RealTraffic", sFilter, WeatherCanSet())) { + if (WeatherCanSet()) { + const float cbWidth = ImGui::CalcTextSize("Auto (if XP set to real weather)____").x; + ImGui::SetNextItemWidth(cbWidth); + int n = dataRefs.GetRTSetWeather(); + if (ImGui::Combo("##RTSetWeather", &n, "Off\0Auto (if XP set to real weather)\0On\0", 3)) + DATA_REFS_LT[DR_CFG_RT_SET_WEATHER].setData(n); + } else { + ImGui::TextUnformatted("Setting weather is supported in X-Plane 12 and later"); + } + ImGui::TableNextCell(); + } + // Historic Data if (ImGui::FilteredLabel("Request Historic Data", sFilter)) { float cbWidth = ImGui::CalcTextSize("Use live data, not historic_____").x;