-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCM3D2.AlwaysColorChangeEx.Plugin.cs
More file actions
1591 lines (1398 loc) · 66.9 KB
/
CM3D2.AlwaysColorChangeEx.Plugin.cs
File metadata and controls
1591 lines (1398 loc) · 66.9 KB
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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityInjector;
using UnityInjector.Attributes;
using CM3D2.AlwaysColorChangeEx.Plugin.Data;
using CM3D2.AlwaysColorChangeEx.Plugin.TexAnim;
using CM3D2.AlwaysColorChangeEx.Plugin.UI;
using CM3D2.AlwaysColorChangeEx.Plugin.UI.Helper;
using CM3D2.AlwaysColorChangeEx.Plugin.Util;
[assembly: AssemblyVersion("0.3.2.0")]
namespace CM3D2.AlwaysColorChangeEx.Plugin {
#if COM3D2
[PluginFilter("COM3D2x64"),
#else
[PluginFilter("CM3D2x64"),
PluginFilter("CM3D2x86"),
PluginFilter("CM3D2VRx64"),
PluginFilter("CM3D2OHx86"),
PluginFilter("CM3D2OHx64"),
PluginFilter("CM3D2OHVRx64"),
#endif
PluginName("CM3D2_ACCex"),
PluginVersion("0.3.2.0")]
class AlwaysColorChangeEx : PluginBase {
public static volatile string PluginName;
public static volatile string Version;
static AlwaysColorChangeEx() {
// 属性クラスからプラグイン名/バージョン番号を取得
try {
var attr = Attribute.GetCustomAttribute( typeof(AlwaysColorChangeEx), typeof( PluginNameAttribute ) ) as PluginNameAttribute;
if( attr != null ) PluginName = attr.Name;
} catch( Exception e ) {
LogUtil.Error( e );
}
try {
var attr = Attribute.GetCustomAttribute( typeof(AlwaysColorChangeEx), typeof( PluginVersionAttribute ) ) as PluginVersionAttribute;
if( attr != null ) Version = attr.Version;
} catch( Exception e ) {
LogUtil.Error( e );
}
}
internal MonoBehaviour plugin;
private readonly CM3D2SceneChecker checker = new CM3D2SceneChecker();
private enum MenuType {
None,
Main,
Color,
NodeSelect,
MaskSelect,
Save,
PresetSelect,
Texture,
MaidSelect,
BoneSlotSelect,
PartsColor,
}
private const string TITLE_LABEL = "ACCex : ";
private const int WIN_ID_MAIN = 20201;
private const int WIN_ID_DIALOG = WIN_ID_MAIN+1;
private const int WIN_ID_TIPS = WIN_ID_MAIN+2;
private const EventModifiers modifierKey = EventModifiers.Shift | EventModifiers.Control | EventModifiers.Alt;
#region Variables
private float fPassedTime;
private float fLastInitTime;
private bool initialized;
private bool bUseStockMaid;
private bool mouseDowned;
private readonly Settings settings = Settings.Instance;
private readonly UIParams uiParams = UIParams.Instance;
private readonly MaidHolder holder = MaidHolder.Instance;
private readonly PresetManager presetMgr = new PresetManager();
private MenuType menuType;
// プリセット名
private readonly List<string> presetNames = new List<string>();
// 操作情報
private readonly Dictionary<string, bool> dDelNodes = new Dictionary<string, bool>();
// 表示中状態
private Dictionary<string, bool> dDelNodeDisps = new Dictionary<string, bool>();
private readonly Dictionary<TBody.SlotID, MaskInfo> dMaskSlots = new Dictionary<TBody.SlotID, MaskInfo>();
PresetData currentPreset;
private string presetName = string.Empty;
private bool bPresetCastoff = true;
private bool bPresetApplyNode;
private bool bPresetApplyMask;
private bool bPresetApplyBody = true;
private bool bPresetApplyWear = true;
private bool bPresetApplyBodyProp = true;
private bool bPresetApplyPartsColor = true;
private bool bPresetSavable;
private Maid toApplyPresetMaid;
private bool isSavable;
private bool isActive;
private bool texSliderUpped;
private const int applyDelayFrame = 10;
private const int tipsSecond = 2;
private readonly IntervalCounter changeCounter = new IntervalCounter(15);
// ゲーム上の表示データの再ロード間隔
private readonly IntervalCounter refreshCounter = new IntervalCounter(60);
private readonly MaidChangeDetector changeDetector = new MaidChangeDetector();
private readonly AnimTargetDetector animDetector = new AnimTargetDetector();
private Vector2 scrollViewPosition = Vector2.zero;
// 表示名切り替え
private bool nameSwitched;
// thumcache等
private readonly Dictionary<int, GUIContent> _contentDic = new Dictionary<int, GUIContent>();
private readonly List<SelectMaidData> _maidList = new List<SelectMaidData>();
private readonly List<SelectMaidData> _manList = new List<SelectMaidData>();
// テクスチャ変更用
// 現在のターゲットのslotに関するメニューが変更されたらGUIを更新。それ以外は更新しない
private int targetMenuId;
private bool slotDropped;
private Material[] targetMaterials;
private readonly Material[] EMPTY_ARRAY = new Material[0];
private List<ACCMaterialsView> materialViews;
private List<ACCTexturesView> texViews;
private ACCSaveMenuView saveView;
private ACCBoneSlotView boneSlotView;
private ACCPartsColorView partsColorView;
private readonly List<BaseView> views = new List<BaseView>();
// 選択画面の一時選択状態のメイド情報
private Maid selectedMaid;
private string selectedName;
private GUIContent title;
// TIPS
private const int TIPS_MARGIN = 24;
private bool displayTips;
private Rect tipRect;
private string tips;
private readonly UIHelper uiHelper = new UIHelper();
private ColorPresetManager colorPresetMgr;
private SliderHelper sliderHelper;
private CheckboxHelper cbHelper;
#endregion
public AlwaysColorChangeEx() {
mouseDowned = false;
plugin = this;
}
#region MonoBehaviour methods
public void Awake() {
DontDestroyOnLoad(this);
// リダイレクトで存在しないパスが渡されてしまうケースがあるため、
// Sybarisチェックを先に行う (リダイレクトによるパスではディレクトリ作成・削除が動作しない)
var dllPath = Path.Combine(DataPath, @"..\..\opengl32.dll");
var dirPath = Path.Combine(DataPath, @"..\..\Sybaris");
if (File.Exists(dllPath) && Directory.Exists(dirPath)) {
dirPath = Path.GetFullPath(dirPath);
settings.presetDirPath = Path.Combine(dirPath, @"Plugins\UnityInjector\Config\ACCPresets");
} else {
settings.presetDirPath = Path.Combine(DataPath, "ACCPresets");
}
ReloadConfig();
settings.Load(key => Preferences["Config"][key].Value);
LogUtil.Log("PresetDir:", settings.presetDirPath);
checker.Init();
LoadPresetList();
uiParams.Update();
// Initialize
ShaderPropType.Initialize();
sliderHelper = new SliderHelper(uiParams);
cbHelper = new CheckboxHelper(uiParams);
colorPresetMgr = ColorPresetManager.Instance;
var colorPresetFile = Path.Combine(settings.presetDirPath, "_ColorPreset.csv");
colorPresetMgr.Count = 40;
colorPresetMgr.SetPath(colorPresetFile);
#if UNITY_5_5_OR_NEWER
SceneManager.sceneLoaded += SceneLoaded;
#endif
saveView = new ACCSaveMenuView(uiParams);
boneSlotView = new ACCBoneSlotView(uiParams, sliderHelper);
views.Add(boneSlotView);
partsColorView = new ACCPartsColorView(uiParams, sliderHelper);
views.Add(partsColorView);
uiParams.Add(UpdateUIParams);
if (settings.enableTexAnim) changeDetector.Add(animDetector.ChangeMenu);
}
private void UpdateUIParams(UIParams uParams) {
colorPresetMgr.BtnStyle.fontSize = uParams.fontSizeS;
colorPresetMgr.BtnWidth = GUILayout.Width(colorPresetMgr.BtnStyle.CalcSize(new GUIContent("Update")).x);
foreach (var view in views) {
view.UpdateUI(uParams);
}
}
public void Start() {
}
public void OnDestroy() {
uiHelper.SetCameraControl(true);
Dispose();
presetNames.Clear();
uiParams.Remove(UpdateUIParams);
//detector.Clear();
#if UNITY_5_5_OR_NEWER
SceneManager.sceneLoaded -= SceneLoaded;
#endif
LogUtil.Debug("Destroyed");
}
#if UNITY_5_5_OR_NEWER
public void SceneLoaded(Scene scene, LoadSceneMode sceneMode) {
LogUtil.Debug(scene.buildIndex, ": ", scene.name);
OnSceneLoaded(scene.buildIndex);
}
#else
public void OnLevelWasLoaded(int level) {
// Log.Debug("OnLevelWasLoaded ", level);
OnSceneLoaded(level);
}
#endif
public void OnSceneLoaded(int level) {
fPassedTime = 0f;
bUseStockMaid = false;
foreach (var view in views) {
view.Clear();
}
changeDetector.Clear();
if ( !checker.IsTarget(level) ) {
if (!isActive) return;
uiHelper.SetCameraControl(true);
initialized = false;
isActive = false;
return;
}
bUseStockMaid = checker.IsStockTarget(level);
menuType = MenuType.None;
mouseDowned = false;
uiHelper.cursorContains = false;
isActive = true;
}
public void Update() {
fPassedTime += Time.deltaTime;
if (!isActive) return;
if (!initialized) {
if (fPassedTime - fLastInitTime <= 1f) return;
fLastInitTime = fPassedTime;
initialized = Initialize();
LogUtil.Debug("Initialized ", initialized);
if (!initialized) return;
}
if (settings.enableTexAnim) changeDetector.Detect(bUseStockMaid);
if (InputModifierKey() && Input.GetKeyDown(settings.toggleKey)) {
SetMenu( (menuType == MenuType.None)? MenuType.Main : MenuType.None );
mouseDowned = false;
}
UpdateCameraControl();
// 選択中のメイドが有効でなければ何もしない
if (!holder.CurrentActivated()) return;
boneSlotView.Update();
if (toApplyPresetMaid != null && !toApplyPresetMaid.IsBusy) {
var targetMaid = toApplyPresetMaid;
toApplyPresetMaid = null;
plugin.StartCoroutine(DelayFrameRecall(applyDelayFrame, () => !ApplyPresetProp(targetMaid,currentPreset)) );
}
if (ACCTexturesView.fileBrowser != null) {
if (Input.GetKeyDown(settings.prevKey)) {
ACCTexturesView.fileBrowser.Prev();
}
if (Input.GetKeyDown(settings.nextKey)) {
ACCTexturesView.fileBrowser.Next();
}
ACCTexturesView.fileBrowser.Update();
}
// テクスチャエディットの反映
if (menuType == MenuType.Texture) {
// マウスが離されたタイミングでのみテクスチャ反映
if (texSliderUpped || Input.GetMouseButtonUp(0)) {
if (ACCTexturesView.IsChangeTarget()) {
ACCTexturesView.UpdateTex(holder.CurrentMaid, targetMaterials);
}
texSliderUpped = false;
}
} else {
// テクスチャモードでなければ、テクスチャ変更対象を消す
ACCTexturesView.ClearTarget();
}
}
private void UpdateSelectMaid() {
InitMaidList();
if (_maidList.Count == 1) {
var maid = _maidList[0].maid;
var maidName = _maidList[0].content.text;
holder.UpdateMaid(maid, maidName, ClearMaidData);
SetMenu(MenuType.Main);
} else {
SetMenu(MenuType.MaidSelect);
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoSelectMaid, Version, uiParams.winStyle);
}
}
public void OnGUI() {
if (!isActive || menuType == MenuType.None) return;
if (settings.SSWithoutUI && !uiHelper.IsEnabledUICamera()) return; // UI無し撮影
try {
if (Event.current.type == EventType.Repaint) return;
if (!holder.CurrentActivated()) {
// メイド未選択、あるいは選択中のメイドが無効化された場合
UpdateSelectMaid();
} else if (ACCTexturesView.fileBrowser != null) {
uiParams.fileBrowserRect = GUI.Window(WIN_ID_DIALOG, uiParams.fileBrowserRect, DoFileBrowser, Version, uiParams.winStyle);
} else if (saveView.showDialog) {
uiParams.modalRect = GUI.ModalWindow(WIN_ID_MAIN, uiParams.modalRect, DoSaveModDialog, "menuエクスポート", uiParams.dialogStyle);
} else {
switch (menuType) {
case MenuType.Main:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoMainMenu, Version, uiParams.winStyle);
break;
case MenuType.Color:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoColorMenu, Version, uiParams.winStyle);
break;
case MenuType.MaskSelect:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoMaskSelectMenu, Version, uiParams.winStyle);
break;
case MenuType.NodeSelect:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoNodeSelectMenu, Version, uiParams.winStyle);
break;
case MenuType.Save:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoSaveMenu, Version, uiParams.winStyle);
break;
case MenuType.PresetSelect:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoSelectPreset, Version, uiParams.winStyle);
break;
case MenuType.Texture:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoSelectTexture, Version, uiParams.winStyle);
break;
case MenuType.BoneSlotSelect:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoSelectBoneSlot, Version, uiParams.winStyle);
break;
case MenuType.PartsColor:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoEditPartsColor, Version, uiParams.winStyle);
break;
case MenuType.MaidSelect:
uiParams.winRect = GUI.Window(WIN_ID_MAIN, uiParams.winRect, DoSelectMaid, Version, uiParams.winStyle);
break;
default:
break;
}
OnTips();
}
// 領域内でマウスダウン => マウスアップ 操作の場合に入力をリセット
if (Input.GetMouseButtonUp(0)) {
if (mouseDowned) {
Input.ResetInputAxes();
texSliderUpped = (menuType == MenuType.Texture);
}
mouseDowned = false;
}
mouseDowned |= uiHelper.cursorContains && Input.GetMouseButtonDown(0);
} finally {
}
}
#endregion
private void OnTips() {
if (displayTips && tips != null) {
GUI.Window(WIN_ID_TIPS, tipRect, DoTips, tips, uiParams.tipsStyle);
}
}
public void SetTips(string message) {
var lineNum = 1;
foreach (var chr in message) {
if (chr == '\n') lineNum++;
}
if (lineNum == 1) lineNum += (message.Length / 15);
float height = lineNum*uiParams.fontSize*19/14 + 30;
if (height > 400) height = 400;
tipRect = new Rect(uiParams.winRect.x+TIPS_MARGIN, uiParams.winRect.yMin+150,
uiParams.winRect.width-TIPS_MARGIN*2, height);
displayTips = true;
tips = message;
plugin.StartCoroutine(DelaySecond(tipsSecond, () => {
displayTips = false;
tips = null;
}) );
}
public void DoTips(int winID) {
GUI.BringWindowToFront(winID);
}
private bool InputModifierKey() {
var em = Event.current.modifiers;
if (settings.toggleModifiers == EventModifiers.None) {
// 修飾キーが押されていない事を確認(Shift/Alt/Ctrl)
return (em & modifierKey) == EventModifiers.None;
}
// 修飾キーが指定されている場合、そのキーの入力チェック
return (em & settings.toggleModifiers) != EventModifiers.None;
}
/// <summary>
/// カーソル位置のチェックを行い、カメラコントロールの有効化/無効化を行う
/// </summary>
private void UpdateCameraControl() {
var cursorContains = false;
if (ACCTexturesView.fileBrowser != null || menuType != MenuType.None) {
var cursor = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
var rect = ACCTexturesView.fileBrowser != null ? uiParams.fileBrowserRect : uiParams.winRect;
cursorContains = rect.Contains(cursor);
if (!cursorContains) {
if (saveView.showDialog) {
cursorContains = uiParams.modalRect.Contains(cursor);
}
}
}
uiHelper.UpdateCameraControl(cursorContains);
}
#region Private methods
private void Dispose() {
ClearMaidData();
uiHelper.SetCameraControl(true);
mouseDowned = false;
// テクスチャキャッシュを開放する
ACCTexturesView.Clear();
ResourceHolder.Instance.Clear();
//OnDestroy();
foreach (var view in views) {
view.Dispose();
}
initialized = false;
}
private bool Initialize() {
InitMaidInfo();
uiParams.Update();
ACCTexturesView.Init(uiParams);
ACCMaterialsView.Init(uiParams);
return true;
//return holder.currentMaid != null;
}
private void InitMaidInfo() {
// ここでは、最初に選択可能なメイドを選択
holder.UpdateMaid(ClearMaidData);
}
// http://qiita.com/toRisouP/items/e402b15b36a8f9097ee9
IEnumerator DelayFrameRecall(int delayFrame, Func<bool> func) {
do {
for (var i = 0; i < delayFrame; i++) {
yield return null;
}
} while (func());
}
IEnumerator DelayFrame(int delayFrame, Action act) {
for (var i = 0; i < delayFrame; i++) {
yield return null;
}
act();
}
IEnumerator DelaySecond(int second, Action act) {
yield return new WaitForSeconds(second);
act();
}
private void ClearMaidData() {
ACCMaterialsView.Clear();
dDelNodes.Clear();
dDelNodeDisps.Clear();
dMaskSlots.Clear();
}
private void SetMenu(MenuType type) {
if (menuType == type) return;
menuType = type;
uiParams.Update();
}
#endregion
private GUIContent GetOrAddMaidInfo(Maid m, int idx=-1) {
GUIContent content;
var id = m.gameObject.GetInstanceID();
if (_contentDic.TryGetValue(id, out content)) return content;
LogUtil.Debug("maid:", m.name);
var maidName = !m.boMAN ? MaidHelper.GetName(m) : "男"+ (idx+1);
var icon = m.GetThumIcon();
content = new GUIContent(maidName, icon);
_contentDic[id] = content;
return content;
}
private bool IsEnabled(Maid m) {
return m.isActiveAndEnabled && m.Visible ;// && m.body0.Face != null;
}
internal class SelectMaidData {
public readonly Maid maid;
public readonly GUIContent content;
internal SelectMaidData(Maid maid0, GUIContent content0) {
maid = maid0;
content = content0;
}
}
private void InitMaidList() {
_maidList.Clear();
_manList.Clear();
var chrMgr = GameMain.Instance.CharacterMgr;
if (bUseStockMaid) {
AddMaidList(_maidList, chrMgr.GetStockMaid, chrMgr.GetStockMaidCount());
} else {
AddMaidList(_maidList, chrMgr.GetMaid, chrMgr.GetMaidCount());
}
if (bUseStockMaid) {
AddMaidList(_manList, chrMgr.GetStockMan, chrMgr.GetStockManCount());
} else {
AddMaidList(_manList, chrMgr.GetMan, chrMgr.GetManCount());
}
}
private void AddMaidList(ICollection<SelectMaidData> list, Func<int, Maid> GetMaid, int count) {
var idx = 0;
for (var i=0; i< count; i++) {
var m = GetMaid(i);
if (m == null || !IsEnabled(m)) continue;
string maidName;
if (!m.boMAN) {
maidName = MaidHelper.GetName(m);
} else {
maidName = "男"+ (idx+1);
idx++;
}
var icon = m.GetThumIcon();
var content = new GUIContent(maidName, icon);
list.Add(new SelectMaidData(m, content));
}
}
private void DoSelectMaid(int winID) {
if (selectedMaid == null) selectedMaid = holder.CurrentMaid;
GUILayout.BeginVertical();
GUILayout.Label("メイド選択", uiParams.lStyleB);
scrollViewPosition = GUILayout.BeginScrollView(scrollViewPosition, uiParams.optSubConWidth, uiParams.optSubConHeight);
// var chrMgr = GameMain.Instance.CharacterMgr;
var hasSelected = false;
try {
foreach (var maidData in _maidList) {
GUI.enabled = IsEnabled(maidData.maid);
var selected = (selectedMaid == maidData.maid);
if (GUI.enabled && selected) hasSelected = true;
GUILayout.BeginHorizontal();
GUILayout.Space(uiParams.marginL);
var changed = GUILayout.Toggle(selected, maidData.content, uiParams.tStyleL);
GUILayout.Space(uiParams.marginL);
GUILayout.EndHorizontal();
if (changed == selected) continue;
selectedMaid = maidData.maid;
selectedName = maidData.content.text;
}
GUI.enabled = true;
if (!_maidList.Any()) GUILayout.Label(" なし", uiParams.lStyleB);
GUILayout.Space(uiParams.marginL);
if (_manList.Any()) {
// LogUtil.Debug("manList:", manList.Count);
GUILayout.Label("男選択", uiParams.lStyleB);
foreach (var manData in _manList) {
var m = manData.maid;
GUI.enabled = IsEnabled(m);
var selected = (selectedMaid == m);
if (GUI.enabled && selected) hasSelected = true;
GUILayout.BeginHorizontal();
GUILayout.Space(uiParams.marginL);
var changed = GUILayout.Toggle(selected, manData.content, uiParams.tStyleL);
GUILayout.Space(uiParams.marginL);
GUILayout.EndHorizontal();
if (changed == selected) continue;
selectedMaid = m;
selectedName = manData.content.text;
}
GUI.enabled = true;
//if (!manList.Any()) GUILayout.Label(" なし", uiParams.lStyleB);
}
} finally {
GUILayout.EndScrollView();
GUILayout.BeginHorizontal();
GUI.enabled = hasSelected;
if (GUILayout.Button( "選択", uiParams.bStyle, uiParams.optSubConHalfWidth)) {
SetMenu(MenuType.Main);
holder.UpdateMaid(selectedMaid, selectedName, ClearMaidData);
selectedMaid = null;
selectedName = null;
_contentDic.Clear();
}
GUI.enabled = true;
if (GUILayout.Button( "一覧更新", uiParams.bStyle, uiParams.optSubConHalfWidth)) {
InitMaidList();
}
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
GUI.DragWindow(uiParams.titleBarRect);
}
private void DoMainMenu(int winID) {
GUILayout.BeginVertical();
try {
var maid = holder.CurrentMaid;
GUILayout.Label(TITLE_LABEL + holder.MaidName, uiParams.lStyle);
if (GUILayout.Button("メイド/男 選択", uiParams.bStyle)) {
InitMaidList();
SetMenu(MenuType.MaidSelect);
}
GUI.enabled = !maid.boMAN;
GUILayout.BeginHorizontal();
try {
if (GUILayout.Button("マスク選択", uiParams.bStyle, uiParams.optSubConHalfWidth)) {
SetMenu(MenuType.MaskSelect);
InitMaskSlots();
}
if (GUILayout.Button("表示ノード選択", uiParams.bStyle, uiParams.optSubConHalfWidth)) {
// 初期化済の場合のみ
if (dDelNodes.Any()) {
dDelNodeDisps = GetDelNodes();
}
SetMenu(MenuType.NodeSelect);
}
} finally {
GUILayout.EndHorizontal();
}
GUILayout.BeginHorizontal();
try {
GUI.enabled &= (holder.isOfficial) && (toApplyPresetMaid == null);
if (GUILayout.Button("プリセット保存", uiParams.bStyle, uiParams.optSubConHalfWidth)) {
SetMenu(MenuType.Save);
}
if (presetNames.Any()) {
if (GUILayout.Button("プリセット適用", uiParams.bStyle, uiParams.optSubConHalfWidth)) {
SetMenu(MenuType.PresetSelect);
}
}
} finally {
GUILayout.EndHorizontal();
}
GUILayout.BeginHorizontal();
try {
if (GUILayout.Button("ボーン表示", uiParams.bStyle, uiParams.optSubConHalfWidth)) {
SetMenu(MenuType.BoneSlotSelect);
}
if (GUILayout.Button("パーツカラー変更", uiParams.bStyle, uiParams.optSubConHalfWidth)) {
SetMenu(MenuType.PartsColor);
}
} finally {
GUILayout.EndHorizontal();
}
GUI.enabled = true;
GUILayout.Space(uiParams.margin);
GUILayout.BeginHorizontal();
GUILayout.Label("マテ情報変更 スロット選択", uiParams.lStyleC);
nameSwitched = GUILayout.Toggle(nameSwitched, "表示切替", uiParams.tStyleS, uiParams.optToggleSWidth);
GUILayout.EndHorizontal();
scrollViewPosition = GUILayout.BeginScrollView(scrollViewPosition,
GUILayout.Width(uiParams.mainRect.width),
GUILayout.Height(uiParams.mainRect.height));
try {
var currentBody = holder.CurrentMaid.body0;
if (holder.isOfficial) {
foreach (var slot in ACConstants.SlotNames.Values) {
if (!slot.enable) continue;
// 身体からノード一覧と表示状態を取得
if (!currentBody.GetSlotLoaded(slot.Id)) continue;
GUILayout.BeginHorizontal();
GUILayout.Space(uiParams.marginL);
if (GUILayout.Button(!nameSwitched?slot.DisplayName: slot.Name, uiParams.bStyleL, GUILayout.ExpandWidth(true))) {
holder.CurrentSlot = slot;
SetMenu(MenuType.Color);
}
if (settings.displaySlotName) {
GUILayout.Label(slot.Name, uiParams.lStyleS, uiParams.optCategoryWidth);
}
GUILayout.Space(uiParams.marginL);
GUILayout.EndHorizontal();
}
} else {
// 下記処理は、公式のスロットIDと異なるスロットを設定するプラグイン等が導入されていた場合のため
var idx = 0;
var count = currentBody.goSlot.Count;
for (var i=0; i< count; i++) {
var tbodySlot = currentBody.goSlot[i];
if (!settings.enableMoza && i == count-1) {
if (tbodySlot.Category == "moza") continue;
}
// if (!slot.enable) continue;
// slot loaded
if (tbodySlot.obj != null) {
GUILayout.BeginHorizontal();
GUILayout.Space(uiParams.marginL);
if (GUILayout.Button(tbodySlot.Category, uiParams.bStyleL, GUILayout.ExpandWidth(true))) {
holder.CurrentSlot = ACConstants.SlotNames[(TBody.SlotID)idx];
SetMenu(MenuType.Color);
}
GUILayout.Space(uiParams.marginL);
GUILayout.EndHorizontal();
}
idx++;
}
}
} finally {
GUI.enabled = true;
GUILayout.EndScrollView();
}
} finally {
GUILayout.EndVertical();
}
GUI.DragWindow(uiParams.titleBarRect);
}
private List<ACCMaterialsView> InitMaterialView(Renderer r, string menufile, int slotIdx) {
var materials = r.materials;
var idx = 0;
var ret = new List<ACCMaterialsView>(materials.Length);
foreach (var material in materials) {
var view = new ACCMaterialsView(r, material, slotIdx, idx++, sliderHelper, cbHelper) {
tipsCall = SetTips
};
ret.Add(view);
// マテリアル数が少ない場合はデフォルトで表示
view.expand = (materials.Length <= 2);
}
return ret;
}
private void DoColorMenu(int winID) {
var slot = holder.GetCurrentSlot();
if (title == null) {
title = new GUIContent("マテリアル情報変更: " + (holder.isOfficial ? holder.CurrentSlot.DisplayName : slot.Category));
}
GUILayout.Label(title, uiParams.lStyleB);
// TODO 選択アイテム名、説明等を表示 可能であればアイコンも
if (holder.CurrentMaid.IsBusy) {
GUILayout.Space(100);
GUILayout.Label("変更中...", uiParams.lStyleB);
return;
}
// **_del.menuを選択の状態が続いたらメインメニューへ
// 衣装セットなどは内部的に一旦_del.menuが選択されるため、一時的に選択された状態をスルー
var menuId = holder.GetCurrentMenuFileID();
if (menuId != 0) {
if (slotDropped) {
if (!changeCounter.Next()) return;
SetMenu(MenuType.Main);
LogUtil.Debug("select slot item dropped. return to main menu.", menuId);
slotDropped = false;
return;
}
}
// ターゲットのmenuファイルが変更された場合にビューを更新
if (targetMenuId != menuId) {
title = null;
// .modファイルは未対応
var menufile = holder.GetCurrentMenuFile();
// LogUtil.Debug("menufile changed.", targetMenuId, "=>", menuId, " : ", menufile);
isSavable = (menufile != null) && !(menufile.ToLower().EndsWith(FileConst.EXT_MOD, StringComparison.Ordinal));
targetMenuId = menuId;
var renderer1 = holder.GetRenderer(slot);
if (renderer1 != null) {
targetMaterials = renderer1.materials;
#if COM3D2
materialViews = InitMaterialView(renderer1, menufile, (int)slot.SlotId);
#else
materialViews = InitMaterialView(renderer1, menufile, slot.CategoryIdx);
#endif
} else {
targetMaterials = EMPTY_ARRAY;
}
// slotにデータが装着されていないかを判定
slotDropped = (slot.obj == null);
changeCounter.Reset();
if (isSavable) {
// 保存未対応スロットを判定(身体は不可)
isSavable &= (holder.CurrentSlot.Id != TBody.SlotID.body);
}
}
if ( GUILayout.Button("テクスチャ変更", uiParams.bStyle) ) {
texViews = InitTexView(targetMaterials);
SetMenu(MenuType.Texture);
return;
}
if (targetMaterials.Length <= 0) return;
scrollViewPosition = GUILayout.BeginScrollView(scrollViewPosition,
GUILayout.Width(uiParams.colorRect.width),
GUILayout.Height(uiParams.colorRect.height));
try {
var reload = Event.current.type == EventType.Layout && refreshCounter.Next();
if (reload) ClipBoardHandler.Instance.Reload();
foreach (var view in materialViews) {
view.Show(reload);
}
} catch (Exception e) {
LogUtil.Error("マテリアル情報変更画面でエラーが発生しました。メイン画面へ移動します", e);
SetMenu(MenuType.Main);
targetMenuId = 0;
} finally {
GUILayout.EndScrollView();
GUI.enabled = isSavable;
if (GUILayout.Button("menuエクスポート", uiParams.bStyle)) ExportMenu();
GUI.enabled = true;
if (GUILayout.Button("閉じる", uiParams.bStyle)) {
SetMenu(MenuType.Main);
targetMenuId = 0;
}
GUI.DragWindow(uiParams.titleBarRect);
}
}
private void ExportMenu() {
var slot = holder.GetCurrentSlot();
if (slot.obj == null) {
var msg = "指定スロットが見つかりません。slot=" + holder.CurrentSlot.Name;
NUty.WinMessageBox(NUty.GetWindowHandle(), msg, "エラー", NUty.MSGBOX.MB_OK);
return;
}
// propは対応するMPNを指定
var prop = holder.CurrentMaid.GetProp(holder.CurrentSlot.mpn);
if (prop == null) return;
{
// 変更可能なmenuファイルがない場合は保存画面へ遷移しない
var targetSlots = saveView.Load(prop.strFileName);
if (targetSlots == null) {
var msg = "変更可能なmenuファイルがありません " + prop.strFileName;
NUty.WinMessageBox(NUty.GetWindowHandle(), msg, "エラー", NUty.MSGBOX.MB_OK);
} else {
// menuファイルで指定されているitemのスロットに関連するマテリアル情報を抽出
foreach (var targetSlot in targetSlots.Keys) {
List<ACCMaterial> edited;
if (targetSlot == holder.CurrentSlot.Id) {
// カレントスロットの場合は、作成済のマテリアル情報を渡す
edited = new List<ACCMaterial>(materialViews.Count);
foreach ( var matView in materialViews ) {
edited.Add(matView.edited);
}
} else {
var materials = holder.GetMaterials(targetSlot);
edited = new List<ACCMaterial>(materials.Length);
edited.AddRange(materials.Select(mat => new ACCMaterial(mat)));
}
saveView.SetEditedMaterials(targetSlot, edited);
}
//if (!saveView.CheckData()) {
// var msg = "保存可能なmenuファイルではありません " + prop.strFileName;
// NUty.WinMessageBox(NUty.GetWindowHandle(), msg, "エラー", NUty.MSGBOX.MB_OK);
//}
}
}
}
private List<ACCTexturesView> InitTexView(ICollection<Material> materials) {
var ret = new List<ACCTexturesView>(materials.Count);
var matNo = 0;
foreach (var material in materials) {
try {
var view = new ACCTexturesView(material, matNo++);
ret.Add(view);
// マテリアル数が少ない場合はデフォルトで表示
view.expand = (materials.Count <= 2);
} catch(Exception e) {
LogUtil.Error(material.name, e);
}
}
return ret;
}
private void DoSelectTexture(int winId) {
// テクスチャ変更画面 GUILayout使用
GUILayout.Label("テクスチャ変更", uiParams.lStyleB);
scrollViewPosition = GUILayout.BeginScrollView(scrollViewPosition,
GUILayout.Width(uiParams.textureRect.width),
GUILayout.Height(uiParams.textureRect.height));
try {
var menuId = holder.GetCurrentMenuFileID();
if (targetMenuId != menuId) {
LogUtil.DebugF("menu file changed. {0}=>{1}", targetMenuId, menuId);
targetMenuId = menuId;
targetMaterials = holder.GetMaterials();
texViews = InitTexView(targetMaterials);
}
foreach (var view in texViews) {
view.Show();
}
} catch(Exception e) {
LogUtil.Debug("failed to create texture change view. ", e);
} finally {
GUILayout.EndScrollView();
if (GUILayout.Button( "閉じる", uiParams.bStyle,
uiParams.optSubConWidth, uiParams.optBtnHeight)) {
SetMenu(MenuType.Color);
}