mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-06-11 05:54:07 +00:00
Clean up things broken by the merge
And refactor flag module yet again
This commit is contained in:
parent
7a909c18bc
commit
39555d92d1
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" ?><Project Sdk="Microsoft.NET.Sdk">
|
<?xml version="1.0" encoding="utf-8"?><Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net48</TargetFramework>
|
<TargetFramework>net48</TargetFramework>
|
||||||
<LangVersion>8</LangVersion>
|
<LangVersion>8</LangVersion>
|
||||||
|
@ -36,22 +36,22 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Remove="dlls\**"/>
|
<Compile Remove="dlls\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Remove="dlls\**"/>
|
<EmbeddedResource Remove="dlls\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Remove="dlls\**"/>
|
<None Remove="dlls\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\.editorconfig" />
|
<None Include="..\.editorconfig" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||||
<Exec Command="/bin/cp -v '$(OutDir)ConformalDecals.dll' '$(SolutionDir)../GameData/ConformalDecals/Plugins/ConformalDecals.dll'" IgnoreExitCode="true"/>
|
<Exec Command="/bin/cp -v '$(OutDir)ConformalDecals.dll' '$(SolutionDir)../GameData/ConformalDecals/Plugins/ConformalDecals.dll'" IgnoreExitCode="true" />
|
||||||
<!--Fuck you MSBuild stop trying to run CMD.exe on macOS-->
|
<!--Fuck you MSBuild stop trying to run CMD.exe on macOS-->
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace ConformalDecals.MaterialProperties {
|
||||||
public string TextureUrl {
|
public string TextureUrl {
|
||||||
get => _textureUrl;
|
get => _textureUrl;
|
||||||
set {
|
set {
|
||||||
|
if (_textureUrl == value) return; // URL hasnt changed
|
||||||
_texture = LoadTexture(value, isNormal);
|
_texture = LoadTexture(value, isNormal);
|
||||||
_textureUrl = value;
|
_textureUrl = value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,14 +441,12 @@ namespace ConformalDecals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// find all valid renderers
|
/// Setup decal by calling update functions relevent for the current situation
|
||||||
var renderers = part.parent.FindModelComponents<MeshRenderer>();
|
protected virtual void SetupDecal() {
|
||||||
foreach (var renderer in renderers) {
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
// skip disabled renderers
|
// Update tweakables in editor mode
|
||||||
if (renderer.gameObject.activeInHierarchy == false) continue;
|
UpdateTweakables();
|
||||||
|
}
|
||||||
// skip blacklisted shaders
|
|
||||||
if (DecalConfig.IsBlacklisted(renderer.material.shader)) continue;
|
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
UpdateAll();
|
UpdateAll();
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
using ConformalDecals.MaterialProperties;
|
|
||||||
using UniLinq;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace ConformalDecals {
|
namespace ConformalDecals {
|
||||||
|
@ -10,8 +8,6 @@ namespace ConformalDecals {
|
||||||
|
|
||||||
[KSPField(isPersistant = true)] public bool useCustomFlag;
|
[KSPField(isPersistant = true)] public bool useCustomFlag;
|
||||||
|
|
||||||
private MaterialTextureProperty _flagTextureProperty;
|
|
||||||
|
|
||||||
public string MissionFlagUrl {
|
public string MissionFlagUrl {
|
||||||
get {
|
get {
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
|
@ -27,28 +23,16 @@ namespace ConformalDecals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnLoad(ConfigNode node) {
|
|
||||||
base.OnLoad(node);
|
|
||||||
|
|
||||||
// Since OnLoad is called for all modules, we only need to update this module
|
|
||||||
// Updating symmetry counterparts would be redundent
|
|
||||||
UpdateFlag();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnStart(StartState state) {
|
public override void OnStart(StartState state) {
|
||||||
base.OnStart(state);
|
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
// Register flag change event
|
// Register flag change event
|
||||||
GameEvents.onMissionFlagSelect.Add(OnEditorFlagSelected);
|
GameEvents.onMissionFlagSelect.Add(OnEditorFlagSelected);
|
||||||
|
|
||||||
// Register reset button event
|
// Register reset button event
|
||||||
Events[nameof(ResetFlag)].guiActiveEditor = useCustomFlag;
|
Events[nameof(ResetFlagButton)].guiActiveEditor = useCustomFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since OnStart is called for all modules, we only need to update this module
|
base.OnStart(state);
|
||||||
// Updating symmetry counterparts would be redundent
|
|
||||||
UpdateFlag();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDestroy() {
|
public override void OnDestroy() {
|
||||||
|
@ -61,7 +45,7 @@ namespace ConformalDecals {
|
||||||
}
|
}
|
||||||
|
|
||||||
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
|
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-select-flag")]
|
||||||
public void SelectFlag() {
|
public void SelectFlagButton() {
|
||||||
// Button for selecting a flag
|
// Button for selecting a flag
|
||||||
// This is a bit of a hack to bring up the stock flag selection menu
|
// This is a bit of a hack to bring up the stock flag selection menu
|
||||||
// When its done, it calls OnCustomFlagSelected()
|
// When its done, it calls OnCustomFlagSelected()
|
||||||
|
@ -72,76 +56,65 @@ namespace ConformalDecals {
|
||||||
}
|
}
|
||||||
|
|
||||||
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-reset-flag")]
|
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "#LOC_ConformalDecals_gui-reset-flag")]
|
||||||
public void ResetFlag() {
|
public void ResetFlagButton() {
|
||||||
|
|
||||||
// we are no longer using a custom flag, so instead use the mission or agency flag
|
// we are no longer using a custom flag, so instead use the mission or agency flag
|
||||||
useCustomFlag = false;
|
SetFlag("Mission", false, true);
|
||||||
flagUrl = "Mission";
|
|
||||||
UpdateFlag(true);
|
|
||||||
|
|
||||||
// disable the reset button, since it no longer makes sense
|
// disable the reset button, since it no longer makes sense
|
||||||
Events[nameof(ResetFlag)].guiActiveEditor = false;
|
Events[nameof(ResetFlagButton)].guiActiveEditor = false;
|
||||||
flagUrl = MissionFlagUrl;
|
|
||||||
useCustomFlag = false;
|
|
||||||
UpdateAll();
|
|
||||||
foreach (var decal in part.symmetryCounterparts.Select(o => o.GetComponent<ModuleConformalFlag>())) {
|
|
||||||
decal.Events[nameof(ResetFlag)].guiActiveEditor = false;
|
|
||||||
decal.flagUrl = flagUrl;
|
|
||||||
decal.useCustomFlag = false;
|
|
||||||
decal.UpdateAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCustomFlagSelected(FlagBrowser.FlagEntry newFlagEntry) {
|
private void OnCustomFlagSelected(FlagBrowser.FlagEntry newFlagEntry) {
|
||||||
// Callback for when a flag is selected in the menu spawned by SelectFlag()
|
// Callback for when a flag is selected in the menu spawned by SelectFlag()
|
||||||
|
|
||||||
// we are now using a custom flag with the URL of the new flag entry
|
// we are now using a custom flag with the URL of the new flag entry
|
||||||
useCustomFlag = true;
|
SetFlag(newFlagEntry.textureInfo.name, true, true);
|
||||||
flagUrl = newFlagEntry.textureInfo.name;
|
|
||||||
UpdateFlag(true);
|
|
||||||
|
|
||||||
// make sure the reset button is now available
|
// make sure the reset button is now available
|
||||||
Events[nameof(ResetFlag)].guiActiveEditor = true;
|
Events[nameof(ResetFlagButton)].guiActiveEditor = true;
|
||||||
flagUrl = newFlagEntry.textureInfo.name;
|
}
|
||||||
useCustomFlag = true;
|
|
||||||
UpdateAll();
|
|
||||||
|
|
||||||
private void OnEditorFlagSelected(string newFlagUrl) {
|
private void OnEditorFlagSelected(string newFlagUrl) {
|
||||||
if (!useCustomFlag) {
|
// Callback for when a new mission flag is selected in the editor
|
||||||
flagUrl = newFlagUrl;
|
|
||||||
// Since this callback is called for all modules, we only need to update this module
|
// Since this callback is called for all modules, we only need to update this module
|
||||||
// Updating symmetry counterparts would be redundent
|
// Updating symmetry counterparts would be redundent
|
||||||
UpdateFlag();
|
|
||||||
|
// if we are using the mission flag, update it. otherwise ignore the call
|
||||||
|
if (!useCustomFlag) {
|
||||||
|
SetFlag(newFlagUrl, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the displayed flag texture for this decal or optionally any symmetry counterparts
|
private void SetFlag(string newFlagUrl, bool isCustom, bool recursive) {
|
||||||
private void UpdateFlag(bool recursive = false) {
|
// Function to set the flag URL, the custom flag
|
||||||
|
|
||||||
|
// Set values
|
||||||
|
flagUrl = newFlagUrl;
|
||||||
|
useCustomFlag = isCustom;
|
||||||
|
|
||||||
|
// Update material and projection
|
||||||
|
UpdateAll();
|
||||||
|
|
||||||
|
// Update symmetry counterparts if called to
|
||||||
|
if (recursive) {
|
||||||
|
foreach (var counterpart in part.symmetryCounterparts) {
|
||||||
|
var decal = counterpart.GetComponent<ModuleConformalFlag>();
|
||||||
|
decal.SetFlag(newFlagUrl, isCustom, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void UpdateMaterials() {
|
||||||
// get the decal material property for the decal texture
|
// get the decal material property for the decal texture
|
||||||
var textureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
var textureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
||||||
|
|
||||||
if(useCustomFlag) {
|
if (useCustomFlag) { // set the texture to the custom flag
|
||||||
// set the texture to the custom flag
|
|
||||||
textureProperty.TextureUrl = flagUrl;
|
textureProperty.TextureUrl = flagUrl;
|
||||||
}
|
} else { // set the texture to the mission flag
|
||||||
else {
|
|
||||||
// set the texture to the mission flag
|
|
||||||
textureProperty.TextureUrl = MissionFlagUrl;
|
textureProperty.TextureUrl = MissionFlagUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateMaterials();
|
base.UpdateMaterials();
|
||||||
UpdateScale();
|
|
||||||
|
|
||||||
if (recursive) {
|
|
||||||
// for each symmetry counterpart, copy this part's properties and update it in turn
|
|
||||||
foreach (var counterpart in part.symmetryCounterparts) {
|
|
||||||
var decal = counterpart.GetComponent<ModuleConformalFlag>();
|
|
||||||
|
|
||||||
decal.useCustomFlag = useCustomFlag;
|
|
||||||
decal.flagUrl = flagUrl;
|
|
||||||
decal.UpdateFlag();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -29,8 +29,7 @@ namespace ConformalDecals {
|
||||||
public void SetText() {
|
public void SetText() {
|
||||||
if (_textEntryController == null) {
|
if (_textEntryController == null) {
|
||||||
_textEntryController = TextEntryController.Create(text, font, style, vertical, lineSpacing, charSpacing, lineSpacingRange, charSpacingRange, OnTextUpdate);
|
_textEntryController = TextEntryController.Create(text, font, style, vertical, lineSpacing, charSpacing, lineSpacingRange, charSpacingRange, OnTextUpdate);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
_textEntryController.Close();
|
_textEntryController.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,8 +46,7 @@ namespace ConformalDecals {
|
||||||
public void SetFillColor() {
|
public void SetFillColor() {
|
||||||
if (_fillColorPickerController == null) {
|
if (_fillColorPickerController == null) {
|
||||||
_fillColorPickerController = ColorPickerController.Create(fillColor, OnFillColorUpdate);
|
_fillColorPickerController = ColorPickerController.Create(fillColor, OnFillColorUpdate);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
_fillColorPickerController.Close();
|
_fillColorPickerController.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,8 +68,7 @@ namespace ConformalDecals {
|
||||||
public void SetOutlineColor() {
|
public void SetOutlineColor() {
|
||||||
if (_outlineColorPickerController == null) {
|
if (_outlineColorPickerController == null) {
|
||||||
_outlineColorPickerController = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
|
_outlineColorPickerController = ColorPickerController.Create(outlineColor, OnOutlineColorUpdate);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
_outlineColorPickerController.Close();
|
_outlineColorPickerController.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,8 +231,7 @@ namespace ConformalDecals {
|
||||||
string fontName = "";
|
string fontName = "";
|
||||||
if (ParseUtil.ParseStringIndirect(ref fontName, node, "fontName")) {
|
if (ParseUtil.ParseStringIndirect(ref fontName, node, "fontName")) {
|
||||||
font = DecalConfig.GetFont(fontName);
|
font = DecalConfig.GetFont(fontName);
|
||||||
}
|
} else if (font == null) font = DecalConfig.GetFont("Calibri SDF");
|
||||||
else if (font == null) font = DecalConfig.GetFont("Calibri SDF");
|
|
||||||
|
|
||||||
int styleInt = 0;
|
int styleInt = 0;
|
||||||
if (ParseUtil.ParseIntIndirect(ref styleInt, node, "style")) {
|
if (ParseUtil.ParseIntIndirect(ref styleInt, node, "style")) {
|
||||||
|
@ -247,28 +243,11 @@ namespace ConformalDecals {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SetupDecal() {
|
protected override void SetupDecal() {
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
|
||||||
// Update tweakables in editor mode
|
|
||||||
UpdateTweakables();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
if (HighLogic.LoadedSceneIsGame) {
|
||||||
// For some reason text rendering fails on the first frame of a scene, so this is my workaround
|
// For some reason text rendering fails on the first frame of a scene, so this is my workaround
|
||||||
StartCoroutine(UpdateTextLate());
|
StartCoroutine(UpdateTextLate());
|
||||||
}
|
} else {
|
||||||
else {
|
base.SetupDecal();
|
||||||
scale = defaultScale;
|
|
||||||
depth = defaultDepth;
|
|
||||||
opacity = defaultOpacity;
|
|
||||||
cutoff = defaultCutoff;
|
|
||||||
wear = defaultWear;
|
|
||||||
|
|
||||||
UpdateTextures();
|
|
||||||
UpdateMaterials();
|
|
||||||
UpdateProjection();
|
|
||||||
|
|
||||||
// QUEUE PART FOR ICON FIXING IN VAB
|
|
||||||
DecalIconFixer.QueuePart(part.name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user