Race customization and data saving

This commit is contained in:
AbstractConcept 2022-09-24 02:17:40 -05:00
parent 2f3f807911
commit d3b676df06
456 changed files with 6388 additions and 419 deletions

View file

@ -54,6 +54,18 @@ namespace RimWorldAnimationStudio
Initialize(true);
}
public void AddCustomRace(InputField field)
{
if (field?.text == null || field.text == "")
{ return; }
AlienRaceDefs.AddDef(new AlienRaceDef(field.text));
ApplicationManager.Instance.SaveAlienRaceDefs();
Initialize(true);
}
public virtual void Initialize(bool addedNewTag = false) { }
}
}

View file

@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using SFB;
using System.IO;
namespace RimWorldAnimationStudio
{
public class RaceSettingsDialog : DialogBox
{
public Dropdown raceSelectDropdown;
public Transform raceSettingsWindow;
public Toggle isHumanoidToggle;
public override void Initialize(bool addedNewTag = false)
{
Reset();
string alienRaceDefName = raceSelectDropdown.value < raceSelectDropdown.options.Count ? raceSelectDropdown.options[raceSelectDropdown.value].text : "Human";
if (alienRaceDefName == null || alienRaceDefName == "") alienRaceDefName = "Human";
AlienRaceDef alienRaceDef = AlienRaceDefs.GetNamed(alienRaceDefName);
if (alienRaceDef == null) return;
isHumanoidToggle.isOn = alienRaceDef.isHumanoid;
Text bodyGraphicsTitle = AddCloneObjectToParent(raceSettingsWindow, 2).GetComponent<Text>();
bodyGraphicsTitle.text = "Body graphic filepaths";
foreach (string bodyType in Tags.bodyTypes)
{
string _bodyType = alienRaceDef.isHumanoid ? bodyType : "None";
if (alienRaceDef.isHumanoid)
{
Text bodyTypeTitle = AddCloneObjectToParent(raceSettingsWindow, 2).GetComponent<Text>();
bodyTypeTitle.text = bodyType;
}
for (int i = 2; i >= 0; i--)
{
CardinalDirection facing = (CardinalDirection)i;
GameObject filepath = AddCloneObjectToParent(raceSettingsWindow, 0);
filepath.GetComponent<Text>().text = facing.ToString();
filepath.transform.Find("FilepathButton").GetComponent<Button>().onClick.AddListener(delegate
{
SetBodyTypeGraphicPath(alienRaceDef, facing, _bodyType);
});
filepath.transform.FindDeepChild("FilepathLabel").GetComponent<Text>().text = alienRaceDef.GetBodyTypeGraphicPath(facing, _bodyType);
}
AddCloneObjectToParent(raceSettingsWindow, 3);
if (alienRaceDef.isHumanoid == false)
{ break; }
}
if (alienRaceDef.isHumanoid)
{
Text headGraphics = AddCloneObjectToParent(raceSettingsWindow, 2).GetComponent<Text>();
headGraphics.text = "Head graphic filepaths";
for (int i = 2; i >= 0; i--)
{
CardinalDirection facing = (CardinalDirection)i;
GameObject filepath = AddCloneObjectToParent(raceSettingsWindow, 0);
filepath.GetComponent<Text>().text = facing.ToString();
filepath.transform.Find("FilepathButton").GetComponent<Button>().onClick.AddListener(delegate
{
SetHeadGraphicPath(alienRaceDef, facing);
});
filepath.transform.FindDeepChild("FilepathLabel").GetComponent<Text>().text = alienRaceDef.GetHeadGraphicPath(facing);
}
AddCloneObjectToParent(raceSettingsWindow, 3);
}
}
public void Reset()
{
RemoveCloneObjectsFromParent(raceSettingsWindow);
}
public void SetIsHumanoid()
{
string alienRaceDefName = raceSelectDropdown.value < raceSelectDropdown.options.Count ? raceSelectDropdown.options[raceSelectDropdown.value].text : "Human";
if (alienRaceDefName == null || alienRaceDefName == "") alienRaceDefName = "Human";
AlienRaceDef alienRaceDef = AlienRaceDefs.GetNamed(alienRaceDefName);
if (alienRaceDef == null) return;
alienRaceDef.isHumanoid = isHumanoidToggle.isOn;
Initialize();
}
public void SetHeadGraphicPath(AlienRaceDef alienRaceDef, CardinalDirection direction)
{
var paths = StandaloneFileBrowser.OpenFilePanel("Select texture File", "", "png", false);
if (paths == null || paths.Any() == false || File.Exists(paths[0]) == false)
{ Debug.LogError("Selected file was null or invalid"); return; }
alienRaceDef.SetHeadGraphicPath(paths[0], direction);
Initialize();
}
public void SetBodyTypeGraphicPath(AlienRaceDef alienRaceDef, CardinalDirection direction, string bodyType)
{
var paths = StandaloneFileBrowser.OpenFilePanel("Select texture File", "", "png", false);
if (paths == null || paths.Any() == false || File.Exists(paths[0]) == false)
{ Debug.LogError("Selected file was null or invalid"); return; }
alienRaceDef.SetBodyTypeGraphicPath(paths[0], direction, bodyType);
Initialize();
}
}
}

