-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFormMain.cs
1517 lines (1227 loc) · 52.7 KB
/
FormMain.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection;
using System.Net;
using System.Threading;
namespace KCB2
{
public partial class FormMain : Form
{
FormShipList _wndShipList = null;
FormItemList _wndItemList = null;
FormSlotItemList _wndSlotItemList = null;
FormLog _wndLog = null;
FormMasterData _wndMaster = null;
LogManager.LogManager _logManager = null;
GSpread.SpreadSheetWrapper _gsWrapper = null;
RingBuffer<JSONData> _logLastJSON = null;
HTTProxy _httProxy = null;
System.Net.IWebProxy _sysProxy = null;
/// <summary>
/// 表示がロックされている時true
/// </summary>
bool _bLock;
bool _bPortable;
#if RESTORE_VOLUME
/// 起動時の音量とミュートフラグ
bool bootMute;
uint bootVol;
#endif
// string _fiddlerOverrideGateway;
/// <summary>
/// コンストラクタ
/// </summary>
/// <param name="bPortable">設定を保存しない時true</param>
public FormMain(bool bPortable)
{
InitializeComponent();
IntPtr ptr = Handle;
_bPortable = bPortable;
MouseWheel += FormMain_MouseWheel;
MouseEnter += FormMain_MouseEnter;
_sysProxy = System.Net.WebRequest.DefaultWebProxy;
var asm = System.Reflection.Assembly.GetExecutingAssembly();
imageListSlotItemType.Images.AddStrip(new Bitmap(
asm.GetManifestResourceStream("KCB2.SlotItemsSmallIcon.bmp")));
imageListSlotItemType.TransparentColor = Color.FromArgb(255, 0, 255);
deckMemberList.SlotItemIconImageList = imageListSlotItemType;
#if RESTORE_VOLUME
///起動時の音量設定を覚えておく
using (var mixer = new MixerAPI())
{
bootVol = mixer.Volume;
bootMute = mixer.Mute;
}
#endif
// WebRequestの同時処理数を引き上げる
if (ServicePointManager.DefaultConnectionLimit < 20)
{
Debug.WriteLine(string.Format("ServicePointManager.DefaultConnectionLimit {0} -> 20",
ServicePointManager.DefaultConnectionLimit));
ServicePointManager.DefaultConnectionLimit = 20;
}
//スレッドプール数を増やす
int minWorkerThread, minCompletionPortThread;
ThreadPool.GetMinThreads(out minWorkerThread, out minCompletionPortThread);
Debug.WriteLine(string.Format("ManagedThread minWorkder:{0} minCompPortThread:{1}",
minWorkerThread, minCompletionPortThread));
if (minWorkerThread < 20)
{
Debug.WriteLine(string.Format("minWorkerThread {0} -> 20", minWorkerThread));
ThreadPool.SetMinThreads(20, minCompletionPortThread);
}
_httProxy = new HTTProxy();
_httProxy.BeforeRequest += _httProxy_BeforeRequest;
_httProxy.AfterSessionCompleted += _httProxy_AfterSessionCompleted;
_httProxy.RequestFailed += _httProxy_RequestFailed;
///過去の設定を引っ張ってる場合。
if (Properties.Settings.Default.ProxyPort <= 0)
Properties.Settings.Default.ProxyPort = 8088;
_gsWrapper = new GSpread.SpreadSheetWrapper();
try
{
_httProxy.Start(Properties.Settings.Default.ProxyPort);
UpdateProxyConfiguration();
}
catch (Exception e)
{
if (e is HttpListenerException)
{
var ex = (HttpListenerException)e;
MessageBox.Show(
string.Format("HttpListenerの起動に失敗しました。情報は取得されません。\n設定を確認してください\n\nプレフィクス:{0}\nコード:0x{1}({2})\n例外:{3}",
_httProxy.Prefix, ex.ErrorCode.ToString("x"), ex.ErrorCode, ex.Message)
);
}
else
{
MessageBox.Show(
string.Format("HttpListenerの起動に失敗しました。情報は取得されません。\n設定を確認してください\n\nプレフィクス:{0}\n例外:{1}",
_httProxy.Prefix, e.Message)
);
}
}
_logManager = new LogManager.LogManager(this);
// _fiddlerOverrideGateway = Properties.Settings.Default.FiddlerOverrideGateway;
#if !DEBUG
if (Properties.Settings.Default.UseDevMenu)
#endif
{
_watchSession = true;
_logLastJSON = new RingBuffer<JSONData>(Properties.Settings.Default.SkipbackJSON+1);
}
deckMemberList.UpdateDeckStatus = UpdateDeckConditionTime;
///縦横切替を使うかどうか
switchViewModeToolStripMenuItem.Visible = false;
setLogStore();
}
/// <summary>
/// プロキシ設定を反映
/// </summary>
void UpdateProxyConfiguration()
{
var proxyHost = "127.0.0.1";
if (Properties.Settings.Default.UseUpstreamProxy)
{
_httProxy.UpstreamProxy = new System.Net.WebProxy(
Properties.Settings.Default.UpstreamProxyHost,
(int)Properties.Settings.Default.UpstreamProxyPort);
HTTProxy.SetProcessProxy(string.Format("http={0}:{1} https={2}:{3}",
proxyHost,
Properties.Settings.Default.ProxyPort,
Properties.Settings.Default.UpstreamProxyHost,
Properties.Settings.Default.UpstreamProxyPort), "");
}
else
{
_httProxy.UpstreamProxy = _sysProxy;
HTTProxy.SetProcessProxy(string.Format("http={0}:{1}",
proxyHost,
Properties.Settings.Default.ProxyPort), "");
}
//Google Spreadsheet API関連のプロクシ設定
_gsWrapper.Proxy = _httProxy.UpstreamProxy;
}
void FormMain_MouseEnter(object sender, EventArgs e)
{
Focus();
}
void FormMain_MouseWheel(object sender, MouseEventArgs e)
{
deckMemberList.DoDeckListMouseWheelEvent(e);
}
/// <summary>
/// ログストアを切り替える
/// </summary>
void setLogStore()
{
Debug.WriteLine("Setting LogType:" + Properties.Settings.Default.LogStoreType.ToString());
switch (Properties.Settings.Default.LogStoreType)
{
case 0:
//CSV
Debug.WriteLine("Set CSVLog");
_logManager.LogStore = new LogStore.CSVLogStore();
return;
case 1:
//GoogleStorage
Debug.WriteLine("Set GoogleLog");
var glogStore = new LogStore.GSpreadLogStore(_gsWrapper);
if (!_gsWrapper.Refresh())
MessageBox.Show("アクセストークンの取得に失敗しました。ログは保存されません。\n\n再認証してください。");
_logManager.LogStore = glogStore;
return;
default:
throw new ArgumentOutOfRangeException("Unknown storeType");
}
}
SessionProcessor _processor = null;
ShipStatusManager _statusManager = new ShipStatusManager();
TimerRPCManager _timerRPC = new TimerRPCManager();
#if DEBUG
FormJSONTest testerWnd;
#endif
FormJSONLog _logWnd = null;
#region フォームハンドラ
private void FormMain_Load(object sender, EventArgs e)
{
webBrowser1.ScriptErrorsSuppressed =
Properties.Settings.Default.SuppressBrowserDialog;
///ジョブキュー起動
_processor = new SessionProcessor(this, _statusManager);
///タイマを起動
if (Properties.Settings.Default.SyncronizeTimerProcess)
{
// TODO:KCBTimer.exeを起動してメッセージループの開始を待つ
using (var proc = Process.Start(GetTimerPath()))
proc.WaitForInputIdle();
//WCFサーバが起動するのを待つ
TimerRPCManager.WaitForWCFStartup();
}
#if DEBUG
testerWnd = new FormJSONTest();
testerWnd.processor = _processor;
testerWnd.Show();
#endif
if (Properties.Settings.Default.UseLogWindow)
{
_wndShipList = new FormShipList(imageListSlotItemType);
if (_wndShipList.Visible = Properties.Settings.Default.ShipListVisible)
_wndShipList.Show();
_wndItemList = new FormItemList(imageListSlotItemType);
if (_wndItemList.Visible = Properties.Settings.Default.ItemListVisible)
_wndItemList.Show();
_wndSlotItemList = new FormSlotItemList(imageListSlotItemType);
if (_wndSlotItemList.Visible = Properties.Settings.Default.SlotItemListVisible)
_wndSlotItemList.Show();
_wndLog = new FormLog(_logManager);
if (_wndLog.Visible = Properties.Settings.Default.LogWndVisible)
_wndLog.Show();
}
if (Properties.Settings.Default.UseMasterDataView)
{
_wndMaster = new FormMasterData(imageListSlotItemType);
masterDataToolStripMenuItem.Visible = true;
if(_wndMaster.Visible = Properties.Settings.Default.MasterDataWndVisible)
_wndMaster.Show();
}
devMenuToolStripMenuItem.Visible = Properties.Settings.Default.UseDevMenu;
#if DEBUG
devMenuToolStripMenuItem.Visible = true;
showJsonLogToolStripMenuItem_Click(null, null);
#endif
// panel内にWebBrowserを入れておかないと何故かLoad時はnullのまま
var obj = webBrowser1.ActiveXInstance;
//セキュリティマネージャの上書き。クロスドメインでのフレームまたぎを許可
KCB.COM.IServiceProvider sp = obj as KCB.COM.IServiceProvider;
object ops;
sp.QueryService(ref KCB.COM.SID_SProfferService, ref KCB.COM.IID_IProfferService, out ops);
KCB.COM.IProfferService ps = ops as KCB.COM.IProfferService;
int cookie = 0;
ps.ProfferService(ref KCB.COM.IID_IInternetSecurityManager, webBrowser1, ref cookie);
Graphics g = Graphics.FromHwnd(Handle);
Debug.WriteLine(string.Format("DPI X:{0} Y:{1}",g.DpiX,g.DpiY));
if(!Properties.Settings.Default.MainFormLocation.IsEmpty)
Location = Properties.Settings.Default.MainFormLocation;
webBrowser1.Navigate(Properties.Settings.Default.GadgetURI);
UpdateStatus("ゲームURIの読み込みを開始します");
}
private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("終了しますか?", "KCBr2", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2,
MessageBoxOptions.DefaultDesktopOnly) != DialogResult.OK)
{
e.Cancel = true;
return;
}
if (Properties.Settings.Default.SyncronizeTimerProcess)
_timerRPC.ShutdownTimer();
_logManager.SaveLog();
//Closeを叩かないと、FormClosingなどが呼ばれずに終わるようで、設定が保存されない
if (_wndShipList != null)
{
Properties.Settings.Default.ShipListVisible
= _wndShipList.Visible && _wndShipList.WindowState != FormWindowState.Minimized;
_wndShipList.Close();
}
if (_wndItemList != null)
{
Properties.Settings.Default.ItemListVisible
= _wndItemList.Visible && _wndItemList.WindowState != FormWindowState.Minimized;
_wndItemList.Close();
}
if (_wndSlotItemList != null)
{
Properties.Settings.Default.SlotItemListVisible
= _wndSlotItemList.Visible && _wndSlotItemList.WindowState != FormWindowState.Minimized;
_wndSlotItemList.Close();
}
if (_wndLog != null)
{
Properties.Settings.Default.LogWndVisible
= _wndLog.Visible && _wndLog.WindowState != FormWindowState.Minimized;
_wndLog.Close();
}
if (_wndMaster != null)
{
Properties.Settings.Default.MasterDataWndVisible
= _wndMaster.Visible && _wndMaster.WindowState != FormWindowState.Minimized;
_wndMaster.Close();
}
}
private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
{
#if DEBUG
testerWnd.Close();
#endif
if(_logWnd != null)
_logWnd.Close();
#if RESTORE_VOLUME
///起動時の設定を戻す
using (var mixer = new MixerAPI())
{
mixer.Volume = bootVol;
mixer.Mute = bootMute;
}
#endif
if (WindowState == FormWindowState.Normal)
Properties.Settings.Default.MainFormLocation = Location;
if (WindowState == FormWindowState.Minimized)
Visible = false;
_httProxy.Stop();
if (!_bPortable)
{
Debug.WriteLine("Save Configuration");
Properties.Settings.Default.Save();
}
}
/// <summary>
/// 最小化前にミュートされていたかどうかの状態フラグ
/// </summary>
bool bMuted = false;
private void FormMain_Resize(object sender, EventArgs e)
{
if (Properties.Settings.Default.MuteOnMinimize)
{
try
{
using (var mixer = new MixerAPI())
{
//ウィンドウが最小化された。
if (WindowState == FormWindowState.Minimized)
{
bMuted = mixer.Mute;
mixer.Mute = true;
}
else
{
mixer.Mute = bMuted;
}
}
}
catch (MixerAPI.MixerException ex)
{
//RDP経由するとMixerが開けなくてコンストラクタが例外を投げる
Debug.WriteLine("MixerException:" + ex.ToString());
}
}
}
#endregion フォームハンドラ
/// <summary>
/// フラッシュ位置を検出してウィンドウをスクロール
/// </summary>
/// <returns>成功したらtrue</returns>
bool adjustFlashPosition()
{
//もしリロード前に表示されていたら消す
enemyFleetList.Visible = false;
KCB.WebBrowserEx.IWebBrowser2 wb = (webBrowser1.ActiveXInstance as KCB.WebBrowserEx.IWebBrowser2);
mshtml.IHTMLDocument3 doc = (wb.Document as mshtml.IHTMLDocument3);
mshtml.IHTMLElement elm = doc.getElementById("game_frame");
if (elm == null)
return false;
/*
* http://stackoverflow.com/questions/10645143/webbrowsercontrol-unauthorizedaccessexception-when-accessing-property-of-a-fram
*/
object ppvObject = null;
mshtml.IHTMLWindow2 wnd = (((mshtml.IHTMLFrameBase2)elm).contentWindow);
((KCB.WebBrowserEx.IServiceProvider)wnd).QueryService(
KCB.WebBrowserEx.IWebBrowserApp_GUID, KCB.WebBrowserEx.IWebBrowser2_GUID, out ppvObject);
KCB.WebBrowserEx.IWebBrowser2 inFrm = ppvObject as KCB.WebBrowserEx.IWebBrowser2;
/* 何故かフレーム間のアクセス制限を解除しておかないとここで例外が飛ぶ。
*/
mshtml.IHTMLDocument3 doc_frm = inFrm.Document as mshtml.IHTMLDocument3;
mshtml.IHTMLElement c_elm = doc_frm.getElementById("externalswf");
if (c_elm == null)
return false;
//スクロールバーを消す
webBrowser1.Document.Body.Style = "overflow-x: hidden;overflow-y: hidden; touch-action: none; -ms-content-zooming: none;";
// iframeのオフセットを算出
int frameOffsetLeft = 0, frameOffsetTop = 0;
while (c_elm != null)
{
Debug.WriteLine(string.Format("FrameOffset {0}+{1}={2},{3}+{4}={5}",
frameOffsetTop, c_elm.offsetTop, frameOffsetTop + c_elm.offsetTop,
frameOffsetLeft, c_elm.offsetLeft, frameOffsetLeft + c_elm.offsetLeft));
frameOffsetTop += c_elm.offsetTop;
frameOffsetLeft += c_elm.offsetLeft;
c_elm = c_elm.offsetParent;
}
//flashオブジェクトのiframe内オフセットを算出
int elementOffsetTop = 0, elementOffsetLeft = 0;
while (elm != null)
{
Debug.WriteLine(string.Format("ElementOffset {0}+{1}={2},{3}+{4}={5}",
elementOffsetTop, elm.offsetTop, elementOffsetTop + elm.offsetTop,
elementOffsetLeft, elm.offsetLeft, elementOffsetLeft + elm.offsetLeft));
elementOffsetTop += elm.offsetTop;
elementOffsetLeft += elm.offsetLeft;
elm = elm.offsetParent;
}
HtmlWindow targetHtmlWnd = webBrowser1.Document.Window;
targetHtmlWnd.ScrollTo(0, 0);
targetHtmlWnd.ScrollTo(elementOffsetLeft + frameOffsetLeft,
elementOffsetTop + frameOffsetTop);
UpdateStatus("表示範囲を調整しました");
return true;
}
#region HTTProxyハンドラ
void _httProxy_AfterSessionCompleted(HTTProxy.SessionInfo info)
{
//MIME形式を見る
if (info.Response.ContentType != "text/plain")
{
Debug.WriteLine("MIMEType is not text/plain. return");
return;
}
var httproxySession = new HTTProxySessionData(info);
if (_watchSession)
{
var q = httproxySession.QueryParam;
if (q.ContainsKey("api_token"))
_updateAPIToken(q["api_token"]);
}
_processor.Add(httproxySession);
}
void _httProxy_BeforeRequest(HTTProxy.SessionInfo info)
{
Debug.WriteLine("BeforeRequest:" + info.Uri);
//ゲーム開始時のトークンと時間を覚えておく
if (info.Uri.ToString().Contains("mainD2.swf"))
{
//別スレッドから呼ばれるのでUIスレッドに処理を投げる
BeginInvoke((MethodInvoker)(() => adjustFlashPosition()));
if (_watchSession)
_logFirstSession(info.Uri.ToString());
}
/* 艦これAPI以外へのアクセスは全部無視する
*/
if (!info.Uri.PathAndQuery.StartsWith("/kcsapi/"))
{
info.Ignore = true;
return;
}
switch (info.Uri.PathAndQuery)
{
case "/kcsapi/api_req_map/next":
CheckShipStatus(info);
return;
}
}
void _httProxy_RequestFailed(HTTProxy.RequestFailedContext ctx)
{
ctx.Retry = MessageBox.Show(
string.Format("{0}へのリクエストが失敗しました\n理由:{1}\n\n再試行しますか?", ctx.Uri, ctx.Message), "KCBr2",
MessageBoxButtons.RetryCancel,MessageBoxIcon.Error,MessageBoxDefaultButton.Button1,MessageBoxOptions.DefaultDesktopOnly)
== DialogResult.Retry;
}
#endregion
DateTime _firstSesson;
DateTime _latestSession;
string _serverHost = "";
string _apiToken = "";
bool _watchSession = false;
/// <summary>
/// mainD2.swfへのアクセスからセッション取得時刻とかを取ってくる
/// </summary>
/// <param name="mainD2URL"></param>
void _logFirstSession(string mainD2URL)
{
_firstSesson = DateTime.Now;
_latestSession = DateTime.Now;
Uri uri = new Uri(mainD2URL);
_serverHost = uri.Host;
var q = SessionData.ParsePostQuery(uri.Query);
_apiToken = q["api_token"];
Debug.WriteLine(string.Format("New session: host:{0} token:{1}",_serverHost,_apiToken));
}
void _updateAPIToken(string currentApiToken)
{
if (_apiToken != currentApiToken)
{
Debug.WriteLine("APIToken update detected");
_latestSession = DateTime.Now;
_apiToken = currentApiToken;
}
}
#region 更新反映ハンドラ
public void AddJSONLog(SessionData oData)
{
if(_logLastJSON != null)
_logLastJSON.Add(new JSONData(oData));
if (_logWnd != null)
_logWnd.AddJSON(new JSONData(oData));
}
public void JSONLogWndClosed()
{
_logWnd = null;
}
/// <summary>
/// ステータスバーへのステータス表示メッセージ更新
/// </summary>
/// <param name="format">書式文字列</param>
/// <param name="args">引数</param>
public void UpdateStatus(string format, params object[] args )
{
string msg = string.Format(format, args);
if (InvokeRequired)
BeginInvoke((MethodInvoker)(() => toolStripStatusLabel1.Text = msg));
else
toolStripStatusLabel1.Text = msg;
}
/// <summary>
/// ウィンドウタイトルを書き換え
/// </summary>
/// <param name="Title"></param>
public void UpdateWindowTitle(string Title)
{
if (InvokeRequired)
BeginInvoke((MethodInvoker)(() => Text = Title));
else
Text = Title;
}
public void UpdateDeckMemberList(MemberData.Ship shipData, IEnumerable<MemberData.Deck.Fleet> deckList)
{
deckMemberList.UpdateDeck(deckList, shipData);
missionList.UpdateMissionList(deckList,shipData);
_timerRPC.UpdateMission(deckList);
}
public void UpdateDockCount(int kdock, int ndock)
{
dockBuild.SetOpenDockCount(kdock);
dockRepair.SetOpenDockCount(ndock);
}
public void UpdateDeckCount(int count)
{
missionList.SetActiveDeck(count);
}
public void UpdateMaterialData(MemberData.Material dat)
{
materialList.Update(dat);
}
public void UpdateBuildDock(MemberData.Dock dock)
{
dockBuild.UpdateDockList(dock.BuildDock);
}
public void UpdateRepairDock(MemberData.Dock dock)
{
dockRepair.UpdateDockList(dock.RepairDock);
_timerRPC.UpdateNDock(dock);
}
public void UpdateQuestList(IEnumerable<MemberData.Quest.Info> questList)
{
currentQuestList = questList;
if(lbQuest.InvokeRequired)
lbQuest.Invoke((MethodInvoker)(() => _updateQuestLBForm(questList)));
else
_updateQuestLBForm(questList);
}
void _updateQuestLBForm(IEnumerable<MemberData.Quest.Info> questList)
{
lbQuest.BeginUpdate();
lbQuest.Items.Clear();
foreach (var it in questList)
{
var item = new ListBoxEx.ListBoxItem();
item.Text = string.Format("{0}{1} {2}",it.StateString,it.Name , it.ProgressMsg);
item.ToolTip = it.Description;
if (it.ProgressFlag == 1)
item.BackColor = Color.LightGreen;
else if (it.ProgressFlag == 2)
item.BackColor = Color.LimeGreen;
lbQuest.Items.Add(item);
}
lbQuest.Refresh();
lbQuest.EndUpdate();
}
public void UpdateShipList(IEnumerable<MemberData.Ship.Info> shipList)
{
if(_wndShipList != null)
_wndShipList.UpdateShipList(shipList);
}
public void UpdateShipListDock(MemberData.Dock dockData)
{
if (_wndShipList != null)
_wndShipList.UpdateShipListDock(dockData);
}
public void UpdateShipListDeck(MemberData.Deck deckData)
{
if (_wndShipList != null)
_wndShipList.UpdateShipListDeck(deckData);
}
public void UpdateMaxShipItemValue(int maxShip, int maxItem)
{
if (_wndShipList != null)
_wndShipList.MaxShip = maxShip;
if (_wndItemList != null)
_wndItemList.MaxItem = maxItem;
if (_wndSlotItemList != null)
_wndSlotItemList.MaxItem = maxItem;
}
public void UpdateShipLock(int ship_id,bool bLock)
{
if (_wndShipList != null)
_wndShipList.UpdateShipLock(ship_id, bLock);
}
public void UpdateItemList(IEnumerable<MemberData.Item.Info> itemList)
{
if (_wndItemList != null)
_wndItemList.UpdateItemList(itemList);
if (_wndSlotItemList != null)
_wndSlotItemList.UpdateSlotItemList(itemList);
}
public void UpdateItemOwner(IDictionary<int, MemberData.Ship.SlotItemOwner> itemOwner,
IDictionary<int,int> itemType)
{
if (_wndItemList != null)
_wndItemList.UpdateItemOwner(itemOwner);
if (_wndSlotItemList != null)
_wndSlotItemList.UpdateSlotItemOwner(itemOwner, itemType);
}
public void UpdateSlotItemLock(int itemId, bool bLock)
{
if (_wndItemList != null)
_wndItemList.UpdateLockState(itemId, bLock);
}
public void AddBattleResult(LogData.BattleResultInfo info)
{
_logManager.AddBattleResult(info);
}
public void AddMissionResult(LogData.MissionResultInfo info)
{
_logManager.AddMissionResult(info);
}
public void AddCreateShipResult(IEnumerable<LogData.CreateShipInfo> infoL)
{
_logManager.AddCreateShipResult(infoL);
}
public void AddCreateItemResult(LogData.CreateItemInfo info)
{
_logManager.AddCreateItemResult(info);
}
public void UpdateMemberID(string memberID)
{
_logManager.LoadLog(memberID);
}
public void AddMaterialsChange(LogData.MaterialChangeInfo info)
{
_logManager.AddMaterialsChangeResult(info);
}
public void UpdateBasicInfo(MemberData.Basic basicInfo)
{
_timerRPC.UpdateParameters(basicInfo);
}
public void UpdateMasterData(MasterData.Ship shipMaster, MasterData.Item itemMaster)
{
if (_wndMaster != null)
_wndMaster.UpdateMaster(shipMaster,itemMaster);
}
public void NotifyFinishBattle(string type)
{
_timerRPC.RPCFinishBattle(type);
}
public void UpdateSlotItemInfo(int ship_id)
{
if (_wndShipList != null)
_wndShipList.UpdateSlotItem(ship_id);
deckMemberList.RedrawFleetList();
}
#endregion
#region コントロールハンドラ
private void rdRepair_CheckedChanged(object sender, EventArgs e)
{
dockBuild.Visible = false;
dockRepair.Visible = true;
lbQuest.Visible = false;
}
private void rdBuild_CheckedChanged(object sender, EventArgs e)
{
dockBuild.Visible = true;
dockRepair.Visible = false;
lbQuest.Visible = false;
}
private void rdQuest_CheckedChanged(object sender, EventArgs e)
{
dockBuild.Visible = false;
dockRepair.Visible = false;
lbQuest.Visible = true;
}
private void reloadBrowserToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_bLock)
{
MessageBox.Show("ロック中は操作できません。", "KCBr2");
return;
}
if (MessageBox.Show("艦これゲームページを再読込します。\nよろしいですか?",
"KCBr2", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question,MessageBoxDefaultButton.Button2) != DialogResult.OK)
return;
webBrowser1.Refresh(WebBrowserRefreshOption.Completely);
enemyFleetList.Visible = false;
UpdateStatus("ゲーム画面の再読み込みを開始します");
}
IEnumerable<MemberData.Quest.Info> currentQuestList = null;
private void showQuestButton_MouseDown(object sender, MouseEventArgs e)
{
if (currentQuestList == null)
{
MessageBox.Show("任務一覧が読み込まれていません。");
return;
}
var dlg = new FormQuestList();
dlg.StartPosition = FormStartPosition.Manual;
dlg.Size = Properties.Settings.Default.QuestListSize;
dlg.QuestList = currentQuestList;
dlg.Location = statusStrip1.PointToScreen(
new Point(showQuestButton.Bounds.Location.X,
showQuestButton.Bounds.Location.Y - dlg.Height - 2));
dlg.Show();
}
private void screenShotButton_Click(object sender, EventArgs ev)
{
//usingでくくるとbmpの挿げ替えが出来ない。
var bmp = webBrowser1.GetScreenShot();
try
{
if (bmp == null)
{
UpdateStatus("スクリーンショットの取得に失敗しました");
return;
}
UpdateStatus("スクリーンショットを取得しました");
using (var dlg = new FormScreenShot())
{
dlg.ActivateSaveFile = Properties.Settings.Default.ImageStoreDir.Length > 0;
if (dlg.ShowDialog() == DialogResult.Cancel)
{
UpdateStatus("取得したスクリーンショットを破棄しました");
return;
}
//ヘッダを隠す
if (dlg.HideHeader)
{
Bitmap offImg = OffsetImage(bmp, new Point(0, 30));
if (offImg != null)
{
bmp.Dispose();
bmp = offImg;
}
}
if (dlg.SaveTarget
== FormScreenShot.ScreenShotSaveTarget.SaveAsFile)
{
string saveFile = DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmss");
string savePath =
string.Format("{0}\\{1}.png", Properties.Settings.Default.ImageStoreDir,
saveFile);
Debug.WriteLine("SaveImage:" + savePath);
try
{
bmp.Save(savePath, System.Drawing.Imaging.ImageFormat.Png);
UpdateStatus("スクリーンショット[{0}]を保存しました", saveFile);
}
catch(Exception e)
{
Debug.WriteLine("Image.Save thrown exception\n" + e.ToString());
UpdateStatus("スクリーンショットの保存に失敗しました[{0}]",e.Message);
}
}
else if (dlg.SaveTarget
== FormScreenShot.ScreenShotSaveTarget.Clipboard)
{
Clipboard.SetImage(bmp);
UpdateStatus("スクリーンショットをクリップボードへ転送しました");
}
}
}
finally
{
if (bmp != null)
bmp.Dispose();
}
}
//画像をオフセットしてコピーする
Bitmap OffsetImage(Bitmap orgBmp,Point origin)
{
Debug.WriteLine(string.Format("OffsetImage:{0},{1}", origin.X, origin.Y));
var bmp = new Bitmap(orgBmp.Width - origin.X, orgBmp.Height - origin.Y);
if (bmp == null)
return null;
using (var g = Graphics.FromImage(bmp))
{
Point ptDraw = new Point(-origin.X, -origin.Y);
g.DrawImage(orgBmp, ptDraw);
}
return bmp;
}
private void shipListToolStripMenuItem_Click(object sender, EventArgs e)
{
if (_wndShipList == null)
return;
if (_wndShipList.WindowState == FormWindowState.Minimized)
_wndShipList.WindowState = FormWindowState.Normal;
if (!_wndShipList.Visible)
_wndShipList.Visible = true;
else
_wndShipList.Activate();
}