Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 95 additions & 92 deletions CommunityEntity.UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public static void DestroyServerCreatedUI()
UiDict.Clear();
requestingTextureImages.Clear();
ScrollViews.Clear();
UnloadTextureCache();

// Cleanup any custom vitals we created
if (NoticeArea.Instance != null)
{
NoticeArea.Instance.DeleteAllCustomVitals();
UnloadTextureCache();
// Cleanup any custom vitals we created
if (NoticeArea.Instance != null)
{
NoticeArea.Instance.DeleteAllCustomVitals();
}
}

Expand Down Expand Up @@ -165,12 +165,12 @@ private void CreateComponents( GameObject go, JSON.Object obj, bool allowUpdate
bool ShouldUpdateField( string fieldName )
{
return !allowUpdate || obj.ContainsKey( fieldName );
}

// Only checks field name (if we want to keep default value)
bool HasField( string fieldName)
{
return obj.ContainsKey(fieldName);
}
// Only checks field name (if we want to keep default value)
bool HasField( string fieldName)
{
return obj.ContainsKey(fieldName);
}

T GetOrAddComponent<T>() where T : Component
Expand Down Expand Up @@ -341,29 +341,29 @@ T GetOrAddComponent<T>() where T : Component
if ( ShouldUpdateField( "imagetype" ) )
img.type = ParseEnum( obj.GetString( "imagetype", "Simple" ), UnityEngine.UI.Image.Type.Simple );

c.image = img;

// Modify the color of the button when hovered
// Have to grab colorBlock, modify then reassign
var colors = c.colors;

if (HasField("normalColor"))
colors.normalColor = ColorEx.Parse(obj.GetString("normalColor", "1.0 1.0 1.0 1.0"));
if (HasField("highlightedColor"))
colors.highlightedColor = ColorEx.Parse(obj.GetString("highlightedColor", "1.0 1.0 1.0 1.0"));
if (HasField("pressedColor"))
colors.pressedColor = ColorEx.Parse(obj.GetString("pressedColor", "1.0 1.0 1.0 1.0"));
if (HasField("selectedColor"))
colors.selectedColor = ColorEx.Parse(obj.GetString("selectedColor", "1.0 1.0 1.0 1.0"));
if (HasField("disabledColor"))
colors.disabledColor = ColorEx.Parse(obj.GetString("disabledColor", "0.5 0.5 0.5 0.5"));
if (HasField("colorMultiplier"))
colors.colorMultiplier = obj.GetFloat("colorMultiplier", 1.0f);
if (HasField("fadeDuration"))
colors.fadeDuration = obj.GetFloat("fadeDuration", 0.1f);

c.colors = colors;

c.image = img;
// Modify the color of the button when hovered
// Have to grab colorBlock, modify then reassign
var colors = c.colors;
if (HasField("normalColor"))
colors.normalColor = ColorEx.Parse(obj.GetString("normalColor", "1.0 1.0 1.0 1.0"));
if (HasField("highlightedColor"))
colors.highlightedColor = ColorEx.Parse(obj.GetString("highlightedColor", "1.0 1.0 1.0 1.0"));
if (HasField("pressedColor"))
colors.pressedColor = ColorEx.Parse(obj.GetString("pressedColor", "1.0 1.0 1.0 1.0"));
if (HasField("selectedColor"))
colors.selectedColor = ColorEx.Parse(obj.GetString("selectedColor", "1.0 1.0 1.0 1.0"));
if (HasField("disabledColor"))
colors.disabledColor = ColorEx.Parse(obj.GetString("disabledColor", "0.5 0.5 0.5 0.5"));
if (HasField("colorMultiplier"))
colors.colorMultiplier = obj.GetFloat("colorMultiplier", 1.0f);
if (HasField("fadeDuration"))
colors.fadeDuration = obj.GetFloat("fadeDuration", 0.1f);
c.colors = colors;
GraphicComponentCreated( img, obj );

break;
Expand Down Expand Up @@ -416,11 +416,11 @@ T GetOrAddComponent<T>() where T : Component
c.text = obj.GetString( "text", "Text" );
if ( ShouldUpdateField( "readOnly" ) )
c.readOnly = obj.GetBoolean( "readOnly", false );

if (ShouldUpdateField("placeholderId"))
{
AssignInputFieldPlaceholder(c, obj.GetString("placeholderId"));
}
if (ShouldUpdateField("placeholderId"))
{
AssignInputFieldPlaceholder(c, obj.GetString("placeholderId"));
}

if ( obj.TryGetBoolean( "password", out var password ) )
{
Expand Down Expand Up @@ -462,6 +462,8 @@ T GetOrAddComponent<T>() where T : Component
var rt = go.GetComponent<RectTransform>();
if ( rt )
{
if ( ShouldUpdateField( "pivot" ) )
rt.pivot = Vector2Ex.Parse( obj.GetString( "pivot", "0.5 0.5" ) );
if ( ShouldUpdateField( "anchormin" ) )
rt.anchorMin = Vector2Ex.Parse( obj.GetString( "anchormin", "0.0 0.0" ) );
if ( ShouldUpdateField( "anchormax" ) )
Expand All @@ -470,7 +472,7 @@ T GetOrAddComponent<T>() where T : Component
rt.offsetMin = Vector2Ex.Parse( obj.GetString( "offsetmin", "0.0 0.0" ) );
if ( ShouldUpdateField( "offsetmax" ) )
rt.offsetMax = Vector2Ex.Parse( obj.GetString( "offsetmax", "1.0 1.0" ) );
if ( ShouldUpdateField( "rotation" ) )
if ( ShouldUpdateField( "rotation" ) )
rt.rotation = Quaternion.Euler( 0, 0, obj.GetFloat("rotation", 0) );


Expand Down Expand Up @@ -762,7 +764,7 @@ T GetOrAddComponent<T>() where T : Component
if(ShouldUpdateField("decelerationRate"))
scrollRect.decelerationRate = obj.GetFloat("decelerationRate", 0.135f);
if(ShouldUpdateField("scrollSensitivity"))
scrollRect.scrollSensitivity = obj.GetFloat("scrollSensitivity", 1f);
scrollRect.scrollSensitivity = obj.GetFloat("scrollSensitivity", 1f);

// add scrollbars if objects are present
GameObject barGO;
Expand Down Expand Up @@ -803,50 +805,50 @@ T GetOrAddComponent<T>() where T : Component
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;

BuildScrollbar(scrollbar, scrollObj, true);
}

// Add ability to set scroll progress
if (ShouldUpdateField("horizontalNormalizedPosition"))
scrollRect.horizontalNormalizedPosition = obj.GetFloat("horizontalNormalizedPosition", 0f);

if (ShouldUpdateField("verticalNormalizedPosition"))
scrollRect.verticalNormalizedPosition = obj.GetFloat("verticalNormalizedPosition", 0f);
}
// Add ability to set scroll progress
if (ShouldUpdateField("horizontalNormalizedPosition"))
scrollRect.horizontalNormalizedPosition = obj.GetFloat("horizontalNormalizedPosition", 0f);
if (ShouldUpdateField("verticalNormalizedPosition"))
scrollRect.verticalNormalizedPosition = obj.GetFloat("verticalNormalizedPosition", 0f);
break;
}
}
}

