Skip to content

Commit

Permalink
Merge pull request #6 from KSP2Community/dev
Browse files Browse the repository at this point in the history
Version 1.2.0
  • Loading branch information
jan-bures authored Jan 22, 2024
2 parents 2ede48e + 1ffbef0 commit 9f52616
Show file tree
Hide file tree
Showing 11 changed files with 979 additions and 10 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Upload release

env:
SPACEDOCK_MOD_ID: 3534

on:
release:
types: [ "published" ]
Expand All @@ -11,18 +14,29 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true

- name: Download NuGet
id: download-nuget
run: sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe

- name: Install jq
uses: dcarbone/[email protected]

- name: Build the solution
run: dotnet build "KerbalLifeHacks.sln" -c Release

- name: Extract current version
id: get-version
run: |
version=$(jq -r '.version' plugin_template/swinfo.json)
echo "Version is $version"
dotnet build "KerbalLifeHacks.sln" -c Release
echo "version=$version" >> $GITHUB_ENV
echo "release_filename=KerbalLifeHacks-$version.zip" >> $GITHUB_ENV
echo "zip=$(ls -1 dist/KerbalLifeHacks-*.zip | head -n 1)" >> $GITHUB_ENV
echo "upload_url=$(wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq '.[0].upload_url' | tr -d \")" >> $GITHUB_ENV
wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq -r '.[0].body' > ./changelog.md
- name: Upload zip to release
uses: shogo82148/[email protected]
Expand All @@ -34,3 +48,16 @@ jobs:
asset_name: ${{ env.release_filename }}
asset_content_type: application/zip

- name: Add Mask
run: echo "::add-mask::${{ secrets.SPACEDOCK_PASSWORD }}"

- name: Update mod on SpaceDock
uses: KSP2Community/[email protected]
with:
username: ${{ secrets.SPACEDOCK_USER }}
password: ${{ secrets.SPACEDOCK_PASSWORD }}
game_id: 22407
mod_id: ${{ env.SPACEDOCK_MOD_ID }}
version: ${{ env.version }}
zipball: ${{ env.zip }}
changelog: ./changelog.md
5 changes: 2 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 KSP2 Community
Copyright (c) 2023-2024 KSP2 Community

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,5 +18,4 @@ 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.

