Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit 8645bde

Browse files
committed
Add Settings button on each window
- Add new textures for close button, settings button, pop out button - Clicking on each settings button opens edit window with that section/window selected - Move Pop out button to the right of the section
1 parent c582d2a commit 8645bde

File tree

17 files changed

+161
-110
lines changed

17 files changed

+161
-110
lines changed

MicroEngineerProject/MicroEngineer/Managers/UI.cs

Lines changed: 68 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,11 @@ private void OnGUI_Flight()
149149

150150
private void DrawSettingsFlightWindow(int id)
151151
{
152-
if (CloseButton(Styles.CloseBtnRect))
153-
_showGuiSettingsFlight = false;
154-
152+
GUILayout.BeginHorizontal();
155153
GUILayout.Label("<b>// SETTINGS</b>");
154+
GUILayout.FlexibleSpace();
155+
_showGuiSettingsFlight = !CloseButton(Styles.CloseBtnStyle);
156+
GUILayout.EndHorizontal();
156157

157158
GUILayout.Space(10);
158159
GUILayout.Label("<b>Edit window entries</b>");
@@ -162,7 +163,10 @@ private void DrawSettingsFlightWindow(int id)
162163
GUILayout.Space(10);
163164
GUILayout.Label("<b>Layout control</b>");
164165
if (GUILayout.Button("SAVE LAYOUT", Styles.NormalBtnStyle))
166+
{
165167
_manager.SaveLayout();
168+
_showGuiSettingsFlight = false;
169+
}
166170
GUILayout.Space(5);
167171
if (GUILayout.Button("LOAD LAYOUT", Styles.NormalBtnStyle))
168172
_manager.LoadLayout();
@@ -176,7 +180,7 @@ private void DrawSettingsFlightWindow(int id)
176180
GUILayout.Label("<b>Theme</b>");
177181
GUILayout.Space(-10);
178182

179-
GUILayout.BeginHorizontal();
183+
GUILayout.BeginHorizontal();
180184
var settingsWindow = Windows.Find(w => w.GetType() == typeof(SettingsWIndow)) as SettingsWIndow;
181185
if (GUILayout.Toggle(Styles.ActiveTheme == Theme.munix, "munix", Styles.SectionToggleStyle))
182186
{
@@ -266,22 +270,21 @@ private void FillMainGUI(int windowID)
266270
{
267271
List<EntryWindow> entryWindows = Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList();
268272

269-
if (SettingsButtonOnMainGui(Styles.SettingsMainBtnBtnRect))
273+
GUILayout.Space(-15);
274+
GUILayout.BeginHorizontal();
275+
if (GUILayout.Button(Styles.Settings20Texture, Styles.SettingsMainGuiBtnStyle))
270276
{
271277
Rect mainGuiRect = Windows.OfType<MainGuiWindow>().FirstOrDefault().FlightRect;
272278
settingsFlightRect = new Rect(mainGuiRect.x - Styles.WindowWidthSettingsFlight, mainGuiRect.y, Styles.WindowWidthSettingsFlight, 0);
273279
_showGuiSettingsFlight = !_showGuiSettingsFlight;
274280
}
281+
GUILayout.FlexibleSpace();
282+
if (CloseButton(Styles.CloseMainGuiBtnStyle))
283+
CloseWindow();
284+
GUILayout.EndHorizontal();
275285

276286
try
277287
{
278-
if (CloseButton(Styles.CloseBtnRect))
279-
{
280-
CloseWindow();
281-
}
282-
283-
GUILayout.Space(5);
284-
285288
GUILayout.BeginHorizontal();
286289

287290
int toggleIndex = -1;
@@ -297,7 +300,7 @@ private void FillMainGUI(int windowID)
297300
window.IsFlightActive = GUILayout.Toggle(window.IsFlightActive, window.Abbreviation, Styles.SectionToggleStyle);
298301
}
299302
GUILayout.EndHorizontal();
300-
GUILayout.Space(5);
303+
GUILayout.Space(-5);
301304

302305
// Draw Stage window next
303306
StageWindow stageWindow = entryWindows.OfType<StageWindow>().FirstOrDefault();
@@ -319,10 +322,9 @@ private void FillMainGUI(int windowID)
319322
if (window.MainWindow == MainWindow.Maneuver && !Utility.ManeuverExists())
320323
continue;
321324

322-
DrawSectionHeader(window.Name, ref window.IsFlightPoppedOut, window.IsLocked, "");
325+
DrawSectionHeader(window.Name, ref window.IsFlightPoppedOut, window.IsLocked);
323326

324327
window.DrawWindowHeader();
325-
GUILayout.Space(10);
326328

327329
for (int i = 0; i < window.Entries.Count; i++)
328330
{
@@ -354,10 +356,10 @@ private void DrawPopoutWindow(int windowIndex)
354356
List<EntryWindow> entryWindows = Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList();
355357
EntryWindow w = Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList()[windowIndex];
356358

357-
DrawSectionHeader(w.Name, ref w.IsFlightPoppedOut, w.IsLocked, "");
358-
359+
GUILayout.Space(-5);
360+
DrawSectionHeader(w.Name, ref w.IsFlightPoppedOut, w.IsLocked);
361+
359362
w.DrawWindowHeader();
360-
GUILayout.Space(10);
361363

362364
for (int i = 0; i < w.Entries.Count; i++)
363365
{
@@ -370,34 +372,43 @@ private void DrawPopoutWindow(int windowIndex)
370372
w.DrawWindowFooter();
371373

372374
DrawSectionEnd(w);
373-
}
375+
}
374376

375-
private void DrawSectionHeader(string sectionName, ref bool isPopout, bool isLocked, string value = "")
377+
private void DrawSectionHeader(string sectionName, ref bool isPopout, bool isLocked)
376378
{
379+
GUILayout.Space(10);
377380
GUILayout.BeginHorizontal();
378381

379382
// If window is popped out and it's not locked => show the close button. If it's not popped out => show to popup arrow
380-
isPopout = isPopout && !isLocked ? !CloseButton(Styles.CloseBtnRect) : !isPopout ? GUILayout.Button("⇖", Styles.PopoutBtnStyle) : isPopout;
383+
//isPopout = isPopout && !isLocked ? !CloseButton(Styles.CloseBtnRect) : !isPopout ? GUILayout.Button("⇖", Styles.PopoutBtnStyle) : isPopout;
384+
//isPopout = isPopout && !isLocked ? !CloseButton(Styles.CloseBtnRect) : !isPopout ? GUILayout.Button("⇖", Styles.PopoutBtnStyle) : isPopout;
381385

382-
GUILayout.Label($"<b>{sectionName}</b>");
383-
GUILayout.FlexibleSpace();
384-
GUILayout.Label(value, Styles.ValueLabelStyle);
385-
GUILayout.Space(5);
386-
GUILayout.Label("", Styles.UnitLabelStyle);
386+
GUILayout.Label($"{sectionName}", Styles.WindowTitleLabelStyle);
387+
GUILayout.FlexibleSpace();
388+
if(GUILayout.Button(Styles.Settings15Texture, Styles.SettingsBtnStyle))
389+
{
390+
_selectedWindowId = Windows.
391+
FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().
392+
FindAll(w => w.IsEditable).
393+
FindIndex(w => w.Name == sectionName);
394+
_showEditWindow = true;
395+
}
396+
isPopout = isPopout && !isLocked ? !CloseButton(Styles.CloseBtnStyle) : !isPopout ? GUILayout.Button(Styles.PopoutTexture, Styles.PopoutBtnStyle) : isPopout;
387397
GUILayout.EndHorizontal();
388-
GUILayout.Space(Styles.SpacingAfterHeader);
398+
399+
GUILayout.Space(Styles.NegativeSpacingAfterHeader);
389400
}
390401

391-
private void DrawEntry(GUIStyle horizontalStyle, string entryName, string value, string unit = "")
402+
private void DrawEntry(GUIStyle backgroundTexture, string entryName, string value, string unit = "")
392403
{
393-
GUILayout.BeginHorizontal(horizontalStyle);
404+
GUILayout.BeginHorizontal(backgroundTexture);
394405
GUILayout.Label(entryName, Styles.NameLabelStyle);
395406
GUILayout.FlexibleSpace();
396407
GUILayout.Label(value, Styles.ValueLabelStyle);
397408
GUILayout.Space(5);
398409
GUILayout.Label(unit, Styles.UnitLabelStyle);
399410
GUILayout.EndHorizontal();
400-
GUILayout.Space(Styles.SpacingAfterEntry);
411+
GUILayout.Space(Styles.NegativeSpacingAfterEntry);
401412
}
402413

403414
private void DrawSectionEnd(EntryWindow window)
@@ -424,7 +435,12 @@ private void DrawEditWindow(int windowIndex)
424435
List<EntryWindow> editableWindows = Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().FindAll(w => w.IsEditable); // Editable windows are all except MainGUI, Settings, Stage and StageInfoOAB
425436
List<BaseEntry> entriesByCategory = _manager.Entries.FindAll(e => e.Category == _selectedCategory); // All window stageInfoOabEntries belong to a category, but they can still be placed in any window
426437

427-
_showEditWindow = !CloseButton(Styles.CloseBtnRect);
438+
GUILayout.Space(-5);
439+
GUILayout.BeginHorizontal();
440+
GUILayout.FlexibleSpace();
441+
_showEditWindow = !CloseButton(Styles.CloseBtnStyle);
442+
GUILayout.EndHorizontal();
443+
GUILayout.Space(5);
428444

429445
#region Selection of window to be edited
430446
GUILayout.BeginHorizontal();
@@ -504,7 +520,7 @@ private void DrawEditWindow(int windowIndex)
504520
if (GUILayout.Button("X", Styles.OneCharacterBtnStyle))
505521
editableWindows[_selectedWindowId].RemoveEntry(index);
506522
GUILayout.EndHorizontal();
507-
GUILayout.Space(Styles.SpacingAfterEntry);
523+
GUILayout.Space(Styles.NegativeSpacingAfterEntry);
508524
}
509525
#endregion
510526

@@ -564,7 +580,7 @@ private void DrawEditWindow(int windowIndex)
564580
GUILayout.Label(entry.Description, Styles.BlueLabelStyle);
565581
GUILayout.EndHorizontal();
566582
}
567-
GUILayout.Space(Styles.SpacingAfterEntry);
583+
GUILayout.Space(Styles.NegativeSpacingAfterEntry);
568584
}
569585
GUILayout.Space(10);
570586
#endregion
@@ -581,16 +597,19 @@ private void DrawStageInfoOAB(int windowID)
581597
EntryWindow stageInfoOabWindow = Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB);
582598
List<BaseEntry> stageInfoOabEntries = stageInfoOabWindow.Entries;
583599

