-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI编辑器.py
3261 lines (2784 loc) · 158 KB
/
AI编辑器.py
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
# -*- coding: utf-8 -*-
import wx
import re
import sqlite3
import shutil
import os
import xml.dom.minidom
def boolchange(string):
if string=='True':
return 1
if string=='False':
return 0
# 存放性格
PerValue={}
# 存放进攻策略
AttackValue={}
# 存放每个性格的开场行为
OpeningDic={}
# 存放新添加的开场行为
NewOpenings=[]
# 存放每个性格的队伍策略
StraDic={}
# 存放新添加的队伍策略名称
NewStra=[]
# 存放每个性格的建造策略
BuildDic={}
# 存放新添加的建造策略名称
NewBuild=[]
# 存放每个性格的喜好单位
PreferDic={}
# 存放每个性格的喜好协议
PowerDic={}
# 存放每个性格的单位上限
CapDic={}
# 存放每个队伍策略的目标
TargetDic={}
# 存放新的已命名物体类型的目标
AddTarget={}
# AI性格信息
PerData=[u'继承自',u'作为遭遇战性格',u'头像',u'资源作弊倍率-简单',u'资源作弊倍率-中等',u'资源作弊倍率-困难',u'资源作弊倍率-凶残',u'开场行为',u'队伍策略',u'建造策略',u'单位喜好',u'协议喜好',u'单位上限']
# 队伍策略信息
AttackData=[u'最大目标数',u'flag',u'活跃时间',u'触发单位',u'目标',u'战术',u'最大活动距离',u'结束时的行为',u'队伍数目',u'排除的类型',u'允许的运动类型',u'优先权',u'总是招募',u'微操',u'生产单位']
# 父性格
FatherPer=['AlliedCoopBaseCampaignPersonality','AlliedCoopBaseSkirmishPersonality','JapanCoopBaseCampaignPersonality','JapanCoopBaseSkirmishPersonality',\
'SovietCoopBaseCampaignPersonality','SovietCoopBaseSkirmishPersonality']
# 对应阵营性格必要的xml
NeededPer=['AlliedCoopBaseCampaignPersonality','AlliedCoopBaseSkirmishPersonality','JapanCoopBaseCampaignPersonality','JapanCoopBaseSkirmishPersonality',\
'SovietCoopBaseCampaignPersonality','SovietCoopBaseSkirmishPersonality','CoopBasePersonality','BasePersonality','AlliedCoopBasePersonality','JapanCoopBasePersonality','SovietCoopBasePersonality']
# 头像
Portrait=['Warren','Lissette','Giles','Shinzo','Naomi','Kenji','Oleg','Moskvin','Zhana']
# 协议列表
SpecialPower={u'空军协议':'PlayerTech_Allied_AirPower',\
u'精确打击':'PlayerTech_Allied_PrecisionStrike',\
u'扫描侦查':'PlayerTech_Allied_SatelliteSweep',\
u'高科技':'PlayerTech_Allied_HighTechnology',\
u'交换物体':'PlayerTech_Allied_ChronoSwap',\
u'自由贸易':'PlayerTech_Allied_FreeTrade',\
u'时空炸弹一级':'PlayerTech_Allied_TimeBomb_Rank1',\
u'时空炸弹二级':'PlayerTech_Allied_TimeBomb_Rank2',\
u'时空炸弹三级':'PlayerTech_Allied_TimeBomb_Rank3',\
u'冷冻一级':'PlayerTech_Allied_CryoSatellite_Rank1',\
u'冷冻二级':'PlayerTech_Allied_CryoSatellite_Rank2',\
u'冷冻三级':'PlayerTech_Allied_CryoSatellite_Rank3',\
u'时空裂缝一级':'PlayerTech_Allied_ChronoRift_Rank1',\
u'时空裂缝二级':'PlayerTech_Allied_ChronoRift_Rank2',\
u'时空裂缝三级':'PlayerTech_Allied_ChronoRift_Rank3',\
u'自杀式小飞机一级':'PlayerTech_Japan_FinalSquadron_Rank1',\
u'自杀式小飞机二级':'PlayerTech_Japan_FinalSquadron_Rank2',\
u'自杀式小飞机三级':'PlayerTech_Japan_FinalSquadron_Rank3',\
u'天皇之怒一级':'PlayerTech_Japan_EmperorsRage_Rank1',\
u'天皇之怒二级':'PlayerTech_Japan_EmperorsRage_Rank2',\
u'天皇之怒三级':'PlayerTech_Japan_EmperorsRage_Rank3',\
u'气球炸弹一级':'PlayerTech_Japan_BalloonAttack_Rank1',\
u'气球炸弹二级':'PlayerTech_Japan_BalloonAttack_Rank2',\
u'气球炸弹三级':'PlayerTech_Japan_BalloonAttack_Rank3',\
u'套子':'PlayerTech_Japan_PointDefenseDrones',\
u'自爆':'PlayerTech_Japan_EnhancedKamikaze',\
u'海军强化':'PlayerTech_Japan_NavalPower',\
u'先进火箭匣':'PlayerTech_Japan_AdvancedMissilePacks',\
u'惊骇伏击':'PlayerTech_Japan_Ambush',\
u'磁力卫星一级':'PlayerTech_Soviet_MagneticSatellite_Rank_1',\
u'磁力卫星二级':'PlayerTech_Soviet_MagneticSatellite_Rank_2',\
u'磁力卫星三级':'PlayerTech_Soviet_MagneticSatellite_Rank_3',\
u'轨道卫星一级':'PlayerTech_Soviet_OrbitalRefuse_Rank1',\
u'轨道卫星二级':'PlayerTech_Soviet_OrbitalRefuse_Rank2',\
u'轨道卫星三级':'PlayerTech_Soviet_OrbitalRefuse_Rank3',\
u'农药协议一级':'PlayerTech_Soviet_DesolatorBomb_Rank1',\
u'农药协议二级':'PlayerTech_Soviet_DesolatorBomb_Rank2',\
u'农药协议三级':'PlayerTech_Soviet_DesolatorBomb_Rank3',\
u'毒素侵蚀':'PlayerTech_Soviet_IrradiateTarget',\
u'钱套':'PlayerTech_Soviet_ProductionKickbacks',\
u'碾压协议':'PlayerTech_Soviet_CrushPuppies',\
u'磁力奇点':'PlayerTech_Soviet_MagneticSingularity',
u'恐怖机器人袭击':'PlayerTech_Soviet_TerrorDroneEggs'}
# 协议选择列表
SpecialPowerkeys=[u'空军协议',u'精确打击',u'扫描侦查',u'高科技',u'交换物体',u'自由贸易',u'时空炸弹一级',u'时空炸弹二级',u'时空炸弹三级',u'冷冻一级',u'冷冻二级',u'冷冻三级',\
u'时空裂缝一级',u'时空裂缝二级',u'时空裂缝三级',u'自杀式小飞机一级',u'自杀式小飞机二级',u'自杀式小飞机三级',u'天皇之怒一级',u'天皇之怒二级',u'天皇之怒三级',\
u'气球炸弹一级',u'气球炸弹二级',u'气球炸弹三级',u'套子',u'自爆',u'海军强化',u'先进火箭匣',u'惊骇伏击',u'磁力卫星一级',u'磁力卫星二级',u'磁力卫星三级',\
u'轨道卫星一级',u'轨道卫星二级',u'轨道卫星三级',u'农药协议一级',u'农药协议二级',u'农药协议三级',u'毒素侵蚀',u'钱套',u'碾压协议',u'磁力奇点',u'恐怖机器人袭击']
# 攻击目标列表
Target=['SafestToGroundStructureHeuristic','SafestToGroundUnitHeuristic','SafestToAirUnitHeuristic','SafestToAirStructureHeuristic','SafestToWaterUnitHeuristic',\
'SafestToWaterStructureHeuristic','ClosestStructureHeuristic','ClosestGroundStructureHeuristic','ClosestWaterStructureHeuristic','ClosestUnitHeuristic',\
'ClosestGroundUnitHeuristic','ClosestWaterUnitHeuristic','SafestToSurfaceHarvesterHeuristic','SafestToSurfaceSurveyorHeuristic','ClosestAllyUnitHeuristic',\
'ClosestAllyCombatUnitHeuristi','ClosestAllyWaterUnitHeuristic','ClosestHarvesterHeuristic']
# 微操列表
MicroManagerList=[u'StandardMicroManager', u'StandardMicroManager_MEDIUM', u'StandardMicroManager_EASY', u'CleanupMicroManager', u'FocusedMicroManager', u'FocusedMicroManager_MEDIUM',\
u'FearlessFocusedMicroManager', u'StandardFullAlphaStrikeMicroManager', u'GrowingAttacksMicroManager', u'GrowingAttacksMicroManager_MEDIUM',u'ReactiveDefenseMicroManager',\
u'FearlessMicroManager', u'FearlessMicroManager_MEDIUM', u'FearlessMicroManager_EASY', u'EmergencyDefenseMicroManager', u'EmergencyDefenseMicroManager_MEDIUM',\
u'EmergencyDefenseMicroManager_EASY', u'DefenseMicroManager', u'DefenseMicroManager_MEDIUM', u'DefenseMicroManager_EASY', u'ExpansionMicroManager', u'BaseDefenseMicroManager',\
u'FearlessDefenseMicroManager', u'FearlessDefenseMicroManager_MEDIUM', u'FearlessDefenseMicroManager_EASY',u'ScoutInfantryMicroManager', u'ScoutMicroManager', \
u'FighterAircraftMicroManager',u'BurstDroneHarassmentMicroManager', u'StealthDetectorMicroManager', u'HarrassmentMicroManager', u'HarrassmentMicroManager_MEDIUM',\
u'FighterAircraftMicroManager_MEDIUM', u'FearlessFighterAircraftMicroManager', u'AssaultAircraftMicroManager', u'TwinbladeMicroManager', u'TwinbladeMicroManager_EASY', \
u'VindicatorMicroManager',u'VindicatorMicroManager_MEDIUM', u'VindicatorMicroManager_EASY', u'FearlessVindicatorMicroManager', u'FearlessAssaultAircraftMicroManager', \
u'CenturyBomberMicroManager',u'FearlessCenturyBomberMicroManager', u'BomberAircraftMicroManager', u'FearlessBomberAircraftMicroManager', u'KirovMicroManager',\
u'FirstAssaultMicroManager', u'SpecialForcesMicroManager', u'HeavyArmorMicroManager', u'ShockSpecialistMicroManager', u'ShockSpecialistMicroManager_MEDIUM', u'AirMarshallMicroManager',\
u'FleetCommandMicroManager', u'AmbushDivisionMicroManager']
class AIEdit(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,u'AI编辑器',size=(760,560))
self.SetMaxSize((760,560))
panel=wx.Panel(self)
self.createMenuBar()
sizer=wx.BoxSizer(wx.HORIZONTAL)
self.tree=wx.TreeCtrl(panel,-1,size=(250,500),style=wx.TR_EDIT_LABELS|wx.TR_DEFAULT_STYLE)
sizer.Add(self.tree,1,wx.ALL)
self.list=wx.ListCtrl(panel,-1,size=(500,500),style=wx.LC_REPORT|wx.LC_SINGLE_SEL)
sizer.Add(self.list,3,wx.ALL)
panel.SetSizer(sizer)
panel.Fit()
self.createTree()
self.createList()
self.ModName=''
self.TreeTextEdit=''
def menuData(self):
return((u'文件',(u'新建',self.OnNew),(u'打开',self.OnOpen),(u'保存',self.OnSave),('',''),(u'退出',self.OnQuit)),
(u'编辑',(u'新增AI性格',self.OnNewPerson),(u'新增AI队伍策略',self.NewStra),(u'新增AI建造策略',self.NewBuild),(u'新增AI开场行为',self.NewOpening),('',''),(u'删除项目',self.OnDelete),(u'重命名项目',self.EnableTreeEdit)))
def createMenuBar(self):
menuBar=wx.MenuBar()
for eachMenuData in self.menuData():
menuLabel=eachMenuData[0]
menuItems=eachMenuData[1:]
menuBar.Append(self.createMenu(menuItems),menuLabel)
self.SetMenuBar(menuBar)
def createMenu(self,menuData):
menu=wx.Menu()
for eachLabel,eachHandler in menuData:
if not eachLabel:
menu.AppendSeparator()
continue
menuItem=menu.Append(-1,eachLabel)
self.Bind(wx.EVT_MENU,eachHandler,menuItem)
return menu
def createTree(self):
self.root=self.tree.AddRoot(u'AI')
self.Person=self.tree.AppendItem(self.root,u'性格')
self.Stra=self.tree.AppendItem(self.root,u'策略')
self.Opening=self.tree.AppendItem(self.root,u'开场行为')
self.AttackStra=self.tree.AppendItem(self.Stra,u'队伍策略')
self.BuildStra=self.tree.AppendItem(self.Stra,u'建造策略')
self.tree.SelectItem(self.Person)
self.Bind(wx.EVT_TREE_SEL_CHANGING, self.OnClickTree, self.tree)
self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT,self.OnBeginEditTree,self.tree)
self.Bind(wx.EVT_TREE_END_LABEL_EDIT,self.OnEndEditTree,self.tree)
def createList(self):
self.list.InsertColumn(0,u'名字')
self.list.InsertColumn(1,u'值')
self.list.SetColumnWidth(0,130)
self.list.SetColumnWidth(1,370)
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED,self.OnItemActivated,self.list)
def OnNew(self,event):
NameDialog=wx.TextEntryDialog(None,u'mod名称',u'新建',style=wx.OK|wx.CANCEL)
if NameDialog.ShowModal()==wx.ID_OK:
if re.match(r'^[a-zA-Z][a-zA-Z0-9_]+$',NameDialog.GetValue())==None:
warning=wx.MessageDialog(None,u'名称不正确',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
NameDialog.Destroy()
return
# 路径名称,以后也许需要修改
pathname='Mods\\'+NameDialog.GetValue()
if os.path.exists(pathname):
warning=wx.MessageDialog(None,u'Mod名称已存在',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
NameDialog.Destroy()
return
self.ModName=NameDialog.GetValue()
title=self.ModName+u' - AI编辑器'
self.SetTitle(title)
NameDialog.Destroy()
def OnOpen(self,event):
ModList=os.listdir('Mods')
for i in ModList:
if re.match(r'^[a-zA-Z]+$',i)==None:
ModList.remove(i)
ModChoice=wx.SingleChoiceDialog(None,u'选择一个mod',u'打开',ModList)
if ModChoice.ShowModal()==wx.ID_OK:
# 清空存放的数据
PerValue.clear()
OpeningDic.clear()
StraDic.clear()
BuildDic.clear()
PreferDic.clear()
PowerDic.clear()
CapDic.clear()
AddTarget.clear()
del NewOpenings[:]
del NewStra[:]
del NewBuild[:]
self.tree.DeleteChildren(self.Person)
self.tree.DeleteChildren(self.AttackStra)
self.tree.DeleteChildren(self.BuildStra)
self.tree.DeleteChildren(self.Opening)
self.ModName=ModChoice.GetStringSelection()
title=self.ModName+u' - AI编辑器'
self.SetTitle(title)
pathname='Mods\\'+ModList[ModChoice.GetSelection()]
for root,dirs,files in os.walk(pathname):
for xmlfile in files:
if xmlfile.endswith('.xml'):
if xmlfile.rstrip('.xml') in NeededPer:
continue
dom=xml.dom.minidom.parse(os.path.join(root,xmlfile))
root=dom.documentElement
if root.getElementsByTagName('AIPersonalityDefinition'):
NewRoot=root.getElementsByTagName('AIPersonalityDefinition')[0]
name=NewRoot.getAttribute('id')
if re.match(r'^[0-9]',name)!=None:
name=name[1:]
self.tree.AppendItem(self.Person,name)
PerValue[name]=[]
NewPerValue=PerValue[name]
for i in range(len(PerData)):
NewPerValue.append('')
OpeningDic[name]={}
StraDic[name]={}
BuildDic[name]={}
PreferDic[name]={}
PowerDic[name]={}
CapDic[name]={}
NewPerValue[0]=NewRoot.getAttribute('inheritFrom')
NewPerValue[1]=NewRoot.getAttribute('SkirmishPersonality').capitalize()
NewPerValue[2]=NewRoot.getAttribute('CommanderPortrait')
CheatNodes=root.getElementsByTagName('ResourceMultiplierCheat')
for Nodes in CheatNodes:
print '1'
if Nodes.getAttribute('Difficulty')!='':
DifficultyStr=Nodes.getAttribute('Difficulty')
if re.search(r'EASY',DifficultyStr)!=None:
NewPerValue[3]=Nodes.getAttribute('Percentage')
if re.search(r'MEDIUM',DifficultyStr)!=None:
NewPerValue[4]=Nodes.getAttribute('Percentage')
if re.search(r'HARD',DifficultyStr)!=None:
NewPerValue[5]=Nodes.getAttribute('Percentage')
if re.search(r'BRUTAL',DifficultyStr)!=None:
NewPerValue[6]=Nodes.getAttribute('Percentage')
OpeningNodes=root.getElementsByTagName('OpeningMove')
Openings=OpeningDic[name]
for Nodes in OpeningNodes:
OpeningName=Nodes.getAttribute('Name')
NewPerValue[7]+=OpeningName+','
Openings[OpeningName]=[]
Openings[OpeningName].append(Nodes.getAttribute('Weight').rstrip('%'))
DifficultyStr=Nodes.getAttribute('Difficulty')
if re.search(r'EASY',DifficultyStr)!=None:
Openings[OpeningName].append('True')
else:
Openings[OpeningName].append('False')
if re.search(r'MEDIUM',DifficultyStr)!=None:
Openings[OpeningName].append('True')
else:
Openings[OpeningName].append('False')
if re.search(r'HARD',DifficultyStr)!=None:
Openings[OpeningName].append('True')
else:
Openings[OpeningName].append('False')
if re.search(r'BRUTAL',DifficultyStr)!=None:
Openings[OpeningName].append('True')
else:
Openings[OpeningName].append('False')
NewPerValue[7]=NewPerValue[7].rstrip(',')
StraNodes=root.getElementsByTagName('StrategicState')
Stra=StraDic[name]
for Nodes in StraNodes:
if Nodes.getAttribute('xai:joinAction')!='':
continue
StraName=Nodes.getAttribute('id')
NewPerValue[8]+=StraName+','
Stra[StraName]=[]
DifficultyStr=Nodes.getAttribute('Difficulty')
if re.search(r'EASY',DifficultyStr)!=None:
Stra[StraName].append('True')
else:
Stra[StraName].append('False')
if re.search(r'MEDIUM',DifficultyStr)!=None:
Stra[StraName].append('True')
else:
Stra[StraName].append('False')
if re.search(r'HARD',DifficultyStr)!=None:
Stra[StraName].append('True')
else:
Stra[StraName].append('False')
if re.search(r'BRUTAL',DifficultyStr)!=None:
Stra[StraName].append('True')
else:
Stra[StraName].append('False')
NewPerValue[8]=NewPerValue[8].rstrip(',')
BuildNodes=root.getElementsByTagName('BuildState')
Build=BuildDic[name]
for Nodes in BuildNodes:
if Nodes.getAttribute('xai:joinAction')!='':
continue
BuildName=Nodes.getAttribute('id')
NewPerValue[9]+=BuildName+','
Build[BuildName]=[]
DifficultyStr=Nodes.getAttribute('Difficulty')
if re.search(r'EASY',DifficultyStr)!=None:
Build[BuildName].append('True')
else:
Build[BuildName].append('False')
if re.search(r'MEDIUM',DifficultyStr)!=None:
Build[BuildName].append('True')
else:
Build[BuildName].append('False')
if re.search(r'HARD',DifficultyStr)!=None:
Build[BuildName].append('True')
else:
Build[BuildName].append('False')
if re.search(r'BRUTAL',DifficultyStr)!=None:
Build[BuildName].append('True')
else:
Build[BuildName].append('False')
NewPerValue[9]=NewPerValue[9].rstrip(',')
conn=sqlite3.connect('UnitList.db')
cur=conn.cursor()
PreferNodes=root.getElementsByTagName('UnitModifier')
Prefer=PreferDic[name]
for Nodes in PreferNodes:
PreferName=Nodes.getAttribute('Unit')
cur.execute("select * from Unitname WHERE name1=(?)",(PreferName,))
res=cur.fetchall()
if res!=[]:
NewPerValue[10]+=res[0][0]+','
Prefer[PreferName]=[]
Prefer[PreferName].append(Nodes.getAttribute('OffensiveModifier'))
Prefer[PreferName].append(Nodes.getAttribute('DefensiveModifier'))
NewPerValue[10]=NewPerValue[10].rstrip(',')
Dic=dict((value,key) for key,value in SpecialPower.items())
PowerNodes=root.getElementsByTagName('PowerChoice')
Power=PowerDic[name]
for Nodes in PowerNodes:
PowerName=Nodes.getAttribute('PlayerPower')
if Dic.has_key(PowerName):
NewPerValue[11]+=Dic[PowerName]+','
Power[PowerName]=Nodes.getAttribute('Weight').rstrip('%')
NewPerValue[11]=NewPerValue[11].rstrip(',')
CapNodes=root.getElementsByTagName('SpecificUnitCap')
Cap=CapDic[name]
for Nodes in CapNodes:
CapName=Nodes.getAttribute('Unit')
cur.execute("select * from Unitname WHERE name1=(?)",(CapName,))
res=cur.fetchall()
if res!=[]:
NewPerValue[12]+=res[0][0]+','
Cap[CapName]=Nodes.getAttribute('Cap')
NewPerValue[12]=NewPerValue[12].rstrip(',')
cur.close()
conn.close()
if root.getElementsByTagName('AIStrategicStateDefinition'):
for NewRoot in root.getElementsByTagName('AIStrategicStateDefinition'):
name=NewRoot.getAttribute('id')
self.tree.AppendItem(self.AttackStra,name)
AttackValue[name]=[]
NewAttackValue=AttackValue[name]
for i in range(len(AttackData)):
NewAttackValue.append('')
TargetDic[name]={}
NewStra.append(name)
NewAttackValue[0]=NewRoot.getAttribute('MaxTargets')
if NewRoot.getElementsByTagName('ScriptedFlagHeuristic'):
NewAttackValue[1]=NewRoot.getElementsByTagName('ScriptedFlagHeuristic')[0].getAttribute('FlagName')
if NewRoot.getElementsByTagName('IntervalHeuristic'):
NewAttackValue[2]=NewRoot.getElementsByTagName('IntervalHeuristic')[0].getAttribute('IntervalTime')+','+NewRoot.getElementsByTagName('IntervalHeuristic')[0].getAttribute('ActiveTime')
conn=sqlite3.connect('UnitList.db')
cur=conn.cursor()
if NewRoot.getElementsByTagName('ObjectOfTypeExistsHeuristic'):
Node=NewRoot.getElementsByTagName('ObjectOfTypeExistsHeuristic')[0]
NewAttackValue[3]=Node.getElementsByTagName('ObjectFilter')[0].getAttribute('Relationship')
index=1
for i in Node.getElementsByTagName('IncludeThing'):
if index==4:
break
NewAttackValue[3]+=','+i.firstChild.data
index=index+1
for i in range(4-len(NewAttackValue[3].split(','))):
NewAttackValue[3]+=u',无'
if NewRoot.getElementsByTagName('TargetHeuristic'):
for i in NewRoot.getElementsByTagName('TargetHeuristic'):
NewAttackValue[4]+=i.getAttribute('TargetHeuristic')+','
Target=TargetDic[name]
Target[i.getAttribute('TargetHeuristic')]=i.getAttribute('Priority')
NewAttackValue[4]=NewAttackValue[4].rstrip(',')
if NewRoot.getElementsByTagName('Tactic'):
NewAttackValue[5]=NewRoot.getElementsByTagName('Tactic')[0].getAttribute('Tactic')
NewAttackValue[6]=NewRoot.getElementsByTagName('Tactic')[0].getAttribute('Distance')
NewAttackValue[7]=NewRoot.getElementsByTagName('Tactic')[0].getAttribute('EndBehavior')
if NewRoot.getElementsByTagName('TeamTemplate'):
NewAttackValue[8]=NewRoot.getElementsByTagName('TeamTemplate')[0].getAttribute('MinUnits')+','+NewRoot.getElementsByTagName('TeamTemplate')[0].getAttribute('MaxUnits')
NewAttackValue[9]=NewRoot.getElementsByTagName('TeamTemplate')[0].getAttribute('ExcludeKindOf')
NewAttackValue[10]=NewRoot.getElementsByTagName('TeamTemplate')[0].getAttribute('AllowedLocomotorTypes')
NewAttackValue[11]=NewRoot.getElementsByTagName('TeamTemplate')[0].getAttribute('Priority')
NewAttackValue[12]=NewRoot.getElementsByTagName('TeamTemplate')[0].getAttribute('AlwaysRecruit').capitalize()
NewAttackValue[13]=NewRoot.getElementsByTagName('TeamTemplate')[0].getAttribute('MicroManager')
Node=NewRoot.getElementsByTagName('TeamTemplate')[0]
if Node.getElementsByTagName('CreateUnits'):
NewAttackValue[14]=Node.getElementsByTagName('CreateUnits')[0].getAttribute('UnitName')+','+Node.getElementsByTagName('CreateUnits')[0].getAttribute('MinUnits')+','+Node.getElementsByTagName('CreateUnits')[0].getAttribute('MaxUnits')
cur.close()
conn.close()
ModChoice.Destroy()
self.tree.SelectItem(self.Person)
self.list.DeleteAllItems()
def OnSave(self,event):
if PerValue=={} and NewStra=={}:
warning=wx.MessageDialog(None,u'没有添加新项目',u'警告')
warning.ShowModal()
warning.Destroy()
return
if self.ModName=='':
NameDialog=wx.TextEntryDialog(None,u'Mod名称',u'输入名称',style=wx.OK|wx.CANCEL)
if NameDialog.ShowModal()==wx.ID_OK:
if re.match(r'^[a-zA-Z][a-zA-Z0-9_]+$',NameDialog.GetValue())==None:
warning=wx.MessageDialog(None,u'名称不正确',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
NameDialog.Destroy()
return
pathname='Mods\\'+NameDialog.GetValue()
if os.path.exists(pathname):
warning=wx.MessageDialog(None,u'Mod名称已存在,是否覆盖?',u'警告',style=wx.OK|wx.CANCEL)
if warning.ShowModal()!=wx.ID_OK:
warning.Destroy()
NameDialog.Destroy()
return
shutil.rmtree(pathname)
self.ModName=NameDialog.GetValue()
title=self.ModName+u' - AI编辑器'
self.SetTitle(title)
else:
return
NameDialog.Destroy()
if os.path.exists('Mods\\'+self.ModName):
shutil.rmtree('Mods\\'+self.ModName)
Data='Mods\\'+self.ModName+'\\Data'
os.makedirs(Data)
FileModXml=Data+'\\mod.xml'
ModXml=open(FileModXml,'w+')
ModXml.write('''<?xml version="1.0" encoding="UTF-8"?>
<AssetDeclaration xmlns="uri:ea.com:eala:asset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Tags></Tags>
<Includes>
<Include type="reference" source="DATA:static.xml" />
<Include type="reference" source="DATA:global.xml" />
<Include type="reference" source="DATA:audio.xml" />\n''')
os.makedirs('Mods\\'+self.ModName+'\\Additional\\Data')
ModStr=open('Mods\\'+self.ModName+'\\Additional\\Data\\mod.str','w+')
if PerValue!={}:
Person=Data+'\\Personalities'
os.makedirs(Person)
ModXml.write('''\n <Include type="all" source="DATA:%s/data/Personalities/CoopBasePersonality.xml" />
<Include type="all" source="DATA:%s/data/Personalities/BasePersonality.xml" />'''%(self.ModName,self.ModName))
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\CoopBasePersonality.xml',Person+'\\CoopBasePersonality.xml')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\BasePersonality.xml',Person+'\\BasePersonality.xml')
parentlist=[]
for Per in PerValue.keys():
parentlist.append(PerValue[Per][0])
if ('AlliedCoopBaseCampaignPersonality' in parentlist) or ('AlliedCoopBaseSkirmishPersonality' in parentlist):
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/AlliedCoopBasePersonality.xml" />''')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\AlliedCoopBasePersonality.xml',Person+'\\AlliedCoopBasePersonality.xml')
if 'AlliedCoopBaseCampaignPersonality' in parentlist:
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/AlliedCoopBaseCampaignPersonality.xml" />''')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\AlliedCoopBaseCampaignPersonality.xml',Person+'\\AlliedCoopBaseCampaignPersonality.xml')
if 'AlliedCoopBaseSkirmishPersonality' in parentlist:
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/AlliedCoopBaseSkirmishPersonality.xml" />''')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\AlliedCoopBaseSkirmishPersonality.xml',Person+'\\AlliedCoopBaseSkirmishPersonality.xml')
if ('JapanCoopBaseCampaignPersonality' in parentlist) or ('JapanCoopBaseSkirmishPersonality' in parentlist):
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/JapanCoopBasePersonality.xml" />''')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\JapanCoopBasePersonality.xml',Person+'\\JapanCoopBasePersonality.xml')
if 'JapanCoopBaseCampaignPersonality' in parentlist:
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/JapanCoopBaseCampaignPersonality.xml" />''')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\JapanCoopBaseCampaignPersonality.xml',Person+'\\JapanCoopBaseCampaignPersonality.xml')
if 'JapanCoopBaseSkirmishPersonality' in parentlist:
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/JapanCoopBaseSkirmishPersonality.xml" />''')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\JapanCoopBaseSkirmishPersonality.xml',Person+'\\JapanCoopBaseSkirmishPersonality.xml')
if ('SovietCoopBaseCampaignPersonality' in parentlist) or ('SovietCoopBaseSkirmishPersonality' in parentlist):
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/SovietCoopBasePersonality.xml" />''')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\SovietCoopBasePersonality.xml',Person+'\\SovietCoopBasePersonality.xml')
if 'SovietCoopBaseCampaignPersonality' in parentlist:
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/SovietCoopBaseCampaignPersonality.xml" />''')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\SovietCoopBaseCampaignPersonality.xml',Person+'\\SovietCoopBaseCampaignPersonality.xml')
if 'SovietCoopBaseSkirmishPersonality' in parentlist:
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/SovietCoopBaseSkirmishPersonality.xml" />''')
shutil.copyfile('SageXml\\SkirmishAI\\Personalities\\SovietCoopBaseSkirmishPersonality.xml',Person+'\\SovietCoopBaseSkirmishPersonality.xml')
index=4
for name,value in PerValue.items():
PerXml=open(Person+'\\'+name+'.xml','w+')
ModStr.write('''Personality:%s
"%s"
END\n'''%(name,name))
if value[0]=='':
warning=wx.MessageDialog(None,name+u'没有继承一个父类',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
if value[1]=='':
warning=wx.MessageDialog(None,name+u'是否为遭遇战性格不明确',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
PerXml.write('''<?xml version="1.0" encoding="utf-8"?>
<AssetDeclaration xmlns="uri:ea.com:eala:asset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Tags></Tags>
<Includes>
<Include type="instance" source="%s" />
</Includes>
<AIPersonalityDefinition
id="%s"
PersonalityType="%s"
inheritFrom="%s"
SkirmishPersonality="%s"
PersonalityUIName="Personality:%s"'''%(value[0]+'.xml',str(index)+name,str(index)+name,value[0],value[1].lower(),name))
if value[2]!='':
PerXml.write('''\n CommanderPortrait="%s"'''%(value[2],))
PerXml.write('''\n >\n''')
if value[3]!='':
PerXml.write('''\n <ResourceMultiplierCheat Percentage="%s" Difficulty="EASY"/>'''%(value[3]+'%',))
if value[4]!='':
PerXml.write('''\n <ResourceMultiplierCheat Percentage="%s" Difficulty="MEDIUM"/>'''%(value[4]+'%',))
if value[5]!='':
PerXml.write('''\n <ResourceMultiplierCheat Percentage="%s" Difficulty="HARD"/>'''%(value[5]+'%',))
if value[6]!='':
PerXml.write('''\n <ResourceMultiplierCheat Percentage="%s" Difficulty="BRUTAL"/>'''%(value[6]+'%',))
PerXml.write('''\n''')
if value[7]!='':
for openingname,Difficulty in OpeningDic[name].items():
weight=Difficulty[0]+'%'
DifficultyStr=''
if Difficulty[1]=='True':
DifficultyStr+='EASY '
if Difficulty[2]=='True':
DifficultyStr+='MEDIUM '
if Difficulty[3]=='True':
DifficultyStr+='HARD '
if Difficulty[4]=='True':
DifficultyStr+='BRUTAL'
if DifficultyStr.endswith(' '):
DifficultyStr=DifficultyStr.rstrip(' ')
PerXml.write('''\n <OpeningMove Name="%s" Weight="%s" Difficulty="%s"/>'''%(weight,DifficultyStr))
PerXml.write('''\n''')
if value[8]!='':
for straName,Difficulty in StraDic[name].items():
DifficultyStr=''
if Difficulty[0]=='True':
DifficultyStr+='EASY '
if Difficulty[1]=='True':
DifficultyStr+='MEDIUM '
if Difficulty[2]=='True':
DifficultyStr+='HARD '
if Difficulty[3]=='True':
DifficultyStr+='BRUTAL'
if DifficultyStr.endswith(' '):
DifficultyStr=DifficultyStr.rstrip(' ')
PerXml.write('''\n <StrategicState id="%s" State="%s" Difficulty="%s"/>'''%(straName,straName,DifficultyStr))
PerXml.write('''\n''')
if value[9]!='':
for buildName,Difficulty in BuildDic[name].items():
DifficultyStr=''
if Difficulty[0]=='True':
DifficultyStr+='EASY '
if Difficulty[1]=='True':
DifficultyStr+='MEDIUM '
if Difficulty[2]=='True':
DifficultyStr+='HARD '
if Difficulty[3]=='True':
DifficultyStr+='BRUTAL'
if DifficultyStr.endswith(' '):
DifficultyStr=DifficultyStr.rstrip(' ')
PerXml.write('''\n <BuildState id="%s" State="%s" Difficulty="%s"/>'''%(buildName,buildName,DifficultyStr))
PerXml.write('''\n''')
if value[10]!='':
for preferName,count in PreferDic[name].items():
PerXml.write('''\n <UnitModifier Unit="%s" OffensiveModifier="%s" DefensiveModifier="%s"/>'''%(preferName,count[0],count[1]))
PerXml.write('''\n''')
if value[11]!='':
for powerName,weight in PowerDic[name].items():
PerXml.write('''\n <PowerChoice PlayerPower="%s" Weight="%s"/>'''%(powerName,weight+'%'))
PerXml.write('''\n''')
if value[12]!='':
for capName,cap in CapDic[name].items():
PerXml.write('''\n <SpecificUnitCap Unit="%s" Cap="%s" Difficulty="EASY MEDIUM HARD BRUTAL"/>'''%(capName,cap))
PerXml.write('''\n''')
PerXml.write('''\n </AIPersonalityDefinition>
</AssetDeclaration>''')
PerXml.close()
index+=1
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Personalities/%s.xml" />'''%(name,))
ModStr.close()
if AttackValue!={}:
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/Strategic/NewStrategic.xml" />''')
Strategic=Data+'\\Strategic'
os.makedirs(Strategic)
StrategicXml=open(Strategic+'\\NewStrategic.xml','w+')
StrategicXml.write('''<?xml version="1.0" encoding="utf-8" ?>
<AssetDeclaration xmlns="uri:ea.com:eala:asset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Tags></Tags>
<Includes></Includes>\n''')
for name,value in AttackValue.items():
if value[0]=='':
warning=wx.MessageDialog(None,name+u'没有最大目标数',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
StrategicXml.write('''\n <AIStrategicStateDefinition
id="%s"
MaxTargets="%s">
<Heuristic>'''%(name,value[0]))
if value[1]!='':
StrategicXml.write('''\n <ScriptedFlagHeuristic FlagName="%s"/>'''%(value[1],))
if value[2]!='':
StrategicXml.write('''\n <IntervalHeuristic IntervalTime="%s" ActiveTime="%s" CountFrom="AI_START"/>'''%(value[2].split(',')[0],value[2].split(',')[1]))
if value[3]!='':
triggerlist=value[3].split(',')
print triggerlist
StrategicXml.write('''\n <ObjectOfTypeExistsHeuristic
PassIfExists="true">
<ObjectFilter
Relationship="%s"
Rule="ANY" >'''%(triggerlist[0],))
if triggerlist[1]!=u'无':
StrategicXml.write('''\n <IncludeThing>%s</IncludeThing>'''%(triggerlist[1],))
if triggerlist[2]!=u'无':
StrategicXml.write('''\n <IncludeThing>%s</IncludeThing>'''%(triggerlist[2],))
if triggerlist[3]!=u'无':
StrategicXml.write('''\n <IncludeThing>%s</IncludeThing>'''%(triggerlist[3],))
StrategicXml.write('''\n </ObjectFilter>
</ObjectOfTypeExistsHeuristic>''')
if value[1]=='' and value[2]=='' and value[3]=='':
StrategicXml.write('''\n <ConstantHeuristic/>''')
StrategicXml.write('''\n </Heuristic>''')
if value[4]=='':
warning=wx.MessageDialog(None,name+u'没有填写目标',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
for TargetName,Pro in TargetDic[name].items():
StrategicXml.write('''\n <TargetHeuristic TargetHeuristic="%s" Priority="%s"/>'''%(TargetName,Pro))
if value[5]=='':
warning=wx.MessageDialog(None,name+u'没有填写战术',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
if value[5]=='DefenseAvoidanceAttack' or value[5]=='SimpleAttack' or value[5]=='SimpleExpansion':
StrategicXml.write('''\n <Tactic id="Attack" Tactic="%s"'''%(value[5],))
if value[5]=='StaticDefense':
StrategicXml.write('''\n <Tactic id="Defend" Tactic="%s"'''%(value[5],))
if value[6]!='':
StrategicXml.write(''' Distance="%s"'''%(value[6],))
if value[7]=='':
warning=wx.MessageDialog(None,name+u'没有填写结束行为',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
StrategicXml.write(''' EndBehavior="%s">'''%(value[7],))
if value[8]=='':
warning=wx.MessageDialog(None,name+u'没有填写队伍数目',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
StrategicXml.write('''\n <TeamTemplate MinUnits="%s" MaxUnits="%s"'''%(value[8].split(',')[0],value[8].split(',')[1]))
StrategicXml.write('''\n IncludeKindOf="CAN_ATTACK" ExcludeKindOf="%s"'''%(value[9],))
if value[10]=='':
warning=wx.MessageDialog(None,name+u'没有填写允许运动类型',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
StrategicXml.write('''\n AllowedLocomotorTypes="%s"'''%(value[10],))
if value[11]=='':
warning=wx.MessageDialog(None,name+u'没有填写优先权',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
StrategicXml.write('''\n Priority="%s"'''%(value[11],))
if value[12]=='':
warning=wx.MessageDialog(None,name+u'没有填写是否招募',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
StrategicXml.write('''\n AlwaysRecruit="%s"'''%(value[12].lower(),))
if value[13]=='':
warning=wx.MessageDialog(None,name+u'没有填写微操',u'警告',style=wx.OK)
warning.ShowModal()
warning.Destroy()
shutil.rmtree('Mods\\'+self.ModName)
return
StrategicXml.write('''\n MicroManager="%s">'''%(value[13],))
if value[14]!='':
StrategicXml.write('''\n <CreateUnits UnitName="%s" MinUnits="%s" MaxUnits="%s"/>'''%(value[14].split(',')[0],value[14].split(',')[1],value[14].split(',')[2]))
StrategicXml.write('''\n</TeamTemplate>
</Tactic>
</AIStrategicStateDefinition>''')
StrategicXml.write('''\n''')
StrategicXml.write('''\n</AssetDeclaration>''')
StrategicXml.close()
if AddTarget!={}:
ModXml.write('''\n <Include type="all" source="DATA:'''+self.ModName+'''/data/AITargetHeuristicLibrary1.xml" />''')
AITarget=open(Data+'\\AITargetHeuristicLibrary1.xml','w+')
AITarget.write('''<?xml version="1.0" encoding="utf-8"?>
<AssetDeclaration xmlns="uri:ea.com:eala:asset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Tags></Tags>
<Includes>
</Includes>\n''')
for name,value in AddTarget.items():
AITarget.write('''\n <AITargetingHeuristic
id="%s"
HeuristicType="NamedObject"
Name="%s"
/>\n'''%(name,value))
AITarget.write('''\n</AssetDeclaration>''')
ModXml.write('''\n </Includes>
</AssetDeclaration>''')
ModXml.close()
def OnQuit(self,event):
self.Close()
def OnNewPerson(self,event):
NewPersonDialog=wx.TextEntryDialog(None,u'AI性格名称',u'新建AI性格')
if NewPersonDialog.ShowModal()==wx.ID_OK:
if re.match(r'[a-zA-Z][a-zA-Z0-9_]+',NewPersonDialog.GetValue())==None:
WarningDialog=wx.MessageDialog(None,u'名称不正确',u'警告',style=wx.OK)
WarningDialog.ShowModal()
WarningDialog.Destroy()
NewPersonDialog.Destroy()
return
self.tree.AppendItem(self.Person,NewPersonDialog.GetValue())
PerValue[NewPersonDialog.GetValue()]=[]
NewPerValue=PerValue[NewPersonDialog.GetValue()]
for i in range(len(PerData)):
NewPerValue.append('')
OpeningDic[NewPersonDialog.GetValue()]={}
StraDic[NewPersonDialog.GetValue()]={}
BuildDic[NewPersonDialog.GetValue()]={}
PreferDic[NewPersonDialog.GetValue()]={}
PowerDic[NewPersonDialog.GetValue()]={}
CapDic[NewPersonDialog.GetValue()]={}
NewPersonDialog.Destroy()
def NewStra(self,event):
NewAttackDialog=wx.TextEntryDialog(None,u'队伍策略名称',u'新建队伍策略')
if NewAttackDialog.ShowModal()==wx.ID_OK:
if re.match(r'[a-zA-Z][a-zA-Z0-9_]+',NewAttackDialog.GetValue())==None:
WarningDialog=wx.MessageDialog(None,u'名称不正确',u'警告',style=wx.OK)
WarningDialog.ShowModal()
WarningDialog.Destroy()
NewAttackDialog.Destroy()
return
self.tree.AppendItem(self.AttackStra,NewAttackDialog.GetValue())
AttackValue[NewAttackDialog.GetValue()]=[]
NewAttackValue=AttackValue[NewAttackDialog.GetValue()]
for i in range(len(AttackData)):
NewAttackValue.append('')
TargetDic[NewAttackDialog.GetValue()]={}
NewStra.append(NewAttackDialog.GetValue())
NewAttackDialog.Destroy()
def NewBuild(self,event):
pass
def NewOpening(self,event):
pass
def OnDelete(self,event):
item=self.tree.GetSelection()
treeText=self.tree.GetItemText(item)
if treeText=='AI'or treeText==u'性格' or treeText==u'队伍策略' or treeText==u'开场行为' or treeText==u'建造策略':
return
if self.tree.GetItemText(self.tree.GetItemParent(item))==u'性格':
warning=wx.MessageDialog(None,u'确认删除这个AI性格?',u'提示',style=wx.OK|wx.CANCEL)
if warning.ShowModal()==wx.ID_OK:
self.tree.Delete(item)
self.tree.SelectItem(self.Person)
self.list.DeleteAllItems()
del PerValue[treeText]
del OpeningDic[treeText]
del StraDic[treeText]
del PreferDic[treeText]
del PowerDic[treeText]
del CapDic[treeText]
warning.Destroy()
return
if self.tree.GetItemText(self.tree.GetItemParent(item))==u'队伍策略':
warning=wx.MessageDialog(None,u'确认删除这个队伍策略?',u'提示',style=wx.OK|wx.CANCEL)
if warning.ShowModal()==wx.ID_OK:
self.tree.Delete(item)
self.tree.SelectItem(self.AttackStra)
self.list.DeleteAllItems()
del AttackValue[treeText]
del TargetDic[treeText]
warning.Destroy()
return
def EnableTreeEdit(self,event):
item=self.tree.GetSelection()
self.tree.EditLabel(item)
def OnItemActivated(self,event):
item=event.GetItem()
treeItem=self.tree.GetSelection()
if item.GetText()==u'继承自':
inheritDialog=wx.Dialog(None,-1,u'继承自')
sizer=wx.BoxSizer(wx.VERTICAL)
box=wx.BoxSizer(wx.HORIZONTAL)
label=wx.StaticText(inheritDialog,-1,u'选择一个父类')
box.Add(label,0,wx.ALIGN_CENTER|wx.ALL,3)
Choice=wx.Choice(inheritDialog,-1,choices=FatherPer)
if self.list.GetItem(event.GetIndex(),1).GetText()=='':
Choice.SetSelection(0)
else:
Choice.SetSelection(FatherPer.index(self.list.GetItem(event.GetIndex(),1).GetText()))
box.Add(Choice,0,wx.ALIGN_CENTER|wx.ALL,3)
sizer.Add(box,0,wx.ALIGN_CENTER|wx.ALL,3)
box=wx.StaticBox(inheritDialog,-1,'')
bsizer=wx.StaticBoxSizer(box,wx.VERTICAL)
label=wx.StaticText(inheritDialog,-1,u'父类决定这个ai性格属于哪个阵营,\nAllied开头的为盟军,\nJapan开头德威帝国,\nSoviet开头的为苏联')
label.SetForegroundColour('DIM GREY')
bsizer.Add(label,0,wx.TOP|wx.LEFT,6)
sizer.Add(bsizer,0,wx.ALIGN_CENTER|wx.ALL,5)
btnsizer=wx.StdDialogButtonSizer()
btn=wx.Button(inheritDialog,wx.ID_OK,size=(-1,25))
btnsizer.AddButton(btn)
btn=wx.Button(inheritDialog,wx.ID_CANCEL,size=(-1,25))
btnsizer.AddButton(btn)
btnsizer.Realize()
sizer.Add(btnsizer,0,wx.ALIGN_CENTER|wx.ALL,10)
inheritDialog.SetSizer(sizer)
inheritDialog.Fit()
if inheritDialog.ShowModal()==wx.ID_OK:
self.list.SetStringItem(event.GetIndex(),1,Choice.GetStringSelection())
PerValue[self.tree.GetItemText(treeItem)][0]=Choice.GetStringSelection()
inheritDialog.Destroy()
return
if item.GetText()==u'作为遭遇战性格':
boolDialog=wx.Dialog(None,-1,u'编辑布尔值')
sizer=wx.BoxSizer(wx.VERTICAL)
Choice=wx.CheckBox(boolDialog,-1,u'作为遭遇战性格 :',style=wx.ALIGN_RIGHT)
if self.list.GetItem(event.GetIndex(),1).GetText()!='':
Choice.SetValue(boolchange(PerValue[self.tree.GetItemText(treeItem)][1]))
sizer.Add(Choice,0,wx.ALIGN_CENTER|wx.ALL,10)
btnsizer=wx.StdDialogButtonSizer()
btn=wx.Button(boolDialog,wx.ID_OK,size=(-1,25))
btnsizer.AddButton(btn)
btn=wx.Button(boolDialog,wx.ID_CANCEL,size=(-1,25))
btnsizer.AddButton(btn)
btnsizer.Realize()
sizer.Add(btnsizer,0,wx.ALIGN_CENTER|wx.ALL,10)
boolDialog.SetSizer(sizer)
boolDialog.Fit()
if boolDialog.ShowModal()==wx.ID_OK:
self.list.SetStringItem(event.GetIndex(),1,str(Choice.GetValue()))
PerValue[self.tree.GetItemText(treeItem)][1]=str(Choice.GetValue())
boolDialog.Destroy()
return
if item.GetText()==u'头像':
PortraitDialog=wx.Dialog(None,-1,u'头像')
sizer=wx.BoxSizer(wx.VERTICAL)
box=wx.BoxSizer(wx.HORIZONTAL)
label=wx.StaticText(PortraitDialog,-1,u'选择一个头像 :')
box.Add(label,0,wx.ALIGN_CENTER|wx.ALL,5)
Choice=wx.Choice(PortraitDialog,-1,choices=Portrait)