-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from KSP2Community/dev
Version 1.2.0
- Loading branch information
Showing
11 changed files
with
979 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" ] | ||
|
@@ -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] | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/AppBarButton.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/KerbalLifeHacks/Hacks/IVAPortraitsToggler/IVAPortraitsToggler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.