Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: KSP-RO/RP-1
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e65db256d3df
Choose a base ref
...
head repository: KSP-RO/RP-1
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 0512a2023ac2
Choose a head ref
  • 4 commits
  • 10 files changed
  • 2 contributors

Commits on Aug 15, 2017

  1. Copy the full SHA
    33617c4 View commit details

Commits on Aug 16, 2017

  1. Refactored and consolidated UI

    Now, the Training and Avionics windows are just extra tabs within the RP-0
     window (TopWindow) alongside the maintenance and tooling tabs.
    ec429 committed Aug 16, 2017
    Copy the full SHA
    ca78265 View commit details
  2. Rebuild DLL

    ec429 committed Aug 16, 2017
    Copy the full SHA
    8969048 View commit details
  3. Merge pull request #754 from ec429/maintUI

    UI Refactor
    NathanKell authored Aug 16, 2017
    Copy the full SHA
    0512a20 View commit details
Binary file modified GameData/RP-0/Plugins/RP0.dll
Binary file not shown.
62 changes: 62 additions & 0 deletions Source/Avionics/AvionicsGUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace RP0
{
public class AvionicsGUI : UIBase
{
private double deltaTime = 0d;
private const double UPDATEINTERVAL = 0.25d;
private float maxMass, vesselMass;
private bool haveParts = false, isControlLocked = false;

public void Update()
{
deltaTime += Time.deltaTime;
if (deltaTime > UPDATEINTERVAL)
{
deltaTime = 0;
haveParts = false;
isControlLocked = false;
List<Part> parts = null;
if ((object)(EditorLogic.fetch.ship) != null)
parts = EditorLogic.fetch.ship.Parts;
if (parts != null)
{
if (parts.Count > 0)
{
isControlLocked = ControlLockerUtils.ShouldLock(parts, false, out maxMass, out vesselMass);
haveParts = true;
}
}
}
}

public void avionicsTab()
{
Update();
if (!haveParts)
return;
GUILayout.BeginHorizontal();
try {
GUILayout.Label("Supports:", HighLogic.Skin.label, GUILayout.Width(80));
GUILayout.Label(maxMass.ToString("N3") + "t", rightLabel, GUILayout.Width(80));
} finally {
GUILayout.EndHorizontal();
}
GUILayout.BeginHorizontal();
try {
GUILayout.Label("Vessel:", HighLogic.Skin.label, GUILayout.Width(80));
GUILayout.Label(vesselMass.ToString("N3") + "t", rightLabel, GUILayout.Width(80));
} finally {
GUILayout.EndHorizontal();
}
if (isControlLocked)
GUILayout.Label("Insufficient avionics!", boldLabel);
else
GUILayout.Label("Avionics are sufficient", HighLogic.Skin.label);
}
}
}

