Skip to content

Commit

Permalink
Add ScrollView support to CuiHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBlue committed Apr 28, 2024
1 parent 3bebab7 commit 56134de
Showing 1 changed file with 75 additions and 2 deletions.
77 changes: 75 additions & 2 deletions src/RustCui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public class CuiElement

[JsonProperty("fadeOut")]
public float FadeOut { get; set; }

[JsonProperty("update", NullValueHandling = NullValueHandling.Ignore)]
public bool Update { get; set; }
}
Expand Down Expand Up @@ -428,10 +428,13 @@ public class CuiNeedsKeyboardComponent : ICuiComponent
public string Type => "NeedsKeyboard";
}

public class CuiRectTransformComponent : ICuiComponent
public class CuiRectTransformComponent : CuiRectTransform, ICuiComponent
{
public string Type => "RectTransform";
}

public class CuiRectTransform
{
// The normalized position in the parent RectTransform that the lower left corner is anchored to
[JsonProperty("anchormin")]
public string AnchorMin { get; set; }
Expand All @@ -449,6 +452,72 @@ public class CuiRectTransformComponent : ICuiComponent
public string OffsetMax { get; set; }
}

public class CuiScrollViewComponent : ICuiComponent
{
public string Type => "UnityEngine.UI.ScrollView";

[JsonProperty("contentTransform")]
public CuiRectTransform ContentTransform { get; set; }

[JsonProperty("horizontal")]
public bool Horizontal { get; set; }

[JsonProperty("vertical")]
public bool Vertical { get; set; }

[JsonProperty("movementType")]
[JsonConverter(typeof(StringEnumConverter))]
public ScrollRect.MovementType MovementType { get; set; }

[JsonProperty("elasticity")]
public float Elasticity { get; set; }

[JsonProperty("inertia")]
public bool Inertia { get; set; }

[JsonProperty("decelerationRate")]
public float DecelerationRate { get; set; }

[JsonProperty("scrollSensitivity")]
public float ScrollSensitivity { get; set; }

[JsonProperty("horizontalScrollbar")]
public CuiScrollbar HorizontalScrollbar { get; set; }

[JsonProperty("verticalScrollbar")]
public CuiScrollbar VerticalScrollbar { get; set; }
}

public class CuiScrollbar
{
[JsonProperty("invert")]
public bool Invert { get; set; }

[JsonProperty("autoHide")]
public bool AutoHide { get; set; }

[JsonProperty("handleSprite")]
public string HandleSprite { get; set; }

[JsonProperty("size")]
public float Size { get; set; }

[JsonProperty("handleColor")]
public string HandleColor { get; set; }

[JsonProperty("highlightColor")]
public string HighlightColor { get; set; }

[JsonProperty("pressedColor")]
public string PressedColor { get; set; }

[JsonProperty("trackSprite")]
public string TrackSprite { get; set; }

[JsonProperty("trackColor")]
public string TrackColor { get; set; }
}

public class ComponentConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
Expand Down Expand Up @@ -504,6 +573,10 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
type = typeof(CuiRectTransformComponent);
break;

case "UnityEngine.UI.ScrollView":
type = typeof(CuiScrollViewComponent);
break;

default:
return null;
}
Expand Down

0 comments on commit 56134de

Please sign in to comment.