Skip to content

Commit a71e30e

Browse files
committed
Source upload
1 parent fef4b92 commit a71e30e

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed

Source/DebugStifle.cs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+

2+
using System.Collections;
3+
using UnityEngine;
4+
using UnityEngine.UI;
5+
using KSP.UI.Screens.DebugToolbar;
6+
using TMPro;
7+
8+
namespace DebugStifle
9+
{
10+
[KSPAddon(KSPAddon.Startup.Instantly, true)]
11+
public class DebugStifle : MonoBehaviour
12+
{
13+
private static bool loaded;
14+
private static bool processed;
15+
16+
private static DebugScreenConsole console;
17+
18+
private bool open;
19+
20+
private void Awake()
21+
{
22+
if (loaded)
23+
{
24+
Destroy(gameObject);
25+
return;
26+
}
27+
28+
loaded = true;
29+
30+
DontDestroyOnLoad(gameObject);
31+
}
32+
33+
private void Update()
34+
{
35+
if (processed)
36+
return;
37+
38+
if (!open && Input.GetKeyDown(KeyCode.F12) && GameSettings.MODIFIER_KEY.GetKey(false))
39+
{
40+
open = true;
41+
42+
StartCoroutine(WaitForDebug());
43+
}
44+
}
45+
46+
private IEnumerator WaitForDebug()
47+
{
48+
int timer = 0;
49+
50+
while (GameObject.FindObjectOfType<DebugScreen>() == null && timer < 20)
51+
{
52+
timer++;
53+
Debug.Log("[Debug_Stifler] Searching For Debug Panel...");
54+
yield return new WaitForSeconds(1);
55+
}
56+
57+
yield return new WaitForSeconds(0.5f);
58+
59+
AlterPrefab();
60+
}
61+
62+
private void AlterPrefab()
63+
{
64+
Debug.Log("[Debug_Stifler] Altering Debug Panel...");
65+
66+
DebugScreen screen = GameObject.FindObjectOfType<DebugScreen>();
67+
68+
if (screen == null)
69+
return;
70+
71+
console = screen.GetComponentInChildren<DebugScreenConsole>();
72+
73+
if (console == null)
74+
return;
75+
76+
Button toggle = GameObject.Instantiate<Button>(console.submitButton);
77+
78+
toggle.transform.SetParent(console.submitButton.transform.parent, false);
79+
80+
toggle.onClick.RemoveAllListeners();
81+
toggle.onClick.AddListener(ToggleInput);
82+
83+
TextMeshProUGUI toggleText = toggle.GetComponentInChildren<TextMeshProUGUI>();
84+
85+
if (toggleText == null)
86+
return;
87+
88+
toggleText.text = "Toggle Input";
89+
90+
console.submitButton.transform.SetAsLastSibling();
91+
92+
LayoutElement layout = toggle.GetComponent<LayoutElement>();
93+
94+
if (layout == null)
95+
return;
96+
97+
layout.minWidth += 38;
98+
layout.preferredWidth += 38;
99+
100+
processed = true;
101+
102+
Debug.Log("[Debug_Stifler] Debug Panel Altered");
103+
104+
Destroy(gameObject);
105+
}
106+
107+
private static void ToggleInput()
108+
{
109+
if (console.inputField.interactable)
110+
{
111+
console.inputField.DeactivateInputField();
112+
console.inputField.interactable = false;
113+
}
114+
else
115+
console.inputField.interactable = true;
116+
}
117+
}
118+
}

Source/DebugStifle.csproj

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{AFA6624E-E06C-4C3B-9F08-FE2A1818654F}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>DebugStifle</RootNamespace>
11+
<AssemblyName>DebugStifle</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="Assembly-CSharp">
34+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
35+
<Private>False</Private>
36+
</Reference>
37+
<Reference Include="System" />
38+
<Reference Include="UnityEngine">
39+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.dll</HintPath>
40+
<Private>False</Private>
41+
</Reference>
42+
<Reference Include="UnityEngine.UI">
43+
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.UI.dll</HintPath>
44+
<Private>False</Private>
45+
</Reference>
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="DebugStifle.cs" />
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
</ItemGroup>
51+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
52+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
53+
Other similar extension points exist, see Microsoft.Common.targets.
54+
<Target Name="BeforeBuild">
55+
</Target>
56+
<Target Name="AfterBuild">
57+
</Target>
58+
-->
59+
</Project>

Source/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("DebugStifle")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("DebugStifle")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("a59f1c3a-0707-47f7-b9d3-78da3717b19f")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.1.0")]
36+
[assembly: AssemblyFileVersion("1.0.1.0")]

0 commit comments

Comments
 (0)