rj-action-library/Runtime/UI/Nodes/UIImage.cs

334 lines
8.7 KiB
C#
Raw Normal View History

2024-08-09 13:52:49 +00:00
using Godot;
using Rokojori;
2024-09-14 06:41:52 +00:00
using System.Collections.Generic;
2024-08-09 13:52:49 +00:00
namespace Rokojori
{
[Tool]
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/UIImage.svg")]
2024-08-09 13:52:49 +00:00
public partial class UIImage:TextureRect, UIStylePropertyContainer
{
[Export]
public bool freezeImageType = false;
UIImageType _imageType;
[Export]
public UIImageType imageType
{
get => _imageType;
set
{
if ( freezeImageType )
{
return;
}
if ( _imageType != value )
{
if ( _imageType != null )
{
_imageType.Clear( this );
}
}
_imageType = value;
this.LogInfo( Material == null ? "null" : ( Material.GetType().Name ) );
UpdateImageType();
this.LogInfo( Material == null ? "null" : ( Material.GetType().Name ) );
}
}
void UpdateImageType()
{
ResetImageType();
if ( _imageType != null )
{
_imageType.Assign( this );
}
}
void ResetImageType()
{
ExpandMode = TextureRect.ExpandModeEnum.IgnoreSize;
StretchMode = TextureRect.StretchModeEnum.Scale;
Material = null;
}
public void CopyNumberShaderPropertyFrom( CustomMaterialProperty<float> name, UINumber number, TransitionSettings transition )
{
SetNumberShaderProperty( name.GetPropertyName<FloatPropertyName>(), number, transition );
}
public void SetNumberShaderProperty( FloatPropertyName name, UINumber number, TransitionSettings transition )
{
if ( name == null || name.propertyName == null )
{
this.LogInfo( "Name is null" );
return;
}
for ( int i = 0; i < numberProperties.Length; i++ )
{
if ( numberProperties[ i ] == null || numberProperties[ i ].floatPropertyName == null )
{
return;
}
}
if ( number == null )
{
var index = Arrays.FindIndex( numberProperties, p => p.floatPropertyName.propertyName == name.propertyName );
numberProperties = Arrays.RemoveIndex( numberProperties, index );
return;
}
var shaderUINumber = Arrays.Find( numberProperties, p => p.floatPropertyName.propertyName == name.propertyName );
if ( shaderUINumber == null )
{
shaderUINumber = new ShaderUINumber();
shaderUINumber.floatPropertyName = name;
numberProperties = Arrays.Add( numberProperties, shaderUINumber );
}
shaderUINumber.number = number;
shaderUINumber.transitionSettings = transition;
}
public void CopyColorShaderPropertyFrom( CustomMaterialProperty<Color> name, UIColor color )
{
SetColorShaderProperty( name.GetPropertyName<ColorPropertyName>(), color );
}
public void SetColorShaderProperty( ColorPropertyName name, UIColor color )
{
if ( name == null || name.propertyName == null )
{
this.LogInfo( "Name is null" );
return;
}
for ( int i = 0; i < colorProperties.Length; i++ )
{
if ( colorProperties[ i ] == null || colorProperties[ i ].colorPropertyName == null )
{
return;
}
}
if ( color == null )
{
var index = Arrays.FindIndex( colorProperties, p => p != null && p.colorPropertyName.propertyName == name.propertyName );
colorProperties = Arrays.RemoveIndex( colorProperties, index );
return;
}
var shaderUIColor = Arrays.Find( colorProperties, p => p != null && p.colorPropertyName.propertyName == name.propertyName );
if ( shaderUIColor == null )
{
shaderUIColor = new ShaderUIColor();
shaderUIColor.colorPropertyName = name;
colorProperties = Arrays.Add( colorProperties, shaderUIColor );
}
shaderUIColor.color = color;
}
2024-08-11 17:38:06 +00:00
[Export]
public UIStyle parentStyle;
2024-09-14 06:41:52 +00:00
[ExportGroup("Size & Margins")]
2024-08-09 13:52:49 +00:00
[Export]
public UINumber width;
[Export]
public UINumber height;
[Export]
public UINumber margin;
[Export]
public UINumber marginLeft;
[Export]
public UINumber marginTop;
[Export]
public UINumber marginRight;
[Export]
public UINumber marginBottom;
2024-09-14 06:41:52 +00:00
[ExportGroup( "Position" )]
2024-08-09 13:52:49 +00:00
[Export]
public UIPosition position;
[Export]
2024-09-14 06:41:52 +00:00
public UILineWrap lineWrap;
[Export]
2024-08-09 13:52:49 +00:00
public UINumber left;
[Export]
public UINumber top;
[Export]
public UINumber right;
[Export]
public UINumber bottom;
2024-09-14 06:41:52 +00:00
[ExportGroup( "Rotation & Scale" )]
2024-08-09 13:52:49 +00:00
[Export]
public UINumber pivotX;
[Export]
public UINumber pivotY;
[Export]
public UINumber rotation;
[Export]
public UINumber scale;
[Export]
public UINumber scaleX;
[Export]
public UINumber scaleY;
2024-09-14 06:41:52 +00:00
[ExportGroup( "Shader Properties" )]
[Export]
public ShaderUIColor[] colorProperties = new ShaderUIColor[ 0 ];
2024-09-14 06:41:52 +00:00
public List<ActiveStyleTransition<UIColor,ColorPropertyName>> activeShaderColorTransitions = new List<ActiveStyleTransition<UIColor,ColorPropertyName>>();
public List<ActiveStyleTransition<UIColor,ColorPropertyName>> GetActiveShaderUIColorTransitions()
{
return activeShaderColorTransitions;
}
[Export]
public ShaderUINumber[] numberProperties = new ShaderUINumber[ 0 ];
2024-09-14 06:41:52 +00:00
public List<ActiveStyleTransition<UINumber,FloatPropertyName>> activeShaderNumberTransitions = new List<ActiveStyleTransition<UINumber,FloatPropertyName>>();
public List<ActiveStyleTransition<UINumber,FloatPropertyName>> GetActiveShaderUINumberTransitions()
{
return activeShaderNumberTransitions;
}
[ExportGroup("Transitions")]
[Export]
public TransitionSettingsAll transitionSettings;
public TransitionSettingsAll GetTransitionSettingsAll()
{
return transitionSettings;
}
[Export]
public UINumberTransition[] numberTransitions = new UINumberTransition[0];
2024-09-14 06:41:52 +00:00
public UINumberTransition[] GetNumberTransitions()
{
return numberTransitions;
}
public List<ActiveStyleTransition<UINumber,UIStyleNumberProperty>> activeNumberTransitions = new List<ActiveStyleTransition<UINumber,UIStyleNumberProperty>>();
public List<ActiveStyleTransition<UINumber,UIStyleNumberProperty>> GetActiveUINumberTransitions()
{
return activeNumberTransitions;
}
[Export]
public UIColorTransition[] colorTransitions = new UIColorTransition[ 0 ];
2024-09-14 06:41:52 +00:00
public UIColorTransition[] GetColorTransitions()
{
return colorTransitions;
}
public List<ActiveStyleTransition<UIColor,UIStyleColorProperty>> activeColorTransitions = new List<ActiveStyleTransition<UIColor,UIStyleColorProperty>>();
public List<ActiveStyleTransition<UIColor,UIStyleColorProperty>> GetActiveUIColorTransitions()
{
return activeColorTransitions;
}
2024-08-09 13:52:49 +00:00
2024-08-11 17:38:06 +00:00
public UIStyle GetUIStyleParent()
{
return parentStyle;
}
public UIPosition GetUIPosition()
{
return position;
}
2024-09-14 06:41:52 +00:00
public UILineWrap GetUILineWrap()
{
return lineWrap;
}
public UILayout GetUILayout()
{
return UILayout.___;
}
public ShaderUIColor[] GetShaderUIColors()
{
return colorProperties;
}
public ShaderUINumber[] GetShaderUINumbers()
{
return numberProperties;
}
2024-08-09 13:52:49 +00:00
public UINumber GetUIStyleNumberProperty( UIStyleNumberProperty property )
{
switch ( property )
{
case UIStyleNumberProperty.Width: return width;
case UIStyleNumberProperty.Height: return height;
case UIStyleNumberProperty.Margin: return margin;
case UIStyleNumberProperty.MarginLeft: return marginLeft;
case UIStyleNumberProperty.MarginRight: return marginRight;
case UIStyleNumberProperty.MarginTop: return marginTop;
case UIStyleNumberProperty.MarginBottom: return marginBottom;
case UIStyleNumberProperty.Left: return left;
case UIStyleNumberProperty.Right: return right;
case UIStyleNumberProperty.Top: return top;
case UIStyleNumberProperty.Bottom: return bottom;
case UIStyleNumberProperty.PivotX: return pivotX;
case UIStyleNumberProperty.PivotY: return pivotY;
case UIStyleNumberProperty.Rotation: return rotation;
case UIStyleNumberProperty.Scale: return scale;
case UIStyleNumberProperty.ScaleX: return scaleX;
case UIStyleNumberProperty.ScaleY: return scaleY;
}
return null;
}
2024-09-14 06:41:52 +00:00
public UIColor GetUIStyleColorProperty( UIStyleColorProperty property )
{
return null;
}
public Font GetFont()
{
return null;
}
public Vector2 GetUISize()
{
return GetSize();
}
2024-08-09 13:52:49 +00:00
}
}