Skip to content

Commit

Permalink
Showing 4 changed files with 101 additions and 21 deletions.
3 changes: 3 additions & 0 deletions Source/Crew/CourseTemplate.cs
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@ public class CourseTemplate
public ConfigNode RewardLog = null; //the flight log to insert
public ConfigNode ExpireLog = null; // expire all these on complete

public bool isTemporary = false;

public CourseTemplate(ConfigNode source)
{
sourceNode = source;
@@ -134,6 +136,7 @@ public void PopulateFromSourceNode(ConfigNode source = null)
source.TryGetValue("expirationUseStupid", ref expirationUseStupid);

source.TryGetValue("required", ref required);
source.TryGetValue("isTemporary", ref isTemporary);

string repeatStr = source.GetValue("repeatable");
if (!string.IsNullOrEmpty(repeatStr))
53 changes: 35 additions & 18 deletions Source/Crew/CrewHandler.cs
Original file line number Diff line number Diff line change
@@ -494,7 +494,35 @@ public void AddExpiration(TrainingExpiration e)
{
expireTimes.Add(e);
}


public void AddCoursesForTechNode(RDTech tech)
{
for (int i = 0; i < tech.partsAssigned.Count; i++)
{
AvailablePart ap = tech.partsAssigned[i];
if (ap.partPrefab.CrewCapacity > 0)
{
AddPartCourses(ap);
}
}
}

public void AddPartCourses(AvailablePart ap)
{
string name = TrainingDatabase.SynonymReplace(ap.name);
if (!partSynsHandled.Contains(name))
{
partSynsHandled.Add(name);
bool isPartUnlocked = ResearchAndDevelopment.PartModelPurchased(ap);

GenerateCourseProf(ap, !isPartUnlocked);
if (isPartUnlocked)
{
GenerateCourseMission(ap);
}
}
}

#endregion

#region Methods
@@ -806,38 +834,26 @@ protected void GenerateOfferedCourses() //somehow provide some variable options

foreach (AvailablePart ap in PartLoader.LoadedPartsList)
{
if (ap.partPrefab.CrewCapacity > 0 /*&& ap.TechRequired != "start"*/)
if (ap.partPrefab.CrewCapacity > 0 && /*&& ap.TechRequired != "start"*/
ResearchAndDevelopment.PartModelPurchased(ap))
{
if (ResearchAndDevelopment.PartModelPurchased(ap))
{
string name = TrainingDatabase.SynonymReplace(ap.name);
if (!partSynsHandled.Contains(name))
{
partSynsHandled.Add(name);
AddPartCourses(ap);
}
}
AddPartCourses(ap);
}
}

Debug.Log("[FS] Offering " + OfferedCourses.Count + " courses.");
//fire an event to let other mods add available courses (where they can pass variables through then)
}

protected void AddPartCourses(AvailablePart ap)
{
GenerateCourseProf(ap);
GenerateCourseMission(ap);
}

