Skip to content

Commit

Permalink
索敵値の計算方法を選択できるように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
Grabacr07 committed Aug 9, 2014
1 parent 5015d5b commit 20bddd4
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Threading.Tasks;
using Grabacr07.KanColleViewer.Properties;
using Grabacr07.KanColleWrapper;
using Grabacr07.KanColleWrapper.Models;
using Livet;
using Livet.EventListeners;
Expand Down
43 changes: 43 additions & 0 deletions Grabacr07.KanColleViewer/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,46 @@ public List<ToolViewModel> ToolPlugins
#endregion


#region ViewRangeType1 変更通知プロパティ

private bool _ViewRangeType1;

public bool ViewRangeType1
{
get { return this._ViewRangeType1; }
set
{
if (this._ViewRangeType1 != value)
{
this._ViewRangeType1 = value;
this.RaisePropertyChanged();
if (value) Settings.Current.KanColleClientSettings.ViewRangeCalcLogic = ViewRangeCalcLogic.Type1;
}
}
}

#endregion

#region ViewRangeType2 変更通知プロパティ

private bool _ViewRangeType2;

public bool ViewRangeType2
{
get { return this._ViewRangeType2; }
set
{
if (this._ViewRangeType2 != value)
{
this._ViewRangeType2 = value;
this.RaisePropertyChanged();
if (value) Settings.Current.KanColleClientSettings.ViewRangeCalcLogic = ViewRangeCalcLogic.Type2;
}
}
}

#endregion


public SettingsViewModel()
{
Expand Down Expand Up @@ -283,6 +323,9 @@ public SettingsViewModel()
});
this.BrowserZoomFactor = zoomFactor;

this._ViewRangeType1 = Settings.Current.KanColleClientSettings.ViewRangeCalcLogic == ViewRangeCalcLogic.Type1;
this._ViewRangeType2 = Settings.Current.KanColleClientSettings.ViewRangeCalcLogic == ViewRangeCalcLogic.Type2;

this.ReloadPlugins();
}

Expand Down
60 changes: 31 additions & 29 deletions Grabacr07.KanColleViewer/Views/Settings/Notification.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,34 +110,36 @@
Style="{DynamicResource SettingsHeaderTextStyleKey}"
Margin="0,10,0,8" />

<TextBlock Text="以下のプラグインを使用して通知されます。"
Style="{DynamicResource DetailTextStyleKey}"
Foreground="{DynamicResource ActiveForegroundBrushKey}" />

<ItemsControl ItemsSource="{Binding NotifierPlugins}"
Margin="0,5">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1"
BorderBrush="{DynamicResource BorderBrushKey}"
Margin="0,5"
Padding="5">
<DockPanel>
<TextBlock DockPanel.Dock="Bottom"
Text="{Binding ErrorMessage}"
HorizontalAlignment="Right"
Visibility="{Binding ErrorMessage, Converter={StaticResource StringToVisiblityConverter}}" />
<controls:CallMethodButton DockPanel.Dock="Right"
Content="テスト"
MethodName="Test"
Padding="8,6"
Margin="5,0,0,0"
VerticalAlignment="Center" />
<settings:PluginInfo />
</DockPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<StackPanel Margin="20,0,0,0">
<TextBlock Text="以下のプラグインを使用して通知されます。"
Style="{DynamicResource DetailTextStyleKey}"
Foreground="{DynamicResource ActiveForegroundBrushKey}" />

<ItemsControl ItemsSource="{Binding NotifierPlugins}"
Margin="0,5">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1"
BorderBrush="{DynamicResource BorderBrushKey}"
Margin="0,5"
Padding="5">
<DockPanel>
<TextBlock DockPanel.Dock="Bottom"
Text="{Binding ErrorMessage}"
HorizontalAlignment="Right"
Visibility="{Binding ErrorMessage, Converter={StaticResource StringToVisiblityConverter}}" />
<controls:CallMethodButton DockPanel.Dock="Right"
Content="テスト"
MethodName="Test"
Padding="8,6"
Margin="5,0,0,0"
VerticalAlignment="Center" />
<settings:PluginInfo />
</DockPanel>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</StackPanel>
</UserControl>
45 changes: 45 additions & 0 deletions Grabacr07.KanColleViewer/Views/Settings/Operation.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,50 @@
<Rectangle Height="1"
Style="{DynamicResource SeparatorRectangleStyleKey}" />

