Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Fix GUI compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dani0105 committed Feb 28, 2022
1 parent 8e5faef commit a5afdfa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
5 changes: 4 additions & 1 deletion RefillMod/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
UnityEngine.Object.DontDestroyOnLoad(menu);
menu.SetActive(true);
Main.menuObject = menu;
return;
}
else

if (menuObject != null)
{
UnityEngine.Object.Destroy(menuObject);
menuObject = null;
}
}

Expand Down
38 changes: 33 additions & 5 deletions RefillMod/Menu.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,62 @@

using SFS.Input;
using SFS.Parts.Modules;
using SFS.World;
using System;
using UnityEngine;
using static UnityEngine.GUI;

namespace RefillMod
{
class Menu : MonoBehaviour
{

private const float MENU_HEIGHT =90f;
private const float MENU_WIDTH = 200f;

public static Rocket playerRocket;

public Rect windowRect = new Rect((float)Screen.width * 0.05f, (float)Screen.height * 0.05f, 200f, 200f);
public Rect windowRect = new Rect((float)Screen.width * 0.2f, (float)Screen.height * 0.05f, MENU_WIDTH, MENU_HEIGHT);

private bool isVisible;
private WindowFunction windosDraw;

private void Start()
{
KeysNode keysNode = GameManager.main.world_Input.keysNode;
KeybindingsPC.Key menuAction = KeyCode.O;
keysNode.AddOnKeyDown(menuAction, new Action(this.toggleMenu));
this.isVisible = true;
this.windosDraw = new GUI.WindowFunction(this.windowFunc);
}

public void toggleMenu()
{
this.isVisible = !this.isVisible;
}

public void OnGUI()
{
windowRect = GUI.Window(0, windowRect, new GUI.WindowFunction(this.windowFunc), "Menu");
if (this.isVisible)
{
windowRect = GUI.Window(GUIUtility.GetControlID(FocusType.Passive), windowRect, this.windosDraw, "RefillMod(Beta)");
}
}

public void windowFunc(int windowID)
{
if (GUI.Button(new Rect(10f, 20f, 190f, 20f), " Refill tanks"))
GUI.Label(new Rect(10f, 20f, MENU_WIDTH - 10f, 20f), "Hide this: Press 'O'");
if (GUI.Button(new Rect(10f, 50f, MENU_WIDTH - 20f, 20f), "Refill tanks"))
{

foreach (ResourceModule tank in Menu.playerRocket.partHolder.GetModules<ResourceModule>())
{
tank.AddResource(1000f);
}

}
GUI.DragWindow();
}

}


}
5 changes: 3 additions & 2 deletions RefillMod/RefillMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{F9FA369A-40BA-4897-9FE8-3B3D72AB4444}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EngineMod</RootNamespace>
<AssemblyName>EngineMod</AssemblyName>
<RootNamespace>RefillMod</RootNamespace>
<AssemblyName>RefillMod</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
Expand Down Expand Up @@ -41,6 +41,7 @@
</Reference>
<Reference Include="ModLoader">
<HintPath>..\Dependecies\ModLoader.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down

0 comments on commit a5afdfa

Please sign in to comment.