584-
GUILayout.BeginHorizontal();
585-
if (SettingsButton(Styles.SettingsOABRect))
586-
_showGuiSettingsOAB = !_showGuiSettingsOAB;
587-
588-
if (CloseButton(Styles.CloseBtnStagesOABRect))
600+
GUILayout.BeginHorizontal();
601+
GUILayout.Label($"<b>Stage Info</b>");
602+
GUILayout.FlexibleSpace();
603+
if (GUILayout.Button(Styles.Settings15Texture, Styles.SettingsBtnStyle))
604+
_showGuiSettingsOAB = !_showGuiSettingsOAB;
605+
606+
if (CloseButton(Styles.CloseBtnStyle))
589607
{
608+
GameObject.Find("BTN-MicroEngineerOAB")?.GetComponent<UIValue_WriteBool_Toggle>()?.SetValue(false);
590609
stageInfoOabWindow.IsEditorActive = false;
591610
ShowGuiOAB = false;
592611
}
593-
GUILayout.Label($"<b>Stage Info</b>");
612+
594613
GUILayout.EndHorizontal();
595614

596615
// Draw StageInfo header - Delta V fields
@@ -606,7 +625,7 @@ private void DrawStageInfoOAB(int windowID)
606625
Torque torque = (Torque)stageInfoOabEntries.Find(e => e.Name == "Torque");
607626
if (torque.IsActive)
608627
{
609-
GUILayout.Space(Styles.SpacingAfterEntry);
628+
GUILayout.Space(Styles.NegativeSpacingAfterEntry);
610629
GUILayout.BeginHorizontal();
611630
GUILayout.Label("Torque", Styles.NameLabelStyle);
612631
GUILayout.FlexibleSpace();
@@ -630,7 +649,7 @@ private void DrawStageInfoOAB(int windowID)
630649
GUILayout.Space(20);
631650
GUILayout.Label("Body", Styles.TableHeaderCenteredLabelStyle, GUILayout.Width(80));
632651
GUILayout.EndHorizontal();
633-
GUILayout.Space(Styles.SpacingAfterEntry);
652+
GUILayout.Space(Styles.NegativeSpacingAfterEntry);
634653

635654
StageInfo_OAB stageInfoOab = (StageInfo_OAB)stageInfoOabWindow.Entries
636655
.Find(e => e.Name == "Stage Info (OAB)");
@@ -672,7 +691,7 @@ private void DrawStageInfoOAB(int windowID)
672691
}
673692
GUILayout.EndVertical();
674693
GUILayout.EndHorizontal();
675-
GUILayout.Space(Styles.SpacingAfterEntry);
694+
GUILayout.Space(Styles.NegativeSpacingAfterEntry);
676695
}
677696

