YSRKEN / KanColleSimulator_KAI

New Simulator of Kantai Collection by C++ and C#
Other
14 stars 2 forks source link

Use data bind kai #141

Closed yumetodo closed 7 years ago

yumetodo commented 7 years ago

try to fix conflict #104

ref: #140

yumetodo commented 7 years ago
        private void FleetSelectComboBox_SelectedIndexChanged(object sender, EventArgs e) {
            if(FleetSelectComboBox.SelectedIndex == -1)
                return;
            // 表示する艦隊を切り換える
            KammusuSelectListBox.DataSource = FormFleet.unit[FleetSelectComboBox.SelectedIndex];
        }

していて、そのあとで

        private void AddKammusuButton_Click(object sender, EventArgs e) {
            var kammusu = (CsvDataSet.ShipsRow)KammusuNameComboBox.SelectedItem;
            if (kammusu == null || FleetSelectComboBox.SelectedIndex == -1)
                return;
            // 1艦隊には6隻まで
            if(FormFleet.unit[FleetSelectComboBox.SelectedIndex].Count == MaxUnitSize)
                return;
            // 艦娘データを作成する
            var id = kammusu.艦船ID;
            var level = KammusuLevelTextBox.Text.ParseInt();
            var luck = KammusuLuckTextBox.Text.ParseInt();
            var cond = KammusuCondTextBox.Text.ParseInt();
            var setKammusu = new Kammusu(id, level, luck, cond);
            // 作成した艦娘データを追加する
            FormFleet.unit[FleetSelectComboBox.SelectedIndex].Add(setKammusu);
            RedrawAntiAirScore();
            RedrawSearchPower();
            file_state_modified(FileState.modified);
        }

としてもKammusuSelectListBox.DataSourceは更新されないのか。

一度艦隊を切り替えてFleetSelectComboBox_SelectedIndexChangedを呼べば反映されているけど。

yumetodo commented 7 years ago

おかしいな、data bindされるはずだから自動追従してくれるはずなのに・・・

yumetodo commented 7 years ago

そりゃそうだ。FormFleet.unitがbindされるんじゃなくて、FormFleet.unit[/*なんか*/]がbindされるんだから、そっちをBindingListにしないとFormの再描画がされない。

yumetodo commented 7 years ago

適当にversion 2.1.0とmergeしたら、KammusuTypeComboBoxから駆逐艦が消えたぞい。というかそもそも魚雷艇はどこに行った

yumetodo commented 7 years ago
                KammusuTypeComboBox.DataSource = MapKammusuTypeComboBox.DataSource = data.Ships
                    .Where(s => s.艦種 < shipTypes.Length)
                    .OrderBy(s => s.艦種)
                    .GroupBy(s => s.艦種, (t, g) => new { Key = shipTypes[t], Value = g.ToArray() })
                    .ToArray();

多分この辺だけど正直この辺何やってるのかわかんない。

yumetodo commented 7 years ago
        internal static readonly string[] shipTypes = {
            "魚雷艇",
            "駆逐艦",
            "軽巡洋艦",
            "重雷装巡洋艦",
            "重巡洋艦",
            "航空巡洋艦",
            "軽空母",
            "巡洋戦艦",
            "戦艦",
            "航空戦艦",
            "正規空母",
            "陸上型",
            "潜水艦",
            "潜水空母",
            "輸送艦",
            "水上機母艦",
            "揚陸艦",
            "装甲空母",
            "工作艦",
            "潜水母艦",
            "練習巡洋艦",
            "給油艦",
        };

この順序とcsvの順序があっていない・・・?電とか駆逐艦が軽巡になっていたり飛鷹とか軽空母が巡洋戦艦になっていたり、つーか全部ひとつずれている

yumetodo commented 7 years ago

@YSRKEN CSVの艦種の番号と名前の対応どうなってましたっけ?

yumetodo commented 7 years ago

とりあえず https://github.com/YSRKEN/KanColleSimulator_KAI/pull/98#issuecomment-210505528 はとりこんだ。

yumetodo commented 7 years ago

KammusuNameComboBoxが更新されない問題発生。 test

yumetodo commented 7 years ago

@YSRKEN margeはしたが、先の問題は解決しないorz

yumetodo commented 7 years ago

image

Just-In-Time (JIT) デバッグを呼び出すための詳細については、
ダイアログ ボックスではなく、このメッセージの最後を参照してください。

************** 例外テキスト **************
System.ArgumentOutOfRangeException: '20' の InvalidArgument=Value は 'SelectedIndex' に対して有効ではありません。
パラメーター名:SelectedIndex
   場所 System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)
   場所 KCS_GUI.MainForm.KammusuSelectListBox_SelectedIndexChanged(Object sender, EventArgs e) 場所 C:\Users\yumetodo\Documents\git\KanColleSimulator_KAI\KCS_GUI\Form1.cs:行 488
   場所 System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)
   場所 System.Windows.Forms.ListBox.WmReflectCommand(Message& m)
   場所 System.Windows.Forms.ListBox.WndProc(Message& m)
   場所 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   場所 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   場所 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** 読み込まれたアセンブリ **************
mscorlib
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
KCS_GUI
    アセンブリ バージョン:2.1.1.0
    Win32 バージョン:2.1.1
    コードベース:file:///C:/Users/yumetodo/Documents/git/KanColleSimulator_KAI/KCS_GUI/bin/Debug/KCS_GUI.exe