View file

@ -10,11 +10,6 @@ namespace RimWorldAnimationStudio
{
public class SelectActorLayerDialog : DialogBox
{
public void OnEnable()
{
Initialize();
}
public void Initialize()
{
if (Workspace.animationDef == null) return;

View file

@ -12,7 +12,7 @@ namespace RimWorldAnimationStudio
{
public override void Initialize(bool addedNewTag = false)
{
IEnumerable<string> allTags = Tags.bodyDefTypes.Concat(CustomTags.interactionDefTypes);
IEnumerable<string> allTags = Tags.bodyDefTypes.Concat(CustomTags.bodyDefTypes);
string placeHolderText = "Enter new body def type...";
Actor actor = Workspace.animationDef.actors[Workspace.actorID];

View file

@ -12,7 +12,7 @@ namespace RimWorldAnimationStudio
{
public override void Initialize(bool addedNewTag = false)
{
IEnumerable<string> allTags = Tags.bodyParts.Concat(CustomTags.interactionDefTypes);
IEnumerable<string> allTags = Tags.bodyParts.Concat(CustomTags.bodyParts);
string placeHolderText = "Enter new body part name...";
Actor actor = Workspace.animationDef.actors[Workspace.actorID];

View file

@ -12,7 +12,7 @@ namespace RimWorldAnimationStudio
{
public override void Initialize(bool addedNewTag = false)
{
IEnumerable<string> allTags = Tags.defNames.Concat(CustomTags.interactionDefTypes);
IEnumerable<string> allTags = AlienRaceDefs.allDefs.Select(x => x.defName);
string placeHolderText = "Enter new def name...";
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
@ -47,7 +47,7 @@ namespace RimWorldAnimationStudio
_optionField.Find("Placeholder").GetComponent<Text>().text = placeHolderText;
InputField fieldComp = _optionField.GetComponent<InputField>();
fieldComp.onEndEdit.AddListener(delegate { AddCustomTag(fieldComp, ref Tags.defNames, ref CustomTags.defNames); });
fieldComp.onEndEdit.AddListener(delegate { AddCustomRace(fieldComp); });
}
public void Reset()

View file

@ -1,59 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class SelectRaceDialog : DialogBox
{
public override void Initialize(bool addedNewTag = false)
{
IEnumerable<string> allTags = Tags.defNames.Concat(CustomTags.interactionDefTypes);
string placeHolderText = "Enter new def name...";
Actor actor = Workspace.animationDef.actors[Workspace.actorID];
Transform contentWindow = transform.FindDeepChild("Content");
Reset();
for (int i = 0; i < allTags.Count(); i++)
{
string tag = allTags.ElementAt(i);
Transform _optionToggle = AddCloneObjectToParent(contentWindow).transform;
_optionToggle.Find("Text").GetComponent<Text>().text = tag;
Toggle toggleComp = _optionToggle.GetComponent<Toggle>();
toggleComp.isOn = actor.defNames.Contains(tag);
toggleComp.onValueChanged.AddListener(delegate
{
if (toggleComp.isOn && actor.defNames.Contains(tag) == false)
{ actor.defNames.Add(tag); }
else if (toggleComp.isOn == false && actor.defNames.Contains(tag))
{ actor.defNames.Remove(tag); }
Workspace.Instance.RecordEvent("Actor def name");
});
if (addedNewTag && i == allTags.Count() - 1)
{ toggleComp.isOn = true; }
}
Transform _optionField = AddCloneObjectToParent(contentWindow, 1).transform;
_optionField.Find("Placeholder").GetComponent<Text>().text = placeHolderText;
InputField fieldComp = _optionField.GetComponent<InputField>();
fieldComp.onEndEdit.AddListener(delegate { AddCustomTag(fieldComp, ref Tags.defNames, ref CustomTags.defNames); });
}
public void Reset()
{
Transform contentWindow = transform.FindDeepChild("Content");
RemoveCloneObjectsFromParent(contentWindow);
}
}
}

View file

@ -12,7 +12,7 @@ namespace RimWorldAnimationStudio
{
public override void Initialize(bool addedNewTag = false)
{
IEnumerable<string> allTags = Tags.sexTypes.Concat(CustomTags.interactionDefTypes);
IEnumerable<string> allTags = Tags.sexTypes.Concat(CustomTags.sexTypes);
string placeHolderText = "Enter new sex type...";
if (Workspace.animationDef == null) return;

View file

@ -12,7 +12,7 @@ namespace RimWorldAnimationStudio
{
public override void Initialize(bool addedNewTag = false)
{
IEnumerable<string> allTags = Tags.soundDefs.Concat(CustomTags.interactionDefTypes);
IEnumerable<string> allTags = Tags.soundDefs.Concat(CustomTags.soundDefs);
string placeHolderText = "Enter new sound def...";
if (Workspace.animationDef == null) return;