/
sgsui_MainWindow.cpp
960 lines (855 loc) · 26 KB
/
sgsui_MainWindow.cpp
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
/*
* sgsui_MainWindow.cpp
*
* Created on: Mar 18, 2012
* Author: latios
*/
#include "sgsui_MainWindow.h"
#include "sgsui_ZhuangbeiArea.h"
#include "sgsui_WujiangArea.h"
#include "sgsui_PlayerArea.h"
#include "sgsui_Shoupai.h"
#include "sgsui_MessageBox.h"
#include "sgsui_DialogBox.h"
#include "sgsui_CardContainer.h"
#include "sgsui_WujiangChooseBox.h"
#include "sgsui_GuanxingBox.h"
#include "sgsui_FanjianBox.h"
#include "sgsui_GameOverBox.h"
#include "sgsui_PixmapAnimationWidget.h"
#include "sgsui_LineAnimationWidget.h"
#include "sgsui_ZhuangbeiLabel.h"
#include "sgsui_WugufengdengBox.h"
#include "sgsui_BlockTimer.h"
#include "sgsui_ZhuangbeiPic.h"
#include "sgsui_AudioPlayer.h"
#include "sgsui_nameConvert.h"
#include "sgsui_output.h"
#include "sgsdata_enum.h"
#include <QtGui>
namespace sgsui {
MainWindow * MainWindow::mainWindowPtr() {
return mainWindowPointer;
}
void MainWindow::appendHistory(const QString &textInput) {
if (!mainWindowPointer)
return;
mainWindowPointer->historyText->append(setColored(textInput, false));
}
void MainWindow::appendDebug(const QString &textInput) {
if (!mainWindowPointer)
return;
mainWindowPointer->debugText->append(textInput);
}
void MainWindow::exec() {
if (!blockLoop.isRunning()) {
emit blocked();
printDebug(
"<font color=red><b>Notice: </b></font>MainWindow::exec: MainWindow is blocked");
blockLoop.exec();
emit
unblocked();
printDebug(
"<font color=red><b>Notice: </b></font>MainWindow::exec: MainWindow is unblocked");
} else
printDebug(
"<font color=red><b>Warning: </b></font>MainWindow::exec: MainWindow is already blocking!");
}
void MainWindow::sleepSomeTime(int sleepTime) {
if (blockTimer)
blockTimer->block(sleepTime);
}
void MainWindow::unblock() {
if (blockLoop.isRunning()) {
blockLoop.quit();
}
}
bool MainWindow::isSingleStep() const {
return singleCheckBox->isChecked();
}
void MainWindow::pause() {
pauseButton->click();
}
void MainWindow::pauseClicked() {
if (responseType != NotResponding || !blockingFrameList.empty()) {
pauseButton->setChecked(!pauseButton->isChecked());
return;
}
if (pauseButton->isChecked()) {
showPauseMessage(
singleCheckBox->isChecked() ?
GUIStaticData::singleStep : GUIStaticData::gamePaused);
exec();
pauseBox->hide();
statusbar->clearMessage();
} else {
unblock();
}
}
bool MainWindow::isBlocked() const {
return blockLoop.isRunning();
}
bool MainWindow::isResponding() const {
if (!GUIresponding
&& blockingFrameMovingAnimation->state()
!= QAbstractAnimation::Running) {
if (!blockingFrameList.empty()) {
QPoint position = blockingFrameList.back()->pos();
QPoint translate(10, 0);
blockingFrameMovingAnimation->setTargetObject(
blockingFrameList.back());
blockingFrameMovingAnimation->setStartValue(position);
blockingFrameMovingAnimation->setKeyValueAt(0.25,
position + translate);
blockingFrameMovingAnimation->setKeyValueAt(0.75,
position - translate);
blockingFrameMovingAnimation->setEndValue(position);
blockingFrameMovingAnimation->start();
} else
printDebug(
"<font color=red><b>Warning: </b></font>MainWindow::isResponding(): MainWindow has been set NOT responding while no widget is blocking it");
}
return GUIresponding && responseType != NotResponding;
}
bool MainWindow::isRespondingNoAnimation() const {
return (responseType != NotResponding) && GUIresponding;
}
void MainWindow::setResponding(bool responding, BlockingFrame *blockWidget) {
if (responding) {
blockingFrameList.remove(blockWidget);
GUIresponding = blockingFrameList.empty();
} else {
blockingFrameList.push_back(blockWidget);
GUIresponding = false;
}
}
bool MainWindow::isSoundOn() const {
return soundCheckBox->isChecked();
}
void MainWindow::addUsedCard(CardFrame * usedCard) {
if (usedCardLayout->count() > GUIStaticData::maxUsedCardContain)
delete usedCardLayout->takeAt(1)->widget();
usedCardLayout->addWidget(usedCard);
}
void MainWindow::addShoupai(const sgs::DataType::Card * card) {
Shoupai* addedShoupai = new Shoupai(card, this);
shoupaiLayout->addWidget(addedShoupai);
shoupaiList.push_back(addedShoupai);
printDebug(
"MainWindow::addShoupai: adding card "
+ cardFullDisplayName(card, false));
}
void MainWindow::removeShoupai(Shoupai * shoupaiToRemove) {
shoupaiLayout->removeWidget(shoupaiToRemove);
shoupaiList.remove(shoupaiToRemove);
delete shoupaiToRemove;
}
void MainWindow::endResponse() {
// this function should only be called at the end of a response
// it set every Shoupai and PlayerArea and ZhuangbeiPic selectable
responseType = NotResponding;
terminateCardSelect();
terminatePlayerSelect();
terminateZhuangbeiSelect();
terminateSkillSelect();
checkButtons();
// clear data
isGoingToAbandon = false;
selectedZhuangbei = 0;
selectedSkill = sgs::ConstData::hkNone;
cancelResponse = false;
selectedShoupaiList.clear();
selectedPlayerAreaList.clear();
maxShoupaiSelect = 0;
minShoupaiSelect = 0;
maxPlayerSelect = 0;
minPlayerSelect = 0;
skillVerShaOrNot = false;
tuxiList.clear();
selectedSkillCardVec.clear();
liuliAttacker = 0;
printDebug("MainWindow::endResponse: response is over");
}
void MainWindow::terminatePlayerSelect() {
for (std::vector<PlayerArea*>::iterator iter =
otherPlayerAreaVector.begin(); iter != otherPlayerAreaVector.end();
++iter) {
(*iter)->setSelectable();
(*iter)->setUnselected();
}
wujiangA->setSelectable();
wujiangA->setUnselected();
}
void MainWindow::terminateCardSelect() {
for (std::list<Shoupai*>::iterator iter = shoupaiList.begin();
iter != shoupaiList.end(); ++iter) {
(*iter)->setUnselected();
(*iter)->setSelectable();
}
}
void MainWindow::terminateZhuangbeiSelect() {
zhuangbeiA->setSelectable(0, true, true);
zhuangbeiA->setSelectable(1, true, true);
zhuangbeiA->setSelectable(2, true, true);
zhuangbeiA->setSelectable(3, true, true);
}
void MainWindow::terminateSkillSelect() {
wujiangA->disableAllSkillButtons();
}
void MainWindow::changeMusicState(bool musicOn) {
if (musicOn)
audioPlayer->startBGM();
else
audioPlayer->pauseBGM();
}
void MainWindow::changeScreenState(bool fullscreen) {
if (fullscreen)
setWindowState(Qt::WindowFullScreen);
else
setWindowState(Qt::WindowMaximized);
}
QPoint MainWindow::cardDeckPoint() const {
return realPos(cardDeckLabel);
}
QPoint MainWindow::lastShoupaiPoint() const {
int cardFrameWidth = 93, verticalMargin = 37;
int maxHorizontalPos = shoupaiArea->width() - cardFrameWidth;
int existingDeckWidth =
static_cast<int>(cardFrameWidth * shoupaiList.size());
return realPos(shoupaiArea)
+ QPoint(
existingDeckWidth > maxHorizontalPos ?
maxHorizontalPos : existingDeckWidth,
verticalMargin);
}
QPoint MainWindow::shoupaiEndPoint() const {
int verticalMargin = 37;
return realPos(shoupaiArea) + QPoint(shoupaiArea->width(), verticalMargin);
}
QPoint MainWindow::usedCardPoint() const {
return realPos(usedCardFrame);
}
QPoint MainWindow::zhuangbeiPoint() const {
QPoint zhuangbeiMargin(20, 20);
return realPos(zhuangbeiArea) + zhuangbeiMargin;
}
QPoint MainWindow::shoupaiCenterPoint() const {
return realPos(shoupaiArea) + QPoint(shoupaiArea->size().width() / 2, 20);
}
QPoint MainWindow::wujiangCenterPoint() const {
return realPos(wujiangArea)
+ QPoint(wujiangArea->size().width() / 2,
wujiangArea->size().height() / 2);
}
QPoint MainWindow::realPos(QWidget* widgetToCal) {
QPoint topLeftCoordinate = widgetToCal->pos();
for (QWidget *thisWidget = widgetToCal->parentWidget();
thisWidget != widgetToCal->window();
thisWidget = thisWidget->parentWidget())
topLeftCoordinate += thisWidget->pos();
return topLeftCoordinate;
}
void MainWindow::showWugu(
const std::vector<std::pair<const sgs::DataType::Card *, bool> >& wuguCards) {
wugufengdengBox->showContainer(wuguCards);
}
void MainWindow::closeEvent(QCloseEvent *event) {
raise();
if (getDialogResponse(GUIStaticData::quitOrNot) == 0) {
event->ignore();
} else {
QApplication::processEvents();
GUIStaticData::quitGame();
}
}
void MainWindow::keyPressEvent(QKeyEvent *event) {
// PlayerArea
if (event->modifiers() == Qt::AltModifier) {
if (event->key() == Qt::Key_0) {
AbstractPlayerArea* clickedPlayer = goToAbstractPlayerArea(0);
if (clickedPlayer)
clickedPlayer->click();
return;
}
if (event->key() == Qt::Key_1) {
AbstractPlayerArea* clickedPlayer = goToAbstractPlayerArea(1);
if (clickedPlayer)
clickedPlayer->click();
return;
}
if (event->key() == Qt::Key_2) {
AbstractPlayerArea* clickedPlayer = goToAbstractPlayerArea(2);
if (clickedPlayer)
clickedPlayer->click();
return;
}
if (event->key() == Qt::Key_3) {
AbstractPlayerArea* clickedPlayer = goToAbstractPlayerArea(3);
if (clickedPlayer)
clickedPlayer->click();
return;
}
if (event->key() == Qt::Key_4) {
AbstractPlayerArea* clickedPlayer = goToAbstractPlayerArea(4);
if (clickedPlayer)
clickedPlayer->click();
return;
}
if (event->key() == Qt::Key_5) {
AbstractPlayerArea* clickedPlayer = goToAbstractPlayerArea(5);
if (clickedPlayer)
clickedPlayer->click();
return;
}
if (event->key() == Qt::Key_6) {
AbstractPlayerArea* clickedPlayer = goToAbstractPlayerArea(6);
if (clickedPlayer)
clickedPlayer->click();
return;
}
if (event->key() == Qt::Key_7) {
AbstractPlayerArea* clickedPlayer = goToAbstractPlayerArea(7);
if (clickedPlayer)
clickedPlayer->click();
return;
}
}
// zhuangbei
if (event->modifiers() == Qt::ControlModifier) {
ZhuangbeiPic* clickedZhuangbei;
if (event->key() == Qt::Key_1) {
clickedZhuangbei = zhuangbeiA->getWuqiPic();
if (clickedZhuangbei)
clickedZhuangbei->click();
return;
}
if (event->key() == Qt::Key_2) {
clickedZhuangbei = zhuangbeiA->getFangjuPic();
if (clickedZhuangbei)
clickedZhuangbei->click();
return;
}
if (event->key() == Qt::Key_3) {
clickedZhuangbei = zhuangbeiA->getJianmaPic();
if (clickedZhuangbei)
clickedZhuangbei->click();
return;
}
if (event->key() == Qt::Key_4) {
clickedZhuangbei = zhuangbeiA->getJiamaPic();
if (clickedZhuangbei)
clickedZhuangbei->click();
return;
}
}
if ((event->key() == Qt::Key_F7 && event->modifiers() == Qt::NoModifier)
|| (event->key() == Qt::Key_P
&& event->modifiers() == Qt::ControlModifier)) {
pauseButton->click();
return;
}
if (event->key() == Qt::Key_F12 && event->modifiers() == Qt::NoModifier) {
singleCheckBox->click();
return;
}
if ((event->key() == Qt::Key_F1 && event->modifiers() == Qt::NoModifier)
|| (event->key() == Qt::Key_H
&& event->modifiers() == Qt::ControlModifier)) {
helpButton->click();
return;
}
if (event->key() == Qt::Key_M
&& event->modifiers() == Qt::ControlModifier) {
musicCheckBox->click();
return;
}
if (event->key() == Qt::Key_S
&& event->modifiers() == Qt::ControlModifier) {
soundCheckBox->click();
return;
}
if (event->key() == Qt::Key_F
&& event->modifiers() == Qt::ControlModifier) {
fullscreenCheckBox->click();
return;
}
if (event->key() == Qt::Key_T
&& event->modifiers() == Qt::ControlModifier) {
AICheckBox->click();
return;
}
if ((event->key() == Qt::Key_F11 && event->modifiers() == Qt::NoModifier)
|| (event->key() == Qt::Key_D
&& event->modifiers() == Qt::ControlModifier)) {
debugCheckBox->click();
if (debugCheckBox->isChecked())
showTipMessage(GUIStaticData::debugTurnedOn);
else
showTipMessage(GUIStaticData::debugTurnedOff);
return;
}
if (event->key() == Qt::Key_Q
&& event->modifiers() == Qt::ControlModifier) {
close();
return;
}
if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
&& event->modifiers() == Qt::NoModifier) {
if (!blockingFrameList.empty())
blockingFrameList.back()->enterKeyPressedEvent();
else
okButton->click();
return;
}
if (event->key() == Qt::Key_Escape
&& event->modifiers() == Qt::NoModifier) {
if (!blockingFrameList.empty())
blockingFrameList.back()->escapeKeyPressedEvent();
else
cancelButton->click();
return;
}
if (event->key() == Qt::Key_Delete
&& event->modifiers() == Qt::NoModifier) {
abandonButton->click();
return;
}
// shoupai select
if (event->key() == Qt::Key_1 && event->modifiers() == Qt::NoModifier) {
CardButton* shoupai = goToShoupai(0);
if (shoupai)
shoupai->click();
return;
}
if (event->key() == Qt::Key_2 && event->modifiers() == Qt::NoModifier) {
CardButton* shoupai = goToShoupai(1);
if (shoupai)
shoupai->click();
return;
}
if (event->key() == Qt::Key_3 && event->modifiers() == Qt::NoModifier) {
CardButton* shoupai = goToShoupai(2);
if (shoupai)
shoupai->click();
return;
}
if (event->key() == Qt::Key_4 && event->modifiers() == Qt::NoModifier) {
CardButton* shoupai = goToShoupai(3);
if (shoupai)
shoupai->click();
return;
}
if (event->key() == Qt::Key_5 && event->modifiers() == Qt::NoModifier) {
CardButton* shoupai = goToShoupai(4);
if (shoupai)
shoupai->click();
}
if (event->key() == Qt::Key_6 && event->modifiers() == Qt::NoModifier) {
CardButton* shoupai = goToShoupai(5);
if (shoupai)
shoupai->click();
return;
}
if (event->key() == Qt::Key_7 && event->modifiers() == Qt::NoModifier) {
CardButton* shoupai = goToShoupai(6);
if (shoupai)
shoupai->click();
return;
}
if (event->key() == Qt::Key_8 && event->modifiers() == Qt::NoModifier) {
CardButton* shoupai = goToShoupai(7);
if (shoupai)
shoupai->click();
return;
}
if (event->key() == Qt::Key_9 && event->modifiers() == Qt::NoModifier) {
CardButton* shoupai = goToShoupai(8);
if (shoupai)
shoupai->click();
return;
}
if (event->key() == Qt::Key_0 && event->modifiers() == Qt::NoModifier) {
if (responseType == NotResponding)
return;
if (responseType == DiscardCard) {
std::vector<Shoupai *> selected_copy(selectedAbandonList.begin(),
selectedAbandonList.end());
for (std::vector<Shoupai *>::iterator iter = selected_copy.begin();
iter != selected_copy.end(); ++iter) {
(*iter)->click();
}
} else {
std::vector<Shoupai *> selected_copy(selectedShoupaiList.begin(),
selectedShoupaiList.end());
for (std::vector<Shoupai *>::iterator iter = selected_copy.begin();
iter != selected_copy.end(); ++iter) {
(*iter)->click();
}
}
return;
}
QMainWindow::keyPressEvent(event);
}
CardButton* MainWindow::goToShoupai(unsigned shoupaiIndex) {
// shoupaiIndex starts from 0
if (shoupaiList.size() > shoupaiIndex) {
std::list<Shoupai *>::iterator iter = shoupaiList.begin();
for (unsigned i = 0; i < shoupaiIndex; ++i) {
++iter;
}
return *iter;
} else
return 0;
}
AbstractPlayerArea* MainWindow::goToAbstractPlayerArea(int pressedKey) {
if (pressedKey <= 0) {
return wujiangA;
} else if (pressedKey < GUIStaticData::getPlayerCount()) {
return otherPlayerAreaAtIndex(pressedKey + 1);
}
return 0;
}
void MainWindow::runPixmapAnimation(int targetPlayerIndex,
PixmapAnimationType animationType) {
if (targetPlayerIndex < 1 || targetPlayerIndex > playerCount) {
printDebug(
"<font color=red><b>Warning: </b></font>MainWindow::runPixmapAnimation: invalid target index");
return;
} else {
printDebug(
"MainWindow::runPixmapAnimation: start, target index (seat + 1) = "
+ QString::number(targetPlayerIndex));
}
QPoint targetPoint = animationPointAtIndex(targetPlayerIndex);
pixmapAnimationWidget->pixmapAnimation(targetPoint, animationType);
if (animationType == DamageAnimation
|| animationType == LightningAnimation) {
if (targetPlayerIndex != playerIndex) {
QWidget* target =
otherPlayerAreaAtIndex(targetPlayerIndex)->parentWidget();
damageMovingAnimation->setTargetObject(target);
QPoint originPos = target->pos();
damageMovingAnimation->setStartValue(originPos);
damageMovingAnimation->setKeyValueAt(0.5,
originPos + QPoint(20, 0));
damageMovingAnimation->setEndValue(originPos);
damageMovingAnimation->start();
}
if (animationType == DamageAnimation)
audioPlayer->playSound(DamageEffectSound,
getSexAtIndex(targetPlayerIndex) == sgs::ConstData::MALE);
else
audioPlayer->playSound(LightningEffectSound);
}
}
void MainWindow::showTipMessage(const QString &tip, bool richText,
int duration) {
duration = duration > 0 ? duration : GUIStaticData::showTipDuration;
tipBox->setGeometry(
QRect(
mainFrame->geometry().center()
- QPoint(tipBox->width() / 2, tipBox->height() / 2),
tipBox->size()));
tipBox->showTipMessage(tip, richText, duration);
statusbar->showStatusBarMessage(tip, richText, duration);
}
void MainWindow::showPauseMessage(const QString & pause, bool richText) {
pauseBox->setGeometry(
QRect(
mainFrame->geometry().center()
- QPoint(pauseBox->width() / 2,
pauseBox->height() / 2), pauseBox->size()));
pauseBox->showPauseMessage(pause);
// -1 means that this statusbar message does not disappear automatically
statusbar->showStatusBarMessage(pause, richText, -1);
}
void MainWindow::showStatusBarMessage(const QString &tip, bool richText,
int duration) {
statusbar->showStatusBarMessage(tip, richText, duration);
}
int MainWindow::getDialogResponse(const QString &message) {
dialogBox = new DialogBox(this);
dialogBox->setGeometry(
QRect(
mainFrame->geometry().center()
- QPoint(dialogBox->width() / 2,
dialogBox->height() / 2),
dialogBox->size()));
int returnValue = dialogBox->exec(message);
delete dialogBox;
dialogBox = 0;
return returnValue;
}
sgs::ConstData::HeroType MainWindow::chooseWujiang(
sgs::ConstData::HeroType zhugong, sgs::ConstData::PlayerRole shenfen,
sgs::ConstData::HeroType avaliable1,
sgs::ConstData::HeroType avaliable2,
sgs::ConstData::HeroType avaliable3) {
sgs::ConstData::HeroType result = wujiangChooseBox->chooseWujiang(zhugong,
shenfen, avaliable1, avaliable2, avaliable3);
audioPlayer->playSound(PlayersCreated);
return result;
}
sgs::ConstData::HeroType MainWindow::chooseZhugongWujiang(
sgs::ConstData::HeroType avaliable1,
sgs::ConstData::HeroType avaliable2,
sgs::ConstData::HeroType avaliable3,
sgs::ConstData::HeroType avaliable4,
sgs::ConstData::HeroType avaliable5) {
sgs::ConstData::HeroType result = wujiangChooseBox->chooseZhugongWujiang(
avaliable1, avaliable2, avaliable3, avaliable4, avaliable5);
audioPlayer->playSound(PlayersCreated);
return result;
}
void MainWindow::runGuanxing() {
// TODO complete it;
}
void MainWindow::runWugufengdeng() {
// TODO complete it;
}
sgs::ConstData::CardColor MainWindow::runFanjian() {
fanjianBox->setGeometry(
QRect(
mainFrame->geometry().center()
- QPoint(fanjianBox->width() / 2,
fanjianBox->height() / 2),
fanjianBox->size()));
return fanjianBox->getFanjianColor();
}
void MainWindow::runLineAnimation(int sourcePlayerIndex, int targetPlayerIndex1,
int targetPlayerIndex2, int targetPlayerIndex3, int targetPlayerIndex4,
int targetPlayerIndex5, int targetPlayerIndex6,
int targetPlayerIndex7) {
int targetCandidates[7] = { targetPlayerIndex1, targetPlayerIndex2,
targetPlayerIndex3, targetPlayerIndex4, targetPlayerIndex5,
targetPlayerIndex6, targetPlayerIndex7 };
int verticalDifference = 50;
lineAnimationWidget->setGeometry(
mainFrame->geometry().adjusted(0, 0, 0, verticalDifference));
QPoint startPoint = animationPointAtIndex(sourcePlayerIndex);
std::vector<QPoint> targetPointVec;
for (int i = 0; i < 7; ++i) {
if (targetCandidates[i])
targetPointVec.push_back(
animationPointAtIndex(targetCandidates[i]));
}
lineAnimationWidget->lineAnimation(startPoint, targetPointVec);
}
PlayerArea* MainWindow::otherPlayerAreaAtIndex(int index) const {
if (index == playerIndex || index < 0 || index > playerCount) {
printDebug(
"MainWindow::otherPlayerAreaAtIndex: index == playerIndex or index invalid");
return 0;
}
int initiatePosition =
(index > playerIndex) ?
(index - playerIndex) : (playerCount + index - playerIndex);
return *(otherPlayerAreaVector.begin() + (initiatePosition - 1));
}
QPoint MainWindow::cardPointAtIndex(int index) const {
if (index == playerIndex) {
return lastShoupaiPoint();
} else {
QPoint cardPointMargin(10, 0);
return otherPlayerAreaAtIndex(index)->topLeftPoint() + cardPointMargin;
}
}
QPoint MainWindow::animationPointAtIndex(int index) const {
if (index == playerIndex)
return shoupaiCenterPoint();
else
return otherPlayerAreaAtIndex(index)->realGeometry().center();
}
QPoint MainWindow::judgePointAtIndex(int index) const {
if (index == playerIndex) {
QPoint judgeMargin(10, -20);
return realPos(zhuangbeiArea) + judgeMargin;
} else {
QPoint judgeMargin(60, -5);
return otherPlayerAreaAtIndex(index)->topLeftPoint() + judgeMargin;
}
}
QPoint MainWindow::zhuangbeiPointAtIndex(int index) const {
if (index == playerIndex)
return zhuangbeiPoint();
else
return otherPlayerAreaAtIndex(index)->realGeometry().center();
}
sgs::ConstData::HeroSex MainWindow::getSexAtIndex(int index) const {
if (index == playerIndex)
return wujiangA->getSex();
else
return otherPlayerAreaAtIndex(index)->getSex();
}
sgs::ConstData::HeroType MainWindow::getHeroTypeAtIndex(int index) const {
if (index == playerIndex)
return wujiangA->getHeroType();
else
return otherPlayerAreaAtIndex(index)->getHeroType();
}
sgs::ConstData::PlayerRole MainWindow::getRoleAtIndex(int index) const {
if (index == playerIndex)
return wujiangA->getRole();
else
return otherPlayerAreaAtIndex(index)->getRole();
}
bool MainWindow::getIsDeadAtIndex(int index) const {
if (index == playerIndex)
return wujiangA->isDead();
else
return otherPlayerAreaAtIndex(index)->isDead();
}
const CardFrame * MainWindow::getWuqiAtIndex(int index) const {
if (index == playerIndex)
return zhuangbeiA->getWuqi();
else
return otherPlayerAreaAtIndex(index)->getWuqi();
}
const CardFrame * MainWindow::getFangjuAtIndex(int index) const {
if (index == playerIndex)
return zhuangbeiA->getFangju();
else
return otherPlayerAreaAtIndex(index)->getFangju();
}
const CardFrame * MainWindow::getJianmaAtIndex(int index) const {
if (index == playerIndex)
return zhuangbeiA->getJianma();
else
return otherPlayerAreaAtIndex(index)->getJianma();
}
const CardFrame * MainWindow::getJiamaAtIndex(int index) const {
if (index == playerIndex)
return zhuangbeiA->getJiama();
else
return otherPlayerAreaAtIndex(index)->getJiama();
}
void MainWindow::addWuqiAtIndex(int index, CardFrame * newWuqiCard) {
if (index == playerIndex)
zhuangbeiA->addWuqi(newWuqiCard);
else
otherPlayerAreaAtIndex(index)->addWuqi(newWuqiCard);
}
void MainWindow::addFangjuAtIndex(int index, CardFrame * newFangjuCard) {
if (index == playerIndex)
zhuangbeiA->addFangju(newFangjuCard);
else
otherPlayerAreaAtIndex(index)->addFangju(newFangjuCard);
}
void MainWindow::addJianmaAtIndex(int index, CardFrame * newJianmaCard) {
if (index == playerIndex)
zhuangbeiA->addJianma(newJianmaCard);
else
otherPlayerAreaAtIndex(index)->addJianma(newJianmaCard);
}
void MainWindow::addJiamaAtIndex(int index, CardFrame * newJiamaCard) {
if (index == playerIndex)
zhuangbeiA->addJiama(newJiamaCard);
else
otherPlayerAreaAtIndex(index)->addJiama(newJiamaCard);
}
void MainWindow::removeWuqiAtIndex(int index) {
if (index == playerIndex)
zhuangbeiA->removeWuqi();
else
otherPlayerAreaAtIndex(index)->removeWuqi();
}
void MainWindow::removeFangjuAtIndex(int index) {
if (index == playerIndex)
zhuangbeiA->removeFangju();
else
otherPlayerAreaAtIndex(index)->removeFangju();
}
void MainWindow::removeJianmaAtIndex(int index) {
if (index == playerIndex)
zhuangbeiA->removeJianma();
else
otherPlayerAreaAtIndex(index)->removeJianma();
}
void MainWindow::removeJiamaAtIndex(int index) {
if (index == playerIndex)
zhuangbeiA->removeJiama();
else
otherPlayerAreaAtIndex(index)->removeJiama();
}
void MainWindow::addJudgeAtIndex(int index,
sgs::ConstData::CardType judgeCard) {
if (index == playerIndex)
zhuangbeiA->addJudge(judgeCard);
else
otherPlayerAreaAtIndex(index)->addJudge(judgeCard);
}
void MainWindow::removeJudgeAtIndex(int index, sgs::ConstData::CardType judgeCard) {
if (index == playerIndex)
zhuangbeiA->removeJudge(judgeCard);
else
otherPlayerAreaAtIndex(index)->removeJudge(judgeCard);
}
void MainWindow::showSkillAtIndex(int index, sgs::ConstData::HeroSkill skill) {
if (index == playerIndex)
wujiangA->showSkill(skill);
else
otherPlayerAreaAtIndex(index)->showSkill(skill);
}
void MainWindow::showZhuangbeiAtIndex(int index,
sgs::ConstData::CardType equipCard) {
if (index == playerIndex) {
QPoint zhuangbeiLabelMargin(10, -60);
zhuangbeiLabel->move(zhuangbeiPoint() + zhuangbeiLabelMargin);
zhuangbeiLabel->showZhuangbei(equipCard);
} else
otherPlayerAreaAtIndex(index)->showZhuangbei(equipCard);
}
void MainWindow::gameOver(char result) {
gameOverBox->showResult(result);
}
AudioPlayer * MainWindow::getAudioPlayer() const {
return audioPlayer;
}
AudioPlayer * MainWindow::getSkillPlayer() const {
return skillPlayer;
}
void MainWindow::setDead(int targetPlayerIndex) {
if (targetPlayerIndex == playerIndex) {
wujiangA->setDead();
} else {
otherPlayerAreaAtIndex(targetPlayerIndex)->setDead();
}
}
void MainWindow::setRespodingPhase(int targetPlayerIndex, bool responding) {
if (targetPlayerIndex == playerIndex) {
/*DO NOTHING, as GUI doesn't has the phase of human player*/
} else {
otherPlayerAreaAtIndex(targetPlayerIndex)->setResponding(responding);
}
}
void MainWindow::setDying(int targetPlayerIndex, bool dying) {
if (targetPlayerIndex == playerIndex) {
wujiangA->setDying(dying);
} else {
otherPlayerAreaAtIndex(targetPlayerIndex)->setDying(dying);
}
}
int MainWindow::getHP(int targetPlayerIndex) const {
if (targetPlayerIndex == playerIndex) {
return wujiangA->getHP();
} else {
return otherPlayerAreaAtIndex(targetPlayerIndex)->getHP();
}
}
void MainWindow::setHP(int targetPlayerIndex, int HP) {
if (targetPlayerIndex == playerIndex) {
wujiangA->setHP(HP);
} else {
otherPlayerAreaAtIndex(targetPlayerIndex)->setHP(HP);
}
}
void MainWindow::setHPDamage(int targetPlayerIndex, int HPDamage) {
if (targetPlayerIndex == playerIndex) {
wujiangA->setHPDamage(HPDamage);
} else {
PlayerArea * targetPlayerArea = otherPlayerAreaAtIndex(
targetPlayerIndex);
targetPlayerArea->setHPDamage(HPDamage);
}
}
} /* namespace sgsui */