2022-09-15 05:17:44 +00:00
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 SelectBodyPartsDialog : DialogBox
{
2022-09-21 21:15:25 +00:00
public override void Initialize ( bool addedNewTag = false )
2022-09-15 05:17:44 +00:00
{
2022-09-24 07:17:40 +00:00
IEnumerable < string > allTags = Tags . bodyParts . Concat ( CustomTags . bodyParts ) ;
2022-09-21 21:15:25 +00:00
string placeHolderText = "Enter new body part name..." ;
2022-09-15 05:17:44 +00:00
2022-09-21 21:15:25 +00:00
Actor actor = Workspace . animationDef . actors [ Workspace . actorID ] ;
Transform contentWindow = transform . FindDeepChild ( "Content" ) ;
Reset ( ) ;
2022-09-15 05:17:44 +00:00
2022-09-21 21:15:25 +00:00
Transform _appendageToggle = AddCloneObjectToParent ( contentWindow ) . transform ;
_appendageToggle . Find ( "Text" ) . GetComponent < Text > ( ) . text = "Any appendage" ;
2022-09-15 05:17:44 +00:00
2022-09-21 21:15:25 +00:00
Toggle appendageToggleComp = _appendageToggle . GetComponent < Toggle > ( ) ;
appendageToggleComp . isOn = actor . isFucking ;
appendageToggleComp . onValueChanged . AddListener ( delegate { actor . isFucking = appendageToggleComp . isOn ; Workspace . Instance . RecordEvent ( "Actor required body part" ) ; } ) ;
2022-09-15 05:17:44 +00:00
2022-09-21 21:15:25 +00:00
Transform _orificeToggle = AddCloneObjectToParent ( contentWindow ) . transform ;
_orificeToggle . Find ( "Text" ) . GetComponent < Text > ( ) . text = "Any orifice" ;
2022-09-15 05:17:44 +00:00
2022-09-21 21:15:25 +00:00
Toggle orificeToggleComp = _orificeToggle . GetComponent < Toggle > ( ) ;
orificeToggleComp . isOn = actor . isFucked ;
orificeToggleComp . onValueChanged . AddListener ( delegate { actor . isFucked = orificeToggleComp . isOn ; Workspace . Instance . RecordEvent ( "Actor required body part" ) ; } ) ;
2022-09-15 05:17:44 +00:00
2022-09-21 21:15:25 +00:00
for ( int i = 0 ; i < allTags . Count ( ) ; i + + )
2022-09-15 05:17:44 +00:00
{
2022-09-21 21:15:25 +00:00
string tag = allTags . ElementAt ( i ) ;
2022-09-15 05:17:44 +00:00
Transform _optionToggle = AddCloneObjectToParent ( contentWindow ) . transform ;
2022-09-21 21:15:25 +00:00
_optionToggle . Find ( "Text" ) . GetComponent < Text > ( ) . text = tag ;
2022-09-15 05:17:44 +00:00
Toggle toggleComp = _optionToggle . GetComponent < Toggle > ( ) ;
2022-09-21 21:15:25 +00:00
toggleComp . isOn = actor . requiredGenitals . Contains ( tag ) ;
toggleComp . onValueChanged . AddListener ( delegate
{
if ( toggleComp . isOn & & actor . requiredGenitals . Contains ( tag ) = = false )
{ actor . requiredGenitals . Add ( tag ) ; }
2022-09-15 05:17:44 +00:00
2022-09-21 21:15:25 +00:00
else if ( toggleComp . isOn = = false & & actor . requiredGenitals . Contains ( tag ) )
{ actor . requiredGenitals . Remove ( tag ) ; }
2022-09-19 05:35:34 +00:00
2022-09-21 05:40:58 +00:00
Workspace . Instance . RecordEvent ( "Actor required body part" ) ;
2022-09-15 05:17:44 +00:00
} ) ;
2022-09-19 05:35:34 +00:00
2022-10-12 05:22:29 +00:00
if ( CustomTags . bodyParts . Contains ( tag ) )
{
Button deleteButton = _optionToggle . Find ( "DeleteButton" ) . GetComponent < Button > ( ) ;
deleteButton . gameObject . SetActive ( true ) ;
deleteButton . onClick . AddListener ( delegate { RemoveCustomTag ( ref CustomTags . bodyParts , tag ) ; } ) ;
}
2022-09-21 21:15:25 +00:00
if ( addedNewTag & & i = = allTags . Count ( ) - 1 )
2022-09-19 05:35:34 +00:00
{ toggleComp . isOn = true ; }
2022-09-15 05:17:44 +00:00
}
Transform _optionField = AddCloneObjectToParent ( contentWindow , 1 ) . transform ;
2022-09-21 21:15:25 +00:00
_optionField . Find ( "Placeholder" ) . GetComponent < Text > ( ) . text = placeHolderText ;
2022-09-15 05:17:44 +00:00
InputField fieldComp = _optionField . GetComponent < InputField > ( ) ;
2022-09-21 21:15:25 +00:00
fieldComp . onEndEdit . AddListener ( delegate { AddCustomTag ( fieldComp , ref Tags . bodyParts , ref CustomTags . bodyParts ) ; } ) ;
2022-09-15 05:17:44 +00:00
}
public void Reset ( )
{
Transform contentWindow = transform . FindDeepChild ( "Content" ) ;
RemoveCloneObjectsFromParent ( contentWindow ) ;
}
}
}