Skip to content

Commit

Permalink
リモートURL設定追加
Browse files Browse the repository at this point in the history
  • Loading branch information
veigr committed Sep 14, 2018
1 parent 5c96fbc commit 20fa718
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 15 deletions.
1 change: 1 addition & 0 deletions EventMapHpViewer/EventMapHpViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<Compile Include="ViewModels\Settings\SettingsViewModel.cs" />
<Compile Include="ViewModels\Settings\TpSettingsViewModel.cs" />
<Compile Include="Views\Controls\DecimalRule.cs" />
<Compile Include="Views\Controls\BossSettingsUrlRule.cs" />
<Compile Include="Views\SettingsView.xaml.cs">
<DependentUpon>SettingsView.xaml</DependentUpon>
</Compile>
Expand Down
2 changes: 1 addition & 1 deletion EventMapHpViewer/MapHpViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 6 additions & 1 deletion EventMapHpViewer/Models/MapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ public async Task<RemainingCount> GetRemainingCount()
else
{
var client = new RemoteSettingsClient();
var remoteBossData = await client.GetSettings<Raw.map_exboss[]>($"https://kctadil.azurewebsites.net/map/maphp/v3.2/{this.Id}/{this.Eventmap.SelectedRank}");
var remoteBossData = await client.GetSettings<Raw.map_exboss[]>(
RemoteSettingsClient.BuildBossSettingsUrl(
MapHpSettings.RemoteBossSettingsUrl,
this.Id,
(int)this.Eventmap.SelectedRank,
this.Eventmap.GaugeNum ?? 1));
client.CloseConnection();

if (remoteBossData == null)
Expand Down
25 changes: 20 additions & 5 deletions EventMapHpViewer/Models/Settings/MapHpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ static class MapHpSettings
= new SerializableProperty<decimal>(GetKey(), roamingProvider) { AutoSave = true };

public static SerializableProperty<string> ShipTypeTpSettings { get; }
= new SerializableProperty<string>(GetKey(), roamingProvider, DynamicJson.Serialize(AutoCalcTpSettings.Default.ShipTypeTp.ToArray())) { AutoSave = true };
= new SerializableProperty<string>(GetKey(), roamingProvider,
DynamicJson.Serialize(AutoCalcTpSettings.Default.ShipTypeTp.ToArray()
)) { AutoSave = true };

public static SerializableProperty<string> SlotItemTpSettings { get; }
= new SerializableProperty<string>(GetKey(), roamingProvider, DynamicJson.Serialize(AutoCalcTpSettings.Default.SlotItemTp.ToArray())) { AutoSave = true };
= new SerializableProperty<string>(GetKey(), roamingProvider,
DynamicJson.Serialize(AutoCalcTpSettings.Default.SlotItemTp.ToArray()
)) { AutoSave = true };

public static SerializableProperty<string> ShipTpSettings { get; }
= new SerializableProperty<string>(GetKey(), roamingProvider, DynamicJson.Serialize(AutoCalcTpSettings.Default.ShipTp.ToArray())) { AutoSave = true };
= new SerializableProperty<string>(GetKey(), roamingProvider,
DynamicJson.Serialize(AutoCalcTpSettings.Default.ShipTp.ToArray()
)) { AutoSave = true };

public static SerializableProperty<bool> UseAutoCalcTpSettings { get; }
= new SerializableProperty<bool>(GetKey(), roamingProvider, true) { AutoSave = true };
= new SerializableProperty<bool>(GetKey(), roamingProvider,
true
) { AutoSave = true };

#endregion

Expand All @@ -43,7 +51,14 @@ static class MapHpSettings
= new SerializableProperty<string>(GetKey(), roamingProvider) { AutoSave = true };

public static SerializableProperty<bool> UseLocalBossSettings { get; }
= new SerializableProperty<bool>(GetKey(), roamingProvider, false) { AutoSave = true };
= new SerializableProperty<bool>(GetKey(), roamingProvider,
false
) { AutoSave = true };

public static SerializableProperty<string> RemoteBossSettingsUrl { get; }
= new SerializableProperty<string>(GetKey(), roamingProvider,
"https://kctadil-admin.azurewebsites.net/admin/maphp/{version}/{id}/{rank}/{gaugeNum}"
) { AutoSave = true };

#endregion

Expand Down
24 changes: 24 additions & 0 deletions EventMapHpViewer/Models/Settings/RemoteSettingsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +80,7 @@ public async Task<T> GetSettings<T>(string url)
}
try
{
Debug.WriteLine($"MapHP - GET: {url}");
var response = await client.GetAsync(url);
if (!response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -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<string, string>
{
{ "version", $"{MapHpViewer.version}" },
{ "id", id.ToString() },
{ "rank", rank.ToString() },
{ "gaugeNum", gaugeNum.ToString() },
});
}

