-
Notifications
You must be signed in to change notification settings - Fork 0
/
fTournier.cs
432 lines (362 loc) · 14.5 KB
/
fTournier.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Project;
using Mahjong;
using Viewer;
using Search;
using System.IO;
namespace TenhouViewerUI
{
public partial class fTournier : NestedForm
{
private Color CActive = Color.Transparent;
private Color CBanned = Color.LightPink;
private Color CReplacement = Color.Yellow;
private double[] GamesCols = { 14.0, 6.0, 20.0, 20.0, 20.0, 20.0 };
private double[] PlayersCols = { 60.0, 10.0, 10.0, 20.0 };
private double[] ResultCols = { 20.0, 8.0, 10.0, 10.0, 10.0, 10.0, 8.0, 8.0, 8.0, 8.0 };
private double[] YakuCols = { 80.0, 20.0 };
private ToolStripMenuItem[] PlayerView, PlayerReplay, PlayerExclude, PlayerInclude,
PlayerMarkR, PlayerUnmarkR;
private ResultPack RP;
public fTournier()
{
InitializeComponent();
PlayerView = new ToolStripMenuItem[] { mViewPlayer1, mViewPlayer2, mViewPlayer3, mViewPlayer4 };
PlayerReplay = new ToolStripMenuItem[] { mViewPlayer1Replay, mViewPlayer2Replay, mViewPlayer3Replay, mViewPlayer4Replay };
PlayerExclude = new ToolStripMenuItem[] { mViewPlayer1Exclude, mViewPlayer2Exclude, mViewPlayer3Exclude, mViewPlayer4Exclude };
PlayerInclude = new ToolStripMenuItem[] { mViewPlayer1Include, mViewPlayer2Include, mViewPlayer3Include, mViewPlayer4Include };
PlayerMarkR = new ToolStripMenuItem[] { mViewPlayer1MarkReplacement, mViewPlayer2MarkReplacement, mViewPlayer3MarkReplacement, mViewPlayer4MarkReplacement };
PlayerUnmarkR = new ToolStripMenuItem[] { mViewPlayer1UnmarkReplacement, mViewPlayer2UnmarkReplacement, mViewPlayer3UnmarkReplacement, mViewPlayer4UnmarkReplacement };
}
/// <summary>
/// Игрок забанен?
/// </summary>
/// <param name="GI"></param>
/// <param name="Player"></param>
/// <returns></returns>
private bool IsPlayerBanned(GameInfo GI, int Player)
{
if (GI.R.PlayerMark[Player]) return true;
if ((RP.UserField != null) && (RP.UserField as PlayerManage).Banned.Contains(GI.R.R.Players[Player].NickName))
return true;
return false;
}
/// <summary>
/// Игрок замены?
/// </summary>
/// <param name="GI"></param>
/// <param name="Player"></param>
/// <returns></returns>
private bool IsPlayerReplacement(GameInfo GI, int Player)
{
PlayerManage PM = RP.UserField as PlayerManage;
return (PM.Replacements.Contains(GI.R.R.Players[Player].NickName))
|| PM.IsReplacementPlayer(GI.R.Hash, Player);
}
/// <summary>
/// Добавить игру в список
/// </summary>
private void AddGame(GameInfo GI)
{
ListViewItem I = new ListViewItem();
I.BackColor = !GI.R.ReplayMark ? CActive : CBanned;
I.Tag = GI;
I.Text = GI.R.R.Date.ToString();
I.UseItemStyleForSubItems = false;
I.SubItems.Add(GI.R.R.Lobby.ToString("0000")); // Lobby
I.SubItems[1].BackColor = I.BackColor;
for (int i = 0; i < GI.R.R.PlayerCount; i++)
{
I.SubItems.Add(GI.GetPlayerInfo(i));
if (IsPlayerBanned(GI, i) || GI.R.ReplayMark)
I.SubItems[i + 2].BackColor = CBanned;
else if (IsPlayerReplacement(GI, i))
I.SubItems[i + 2].BackColor = CReplacement;
else
I.SubItems[i + 2].BackColor = CActive;
}
lGames.Items.Add(I);
}
/// <summary>
/// Обновить отображение игры
/// </summary>
/// <param name="GI"></param>
private void UpdateGameInfo(GameInfo GI)
{
foreach (ListViewItem I in lGames.Items)
{
if (I.Tag == GI)
{
I.BackColor = !GI.R.ReplayMark ? CActive : CBanned;
I.SubItems[1].BackColor = I.BackColor;
for (int i = 0; i < GI.R.R.PlayerCount; i++)
{
if(IsPlayerBanned(GI, i) || GI.R.ReplayMark)
I.SubItems[i + 2].BackColor = CBanned;
else if(IsPlayerReplacement(GI, i))
I.SubItems[i + 2].BackColor = CReplacement;
else
I.SubItems[i + 2].BackColor = CActive;
}
break;
}
}
}
/// <summary>
/// Получить выбранную игру
/// </summary>
/// <returns></returns>
private GameInfo GetSelectedGame()
{
return (lGames.SelectedItems.Count > 0) ? lGames.SelectedItems[0].Tag as GameInfo : null;
}
/// <summary>
/// Загрузить игры
/// </summary>
private void LoadGames()
{
if (File.Exists(TP.Dir + "tournier.xml"))
{
RP = ResultPack.Load(TP.Dir, "tournier.xml", TP);
if (RP.UserField == null) RP.UserField = new PlayerManage();
lGames.BeginUpdate();
for (int i = 0; i < RP.Results.Count; i++)
AddGame(new GameInfo(RP.Results[i]));
lGames.EndUpdate();
}
else
{
RP = new ResultPack();
RP.UserField = new PlayerManage();
lGames.BeginUpdate();
for (int i = 0; i < TP.Hashes.Count; i++)
{
LightResult R = new LightResult(TP.GetGameReplay(TP.Hashes[i]));
RP.Results.Add(R);
AddGame(new GameInfo(R));
}
lGames.EndUpdate();
}
}
/// <summary>
/// Загрузить игры, которые ещё не загружены
/// </summary>
private void LoadOtherGames()
{
lGames.BeginUpdate();
for (int i = 0; i < TP.Hashes.Count; i++)
{
if (RP.IsExists(TP.Hashes[i])) continue;
LightResult R = new LightResult(TP.GetGameReplay(TP.Hashes[i]));
RP.Results.Add(R);
AddGame(new GameInfo(R));
}
lGames.EndUpdate();
}
/// <summary>
/// Сохранить
/// </summary>
private void SaveGames()
{
RP.Save(TP.Dir, "tournier.xml");
}
protected override void OnProjectLoad()
{
LoadGames();
CalcPlayers();
LoadPlayerList();
}
protected override void OnProjectUnload()
{
SaveGames();
lPlayers.Items.Clear();
lGames.Items.Clear();
RP = null;
}
private void fTournier_Load(object sender, EventArgs e)
{
ResizeColumns(lGames, GamesCols);
ResizeColumns(lPlayers, PlayersCols);
ResizeColumns(lResult, ResultCols);
ResizeColumns(lYaku, YakuCols);
CheckProject();
}
private void ResizeTables(int W, int H)
{
lGames.Width = W;
lGames.Height = H;
lPlayers.Width = W;
lPlayers.Height = H;
lResult.Width = W;
lResult.Height = H;
lYaku.Width = W;
lYaku.Height = H;
}
private void fTournier_Resize(object sender, EventArgs e)
{
lGames.BeginUpdate();
lPlayers.BeginUpdate();
lResult.BeginUpdate();
lYaku.BeginUpdate();
if (WindowState == FormWindowState.Maximized)
{
tbTabs.Left = 0;
tbTabs.Top = 0;
tbTabs.Width = ClientSize.Width;
tbTabs.Height = ClientSize.Height;
}
else
{
tbTabs.Left = 12;
tbTabs.Top = 12;
tbTabs.Width = ClientSize.Width - 24;
tbTabs.Height = ClientSize.Height - 24;
}
if (tbTabs.SelectedTab == tGames)
ResizeTables(tGames.ClientSize.Width, tGames.ClientSize.Height);
else if (tbTabs.SelectedTab == tPlayers)
ResizeTables(tPlayers.ClientSize.Width, tPlayers.ClientSize.Height);
else if (tbTabs.SelectedTab == tTable)
ResizeTables(tTable.ClientSize.Width, tTable.ClientSize.Height);
ResizeColumns(lGames, GamesCols);
ResizeColumns(lPlayers, PlayersCols);
ResizeColumns(lResult, ResultCols);
ResizeColumns(lYaku, YakuCols);
lYaku.EndUpdate();
lPlayers.EndUpdate();
lGames.EndUpdate();
lResult.EndUpdate();
}
private void fTournier_ResizeEnd(object sender, EventArgs e)
{
}
/// <summary>
/// Адаптировать контекстное меню
/// </summary>
/// <param name="Index"></param>
private void SetupMenuForPlayer(GameInfo GI, int Index)
{
PlayerManage PM = RP.UserField as PlayerManage;
bool IsTempReplacement = PM.IsReplacementPlayer(GI.R.Hash, Index);
bool IsReplacement = PM.Replacements.Contains(GI.R.R.Players[Index].NickName);
bool IsBanned = PM.Banned.Contains(GI.R.R.Players[Index].NickName);
PlayerView[Index].Visible = (GI.R.R.PlayerCount > Index);
if (GI.R.R.PlayerCount <= Index) return;
PlayerView[Index].Text = GI.GetPlayerRankedInfo(Index);
PlayerView[Index].Image = IsPlayerBanned(GI, Index) ?
imgState.Images[0] :
(IsPlayerReplacement(GI, Index) ? imgState.Images[1] : null);
PlayerExclude[Index].Visible = !GI.R.PlayerMark[Index] && !IsBanned;
PlayerInclude[Index].Visible = GI.R.PlayerMark[Index] && !IsBanned;
PlayerMarkR[Index].Visible = !IsTempReplacement && !IsReplacement && !IsBanned && !GI.R.PlayerMark[Index];
PlayerUnmarkR[Index].Visible = IsTempReplacement && !IsReplacement && !IsBanned && !GI.R.PlayerMark[Index];
}
private void mView_Opening(object sender, CancelEventArgs e)
{
var GI = GetSelectedGame();
if (GI == null)
{
e.Cancel = true;
return;
}
// Запишем ники игроков
for (int i = 0; i < GI.R.R.PlayerCount; i++)
SetupMenuForPlayer(GI, i);
mViewExcludeGame.Visible = !GI.R.ReplayMark;
mViewIncludeGame.Visible = GI.R.ReplayMark;
mViewLoadOther.Enabled = lGames.Items.Count != RP.Results.Count;
}
private void mViewPlayerReplay_Click(object sender, EventArgs e)
{
var GI = GetSelectedGame();
if (GI == null) return;
int Player = Convert.ToInt32(((sender as ToolStripDropDownItem).Tag));
TP.ViewReplayExternal(GI.R.R.Hash, Player);
}
private void mViewPlayerExclude_Click(object sender, EventArgs e)
{
var GI = GetSelectedGame();
if (GI == null) return;
int Player = Convert.ToInt32(((sender as ToolStripDropDownItem).Tag));
GI.R.PlayerMark[Player] = true;
UpdateGameInfo(GI);
}
private void mViewPlayerInclude_Click(object sender, EventArgs e)
{
var GI = GetSelectedGame();
if (GI == null) return;
int Player = Convert.ToInt32(((sender as ToolStripDropDownItem).Tag));
GI.R.PlayerMark[Player] = false;
UpdateGameInfo(GI);
}
private void mViewPlayerMarkReplacement_Click(object sender, EventArgs e)
{
var GI = GetSelectedGame();
if (GI == null) return;
int Player = Convert.ToInt32(((sender as ToolStripDropDownItem).Tag));
PlayerManage PM = RP.UserField as PlayerManage;
if (!PM.IsReplacementPlayer(GI.R.Hash, Player))
PM.TempReplacements.Add(new TempReplacement(GI.R.Hash, Player));
UpdateGameInfo(GI);
}
private void mViewPlayerUnmarkReplacement_Click(object sender, EventArgs e)
{
var GI = GetSelectedGame();
if (GI == null) return;
int Player = Convert.ToInt32(((sender as ToolStripDropDownItem).Tag));
PlayerManage PM = RP.UserField as PlayerManage;
for (int i = 0; i < PM.TempReplacements.Count; i++)
{
var TR = PM.TempReplacements[i];
if ((TR.Hash.CompareTo(GI.R.Hash) == 0) && TR.Player == Player)
{
PM.TempReplacements.Remove(TR);
break;
}
}
UpdateGameInfo(GI);
}
private void mViewPaifu_Click(object sender, EventArgs e)
{
var GI = GetSelectedGame();
if (GI == null) return;
Form F = new fPaifuViewer(GI.R.Hash, 0);
F.MdiParent = MdiParent;
F.Show();
}
private void mViewExcludeIncludeGame_Click(object sender, EventArgs e)
{
var GI = GetSelectedGame();
if (GI == null) return;
int Value = Convert.ToInt32(((sender as ToolStripDropDownItem).Tag));
GI.R.ReplayMark = (Value != 1);
UpdateGameInfo(GI);
}
private void fTournier_FormClosing(object sender, FormClosingEventArgs e)
{
SaveGames();
}
private void tbTabs_SelectedIndexChanged(object sender, EventArgs e)
{
if (tbTabs.SelectedTab == tGames) lGames.Select();
if (tbTabs.SelectedTab == tPlayers) lPlayers.Select();
if (tbTabs.SelectedTab == tTable)
{
CalcResult();
BuildResultTable();
lResult.Select();
}
if (tbTabs.SelectedTab == tYaku)
{
BuildYakuTable();
lYaku.Select();
}
}
}
}