<TextBlock Text="索敵値計算"
Style="{DynamicResource SettingsHeaderTextStyleKey}"
Margin="0,10" />

<StackPanel Margin="20,0,0,0">
<TextBlock Text="艦隊の索敵値の算出に使用する計算式は、以下を使用する" />

<StackPanel Margin="0,5">
<RadioButton IsChecked="{Binding ViewRangeType1}"
Margin="0,5">
<TextBlock Style="{DynamicResource DefaultTextStyleKey}"
LineHeight="16">
<Run Text="艦娘と装備の索敵値の単純な合計"
Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type RadioButton}}, Path=Foreground}" />
<LineBreak />
<Run Text="KanColleViewer での従来の計算方法" />
</TextBlock>
</RadioButton>

<RadioButton IsChecked="{Binding ViewRangeType2}"
Margin="0,5">
<TextBlock Style="{DynamicResource DefaultTextStyleKey}"
LineHeight="18">
<Run Text="(偵察機 × 2) + (電探) + √(装備込みの艦隊索敵値合計 - 偵察機 - 電探)"
Foreground="{Binding RelativeSource={RelativeSource AncestorType={x:Type RadioButton}}, Path=Foreground}" />
<LineBreak />
<Run Text="装備による索敵値が重要とされる場合の計算方法 (推定)" />
<LineBreak />
<Run Text="偵察機" />
<Run Text="" />
<Run Text="水上偵察機"
ToolTip="零式水上偵察機、零式水上観測機、九八式水上偵察機(夜偵)" />
<Run Text="" />
<Run Text="水上爆撃機"
ToolTip="瑞雲、瑞雲(六三四空)、試製晴嵐" />
<Run Text="" />
<Run Text="艦上偵察機"
ToolTip="彩雲、二式艦上偵察機" />
</TextBlock>
</RadioButton>
</StackPanel>
</StackPanel>

<Rectangle Height="1"
Style="{DynamicResource SeparatorRectangleStyleKey}" />
</StackPanel>
</UserControl>
54 changes: 54 additions & 0 deletions Grabacr07.KanColleWrapper/Calculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Grabacr07.KanColleWrapper.Internal;
using Grabacr07.KanColleWrapper.Models;

namespace Grabacr07.KanColleWrapper
Expand Down Expand Up @@ -32,5 +33,58 @@ public static int CalcAirSuperiorityPotential(this Ship ship)
{
return ship.SlotItems.Zip(ship.OnSlot, (item, i) => item.CalcAirSuperiorityPotential(i)).Sum();
}


/// <summary>
/// 艦隊の索敵値を計算します。
/// </summary>
/// <returns></returns>
public static int CalcFleetViewRange(this Fleet fleet, ViewRangeCalcLogic logic)
{
if (fleet == null || fleet.Ships.Length == 0) return 0;

if (logic == ViewRangeCalcLogic.Type1)
{
return fleet.Ships.Sum(x => x.ViewRange);
}

if (logic == ViewRangeCalcLogic.Type2)
{
// http://wikiwiki.jp/kancolle/?%C6%EE%C0%BE%BD%F4%C5%E7%B3%A4%B0%E8#area5
// [索敵装備と装備例] によって示されている計算式
// stype=7 が偵察機 (2 倍する索敵値)、stype=8 が電探

Func<SlotItemInfo, int, int> calcSlotItems = (item, slot) =>
{
var stype = item.RawData.api_type.Get(1);
if (stype == null) return 0;

if (stype == 7 && slot > 0) return item.RawData.api_saku * 2;
if (stype == 8) return item.RawData.api_saku;
return 0;
};
var items = fleet.Ships.SelectMany(x => x.SlotItems.Zip(x.OnSlot, (s, o) => calcSlotItems(s.Info, o))).Sum();
return items + (int)Math.Sqrt(fleet.Ships.Sum(x => x.ViewRange) - items);
}

return 0;
}
}


/// <summary>
/// 索敵値の計算に使用するロジックの種類を示す識別します。
/// </summary>
public enum ViewRangeCalcLogic
{
/// <summary>
/// 単純な索敵合計値。
/// </summary>
Type1,

/// <summary>
/// (偵察機 × 2) + (電探) + √(装備込みの艦隊索敵値合計 - 偵察機 - 電探)。
/// </summary>
Type2,
}
}
18 changes: 18 additions & 0 deletions Grabacr07.KanColleWrapper/KanColleClientSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,23 @@ public bool EnableLogging