private void AssignInputFieldPlaceholder(InputField input, string panelId)
{
// If clearing placeholder
if (string.IsNullOrEmpty(panelId))
{
input.placeholder = null;
return;
}

// Search for panel
var panel = FindPanel(panelId);

if (panel == null)
{
Debug.LogWarning($"[AddUI] Unable to find placeholder panel '{panelId}' for InputField '{input.name}'");
input.placeholder = null;
return;
}

// Get graphic component
var graphic = panel.GetComponent<Graphic>();

if (graphic == null)
{
Debug.LogWarning($"[AddUI] Unable to find Graphic component on placeholder panel '{panelId}' for InputField '{input.name}'");
input.placeholder = null;
return;
}

// Assign if it's all good
input.placeholder = graphic;
}
private void AssignInputFieldPlaceholder(InputField input, string panelId)
{
// If clearing placeholder
if (string.IsNullOrEmpty(panelId))
{
input.placeholder = null;
return;
}
// Search for panel
var panel = FindPanel(panelId);
if (panel == null)
{
Debug.LogWarning($"[AddUI] Unable to find placeholder panel '{panelId}' for InputField '{input.name}'");
input.placeholder = null;
return;
}
// Get graphic component
var graphic = panel.GetComponent<Graphic>();
if (graphic == null)
{
Debug.LogWarning($"[AddUI] Unable to find Graphic component on placeholder panel '{panelId}' for InputField '{input.name}'");
input.placeholder = null;
return;
}
// Assign if it's all good
input.placeholder = graphic;
}

private void BuildScrollbar(Scrollbar scrollbar, JSON.Object obj, bool vertical){
Expand Down Expand Up @@ -951,15 +953,15 @@ private void GraphicComponentCreated( UnityEngine.UI.Graphic c, JSON.Object obj
{
c.canvasRenderer.SetAlpha( 0f );
c.CrossFadeAlpha( 1f, obj.GetFloat( "fadeIn", 0 ), true );
}

if (obj.ContainsKey("placeholderParentId"))
{
var panel = FindPanel(obj.GetString("placeholderParentId"));
if (panel != null && panel.TryGetComponent<InputField>( out var input))
{
input.placeholder = c;
}
}
if (obj.ContainsKey("placeholderParentId"))
{
var panel = FindPanel(obj.GetString("placeholderParentId"));
if (panel != null && panel.TryGetComponent<InputField>( out var input))
{
input.placeholder = c;
}
}
}

Expand Down Expand Up @@ -1039,3 +1041,4 @@ private void DestroyPanel( string pnlName )
}

#endif