678697
GUILayout.Space(Styles.SpacingBelowPopout);
@@ -707,8 +726,10 @@ private void DrawCelestialBodySelection(int id)
707726
/// </summary>
708727
private void DrawSettingsOabWindow(int id)
709728
{
710-
if (CloseButton(Styles.CloseBtnSettingsOABRect))
711-
_showGuiSettingsOAB = false;
729+
GUILayout.BeginHorizontal();
730+
GUILayout.FlexibleSpace();
731+
_showGuiSettingsOAB = !CloseButton(Styles.CloseBtnStyle);
732+
GUILayout.EndHorizontal();
712733

713734
EntryWindow stageInfoOabWindow = Windows.FindAll(w => w is EntryWindow).Cast<EntryWindow>().ToList().Find(w => w.MainWindow == MainWindow.StageInfoOAB);
714735
List<BaseEntry> stageInfoOabEntries = stageInfoOabWindow.Entries;
@@ -718,16 +739,6 @@ private void DrawSettingsOabWindow(int id)
718739
GUILayout.Space(15);
719740
}
720741

721-
/// <summary>
722-
/// Draws a Settings button (≡)
723-
/// </summary>
724-
/// <param name="settingsOABRect"></param>
725-
/// <returns></returns>
726-
private bool SettingsButton(Rect rect)
727-
{
728-
return GUI.Button(rect, "≡", Styles.SettingsBtnStyle);
729-
}
730-
731742
#endregion
732743

733744
private void CloseWindow()
@@ -741,14 +752,10 @@ private void CloseWindow()
741752
/// </summary>
742753
/// <param name="rect">Where to position the close button</param>
743754
/// <returns></returns>
744-
internal bool CloseButton(Rect rect)
745-
{
746-
return GUI.Button(rect, "X", Styles.CloseBtnStyle);
747-
}
748-
749-
private bool SettingsButtonOnMainGui(Rect rect)
755+
internal bool CloseButton(GUIStyle style)//Rect rect)
750756
{
751-
return GUI.Button(rect, Styles.SettingsIcon, Styles.SettingsMainGuiBtnStyle);
757+
//return GUI.Button(rect, Styles.CloseButtonTexture, Styles.CloseBtnStyle);
758+
return GUILayout.Button(Styles.CloseButtonTexture, style);
752759
}
753760
}
754761
}

0 commit comments

Comments
 (0)