Skip to content

Commit 0238544

Browse files
committed
Retain menu selections after exiting edit mode
1 parent 6f4240f commit 0238544

4 files changed

Lines changed: 38 additions & 7 deletions

File tree

DressCode.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,21 @@ private static void DailyCtrl_OnInit(DailyCtrl __instance) {
528528
private static void BasePanelMgr_BeforeFadeIn(BasePanelMgr __instance) {
529529
if (__instance is DailyMgr dailyMgr && ReopenPanel) {
530530
ReopenPanel = false;
531-
Open(dailyMgr);
531+
Open(dailyMgr, true);
532532
}
533533
}
534534

535-
private static void Open(DailyMgr dailyMgr) {
535+
private static void Open(DailyMgr dailyMgr, bool retainSelections = false) {
536536
var maid = PrivateModeMgr.Instance.PrivateMaid;
537537
if (maid != null) {
538538
maid.Visible = false;
539539
}
540540
dailyMgr.m_ctrl.m_goPanel.gameObject.SetActive(false);
541541
var manager = dailyMgr.GetManager<DressCodeManager>();
542542
manager.SetBackground();
543+
if (!retainSelections) {
544+
manager.ResetSelections();
545+
}
543546
manager.OpenPanel();
544547
}
545548
}

DressCodeControl.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ internal class DressCodeControl : MonoBehaviour {
1010
private static readonly Vector2 ScopeListSize = new(144, 925);
1111
private static readonly Vector2 MaidListSize = new(502, 925);
1212

13+
private static SelectionState _selectionState;
14+
1315
private SceneList _sceneList;
1416
private ScopeList _scopeList;
1517
private MaidSelectPanel _maidSelectPanel;
@@ -18,7 +20,6 @@ internal class DressCodeControl : MonoBehaviour {
1820
private DressCodeManager m_mgr;
1921
private GameObject m_goPanel;
2022

21-
2223
public CostumeScene SelectedScene {
2324
get => _sceneList.SelectedValue;
2425
set => _sceneList.SelectValue(value);
@@ -86,10 +87,20 @@ public void Init(DressCodeManager manager, CanvasComponent panel) {
8687
}
8788

8889
public void CreateSelector() {
89-
SelectedScope = ProfileScope.Scene;
90+
var previousSelection = _selectionState;
9091
_maidSelectPanel.Initialize();
92+
if (previousSelection != null) {
93+
SelectedScene = previousSelection.Scene;
94+
SelectedScope = previousSelection.Scope;
95+
SelectedMaid = previousSelection.Maid;
96+
} else {
97+
SelectedScope = ProfileScope.Scene;
98+
_sceneList.SelectFirstAvailable();
99+
}
91100
}
92101

102+
internal void ResetSelections() => _selectionState = null;
103+
93104
private void SetSceneMode() {
94105
_maidSelectPanel.SetActive(false);
95106
_profilePanel.SetSceneMode();
@@ -114,11 +125,16 @@ private void UpdateScopeSelection() {
114125

115126
private void UpdateMaidSelection() {
116127
_sceneList.SetNpcMode(SelectedScope == ProfileScope.Maid && SelectedMaid.status.heroineType is not (MaidStatus.HeroineType.Original or MaidStatus.HeroineType.Transfer));
117-
_sceneList.SelectFirstAvailable();
128+
_sceneList.SelectFirstAvailable(SelectedScene);
118129
UpdateProfileSelection();
119130
}
120131

121132
private void UpdateProfileSelection() {
133+
_selectionState = new() {
134+
Scene = SelectedScene,
135+
Scope = SelectedScope,
136+
Maid = SelectedMaid,
137+
};
122138
var profile = SelectedScope switch {
123139
ProfileScope.Scene => DressCode.GetPreferredProfile(SelectedScene),
124140
ProfileScope.Maid => DressCode.GetPreferredProfile(SelectedMaid, SelectedScene),
@@ -148,4 +164,10 @@ private void OnProfileChanged(object sender, ProfilePanel.ProfileSelectedEventAr
148164
}
149165
}
150166
}
167+
168+
class SelectionState {
169+
public CostumeScene Scene { get; set; }
170+
public ProfileScope Scope { get; set; }
171+
public Maid Maid { get; set; }
172+
}
151173
}

DressCodeManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using com.workman.cm3d2.scene.dailyEtc;
1+
using com.workman.cm3d2.scene.dailyEtc;
22
using PrivateMaidMode;
33

44
namespace COM3D2.DressCode;
@@ -28,6 +28,8 @@ public override void OpenPanel() {
2828
m_Ctrl.CreateSelector();
2929
}
3030

31+
internal void ResetSelections() => m_Ctrl.ResetSelections();
32+
3133
internal void SetBackground() {
3234
GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
3335
GameMain.Instance.MainCamera.SetTargetPos(new(-0.05539433f, 0.95894f, 0.1269088f));

Panels/SceneList.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public SceneList(BaseComponent parent) : base(parent, nameof(SceneList)) {
2424
UpdateChildren();
2525
}
2626

27-
public void SelectFirstAvailable() {
27+
public void SelectFirstAvailable(CostumeScene preferredScene = CostumeScene.None) {
28+
if (preferredScene != CostumeScene.None && Buttons.First(e => e.Value == preferredScene).IsEnabled) {
29+
SelectValue(preferredScene);
30+
return;
31+
}
2832
var button = Buttons.First(e => e.IsEnabled);
2933
SelectValue(button.Value);
3034
}

0 commit comments

Comments
 (0)