----------------------------------------
System.Windows.Forms
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Data
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Core
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Data.DataSetExtensions
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Data.DataSetExtensions/v4.0_4.0.0.0__b77a5c561934e089/System.Data.DataSetExtensions.dll
----------------------------------------
System.Configuration
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Windows.Forms.resources
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_ja_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
System.Numerics
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
System.Transactions
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
Newtonsoft.Json
    アセンブリ バージョン:8.0.0.0
    Win32 バージョン:8.0.3.19514
    コードベース:file:///C:/Users/yumetodo/Documents/git/KanColleSimulator_KAI/KCS_GUI/bin/Debug/Newtonsoft.Json.DLL
----------------------------------------
System.Runtime.Serialization
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------
System.Xml.Linq
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml.Linq/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll
----------------------------------------
mscorlib.resources
    アセンブリ バージョン:4.0.0.0
    Win32 バージョン:4.6.1586.0 built by: NETFXREL2
    コードベース:file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_ja_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------

************** JIT デバッグ **************
Just-In-Time (JIT) デバッグを有効にするには、このアプリケーション、
またはコンピューター (machine.config) の構成ファイルの jitDebugging 
値を system.windows.forms セクションで設定しなければなりません。
アプリケーションはまた、デバッグを有効にしてコンパイルされなければ
なりません。

例:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

JIT デバッグが有効なときは、このダイアログ ボックスで処理するよりも、
ハンドルされていない例外はすべてコンピューターに登録された
JIT デバッガーに設定されなければなりません。
yumetodo commented 7 years ago

test2

yumetodo commented 7 years ago
        private void KammusuSelectListBox_SelectedIndexChanged(object sender, EventArgs e) {
            var kammusu = (Kammusu)KammusuSelectListBox.SelectedItem;
            if (kammusu == null)
                return;
            // 表示する艦娘を切り替える
            int showKammusuType = kammusu.row.艦種 - 1;
            KammusuTypeComboBox.SelectedIndex = showKammusuType;
            KammusuNameComboBox.SelectedItem = kammusu;//ここ
            RedrawKammusuNameList();
            KammusuLevelTextBox.Text = kammusu.lv.ToString();
            KammusuLuckTextBox.Text = kammusu.luck.ToString();
            KammusuCondTextBox.Text = kammusu.cond.ToString();
            // 装備一覧を更新する
            WeaponSelectListBox.DataSource = kammusu.items;
        }

うーん、 kammusu.row.艦種のほうがおかしい説あるか?

yumetodo commented 7 years ago

いや、kammusu.row.艦種のset部分よりかは https://github.com/YSRKEN/KanColleSimulator_KAI/commit/7c3bcc6d04449d3fb79161b3f00249395ecd6ede でのcsv更新を疑うべきだな・・・

YSRKEN commented 7 years ago

CSV変更はnullが含まれる部分を削除しただけで大きな影響など…… と言いたいところですが、null部分削除が#104 と現在のmasterとの間にあれば関係性もありうるかも?

YSRKEN commented 7 years ago

とりあえずdiff 2016-10-15_224841

yumetodo commented 7 years ago

exceptionの方は

int showKammusuType = kammusu.row.艦種 - 2;

にすれば消えるんですけど、根本的な解決になっていないというか・・・

yumetodo commented 7 years ago

というかなんで

KammusuNameComboBox.SelectedItem = kammusu;

ではKammusuNameComboBox.SelectedIndexが変わらないんだ?

yumetodo commented 7 years ago

https://msdn.microsoft.com/ja-jp/library/system.windows.forms.combobox.selecteditem(v=vs.110).aspx When you set the SelectedItem property to an object, the ComboBox attempts to make that object the currently selected one in the list.If the object is found in the list, it is displayed in the edit portion of the ComboBox and the SelectedIndex property is set to the corresponding index.If the object does not exist in the list, the SelectedIndex property is left at its current value.

つまり見つからねぇと。

yumetodo commented 7 years ago
                KammusuTypeComboBox.DataSource = MapKammusuTypeComboBox.DataSource = data.Ships
                    .Where(s => s.艦種 < shipTypes.Length)
                    .OrderBy(s => s.艦種)
                    .GroupBy(s => s.艦種, (t, g) => new { Key = shipTypes[t - 1], Value = g.ToArray() })
                    .ToArray();

KammusuNameComboBox.DataSourceはここで作られたものが入るので、KammusuNameComboBox.SelectedItemnew {string, ShipRow[]}型の匿名オブジェクト。

一方kammusuはKammusu型。

だから一致していないから代入と言うかsetterでコケているのか?

yumetodo commented 7 years ago

http://stackoverflow.com/questions/450059/how-do-i-set-the-selected-item-in-a-combobox-to-match-my-string-using-c#answer-450096

This should do the trick:

Combox1.SelectedIndex = Combox1.FindStringExact("test1")

うおおおおおおお!それだっ!

@YSRKEN というわけでfixしてみました。多分これにて作業完了のはず、新たにバグが見つからなければ!

yumetodo commented 7 years ago

@YSRKEN んて、developbranch動いてるということはそっちにpull request投げ直すべきです?

yumetodo commented 7 years ago

このpull requestも #136 #130 あたりとconflictするというか作業の前提になる

YSRKEN commented 7 years ago

developに投げ直してくださると嬉しいですが…… ん、投げ直さない場合は、masterへmerge→developにmasterをmergeという手順に?

yumetodo commented 7 years ago

140 でdepelop branchが始動したため、投げ直すためにcloseする。