diff --git a/EventMapHpViewer/EventMapHpViewer.csproj b/EventMapHpViewer/EventMapHpViewer.csproj index 312d8fc..12d4c35 100644 --- a/EventMapHpViewer/EventMapHpViewer.csproj +++ b/EventMapHpViewer/EventMapHpViewer.csproj @@ -165,6 +165,7 @@ + SettingsView.xaml diff --git a/EventMapHpViewer/MapHpViewer.cs b/EventMapHpViewer/MapHpViewer.cs index 933da04..61a26f0 100644 --- a/EventMapHpViewer/MapHpViewer.cs +++ b/EventMapHpViewer/MapHpViewer.cs @@ -18,7 +18,7 @@ namespace EventMapHpViewer public class MapHpViewer : IPlugin, ITool, ISettings { internal const string title = "MapHPViewer"; - internal const string version = "3.3.4"; + internal const string version = "3.4.0"; private ToolViewModel toolVm; private SettingsViewModel settingsVm; diff --git a/EventMapHpViewer/Models/MapData.cs b/EventMapHpViewer/Models/MapData.cs index d00e36a..8b5f6e2 100644 --- a/EventMapHpViewer/Models/MapData.cs +++ b/EventMapHpViewer/Models/MapData.cs @@ -86,7 +86,12 @@ public async Task GetRemainingCount() else { var client = new RemoteSettingsClient(); - var remoteBossData = await client.GetSettings($"https://kctadil.azurewebsites.net/map/maphp/v3.2/{this.Id}/{this.Eventmap.SelectedRank}"); + var remoteBossData = await client.GetSettings( + RemoteSettingsClient.BuildBossSettingsUrl( + MapHpSettings.RemoteBossSettingsUrl, + this.Id, + (int)this.Eventmap.SelectedRank, + this.Eventmap.GaugeNum ?? 1)); client.CloseConnection(); if (remoteBossData == null) diff --git a/EventMapHpViewer/Models/Settings/MapHpSettings.cs b/EventMapHpViewer/Models/Settings/MapHpSettings.cs index 4f3762e..5f5ce53 100644 --- a/EventMapHpViewer/Models/Settings/MapHpSettings.cs +++ b/EventMapHpViewer/Models/Settings/MapHpSettings.cs @@ -24,16 +24,24 @@ static class MapHpSettings = new SerializableProperty(GetKey(), roamingProvider) { AutoSave = true }; public static SerializableProperty ShipTypeTpSettings { get; } - = new SerializableProperty(GetKey(), roamingProvider, DynamicJson.Serialize(AutoCalcTpSettings.Default.ShipTypeTp.ToArray())) { AutoSave = true }; + = new SerializableProperty(GetKey(), roamingProvider, + DynamicJson.Serialize(AutoCalcTpSettings.Default.ShipTypeTp.ToArray() + )) { AutoSave = true }; public static SerializableProperty SlotItemTpSettings { get; } - = new SerializableProperty(GetKey(), roamingProvider, DynamicJson.Serialize(AutoCalcTpSettings.Default.SlotItemTp.ToArray())) { AutoSave = true }; + = new SerializableProperty(GetKey(), roamingProvider, + DynamicJson.Serialize(AutoCalcTpSettings.Default.SlotItemTp.ToArray() + )) { AutoSave = true }; public static SerializableProperty ShipTpSettings { get; } - = new SerializableProperty(GetKey(), roamingProvider, DynamicJson.Serialize(AutoCalcTpSettings.Default.ShipTp.ToArray())) { AutoSave = true }; + = new SerializableProperty(GetKey(), roamingProvider, + DynamicJson.Serialize(AutoCalcTpSettings.Default.ShipTp.ToArray() + )) { AutoSave = true }; public static SerializableProperty UseAutoCalcTpSettings { get; } - = new SerializableProperty(GetKey(), roamingProvider, true) { AutoSave = true }; + = new SerializableProperty(GetKey(), roamingProvider, + true + ) { AutoSave = true }; #endregion @@ -43,7 +51,14 @@ static class MapHpSettings = new SerializableProperty(GetKey(), roamingProvider) { AutoSave = true }; public static SerializableProperty UseLocalBossSettings { get; } - = new SerializableProperty(GetKey(), roamingProvider, false) { AutoSave = true }; + = new SerializableProperty(GetKey(), roamingProvider, + false + ) { AutoSave = true }; + + public static SerializableProperty RemoteBossSettingsUrl { get; } + = new SerializableProperty(GetKey(), roamingProvider, + "https://kctadil-admin.azurewebsites.net/admin/maphp/{version}/{id}/{rank}/{gaugeNum}" + ) { AutoSave = true }; #endregion diff --git a/EventMapHpViewer/Models/Settings/RemoteSettingsClient.cs b/EventMapHpViewer/Models/Settings/RemoteSettingsClient.cs index 2746a58..35cc807 100644 --- a/EventMapHpViewer/Models/Settings/RemoteSettingsClient.cs +++ b/EventMapHpViewer/Models/Settings/RemoteSettingsClient.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Net; using System.Net.Http; +using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -79,6 +80,7 @@ public async Task GetSettings(string url) } try { + Debug.WriteLine($"MapHP - GET: {url}"); var response = await client.GetAsync(url); if (!response.IsSuccessStatusCode) { @@ -144,5 +146,27 @@ private static HttpClientHandler GetProxyConfiguredHandler() return new HttpClientHandler(); } } + + public static string BuildBossSettingsUrl(string url, int id, int rank, int gaugeNum) + { + return BuildUrl(url, new Dictionary + { + { "version", $"{MapHpViewer.version}" }, + { "id", id.ToString() }, + { "rank", rank.ToString() }, + { "gaugeNum", gaugeNum.ToString() }, + }); + } + + public static string BuildUrl(string url, IDictionary placeHolders) + { + if (placeHolders == null) + return url; + foreach(var placeHolder in placeHolders) + { + url = url.Replace($"{{{placeHolder.Key}}}", placeHolder.Value); + } + return url; + } } } diff --git a/EventMapHpViewer/Properties/AssemblyInfo.cs b/EventMapHpViewer/Properties/AssemblyInfo.cs index 1f805f6..7101c5b 100644 --- a/EventMapHpViewer/Properties/AssemblyInfo.cs +++ b/EventMapHpViewer/Properties/AssemblyInfo.cs @@ -43,4 +43,4 @@ // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を // 既定値にすることができます: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.3.4.0")] +[assembly: AssemblyVersion("3.4.0.0")] diff --git a/EventMapHpViewer/ViewModels/Settings/BossSettingsViewModel.cs b/EventMapHpViewer/ViewModels/Settings/BossSettingsViewModel.cs index b0a6a8b..097bf33 100644 --- a/EventMapHpViewer/ViewModels/Settings/BossSettingsViewModel.cs +++ b/EventMapHpViewer/ViewModels/Settings/BossSettingsViewModel.cs @@ -210,6 +210,23 @@ public ReadOnlyNotifyChangedCollection BossSettings } #endregion + #region RemoteBossSettingsUrl + public string RemoteBossSettingsUrl + { + get => MapHpSettings.RemoteBossSettingsUrl.Value; + set + { + if (MapHpSettings.RemoteBossSettingsUrl.Value == value) + return; + if (value == null) + MapHpSettings.RemoteBossSettingsUrl.Reset(); + else + MapHpSettings.RemoteBossSettingsUrl.Value = value; + this.RaisePropertyChanged(); + } + } + #endregion + private BossSettingsWrapper Settings { get; } public BossSettingsViewModel() @@ -251,6 +268,11 @@ public void Remove() this.UpdateButtonState(); } + public void RestoreDefaultRemoteBossSettingsUrl() + { + this.RemoteBossSettingsUrl = MapHpSettings.RemoteBossSettingsUrl?.Default; + } + private void UpdateButtonState() { this.RaisePropertyChanged(nameof(this.IsAddEnabled)); diff --git a/EventMapHpViewer/ViewModels/ToolViewModel.cs b/EventMapHpViewer/ViewModels/ToolViewModel.cs index 2a35dd3..f153a67 100644 --- a/EventMapHpViewer/ViewModels/ToolViewModel.cs +++ b/EventMapHpViewer/ViewModels/ToolViewModel.cs @@ -46,6 +46,8 @@ public ToolViewModel(MapInfoProxy proxy) MapHpSettings.UseLocalBossSettings.Subscribe(_ => this.UpdateRemainingCount()).AddTo(this); MapHpSettings.BossSettings.Subscribe(_ => this.UpdateRemainingCount()).AddTo(this); + // RemoteBossSettingsUrl は文字入力の度にリクエスト飛ぶようになるのは現実的ではないので、変更検知しない + //MapHpSettings.RemoteBossSettingsUrl.Subscribe(_ => this.UpdateRemainingCount()).AddTo(this); MapHpSettings.UseAutoCalcTpSettings.Subscribe(_ => this.UpdateTransportCapacity()).AddTo(this); MapHpSettings.TransportCapacityS.Subscribe(_ => this.UpdateTransportCapacity()).AddTo(this); diff --git a/EventMapHpViewer/Views/Controls/BossSettingsUrlRule.cs b/EventMapHpViewer/Views/Controls/BossSettingsUrlRule.cs new file mode 100644 index 0000000..e1bbb7f --- /dev/null +++ b/EventMapHpViewer/Views/Controls/BossSettingsUrlRule.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Controls; +using EventMapHpViewer.Models.Settings; + +namespace EventMapHpViewer.Views.Controls +{ + public class BossSettingsUrlRule : ValidationRule + { + public bool AllowsEmpty { get; set; } + + public override ValidationResult Validate(object value, CultureInfo cultureInfo) + { + var urlAsString = value as string; + if (string.IsNullOrEmpty(urlAsString)) + { + return this.AllowsEmpty + ? new ValidationResult(true, null) + : new ValidationResult(false, "値を入力してください。"); + } + + var url = RemoteSettingsClient.BuildBossSettingsUrl(urlAsString, 0, 0, 0); + + if(Uri.TryCreate(url, UriKind.Absolute, out var _)) + { + return new ValidationResult(true, null); + } + else + { + return new ValidationResult(false, "URL 形式を入力して下さい。"); + } + } + } +} diff --git a/EventMapHpViewer/Views/Settings/BossSettings.xaml b/EventMapHpViewer/Views/Settings/BossSettings.xaml index f98ba99..17db2ba 100644 --- a/EventMapHpViewer/Views/Settings/BossSettings.xaml +++ b/EventMapHpViewer/Views/Settings/BossSettings.xaml @@ -7,12 +7,13 @@ xmlns:metro="http://schemes.grabacr.net/winfx/2014/controls" xmlns:metro2="http://schemes.grabacr.net/winfx/2015/personal/controls" xmlns:vm="clr-namespace:EventMapHpViewer.ViewModels.Settings" + xmlns:controls="clr-namespace:EventMapHpViewer.Views.Controls" mc:Ignorable="d" d:DesignWidth="595" - d:DesignHeight="270" + d:DesignHeight="388" d:DataContext="{d:DesignInstance vm:BossSettingsViewModel}" - MinWidth="314" - MinHeight="270"> + MinWidth="315" + MinHeight="390"> @@ -45,6 +46,7 @@ + @@ -56,14 +58,53 @@ Content="リモートから情報を取得する" Margin="0,0,0,10" IsChecked="{Binding UseLocalBossSettings, Converter={StaticResource ReverseBooelanConverter}}"/> - + + + + + + + + + + + + + + + + + + + + + + + + + - -