SOFTWARE.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,36 @@ changes, or _life hacks_, that don't fit into the scope of Community Fixes.
- Requires **[SpaceWarp 1.7.0+](https://github.com/SpaceWarpDev/SpaceWarp/releases/)**
## Features
Currently, this mod includes the following life hacks:
- **VAB Mission Tracker** by [munix](https://github.com/jan-bures) - Adds the Mission Tracker button to the VAB app tray.
### UI tweaks
#### Flight view
- **IVA Portraits Toggler** by [WiS3](https://github.com/WiS3) - Adds a button to the app bar to toggle the Kerbal
portraits panel.
#### Map
- **Warp To Orbital Points** by [munix](https://github.com/jan-bures) - Adds buttons to warp to apoapsis, periapsis and
SOI change.
- **Orbital Line Colors** by [munix](https://github.com/jan-bures) - Colors the various orbital lines of the current
vessel to make them easier to distinguish.
#### VAB
- **VAB Mission Tracker** by [munix](https://github.com/jan-bures) - Adds the Mission Tracker button to the VAB app
tray.
### Gameplay
- **Disable Contrails** by [munix](https://github.com/jan-bures) - Disables contrails and wingtip vortices. Disabled by
default, see the [Configuration](#Configuration) section for details.
- **Better Experiments** by [dmarcuse](https://github.com/dmarcuse) - Automatically resumes paused experiments when
re-entering the correct region, and ignores animation state.

## Installation
### Recommended
1. Use [CKAN](https://github.com/KSP-CKAN/CKAN/releases/latest) to download and install Kerbal Life Hacks.
### Manual
1. Download and extract [UITK for KSP 2](https://github.com/UitkForKsp2/UitkForKsp2/releases) into your game folder (this is a dependency of SpaceWarp).
1. Download and extract [UITK for KSP 2](https://github.com/UitkForKsp2/UitkForKsp2/releases) into your game folder
(this is a dependency of SpaceWarp).
2. Download and extract [SpaceWarp](https://github.com/SpaceWarpDev/SpaceWarp/releases) into your game folder.
3. Download and extract this mod into the game folder. If done correctly, you should have the following folder structure: `<KSP Folder>/BepInEx/plugins/KerbalLifeHacks`.
3. Download and extract this mod into the game folder. If done correctly, you should have the following folder
structure: `<KSP Folder>/BepInEx/plugins/KerbalLifeHacks`.
## Configuration
All life hacks can be toggled on or off in `Main menu` -> `Settings` -> `Mods` -> `Kerbal Life Hacks`. The changes will
take effect after the game is restarted. Life hacks are enabled by default unless otherwise noted.
take effect after the game is restarted. Life hacks are enabled by default unless otherwise noted.
## Contributing
If you'd like to contribute to this project, please take a look at
[our wiki](https://github.com/KSP2Community/KerbalLifeHacks/wiki/Adding-your-hack).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions plugin_template/localizations/warp_to_orbital_point.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Key,Type,Desc,English
KerbalLifeHacks/Map/WarpToAp,text,,Warp to Apoapsis
KerbalLifeHacks/Map/WarpToPe,text,,Warp to Periapsis
KerbalLifeHacks/Map/WarpToSOI,text,,Warp to SOI Change
4 changes: 2 additions & 2 deletions plugin_template/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Kerbal Life Hacks",
"description": "A counterpart to Community Fixes which contains quality of life improvements and tuning tweaks.",
"source": "https://github.com/KSP2Community/KerbalLifeHacks",
"version": "1.1.0",
"version": "1.2.0",
"version_check": "https://raw.githubusercontent.com/KSP2Community/KerbalLifeHacks/main/plugin_template/swinfo.json",
"ksp2_version": {
"min": "0.2.0",
Expand All @@ -20,4 +20,4 @@
}
}
]
}
}
75 changes: 75 additions & 0 deletions src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/AppBarButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using KSP.Api.CoreTypes;
using KSP.UI;
using KSP.UI.Binding;
using SpaceWarp.API.UI.Appbar;
using UnityEngine;
using UnityEngine.UI;
using UnityObject = UnityEngine.Object;

namespace KerbalLifeHacks.Hacks.IVAPortraitsToggler;

internal class AppBarButton
{
private readonly UIValue_WriteBool_Toggle _buttonState;

public AppBarButton(
string buttonTooltip,
string buttonId,
Texture2D buttonIcon,
Action<bool> function,
int siblingIndex = -1
)
{
// Find 'ButtonBar' game object
var list = GameObject.Find(
"GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Scaled Popup Canvas/Container/ButtonBar"
);

// Get 'NonStageable-Resources' button
var nonStageableResources = list != null ? list.GetChild("BTN-NonStageable-Resources") : null;

if (list == null || nonStageableResources == null)
{
return;
}

// Clone 'NonStageable-Resources' button

var barButton = UnityObject.Instantiate(nonStageableResources, list.transform);
if (siblingIndex >= 0 && siblingIndex < list.transform.childCount - 1)
{
barButton.transform.SetSiblingIndex(siblingIndex);
}

barButton.name = buttonId;

// Change the tooltip
barButton.GetComponent<BasicTextTooltipData>()._tooltipTitleKey = buttonTooltip;

// Change the icon
var sprite = Appbar.GetAppBarIconFromTexture(buttonIcon);
var icon = barButton.GetChild("Content").GetChild("GRP-icon");
var image = icon.GetChild("ICO-asset").GetComponent<Image>();
image.sprite = sprite;

// Add our function call to the toggle
var toggle = barButton.GetComponent<ToggleExtended>();
toggle.onValueChanged.AddListener(state => function(state));
toggle.onValueChanged.AddListener(SetButtonState);

// Set the initial state of the button
_buttonState = barButton.GetComponent<UIValue_WriteBool_Toggle>();
_buttonState.valueKey = $"Is{buttonId}Visible";
_buttonState.BindValue(new Property<bool>(false));
}

public void SetButtonState(bool state)
{
if (_buttonState == null)
{
return;
}

_buttonState.SetValue(state);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using KSP.Game;
using KSP.Messages;
using SpaceWarp.API.Assets;
using UnityEngine;

namespace KerbalLifeHacks.Hacks.IVAPortraitsToggler;

[Hack("IVA Portraits Toggler")]
public class IVAPortraitsToggler : BaseHack
{
private AppBarButton _buttonBar;

// ReSharper disable once InconsistentNaming, IdentifierTypo
private Canvas _ivaportraits_canvas;

public override void OnInitialized()
{
Messages.PersistentSubscribe<FlightViewEnteredMessage>(OnFlightViewEnteredMessage);
Messages.PersistentSubscribe<VesselChangedMessage>(OnVesselChangedMessage);
}

private void OnFlightViewEnteredMessage(MessageCenterMessage msg)
{
if (_ivaportraits_canvas == null)
{
var instruments = GameManager.Instance.Game.UI.FlightHud._instruments;
// ReSharper disable once StringLiteralTypo
instruments.TryGetValue("group_ivaportraits", out var ivaPortraits);
if (ivaPortraits != null)
{
_ivaportraits_canvas = ivaPortraits._parentCanvas;
}
}

if (_buttonBar != null)
{
return;
}

_buttonBar = new AppBarButton(
"IVA Portraits",
"BTN-IVA-Portraits",
AssetManager.GetAsset<Texture2D>($"KerbalLifeHacks/images/IVAPortraitsToggler-icon.png"),
ToggleIVAPortraitsCanvas,
0
);
}

private void OnVesselChangedMessage(MessageCenterMessage msg)
{
if (msg is not VesselChangedMessage { Vessel: { } vessel })
{
return;
}

var vesselGuid = vessel.GetControlOwner().GlobalId;
var allKerbalsInSimObject = GameManager.Instance.Game.KerbalManager._kerbalRosterManager
?.GetAllKerbalsInSimObject(vesselGuid);
var state = allKerbalsInSimObject?.Count > 0;

ToggleIVAPortraitsCanvas(state);
_buttonBar.SetButtonState(state);
}

public void ToggleIVAPortraitsCanvas(bool state)
{
_ivaportraits_canvas.enabled = state;
}
}
Loading

0 comments on commit 9f52616

Please sign in to comment.