125 changes: 0 additions & 125 deletions Source/Avionics/ControlLocker.cs
Original file line number Diff line number Diff line change
@@ -93,131 +93,6 @@ public static bool ShouldLock(List<Part> parts, bool countClamps, out float maxM
return true;
}
}
/// <summary>
/// This class will display a warning in the editor when there is insufficient avionics
/// </summary>
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
class ControlLockerEditor : MonoBehaviour
{
// GUI
static Rect windowPos = new Rect(500, 200, 0, 0);
static bool guiEnabled = true;
bool haveParts = false;
static bool showOnlyWarning = false;

// settings
//static KSP.IO.PluginConfiguration config;
static public KeyCode key = KeyCode.I;
double deltaTime = 0d;
const double UPDATEINTERVAL = 0.25d;

// data
bool isControlLocked = false;
float maxMass, vesselMass;

static public ControlLockerEditor fetch;

public void Start()
{
//config = KSP.IO.PluginConfiguration.CreateForType<ControlLockerEditor>
enabled = true;
//config.load();
//windowPos = config.GetValue<Rect>
fetch = this;
}
public void Update()
{
// toggle visibility
if (GameSettings.MODIFIER_KEY.GetKey() && Input.GetKeyDown(key))
{
if (guiEnabled && showOnlyWarning && !isControlLocked)
showOnlyWarning = false;
else
guiEnabled = !guiEnabled;
}

deltaTime += Time.deltaTime;
if (deltaTime > UPDATEINTERVAL)
{
deltaTime = 0;
haveParts = false;
isControlLocked = false;
List<Part> parts = null;
if ((object)(EditorLogic.fetch.ship) != null)
parts = EditorLogic.fetch.ship.Parts;
if (parts != null)
{
if (parts.Count > 0)
{
isControlLocked = ControlLockerUtils.ShouldLock(parts, false, out maxMass, out vesselMass);
haveParts = true;
}
}
}
}
public void OnGUI()
{
if(guiEnabled && haveParts && (!showOnlyWarning || (showOnlyWarning && isControlLocked)))
windowPos = GUILayout.Window("RP0ControlLocker".GetHashCode(), windowPos, DrawWindow, "Avionics");
}
public void DrawWindow(int windowID)
{
// Enable closing of the window tih "x"
GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
buttonStyle.padding = new RectOffset(5, 5, 3, 0);
buttonStyle.margin = new RectOffset(1, 1, 1, 1);
buttonStyle.stretchWidth = false;
buttonStyle.stretchHeight = false;
GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
labelStyle.wordWrap = false;

GUILayout.BeginVertical();

GUILayout.FlexibleSpace();

GUILayout.BeginHorizontal();
if (GUILayout.Button("X", buttonStyle))
{
guiEnabled = false;
}
GUILayout.EndHorizontal();

if (isControlLocked)
{
GUILayout.BeginHorizontal();
GUILayout.Label("WARNING", labelStyle);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Insufficient avionics!", labelStyle);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Supports: " + maxMass.ToString("N3") + "t", labelStyle);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Vessel: " + vesselMass.ToString("N3") + "t", labelStyle);
GUILayout.EndHorizontal();
}
else
{
GUILayout.BeginHorizontal();
GUILayout.Label("Avionics OK!", labelStyle);
GUILayout.EndHorizontal();
}

GUILayout.BeginHorizontal();
if (GUILayout.Button(showOnlyWarning ? "Set to show always" : "Set to hide if OK", buttonStyle))
{
showOnlyWarning = !showOnlyWarning;
}
GUILayout.EndHorizontal();



GUILayout.EndVertical();
GUI.DragWindow();
}

}

/// <summary>
/// This class will lock controls if and only if avionics requirements exist and are not met
119 changes: 26 additions & 93 deletions Source/Crew/FSGUI.cs
Original file line number Diff line number Diff line change
@@ -8,56 +8,13 @@

namespace RP0.Crew
{
public class FSGUI
public class FSGUI : UIBase
{
public bool showMain = false;
public Rect MainGUIPos = new Rect(200, 200, 540, 360);
public void SetGUIPositions(GUI.WindowFunction OnWindow)
{
if (showMain) MainGUIPos = GUILayout.Window(7349, MainGUIPos, DrawMainGUI, "Training");
}

public void DrawGUIs(int windowID)
{
if (showMain) DrawMainGUI(windowID);
}

private enum tabs { Summary, Courses, NewCourse, Naut };
private tabs currentTab = tabs.Summary;
ActiveCourse selectedCourse = null;
ProtoCrewMember selectedNaut = null;
Vector2 nautListScroll = new Vector2();
private GUIStyle rightLabel, boldLabel, pressedButton;
private ActiveCourse selectedCourse = null;
private ProtoCrewMember selectedNaut = null;
private Vector2 nautListScroll = new Vector2();
private Dictionary<ProtoCrewMember, ActiveCourse> activeMap = new Dictionary<ProtoCrewMember, ActiveCourse>();

public FSGUI()
{
rightLabel = new GUIStyle(HighLogic.Skin.label);
rightLabel.alignment = TextAnchor.MiddleRight;
boldLabel = new GUIStyle(HighLogic.Skin.label);
boldLabel.fontStyle = FontStyle.Bold;
pressedButton = new GUIStyle(HighLogic.Skin.button);
pressedButton.normal = pressedButton.active;
}

private bool toggleButton(string text, bool selected, params GUILayoutOption[] options)
{
return GUILayout.Button(text, selected ? pressedButton : HighLogic.Skin.button, options);
}

private void tabSelector()
{
GUILayout.BeginHorizontal();
try {
if (toggleButton("Summary", currentTab == tabs.Summary))
currentTab = tabs.Summary;
if (toggleButton("Courses", currentTab == tabs.Courses))
currentTab = tabs.Courses;
} finally {
GUILayout.EndHorizontal();
}
}

protected void nautListHeading()
{
GUILayout.BeginHorizontal();
@@ -109,7 +66,7 @@ private void cancelCourse(ActiveCourse course)
PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin);
}

protected void nautListRow(ProtoCrewMember student)
protected void nautListRow(tabs currentTab, ProtoCrewMember student)
{
GUIStyle style = HighLogic.Skin.label;
ActiveCourse currentCourse = null;
@@ -129,9 +86,8 @@ protected void nautListRow(ProtoCrewMember student)
else
selectedCourse.AddStudent(student);
}
} else if (currentTab == tabs.Summary) {
} else if (currentTab == tabs.Training) {
if (GUILayout.Button(student.name, GUILayout.Width(96))) {
currentTab = tabs.Naut;
selectedNaut = student;
}
} else {
@@ -171,38 +127,47 @@ protected void nautListRow(ProtoCrewMember student)
}
}