public static string BuildUrl(string url, IDictionary<string, string> placeHolders)
{
if (placeHolders == null)
return url;
foreach(var placeHolder in placeHolders)
{
url = url.Replace($"{{{placeHolder.Key}}}", placeHolder.Value);
}
return url;
}
}
}
2 changes: 1 addition & 1 deletion EventMapHpViewer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.3.4.0")]
[assembly: AssemblyVersion("3.4.0.0")]
22 changes: 22 additions & 0 deletions EventMapHpViewer/ViewModels/Settings/BossSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,23 @@ public ReadOnlyNotifyChangedCollection<BossSetting> 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()
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions EventMapHpViewer/ViewModels/ToolViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 37 additions & 0 deletions EventMapHpViewer/Views/Controls/BossSettingsUrlRule.cs
Original file line number Diff line number Diff line change
@@ -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 形式を入力して下さい。");
}
}
}
}
55 changes: 48 additions & 7 deletions EventMapHpViewer/Views/Settings/BossSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<UserControl.Resources>
<ResourceDictionary>
Expand Down Expand Up @@ -45,6 +46,7 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
Expand All @@ -56,14 +58,53 @@
Content="リモートから情報を取得する"
Margin="0,0,0,10"
IsChecked="{Binding UseLocalBossSettings, Converter={StaticResource ReverseBooelanConverter}}"/>
<RadioButton Grid.Row="1"

<StackPanel Grid.Row="1"
Grid.ColumnSpan="2"
IsEnabled="{Binding UseLocalBossSettings, Converter={StaticResource ReverseBooelanConverter}}">
<Grid Margin="8,0,4,4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
Text="URL: "/>
<metro:PromptTextBox Grid.Column="1"
Margin="0,0,8,0"
VerticalAlignment="Center">
<Binding Path="RemoteBossSettingsUrl"
Mode="TwoWay"
UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<controls:BossSettingsUrlRule/>
</Binding.ValidationRules>
</Binding>
</metro:PromptTextBox>
<metro2:CallMethodButton Grid.Column="2"
MethodTarget="{Binding}"
MethodName="RestoreDefaultRemoteBossSettingsUrl"
Content="既定値に戻す"
Width="110"
Padding="16,6"/>
</Grid>
<TextBlock Style="{DynamicResource DefaultTextStyleKey}"
Margin="8,0,0,8">
<Run Text="{}{version}: プラグイン バージョン"/><LineBreak/>
<Run Text="{}{id}: マップ ID"/><LineBreak/>
<Run Text="{}{rank}: 難易度"/><LineBreak/>
<Run Text="{}{gaugeNum}: ゲージ番号"/>
</TextBlock>
</StackPanel>

<RadioButton Grid.Row="2"
Grid.ColumnSpan="2"
GroupName="BossSettings"
Content="自分で設定する"
Margin="0,0,0,10"
IsChecked="{Binding UseLocalBossSettings}"/>

<ListView Grid.Row="2"
<ListView Grid.Row="3"
Grid.Column="0"
IsEnabled="{Binding UseLocalBossSettings}"
ItemsSource="{Binding BossSettings}"
Expand Down Expand Up @@ -103,9 +144,9 @@
</ListView.View>
</ListView>

<Grid Grid.Row="2"
<Grid Grid.Row="3"
Grid.Column="1"
Margin="5,0"
Margin="4,0"
IsEnabled="{Binding UseLocalBossSettings}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand Down

0 comments on commit 20fa718

Please sign in to comment.