VOID_Module: Improved unlocking behavior around the close button.
VOID_Module: Improved unlocking behavior around the close button.

// VOID // VOID
// //
// VOID_Module.cs // VOID_Module.cs
// //
// Copyright © 2014, toadicus // Copyright © 2014, toadicus
// All rights reserved. // All rights reserved.
// //
// Redistribution and use in source and binary forms, with or without modification, // Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met: // are permitted provided that the following conditions are met:
// //
// 1. Redistributions of source code must retain the above copyright notice, // 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer. // this list of conditions and the following disclaimer.
// //
// 2. Redistributions in binary form must reproduce the above copyright notice, // 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or other // this list of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution. // materials provided with the distribution.
// //
// 3. Neither the name of the copyright holder nor the names of its contributors may be used // 3. Neither the name of the copyright holder nor the names of its contributors may be used
// to endorse or promote products derived from this software without specific prior written permission. // to endorse or promote products derived from this software without specific prior written permission.
// //
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using ToadicusTools; using ToadicusTools;
using UnityEngine; using UnityEngine;
   
namespace VOID namespace VOID
{ {
public abstract class VOID_Module : IVOID_Module public abstract class VOID_Module : IVOID_Module
{ {
/* /*
* Fields * Fields
* */ * */
[AVOID_SaveValue("Active")] [AVOID_SaveValue("Active")]
protected VOID_SaveValue<bool> active = (VOID_SaveValue<bool>)false; protected VOID_SaveValue<bool> active = (VOID_SaveValue<bool>)false;
   
protected float lastUpdate = 0; protected float lastUpdate = 0;
   
private GameScenes[] validScenes; private GameScenes[] validScenes;
private Game.Modes[] validModes; private Game.Modes[] validModes;
   
/* /*
* Properties * Properties
* */ * */
   
public virtual bool Active public virtual bool Active
{ {
get get
{ {
return this.active && this.InValidGame && this.InValidScene; return this.active && this.InValidGame && this.InValidScene;
} }
set set
{ {
this.active.value = value && this.InValidGame && this.InValidScene; this.active.value = value && this.InValidGame && this.InValidScene;
} }
} }
   
public virtual bool GUIRunning public virtual bool GUIRunning
{ {
get get
{ {
if ( if (
RenderingManager.fetch == null || RenderingManager.fetch == null ||
RenderingManager.fetch.postDrawQueue == null || RenderingManager.fetch.postDrawQueue == null ||
RenderingManager.fetch.postDrawQueue.Length < 4 RenderingManager.fetch.postDrawQueue.Length < 4
) )
{ {
return false; return false;
} }
else else
{ {
Delegate callback = RenderingManager.fetch.postDrawQueue[3]; Delegate callback = RenderingManager.fetch.postDrawQueue[3];
if (callback == null) if (callback == null)
{ {
return false; return false;
} }
   
return callback.GetInvocationList().Contains((Callback)this.DrawGUI); return callback.GetInvocationList().Contains((Callback)this.DrawGUI);
} }
} }
} }
   
public virtual bool InValidGame public virtual bool InValidGame
{ {
get get
{ {
return this.ValidModes.Contains(HighLogic.CurrentGame.Mode); return this.ValidModes.Contains(HighLogic.CurrentGame.Mode);
} }
} }
   
public virtual bool InValidScene public virtual bool InValidScene
{ {
get get
{ {
return this.ValidScenes.Contains(HighLogic.LoadedScene); return this.ValidScenes.Contains(HighLogic.LoadedScene);
} }
} }
   
public virtual string Name public virtual string Name
{ {
get; get;
protected set; protected set;
} }
   
public virtual Game.Modes[] ValidModes public virtual Game.Modes[] ValidModes
{ {
get get
{ {
if (this.validModes == null) if (this.validModes == null)
{ {
Tools.PostDebugMessage(this, "validModes is null when checking inValidGame; fetching attribute."); Tools.PostDebugMessage(this, "validModes is null when checking inValidGame; fetching attribute.");
foreach (var attr in this.GetType().GetCustomAttributes(false)) foreach (var attr in this.GetType().GetCustomAttributes(false))
{ {
if (attr is VOID_GameModesAttribute) if (attr is VOID_GameModesAttribute)
{ {
VOID_GameModesAttribute addonAttr = (VOID_GameModesAttribute)attr; VOID_GameModesAttribute addonAttr = (VOID_GameModesAttribute)attr;
   
this.validModes = addonAttr.ValidModes; this.validModes = addonAttr.ValidModes;
   
Tools.PostDebugMessage("Found VOID_GameModesAttribute; validScenes set."); Tools.PostDebugMessage("Found VOID_GameModesAttribute; validScenes set.");
   
break; break;
} }
} }
   
if (this.validModes == null) if (this.validModes == null)
{ {
this.validModes = new Game.Modes[] this.validModes = new Game.Modes[]
{ {
Game.Modes.CAREER, Game.Modes.CAREER,
Game.Modes.SANDBOX, Game.Modes.SANDBOX,
Game.Modes.SCENARIO, Game.Modes.SCENARIO,
Game.Modes.SCENARIO_NON_RESUMABLE, Game.Modes.SCENARIO_NON_RESUMABLE,
Game.Modes.SCIENCE_SANDBOX Game.Modes.SCIENCE_SANDBOX
}; };
   
Tools.PostDebugMessage("No VOID_GameModesAttribute found; validScenes defaulted to flight."); Tools.PostDebugMessage("No VOID_GameModesAttribute found; validScenes defaulted to flight.");
} }
} }
   
return this.validModes; return this.validModes;
} }
} }
   
public virtual GameScenes[] ValidScenes public virtual GameScenes[] ValidScenes
{ {
get get
{ {
if (this.validScenes == null) if (this.validScenes == null)
{ {
Tools.PostDebugMessage(this, "validScenes is null when checking inValidScene; fetching attribute."); Tools.PostDebugMessage(this, "validScenes is null when checking inValidScene; fetching attribute.");
foreach (var attr in this.GetType().GetCustomAttributes(false)) foreach (var attr in this.GetType().GetCustomAttributes(false))
{ {
if (attr is VOID_ScenesAttribute) if (attr is VOID_ScenesAttribute)
{ {
VOID_ScenesAttribute addonAttr = (VOID_ScenesAttribute)attr; VOID_ScenesAttribute addonAttr = (VOID_ScenesAttribute)attr;
   
this.validScenes = addonAttr.ValidScenes; this.validScenes = addonAttr.ValidScenes;
   
Tools.PostDebugMessage("Found VOID_ScenesAttribute; validScenes set."); Tools.PostDebugMessage("Found VOID_ScenesAttribute; validScenes set.");
   
break; break;
} }
} }
   
if (this.validScenes == null) if (this.validScenes == null)
{ {
this.validScenes = new GameScenes[] { GameScenes.FLIGHT }; this.validScenes = new GameScenes[] { GameScenes.FLIGHT };
Tools.PostDebugMessage("No VOID_ScenesAttribute found; validScenes defaulted to flight."); Tools.PostDebugMessage("No VOID_ScenesAttribute found; validScenes defaulted to flight.");
} }
} }
   
return this.validScenes; return this.validScenes;
} }
} }
   
public virtual Vessel Vessel public virtual Vessel Vessel
{ {
get get
{ {
return FlightGlobals.ActiveVessel; return FlightGlobals.ActiveVessel;
} }
} }
   
protected virtual VOIDCore core protected virtual VOIDCore core
{ {
get get
{ {
return VOID_Data.Core; return VOID_Data.Core;
} }
} }
   
protected virtual bool timeToUpdate protected virtual bool timeToUpdate
{ {
get get
{ {
return ( return (
(this.core.UpdateTimer - this.lastUpdate) > this.core.UpdatePeriod || (this.core.UpdateTimer - this.lastUpdate) > this.core.UpdatePeriod ||
this.lastUpdate > this.core.UpdateTimer this.lastUpdate > this.core.UpdateTimer
); );
} }
} }
   
/* /*
* Methods * Methods
* */ * */
public virtual void StartGUI() public virtual void StartGUI()
{ {
if (!this.Active || this.GUIRunning) if (!this.Active || this.GUIRunning)
{ {
return; return;
} }
   
Tools.PostDebugMessage (string.Format("Adding {0} to the draw queue.", this.GetType().Name)); Tools.PostDebugMessage (string.Format("Adding {0} to the draw queue.", this.GetType().Name));
RenderingManager.AddToPostDrawQueue (3, this.DrawGUI); RenderingManager.AddToPostDrawQueue (3, this.DrawGUI);
} }
   
public virtual void StopGUI() public virtual void StopGUI()
{ {
if (!this.GUIRunning) if (!this.GUIRunning)
{ {
return; return;
} }
Tools.PostDebugMessage (string.Format("Removing {0} from the draw queue.", this.GetType().Name)); Tools.PostDebugMessage (string.Format("Removing {0} from the draw queue.", this.GetType().Name));
RenderingManager.RemoveFromPostDrawQueue (3, this.DrawGUI); RenderingManager.RemoveFromPostDrawQueue (3, this.DrawGUI);
} }
   
public abstract void DrawGUI(); public abstract void DrawGUI();
   
public virtual void DrawConfigurables() {} public virtual void DrawConfigurables() {}
   
public virtual void LoadConfig() public virtual void LoadConfig()
{ {
var config = KSP.IO.PluginConfiguration.CreateForType<VOID_Module> (); var config = KSP.IO.PluginConfiguration.CreateForType<VOID_Module> ();
config.load (); config.load ();
   
if (this is VOIDCore) if (this is VOIDCore)
{ {
int configVersion = config.GetValue("VOID_Core_configValue", 2); int configVersion = config.GetValue("VOID_Core_configValue", 2);
   
if (configVersion < VOIDCore.CONFIG_VERSION) if (configVersion < VOIDCore.CONFIG_VERSION)
{ {
((VOIDCore)this).configNeedsUpdate = true; ((VOIDCore)this).configNeedsUpdate = true;
} }
} }
   
foreach (var field in this.GetType().GetMembers( foreach (var field in this.GetType().GetMembers(
BindingFlags.NonPublic | BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Instance |
BindingFlags.FlattenHierarchy BindingFlags.FlattenHierarchy
)) ))
{ {
if (!(field is FieldInfo || field is PropertyInfo)) if (!(field is FieldInfo || field is PropertyInfo))
{ {
continue; continue;
} }
   
if (field is PropertyInfo && (field as PropertyInfo).GetIndexParameters().Length > 0) if (field is PropertyInfo && (field as PropertyInfo).GetIndexParameters().Length > 0)
{ {
continue; continue;
} }
   
object[] attrs = field.GetCustomAttributes(typeof(AVOID_SaveValue), false); object[] attrs = field.GetCustomAttributes(typeof(AVOID_SaveValue), false);
   
if (attrs.Length == 0) { if (attrs.Length == 0) {
continue; continue;
} }
   
AVOID_SaveValue attr = attrs.FirstOrDefault () as AVOID_SaveValue; AVOID_SaveValue attr = attrs.FirstOrDefault () as AVOID_SaveValue;
   
string fieldName = string.Empty; string fieldName = string.Empty;
   
if (this is VOIDCore || this.core.configNeedsUpdate) if (this is VOIDCore || this.core.configNeedsUpdate)
{ {
string typeName = this.GetType().Name;; string typeName = this.GetType().Name;;
   
if (this is VOIDCore && ((VOIDCore)this).configNeedsUpdate) if (this is VOIDCore && ((VOIDCore)this).configNeedsUpdate)
{ {
if (this is VOIDCore_Flight) if (this is VOIDCore_Flight)
{ {
typeName = "VOID_Core"; typeName = "VOID_Core";
} }
else if (this is VOIDCore_Editor) else if (this is VOIDCore_Editor)
{ {
typeName = "VOID_EditorCore"; typeName = "VOID_EditorCore";
} }
} }
   
fieldName = string.Format("{0}_{1}", typeName, attr.Name); fieldName = string.Format("{0}_{1}", typeName, attr.Name);
} }
else else
{ {
fieldName = string.Format( fieldName = string.Format(
"{0}_{1}_{2}", "{0}_{1}_{2}",
this.GetType().Name, this.GetType().Name,
Enum.GetName(typeof(GameScenes), HighLogic.LoadedScene), Enum.GetName(typeof(GameScenes), HighLogic.LoadedScene),
attr.Name attr.Name
); );
} }
   
Tools.PostDebugMessage(string.Format("{0}: Loading field {1}.", this.GetType().Name, fieldName)); Tools.PostDebugMessage(string.Format("{0}: Loading field {1}.", this.GetType().Name, fieldName));
   
object fieldValue; object fieldValue;
   
if (field is FieldInfo) if (field is FieldInfo)
{ {
fieldValue = (field as FieldInfo).GetValue(this); fieldValue = (field as FieldInfo).GetValue(this);
} }
else else
{ {
fieldValue = (field as PropertyInfo).GetValue(this, null); fieldValue = (field as PropertyInfo).GetValue(this, null);
} }
   
bool convertBack = false; bool convertBack = false;
if (fieldValue is IVOID_SaveValue) if (fieldValue is IVOID_SaveValue)
{ {
fieldValue = (fieldValue as IVOID_SaveValue).value; fieldValue = (fieldValue as IVOID_SaveValue).value;
convertBack = true; convertBack = true;
} }
   
fieldValue = config.GetValue(fieldName, fieldValue); fieldValue = config.GetValue(fieldName, fieldValue);
   
if (convertBack) if (convertBack)
{ {
Type type = typeof(VOID_SaveValue<>).MakeGenericType (fieldValue.GetType ()); Type type = typeof(VOID_SaveValue<>).MakeGenericType (fieldValue.GetType ());
IVOID_SaveValue convertValue = Activator.CreateInstance (type) as IVOID_SaveValue; IVOID_SaveValue convertValue = Activator.CreateInstance (type) as IVOID_SaveValue;
convertValue.SetValue (fieldValue); convertValue.SetValue (fieldValue);
fieldValue = convertValue; fieldValue = convertValue;
} }
   
if (field is FieldInfo) if (field is FieldInfo)
{ {
(field as FieldInfo).SetValue(this, fieldValue); (field as FieldInfo).SetValue(this, fieldValue);
} }
else else
{ {
(field as PropertyInfo).SetValue(this, fieldValue, null); (field as PropertyInfo).SetValue(this, fieldValue, null);
} }
   
Tools.PostDebugMessage(string.Format("{0}: Loaded field {1}.", this.GetType().Name, fieldName)); Tools.PostDebugMessage(string.Format("{0}: Loaded field {1}.", this.GetType().Name, fieldName));
} }
} }
   
public virtual void Save(KSP.IO.PluginConfiguration config) public virtual void Save(KSP.IO.PluginConfiguration config)
{ {
foreach (var field in this.GetType().GetMembers( foreach (var field in this.GetType().GetMembers(
BindingFlags.Instance | BindingFlags.Instance |
BindingFlags.NonPublic | BindingFlags.NonPublic |
BindingFlags.Public | BindingFlags.Public |
BindingFlags.FlattenHierarchy BindingFlags.FlattenHierarchy
)) ))
{ {
object[] attrs = field.GetCustomAttributes(typeof(AVOID_SaveValue), false); object[] attrs = field.GetCustomAttributes(typeof(AVOID_SaveValue), false);
   
if (attrs.Length == 0) { if (attrs.Length == 0) {
continue; continue;
} }
   
AVOID_SaveValue attr = attrs.FirstOrDefault () as AVOID_SaveValue; AVOID_SaveValue attr = attrs.FirstOrDefault () as AVOID_SaveValue;
   
string fieldName; string fieldName;
   
if (this is VOIDCore) if (this is VOIDCore)
{ {
fieldName = string.Format("{0}_{1}", this.GetType().Name, attr.Name); fieldName = string.Format("{0}_{1}", this.GetType().Name, attr.Name);
} }
else else
{ {
fieldName = string.Format( fieldName = string.Format(
"{0}_{1}_{2}", "{0}_{1}_{2}",
this.GetType().Name, this.GetType().Name,
Enum.GetName(typeof(GameScenes), HighLogic.LoadedScene), Enum.GetName(typeof(GameScenes), HighLogic.LoadedScene),
attr.Name attr.Name
); );
} }
   
object fieldValue; object fieldValue;
   
if (field is FieldInfo) if (field is FieldInfo)
{ {
fieldValue = (field as FieldInfo).GetValue(this); fieldValue = (field as FieldInfo).GetValue(this);
} }
else else
{ {
fieldValue = (field as PropertyInfo).GetValue(this, null); fieldValue = (field as PropertyInfo).GetValue(this, null);
} }
   
if (fieldValue is IVOID_SaveValue) if (fieldValue is IVOID_SaveValue)
{ {
fieldValue = (fieldValue as IVOID_SaveValue).value; fieldValue = (fieldValue as IVOID_SaveValue).value;
} }
   
config.SetValue(fieldName, fieldValue); config.SetValue(fieldName, fieldValue);
   
Tools.PostDebugMessage(string.Format("{0}: Saved field {1}.", this.GetType().Name, fieldName)); Tools.PostDebugMessage(string.Format("{0}: Saved field {1}.", this.GetType().Name, fieldName));
} }
} }
} }
   
public abstract class VOID_WindowModule : VOID_Module public abstract class VOID_WindowModule : VOID_Module
{ {
[AVOID_SaveValue("WindowPos")] [AVOID_SaveValue("WindowPos")]
protected Rect WindowPos; protected Rect WindowPos;
protected float defWidth; protected float defWidth;
protected float defHeight; protected float defHeight;
   
protected bool decorateWindow; protected bool decorateWindow;
   
protected string inputLockName; protected string inputLockName;
   
public VOID_WindowModule() : base() public VOID_WindowModule() : base()
{ {
this.defWidth = 250f; this.defWidth = 250f;
this.defHeight = 50f; this.defHeight = 50f;
   
this.decorateWindow = true; this.decorateWindow = true;
   
this.inputLockName = string.Concat(this.Name, "_edlock"); this.inputLockName = string.Concat(this.Name, "_edlock");
   
this.WindowPos = new Rect(Screen.width / 2, Screen.height / 2, this.defWidth, this.defHeight); this.WindowPos = new Rect(Screen.width / 2, Screen.height / 2, this.defWidth, this.defHeight);
} }
   
public virtual void ModuleWindow(int id) public virtual void ModuleWindow(int id)
{ {
GUIStyle buttonStyle = this.core.Skin.button; GUIStyle buttonStyle = this.core.Skin.button;
RectOffset padding = buttonStyle.padding; RectOffset padding = buttonStyle.padding;
RectOffset border = buttonStyle.border; RectOffset border = buttonStyle.border;
   
Rect closeRect = new Rect( Rect closeRect = new Rect(
0f, 0f,
0f, 0f,
border.left + border.right, border.left + border.right,
border.top + border.bottom border.top + border.bottom
); );
   
closeRect.width = Mathf.Max(closeRect.width, 16f); closeRect.width = Mathf.Max(closeRect.width, 16f);
closeRect.height = Mathf.Max(closeRect.height, 16f); closeRect.height = Mathf.Max(closeRect.height, 16f);
   
closeRect.x = this.WindowPos.width - closeRect.width - 2f; closeRect.x = this.WindowPos.width - closeRect.width - 2f;
closeRect.y = 2f; closeRect.y = 2f;
   
GUI.Button(closeRect, GUIContent.none, buttonStyle); GUI.Button(closeRect, GUIContent.none, buttonStyle);
   
if (Event.current.type == EventType.repaint && Input.GetMouseButtonUp(0)) if (Event.current.type == EventType.repaint && Input.GetMouseButtonUp(0))
{ {
if (closeRect.Contains(Event.current.mousePosition)) if (closeRect.Contains(Event.current.mousePosition))
{ {
this.Active = false; this.Active = false;
  this.removeUILock();
} }
} }
   
GUI.DragWindow(); GUI.DragWindow();
} }
   
public override void DrawGUI() public override void DrawGUI()
{ {
GUI.skin = this.core.Skin; GUI.skin = this.core.Skin;
   
Rect _Pos = this.WindowPos; Rect _Pos = this.WindowPos;
   
_Pos = GUILayout.Window( _Pos = GUILayout.Window(
this.core.WindowID, this.core.WindowID,
_Pos, _Pos,
VOID_Tools.GetWindowHandler(this.ModuleWindow), VOID_Tools.GetWindowHandler(this.ModuleWindow),
this.Name, this.Name,
GUILayout.Width(this.defWidth), GUILayout.Width(this.defWidth),
GUILayout.Height(this.defHeight) GUILayout.Height(this.defHeight)
); );
   
bool cursorInWindow = _Pos.Contains(Mouse.screenPos); bool cursorInWindow = _Pos.Contains(Mouse.screenPos);
   
  if (cursorInWindow)
  {
  this.setUILock();
  }
  else
  {
  this.removeUILock();
  }
   
  if (HighLogic.LoadedSceneIsEditor)
  {
  _Pos = Tools.ClampRectToEditorPad(_Pos);
  }
  else
  {
  _Pos = Tools.ClampRectToScreen(_Pos);
  }
   
  if (_Pos != this.WindowPos)
  {
  this.WindowPos = _Pos;
  this.core.configDirty = true;
  }
  }
   
  protected void setUILock()
  {
switch (HighLogic.LoadedScene) switch (HighLogic.LoadedScene)
{ {
case GameScenes.EDITOR: case GameScenes.EDITOR:
if (cursorInWindow) InputLockManager.SetControlLock(
{ ControlTypes.EDITOR_ICON_HOVER | ControlTypes.EDITOR_ICON_PICK |
InputLockManager.SetControlLock( ControlTypes.EDITOR_PAD_PICK_COPY | ControlTypes.EDITOR_PAD_PICK_COPY,
ControlTypes.EDITOR_ICON_HOVER | ControlTypes.EDITOR_ICON_PICK | this.inputLockName
ControlTypes.EDITOR_PAD_PICK_COPY | ControlTypes.EDITOR_PAD_PICK_COPY, );
this.inputLockName EditorLogic.fetch.Lock(false, false, false, this.inputLockName);
);  
EditorLogic.fetch.Lock(false, false, false, this.inputLockName);  
}  
else  
{  
EditorLogic.fetch.Unlock(this.inputLockName);  
}  
break; break;
case GameScenes.FLIGHT: case GameScenes.FLIGHT:
if (cursorInWindow) InputLockManager.SetControlLock(ControlTypes.CAMERACONTROLS, this.inputLockName);
{  
InputLockManager.SetControlLock(ControlTypes.CAMERACONTROLS, this.inputLockName);  
}  
else if (InputLockManager.GetControlLock(this.inputLockName) != ControlTypes.None)  
{  
InputLockManager.RemoveControlLock(this.inputLockName);  
}  
break; break;
case GameScenes.SPACECENTER: case GameScenes.SPACECENTER:
if (cursorInWindow) InputLockManager.SetControlLock(
{ ControlTypes.KSC_FACILITIES | ControlTypes.CAMERACONTROLS,
InputLockManager.SetControlLock( this.inputLockName
ControlTypes.KSC_FACILITIES | ControlTypes.CAMERACONTROLS, );
this.inputLockName  
);  
}  
else if (InputLockManager.GetControlLock(this.inputLockName) != ControlTypes.None)  
{  
InputLockManager.RemoveControlLock(this.inputLockName);  
}  
break; break;
} }
  }
if (HighLogic.LoadedSceneIsEditor)  
{ protected void removeUILock()
_Pos = Tools.ClampRectToEditorPad(_Pos); {
} switch (HighLogic.LoadedScene)
else {
{ case GameScenes.EDITOR:
_Pos = Tools.ClampRectToScreen(_Pos); EditorLogic.fetch.Unlock(this.inputLockName);
} break;
  case GameScenes.FLIGHT:
if (_Pos != this.WindowPos) InputLockManager.RemoveControlLock(this.inputLockName);
{ break;
this.WindowPos = _Pos; case GameScenes.SPACECENTER:
this.core.configDirty = true; InputLockManager.RemoveControlLock(this.inputLockName);
  break;
} }
} }
} }
} }