mirror of
https://github.com/drewcassidy/KSP-Conformal-Decals.git
synced 2024-09-01 18:23:54 +00:00
Merge branch 'hotfix'
This commit is contained in:
commit
a82369e595
1
.gitignore
vendored
1
.gitignore
vendored
@ -54,3 +54,4 @@ Source/ConformalDecals/bin
|
|||||||
.idea
|
.idea
|
||||||
obj
|
obj
|
||||||
*.swp
|
*.swp
|
||||||
|
@thumbs
|
||||||
|
@ -481,6 +481,9 @@ namespace ConformalDecals {
|
|||||||
foreach (var renderer in renderers) {
|
foreach (var renderer in renderers) {
|
||||||
// skip disabled renderers
|
// skip disabled renderers
|
||||||
if (renderer.gameObject.activeInHierarchy == false) continue;
|
if (renderer.gameObject.activeInHierarchy == false) continue;
|
||||||
|
|
||||||
|
// skip transparentFX layer, which causes issues with Waterfall
|
||||||
|
if (renderer.gameObject.layer == 1) continue;
|
||||||
|
|
||||||
// skip blacklisted shaders
|
// skip blacklisted shaders
|
||||||
if (DecalConfig.IsBlacklisted(renderer.material.shader)) continue;
|
if (DecalConfig.IsBlacklisted(renderer.material.shader)) continue;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
using ConformalDecals.Util;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace ConformalDecals {
|
namespace ConformalDecals {
|
||||||
@ -9,6 +8,7 @@ namespace ConformalDecals {
|
|||||||
|
|
||||||
[KSPField(isPersistant = true)] public bool useCustomFlag;
|
[KSPField(isPersistant = true)] public bool useCustomFlag;
|
||||||
|
|
||||||
|
// The URL of the flag for the current mission or agency
|
||||||
public string MissionFlagUrl {
|
public string MissionFlagUrl {
|
||||||
get {
|
get {
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
@ -19,6 +19,7 @@ namespace ConformalDecals {
|
|||||||
return string.IsNullOrEmpty(part.flagURL) ? HighLogic.CurrentGame.flagURL : part.flagURL;
|
return string.IsNullOrEmpty(part.flagURL) ? HighLogic.CurrentGame.flagURL : part.flagURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are not in game, use the default flag (for icon rendering)
|
||||||
return DefaultFlag;
|
return DefaultFlag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -26,84 +27,106 @@ namespace ConformalDecals {
|
|||||||
public override void OnLoad(ConfigNode node) {
|
public override void OnLoad(ConfigNode node) {
|
||||||
base.OnLoad(node);
|
base.OnLoad(node);
|
||||||
|
|
||||||
if (useCustomFlag) {
|
// Since OnLoad is called for all modules, we only need to update this module
|
||||||
SetFlag(flagUrl);
|
// Updating symmetry counterparts would be redundent
|
||||||
}
|
UpdateFlag();
|
||||||
else {
|
|
||||||
SetFlag(MissionFlagUrl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnStart(StartState state) {
|
public override void OnStart(StartState state) {
|
||||||
base.OnStart(state);
|
base.OnStart(state);
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsGame) {
|
|
||||||
GameEvents.onMissionFlagSelect.Add(OnEditorFlagSelected);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HighLogic.LoadedSceneIsEditor) {
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
|
// Register flag change event
|
||||||
|
GameEvents.onMissionFlagSelect.Add(OnEditorFlagSelected);
|
||||||
|
|
||||||
|
// Register reset button event
|
||||||
Events[nameof(ResetFlag)].guiActiveEditor = useCustomFlag;
|
Events[nameof(ResetFlag)].guiActiveEditor = useCustomFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useCustomFlag) {
|
// Since OnStart is called for all modules, we only need to update this module
|
||||||
SetFlag(flagUrl);
|
// Updating symmetry counterparts would be redundent
|
||||||
}
|
UpdateFlag();
|
||||||
else {
|
|
||||||
SetFlag(MissionFlagUrl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnDestroy() {
|
public override void OnDestroy() {
|
||||||
GameEvents.onMissionFlagSelect.Remove(SetFlag);
|
if (HighLogic.LoadedSceneIsEditor) {
|
||||||
|
// Unregister flag change event
|
||||||
|
GameEvents.onMissionFlagSelect.Remove(OnEditorFlagSelected);
|
||||||
|
}
|
||||||
|
|
||||||
base.OnDestroy();
|
base.OnDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
[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 SelectFlag() {
|
||||||
|
// Button for selecting a flag
|
||||||
|
// This is a bit of a hack to bring up the stock flag selection menu
|
||||||
|
// When its done, it calls OnCustomFlagSelected()
|
||||||
|
|
||||||
|
// ReSharper disable once PossibleNullReferenceException
|
||||||
var flagBrowser = (Instantiate((Object) (new FlagBrowserGUIButton(null, null, null, null)).FlagBrowserPrefab) as GameObject).GetComponent<FlagBrowser>();
|
var flagBrowser = (Instantiate((Object) (new FlagBrowserGUIButton(null, null, null, null)).FlagBrowserPrefab) as GameObject).GetComponent<FlagBrowser>();
|
||||||
flagBrowser.OnFlagSelected = OnCustomFlagSelected;
|
flagBrowser.OnFlagSelected = OnCustomFlagSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
[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 ResetFlag() {
|
||||||
SetFlag(MissionFlagUrl);
|
|
||||||
SetFlagSymmetryCounterparts(MissionFlagUrl);
|
// we are no longer using a custom flag, so instead use the mission or agency flag
|
||||||
|
|
||||||
useCustomFlag = false;
|
useCustomFlag = false;
|
||||||
|
flagUrl = "Mission";
|
||||||
|
UpdateFlag(true);
|
||||||
|
|
||||||
|
// disable the reset button, since it no longer makes sense
|
||||||
Events[nameof(ResetFlag)].guiActiveEditor = false;
|
Events[nameof(ResetFlag)].guiActiveEditor = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCustomFlagSelected(FlagBrowser.FlagEntry newFlagEntry) {
|
private void OnCustomFlagSelected(FlagBrowser.FlagEntry newFlagEntry) {
|
||||||
SetFlag(newFlagEntry.textureInfo.name);
|
// Callback for when a flag is selected in the menu spawned by SelectFlag()
|
||||||
SetFlagSymmetryCounterparts(newFlagEntry.textureInfo.name);
|
|
||||||
|
// we are now using a custom flag with the URL of the new flag entry
|
||||||
useCustomFlag = true;
|
useCustomFlag = true;
|
||||||
|
flagUrl = newFlagEntry.textureInfo.name;
|
||||||
|
UpdateFlag(true);
|
||||||
|
|
||||||
|
// make sure the reset button is now available
|
||||||
Events[nameof(ResetFlag)].guiActiveEditor = true;
|
Events[nameof(ResetFlag)].guiActiveEditor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEditorFlagSelected(string newFlagUrl) {
|
private void OnEditorFlagSelected(string newFlagUrl) {
|
||||||
if (!useCustomFlag) {
|
if (!useCustomFlag) {
|
||||||
SetFlag(newFlagUrl);
|
flagUrl = newFlagUrl;
|
||||||
SetFlagSymmetryCounterparts(newFlagUrl);
|
// Since this callback is called for all modules, we only need to update this module
|
||||||
|
// Updating symmetry counterparts would be redundent
|
||||||
|
UpdateFlag();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetFlag(string newFlagUrl) {
|
// Update the displayed flag texture for this decal or optionally any symmetry counterparts
|
||||||
this.Log($"Loading flag texture '{newFlagUrl}'.");
|
private void UpdateFlag(bool recursive = false) {
|
||||||
|
// get the decal material property for the decal texture
|
||||||
flagUrl = newFlagUrl;
|
var textureProperty = materialProperties.AddOrGetTextureProperty("_Decal", true);
|
||||||
materialProperties.AddOrGetTextureProperty("_Decal", true).TextureUrl = newFlagUrl;
|
|
||||||
|
if(useCustomFlag) {
|
||||||
|
// set the texture to the custom flag
|
||||||
|
textureProperty.TextureUrl = flagUrl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// set the texture to the mission flag
|
||||||
|
textureProperty.TextureUrl = MissionFlagUrl;
|
||||||
|
}
|
||||||
|
|
||||||
UpdateMaterials();
|
UpdateMaterials();
|
||||||
UpdateScale();
|
UpdateScale();
|
||||||
}
|
|
||||||
|
|
||||||
private void SetFlagSymmetryCounterparts(string newFlagUrl) {
|
if (recursive) {
|
||||||
foreach (var counterpart in part.symmetryCounterparts) {
|
// for each symmetry counterpart, copy this part's properties and update it in turn
|
||||||
var decal = counterpart.GetComponent<ModuleConformalFlag>();
|
foreach (var counterpart in part.symmetryCounterparts) {
|
||||||
|
var decal = counterpart.GetComponent<ModuleConformalFlag>();
|
||||||
decal.SetFlag(newFlagUrl);
|
|
||||||
decal.useCustomFlag = useCustomFlag;
|
decal.useCustomFlag = useCustomFlag;
|
||||||
|
decal.flagUrl = flagUrl;
|
||||||
|
decal.UpdateFlag();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ namespace ConformalDecals {
|
|||||||
this.vertical = newVertical;
|
this.vertical = newVertical;
|
||||||
this.lineSpacing = newLineSpacing;
|
this.lineSpacing = newLineSpacing;
|
||||||
this.charSpacing = newCharSpacing;
|
this.charSpacing = newCharSpacing;
|
||||||
UpdateTextRecursive();
|
UpdateText(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnFillColorUpdate(Color rgb, Util.ColorHSV hsv) {
|
public void OnFillColorUpdate(Color rgb, Util.ColorHSV hsv) {
|
||||||
@ -240,40 +240,37 @@ namespace ConformalDecals {
|
|||||||
base.OnDetach();
|
base.OnDetach();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTextRecursive() {
|
|
||||||
UpdateText();
|
|
||||||
|
|
||||||
foreach (var counterpart in part.symmetryCounterparts) {
|
|
||||||
var decal = counterpart.GetComponent<ModuleConformalText>();
|
|
||||||
decal.text = text;
|
|
||||||
decal.font = font;
|
|
||||||
decal.style = style;
|
|
||||||
decal.vertical = vertical;
|
|
||||||
decal.charSpacing = charSpacing;
|
|
||||||
decal.lineSpacing = lineSpacing;
|
|
||||||
|
|
||||||
decal._currentText = _currentText;
|
|
||||||
decal.UpdateText();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private IEnumerator UpdateTextLate() {
|
private IEnumerator UpdateTextLate() {
|
||||||
yield return null;
|
yield return null;
|
||||||
UpdateText();
|
UpdateText();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateText() {
|
private void UpdateText(bool recursive = false) {
|
||||||
// Render text
|
// Render text
|
||||||
var newText = new DecalText(text, font, style, vertical, lineSpacing, charSpacing);
|
var newText = new DecalText(text, font, style, vertical, lineSpacing, charSpacing);
|
||||||
var output = TextRenderer.UpdateText(_currentText, newText);
|
var output = TextRenderer.UpdateText(_currentText, newText);
|
||||||
|
|
||||||
|
// update the _currentText state variable
|
||||||
|
// this is the ONLY place this variable should be set! otherwise the current state is lost
|
||||||
_currentText = newText;
|
_currentText = newText;
|
||||||
|
|
||||||
|
// Update the texture with the new rendered output
|
||||||
UpdateTexture(output);
|
UpdateTexture(output);
|
||||||
|
|
||||||
// TODO: ASYNC RENDERING
|
// If recursive, copy parameters to other parts and perform the same operation
|
||||||
// var newText = new DecalText(text, _font, _style);
|
if (recursive) {
|
||||||
// _currentJob = TextRenderer.UpdateText(_currentText, newText, UpdateTexture);
|
foreach (var counterpart in part.symmetryCounterparts) {
|
||||||
// _currentText = newText;
|
var decal = counterpart.GetComponent<ModuleConformalText>();
|
||||||
|
decal.text = text;
|
||||||
|
decal.font = font;
|
||||||
|
decal.style = style;
|
||||||
|
decal.vertical = vertical;
|
||||||
|
decal.charSpacing = charSpacing;
|
||||||
|
decal.lineSpacing = lineSpacing;
|
||||||
|
|
||||||
|
decal.UpdateText();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateTexture(TextRenderOutput output) {
|
public void UpdateTexture(TextRenderOutput output) {
|
||||||
|
Loading…
Reference in New Issue
Block a user