protected void summaryTab()
private void summaryBody(tabs currentTab)
{
updateActiveMap();
nautListScroll = GUILayout.BeginScrollView(nautListScroll, GUILayout.Width(480), GUILayout.Height(144));
try {
nautListHeading();
for (int i = 0; i < HighLogic.CurrentGame.CrewRoster.Count; i++)
{
ProtoCrewMember student = HighLogic.CurrentGame.CrewRoster[i];
if (student.type == ProtoCrewMember.KerbalType.Crew)
nautListRow(student);
nautListRow(currentTab, student);
}
} finally {
GUILayout.EndScrollView();
}
}

public tabs summaryTab()
{
selectedCourse = null;
selectedNaut = null;
summaryBody(tabs.Training);
return selectedNaut == null ? tabs.Training : tabs.Naut;
}

protected void courseSelector()
{
foreach (CourseTemplate course in CrewHandler.Instance.OfferedCourses) {
if (GUILayout.Button(course.name)) {
if (GUILayout.Button(course.name))
selectedCourse = new ActiveCourse(course);
currentTab = tabs.NewCourse;
}
}
}

protected void coursesTab()
public tabs coursesTab()
{
selectedCourse = null;
courseSelector();
return selectedCourse == null ? tabs.Courses : tabs.NewCourse;
}

protected void newCourseTab()
public tabs newCourseTab()
{
GUILayout.BeginHorizontal();
try {
@@ -213,7 +178,7 @@ protected void newCourseTab()
GUILayout.EndHorizontal();
}
GUILayout.Label(selectedCourse.description);
summaryTab();
summaryBody(tabs.NewCourse);
if (selectedCourse.seatMax > 0)
GUILayout.Label(selectedCourse.seatMax - selectedCourse.Students.Count + " remaining seat(s).");
if (selectedCourse.seatMin > selectedCourse.Students.Count)
@@ -224,13 +189,14 @@ protected void newCourseTab()
if (selectedCourse.StartCourse()) {
CrewHandler.Instance.ActiveCourses.Add(selectedCourse);
selectedCourse = null;
currentTab = tabs.Summary;
}
}
return selectedCourse == null ? tabs.Training : tabs.NewCourse;
}

protected void nautTab()
public void nautTab()
{
updateActiveMap();
GUILayout.BeginHorizontal();
try {
GUILayout.FlexibleSpace();
@@ -278,38 +244,5 @@ private void updateActiveMap()
}
}
}

protected void DrawMainGUI(int windowID)
{
updateActiveMap();
try {
GUILayout.BeginVertical();
try {
tabSelector();
switch (currentTab) {
case tabs.Summary:
selectedCourse = null;
summaryTab();
break;
case tabs.Courses:
coursesTab();
break;
case tabs.NewCourse:
newCourseTab();
break;
case tabs.Naut:
nautTab();
break;
default: // can't happen
break;
}
} finally {
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
} finally {
GUI.DragWindow();
}
}
}
}
Loading