#endregion

#region ViewRangeCalcLogic 変更通知プロパティ

private ViewRangeCalcLogic _ViewRangeCalcLogic;

public ViewRangeCalcLogic ViewRangeCalcLogic
{
get { return this._ViewRangeCalcLogic; }
set
{
if (this._ViewRangeCalcLogic != value)
{
this._ViewRangeCalcLogic = value;
this.RaisePropertyChanged();
}
}
}

#endregion
}
}
13 changes: 12 additions & 1 deletion Grabacr07.KanColleWrapper/Models/Fleet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Grabacr07.KanColleWrapper.Models.Raw;
using Grabacr07.KanColleWrapper.Internal;
using Livet;
using Livet.EventListeners.WeakEvents;

namespace Grabacr07.KanColleWrapper.Models
{
Expand All @@ -16,6 +17,7 @@ public class Fleet : NotificationObject, IDisposable, IIdentifiable
private readonly Homeport homeport;
private Ship[] originalShips; // null も含んだやつ
private bool isInSortie;
private LivetCompositeDisposable compositeDisposable;

#region Id 変更通知プロパティ

Expand Down Expand Up @@ -311,6 +313,14 @@ internal Fleet(Homeport parent, kcsapi_deck rawData)
this.Condition = new FleetCondition(this);
this.Expedition = new Expedition(this);
this.Update(rawData);

this.compositeDisposable = new LivetCompositeDisposable
{
new PropertyChangedWeakEventListener(KanColleClient.Current.Settings)
{
{ "ViewRangeCalcLogic", (sender, args) => this.Calculate() }
}
};
}


Expand Down Expand Up @@ -395,7 +405,7 @@ internal void Calculate()
this.TotalLevel = this.Ships.HasItems() ? this.Ships.Sum(x => x.Level) : 0;
this.AverageLevel = this.Ships.HasItems() ? (double)this.TotalLevel / this.Ships.Length : 0.0;
this.AirSuperiorityPotential = this.Ships.Sum(s => s.CalcAirSuperiorityPotential());
this.TotalViewRange = this.Ships.Sum(s => s.ViewRange);
this.TotalViewRange = this.CalcFleetViewRange(KanColleClient.Current.Settings.ViewRangeCalcLogic);
this.Speed = this.Ships.All(s => s.Info.Speed == Speed.Fast) ? Speed.Fast : Speed.Low;
}

Expand Down Expand Up @@ -473,6 +483,7 @@ public override string ToString()

public virtual void Dispose()
{
this.compositeDisposable.Dispose();
this.Expedition.SafeDispose();
this.Condition.SafeDispose();
}
Expand Down
23 changes: 21 additions & 2 deletions Plugins/MasterDataViewer/Views/Portal.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:viewModels="clr-namespace:Grabacr07.KanColleViewer.Plugins.ViewModels"
xmlns:converters="clr-namespace:Grabacr07.Desktop.Metro.Converters;assembly=Desktop.Metro"
xmlns:metro2="clr-namespace:Grabacr07.Desktop.Metro.Controls;assembly=Desktop.Metro"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300"
d:DataContext="{d:DesignInstance viewModels:PortalViewModel}">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MetroRadiance;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MetroRadiance;component/Styles/Icons.xaml" />
<ResourceDictionary Source="pack://application:,,,/MetroRadiance;component/Themes/Dark.xaml" />
<ResourceDictionary Source="pack://application:,,,/MetroRadiance;component/Themes/Accents/Purple.xaml" />

<StackPanel>
<ResourceDictionary Source="pack://application:,,,/Desktop.Metro;component/Styles/Controls.xaml" />

<ResourceDictionary Source="pack://application:,,,/KanColleViewer;component/Styles/Colors.xaml" />
<ResourceDictionary Source="pack://application:,,,/KanColleViewer;component/Styles/Controls.xaml" />
</ResourceDictionary.MergedDictionaries>

<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</ResourceDictionary>
</UserControl.Resources>

<StackPanel Margin="8,0,8,8">
<TextBlock Text="艦これのマスター データを閲覧します。"
Style="{DynamicResource HeaderTextStyleKey}" />

<metro2:CallMethodButton />
</StackPanel>
</UserControl>

0 comments on commit 20bddd4

Please sign in to comment.