forked from jrossignol/ContractConfigurator
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCelestialBodyCoverageParameter.cs
91 lines (82 loc) · 2.94 KB
/
CelestialBodyCoverageParameter.cs
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
using ContractConfigurator.Parameters;
using Contracts;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using UnityEngine;
using KSP.Localization;
using RemoteTech;
using ContractConfigurator;
namespace ContractConfigurator.RemoteTech
{
/// <summary>
/// Parameter to check the percentage coverage of the surface of a celestial body.
/// </summary>
public class CelestialBodyCoverageParameter : ContractConfiguratorParameter
{
protected double coverage { get; set; }
private double currentCoverage = -1.0;
public CelestialBodyCoverageParameter()
: this(0.0, null)
{
}
public CelestialBodyCoverageParameter(double coverage, CelestialBody targetBody, string title = null)
: base(title)
{
this.coverage = coverage;
this.targetBody = targetBody;
disableOnStateChange = false;
}
protected override string GetParameterTitle()
{
string output;
if (string.IsNullOrEmpty(title))
{
if (currentCoverage > 0.0 && state != ParameterState.Complete)
{
output = Localizer.Format("#cc.remotetech.param.CelestialBodyCoverage.inProgress", targetBody.displayName, (currentCoverage * 100).ToString("N0"), (coverage * 100).ToString("N0"));
}
else
{
output = Localizer.Format("#cc.remotetech.param.CelestialBodyCoverage", targetBody.displayName, (coverage * 100).ToString("N0"));
}
}
else
{
output = title;
}
return output;
}
protected override void OnParameterSave(ConfigNode node)
{
node.AddValue("coverage", coverage);
node.AddValue("targetBody", targetBody.name);
}
protected override void OnParameterLoad(ConfigNode node)
{
coverage = ConfigNodeUtil.ParseValue<double>(node, "coverage");
targetBody = ConfigNodeUtil.ParseValue<CelestialBody>(node, "targetBody");
}
protected override void OnUpdate()
{
if (RemoteTechProgressTracker.Instance != null)
{
double oldCoverage = currentCoverage;
currentCoverage = RemoteTechProgressTracker.GetCoverage(targetBody);
if (currentCoverage >= coverage)
{
SetState(ParameterState.Complete);
RemoteTechProgressTracker.Instance.RemoveFromPriorityList(targetBody);
}
else
{
SetState(ParameterState.Incomplete);
RemoteTechProgressTracker.Instance.AddToPriorityList(targetBody);
}
// Update contract window
GetTitle();
}
}
}
}