Skip to content

Commit

Permalink
Import AeroplaneMode 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dbent committed Dec 28, 2014
0 parents commit 9596b09
Show file tree
Hide file tree
Showing 10 changed files with 1,120 additions and 0 deletions.
167 changes: 167 additions & 0 deletions AeroplaneMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
//using Toolbar;

namespace AeroplaneMode
{
[KSPAddon(KSPAddon.Startup.Flight, false)]

public class AeroplaneMode : MonoBehaviour
{
public static KeyBinding TOGGLE_CONTROL_MODE = new KeyBinding(KeyCode.ScrollLock);
public static KeyBinding HOLD_CONTROL_MODE = new KeyBinding(KeyCode.Home);

private bool pitch_invert;
private bool control_mode_state;

private bool toolbar_installed;
private IButton control_mode_button;

private ScreenMessage control_mode_message_aeroplane = new ScreenMessage("Aeroplane mode", 5, ScreenMessageStyle.LOWER_CENTER);
private ScreenMessage control_mode_message_rocket = new ScreenMessage("Rocket mode", 5, ScreenMessageStyle.LOWER_CENTER);

internal AeroplaneMode()
{

if (ToolbarManager.ToolbarAvailable)
{
toolbar_installed = true;

control_mode_button = ToolbarManager.Instance.add("AeroplaneMode", "control_mode_button");
control_mode_button.TexturePath = "AeroplaneMode/rocket_mode";
control_mode_button.ToolTip = "Toggle Aeroplane Mode";

control_mode_button.Visibility = new GameScenesVisibility(GameScenes.FLIGHT);

control_mode_button.OnClick += (e) =>
{
control_mode_state = !control_mode_state;

ScreenMessages.RemoveMessage(control_mode_message_aeroplane);
ScreenMessages.RemoveMessage(control_mode_message_rocket);

update_interface();

if (control_mode_state)
{
ScreenMessages.PostScreenMessage(control_mode_message_aeroplane, true);
}

else
{
ScreenMessages.PostScreenMessage(control_mode_message_rocket, true);
}
};
}

else
{
toolbar_installed = false;
}
}

public void Start()
{
pitch_invert = false;
control_mode_state = false;

load_key_config();

FlightGlobals.ActiveVessel.OnFlyByWire += toggle_control_mode;
}

public void Update()
{
if ( (TOGGLE_CONTROL_MODE.GetKeyDown()) ||
(HOLD_CONTROL_MODE.GetKeyDown()) ||
(HOLD_CONTROL_MODE.GetKeyUp()) )
{
control_mode_state = !control_mode_state;
update_interface();
}
}

private void load_key_config()
{
try
{
foreach (ConfigNode config in GameDatabase.Instance.GetConfigNodes("aeroplane_mode_config"))
{
if (config.HasNode("TOGGLE_CONTROL_MODE"))
{
TOGGLE_CONTROL_MODE.Load(config.GetNode("TOGGLE_CONTROL_MODE"));
}

if (config.HasNode("HOLD_CONTROL_MODE"))
{
HOLD_CONTROL_MODE.Load(config.GetNode("HOLD_CONTROL_MODE"));
}

if (config.HasValue("pitch_invert"))
{
pitch_invert = bool.Parse(config.GetValue("pitch_invert"));
}
}
}

catch (Exception e)
{
Debug.Log("Config file loading failed: " + e.ToString());
}
}

private void update_interface()
{
ScreenMessages.RemoveMessage(control_mode_message_aeroplane);
ScreenMessages.RemoveMessage(control_mode_message_rocket);

if (control_mode_state)
{
ScreenMessages.PostScreenMessage(control_mode_message_aeroplane, true);
if (toolbar_installed) control_mode_button.TexturePath = "AeroplaneMode/aero_mode";
}

else
{
ScreenMessages.PostScreenMessage(control_mode_message_rocket, true);
if (toolbar_installed) control_mode_button.TexturePath = "AeroplaneMode/rocket_mode";
}
}

private void toggle_control_mode(FlightCtrlState control_state)
{
float pitch, yaw, roll;

if (control_mode_state)
{
yaw = control_state.yaw;
roll = control_state.roll;
pitch = control_state.pitch;

if ((yaw != 0) || (roll != 0) || ((pitch != 0) && pitch_invert))
{
FlightGlobals.ActiveVessel.VesselSAS.ManualOverride(true);

control_state.yaw = roll;
control_state.roll = yaw;

if (pitch_invert) control_state.pitch = -pitch;
}

else
{
FlightGlobals.ActiveVessel.VesselSAS.ManualOverride(false);
}
}
}

public void OnDestroy()
{
if (toolbar_installed) control_mode_button.Destroy();
FlightGlobals.ActiveVessel.OnFlyByWire -= toggle_control_mode;
}
}
}
64 changes: 64 additions & 0 deletions AeroplaneMode.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{26BDAE1E-3F27-4A7B-81A1-C461F96A3064}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AeroplaneMode</RootNamespace>
<AssemblyName>AeroplaneMode</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\AeroplaneMode\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AeroplaneMode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ToolbarWrapper.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
5 changes: 5 additions & 0 deletions Changes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0.1
- first release

0.2
- added option to invert pitch in aero mode
7 changes: 7 additions & 0 deletions License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) <2014>, <Phillip Reiss>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 changes: 36 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AeroplaneMode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AeroplaneMode")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4b5c699f-5de6-4831-82b0-bac1d6e154da")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
25 changes: 25 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
OVERVIEW
========

This small plugin allows you to swap your roll and yaw axes in flight. This is a minor fix for joystick users like myself who found some of the other workarounds unweildy.

The default keyboard commands are:

Hit the 'Scroll Lock' key to toggle control modes, or press and hold the 'Home' key to temporarily change control mode.

These keys can be rebound, and the plugin supports blizzy's toolbar if you have it installed, adding a small icon that can be clicked to toggle modes.


SETUP
=====

1) Place the the 'AeroplaneMode' directory in your copy of KSP's GameData folder.

2) If you want to change the keybindings, open 'settings.cfg' in a text editor, and change the "primary = ... " entry for each command, to your prefered key. A list of key codes can be found here: Http://docs.unity3d.com/ScriptReference/KeyCode.html

3) If you'd like pitch control to be reveresd when switching modes change "pitch_invert = false" to true.

3) In KSP's control settings menu, bind your joystick axes the way you would like them to work when flying rockets.

4) OPtional: bind the keys you set in step 2, to buttons on your joystick.

Loading

0 comments on commit 9596b09

Please sign in to comment.