protected void GenerateCourseProf(AvailablePart ap)
protected void GenerateCourseProf(AvailablePart ap, bool isTemporary)
{
ConfigNode n = new ConfigNode("FS_COURSE");
string name = TrainingDatabase.SynonymReplace(ap.name);

n.AddValue("id", "prof_" + name);
n.AddValue("name", "Proficiency: " + name);
n.AddValue("time", 1d + (TrainingDatabase.GetTime(name) * 86400d));
n.AddValue("isTemporary", isTemporary);

n.AddValue("conflicts", "TRAINING_proficiency:" + name);

@@ -859,6 +875,7 @@ protected void GenerateCourseMission(AvailablePart ap)
n.AddValue("id", "msn_" + name);
n.AddValue("name", "Mission: " + name);
n.AddValue("time", 1d + TrainingDatabase.GetTime(name + "-Mission") * 86400d);
n.AddValue("isTemporary", false);
n.AddValue("timeUseStupid", true);
n.AddValue("seatMax", ap.partPrefab.CrewCapacity * 2);
n.AddValue("expiration", settings.trainingMissionExpirationDays * 86400d);
22 changes: 20 additions & 2 deletions Source/Crew/FSGUI.cs
Original file line number Diff line number Diff line change
@@ -14,6 +14,8 @@ public class FSGUI : UIBase
private Vector2 nautListScroll = new Vector2();
private Dictionary<ProtoCrewMember, ActiveCourse> activeMap = new Dictionary<ProtoCrewMember, ActiveCourse>();
private Vector2 courseSelectorScroll = new Vector2();
private GUIStyle courseBtnStyle = null;
private GUIStyle tempCourseLblStyle = null;
private GUIContent nautRowAlarmBtnContent = new GUIContent(GameDatabase.Instance.GetTexture("RP-0/KACIcon15", false));

protected void nautListHeading()
@@ -171,10 +173,17 @@ public tabs summaryTab()

protected void courseSelector()
{
if (courseBtnStyle == null)
{
courseBtnStyle = new GUIStyle(GUI.skin.button);
courseBtnStyle.normal.textColor = Color.yellow;
}

courseSelectorScroll = GUILayout.BeginScrollView(courseSelectorScroll, GUILayout.Width(505), GUILayout.Height(430));
try {
foreach (CourseTemplate course in CrewHandler.Instance.OfferedCourses) {
if (GUILayout.Button(course.name))
var style = course.isTemporary ? courseBtnStyle : GUI.skin.button;
if (GUILayout.Button(course.name, style))
selectedCourse = new ActiveCourse(course);
}
} finally {
@@ -191,6 +200,12 @@ public tabs coursesTab()

public tabs newCourseTab()
{
if (tempCourseLblStyle == null)
{
tempCourseLblStyle = new GUIStyle(GUI.skin.label);
tempCourseLblStyle.normal.textColor = Color.yellow;
}

GUILayout.BeginHorizontal();
try {
GUILayout.FlexibleSpace();
@@ -199,7 +214,10 @@ public tabs newCourseTab()
} finally {
GUILayout.EndHorizontal();
}
GUILayout.Label(selectedCourse.description);
if (!string.IsNullOrEmpty(selectedCourse.description))
GUILayout.Label(selectedCourse.description);
if (selectedCourse.isTemporary)
GUILayout.Label("Tech for this part is still being researched", tempCourseLblStyle);
summaryBody(tabs.NewCourse);
if (selectedCourse.seatMax > 0)
GUILayout.Label(selectedCourse.seatMax - selectedCourse.Students.Count + " remaining seat(s).");
44 changes: 43 additions & 1 deletion Source/KCTBinderModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections;
using KerbalConstructionTime;
using RP0.Crew;
using UnityEngine;

namespace RP0
{
@@ -18,6 +20,8 @@ public class KCTBinderModule : ScenarioModule
protected bool skipOne = true;
protected bool skipTwo = true;

private EventData<RDTech> onKctTechQueuedEvent;

public override void OnAwake()
{
base.OnAwake();
@@ -26,6 +30,22 @@ public override void OnAwake()
KCT_GUI.AvailabilityChecker = CheckCrewForPart;
}

public void Start()
{
onKctTechQueuedEvent = GameEvents.FindEvent<EventData<RDTech>>("OnKctTechQueued");
if (onKctTechQueuedEvent != null)
{
onKctTechQueuedEvent.Add(OnKctTechQueued);
}

StartCoroutine(CreateCoursesRoutine());
}

public void OnDestroy()
{
if (onKctTechQueuedEvent != null) onKctTechQueuedEvent.Remove(OnKctTechQueued);
}

public static bool CheckCrewForPart(ProtoCrewMember pcm, string partName)
{
// lolwut. But just in case.
@@ -112,7 +132,6 @@ protected void Update()
if (buildRate > 0.001d)
MaintenanceHandler.Instance.kctBuildRates[ksc.KSCName] = buildRate;


for (int i = ksc.LaunchPads.Count; i-- > 0;)
{
int lvl = ksc.LaunchPads[i].level;
@@ -125,5 +144,28 @@ protected void Update()
MaintenanceHandler.Instance.kctResearchRate = RDRate;
MaintenanceHandler.Instance.kctPadCounts = padCounts;
}

private void OnKctTechQueued(RDTech data)
{
CrewHandler.Instance.AddCoursesForTechNode(data);
}

private IEnumerator CreateCoursesRoutine()
{
yield return new WaitForFixedUpdate();

for (int i = 0; i < PartLoader.LoadedPartsList.Count; i++)
{
var ap = PartLoader.LoadedPartsList[i];
if (ap.partPrefab.CrewCapacity > 0)
{
var kctTech = KCT_GameStates.TechList.Find(t => t.techID == ap.TechRequired);
if (kctTech != null)
{
CrewHandler.Instance.AddPartCourses(ap);
}
}
}
}
}
}

0 comments on commit 079654c

Please sign in to comment.