Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added text instance lists to buttons and Containers #107

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Assets/Plugins/UIToolkit/BaseElements/ITouchable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface ITouchable
#endif
bool highlighted { get; set; }
bool hidden { get; set; }
bool inFocus { get; set; }
Rect touchFrame { get; }
Vector3 position { get; set; }

Expand Down
36 changes: 36 additions & 0 deletions Assets/Plugins/UIToolkit/BaseElements/UIAbstractContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum UILayoutType { Horizontal, Vertical, BackgroundLayout, AbsoluteLayou
protected float _scrollPosition; // scroll position calculated from the top (vertical) or left (horizontal)

protected List<UISprite> _children = new List<UISprite>();
protected List<UITextInstance> _textChildren = new List<UITextInstance>();
protected bool _suspendUpdates; // when true, layoutChildren will do nothing


Expand All @@ -49,9 +50,35 @@ public virtual bool hidden
// apply state to the children
foreach( var child in _children )
child.hidden = value;
foreach( var child in _textChildren )
child.hidden = value;
}
}

/// <summary>
/// leaves the container and all its children visible
/// but removes focus (so a popup can be on top and take input)
/// </summary>
private bool _inFocus=true;
public bool inFocus
{
get
{
return(_inFocus);
}
set
{
if (value==_inFocus)
{
return;
}
_inFocus=value;
foreach (var child in _children)
{
child.inFocus=value;
}
}
}


/// <summary>
Expand Down Expand Up @@ -86,7 +113,16 @@ public virtual void addChild( params UISprite[] children )

layoutChildren();
}
public virtual void addText( params UITextInstance[] children )
{
foreach( var child in children )
{
//child.parentUIObject = this;
_textChildren.Add( child );
}

//layoutChildren();
}

/// <summary>
/// Removes a child from the container and optionally from it's manager. If it is removed from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ public abstract class UIAbstractTouchableContainer : UIAbstractContainer, ITouch
public bool pagingEnabled; // enables paging support which will snap scrolling. page size is the container width


//private bool __hidden = false;
public virtual bool _hidden
{
get { return base.hidden; }
set
{
base.hidden=value;
_velocities.Clear();
}
}

public override float width
{
get { return _touchFrame.width; }
Expand Down Expand Up @@ -400,14 +411,24 @@ public virtual void onTouchBegan( Touch touch, Vector2 touchPos )
_isDragging = true;
_velocities.Clear();

if (!inFocus)
{
return;
}

// kick off a new check
_manager.StartCoroutine( checkDelayedContentTouch() );
}


public virtual void onTouchMoved( Touch touch, Vector2 touchPos )
{

if( _activeTouchable != null )
{
// we dont pass onTouchEnded here because technically we are still over the ITouchable
_activeTouchable.highlighted = false;
_activeTouchable = null;
}
}


Expand Down Expand Up @@ -488,7 +509,10 @@ public override void addChild( params UISprite[] children )
foreach( var child in children )
{
if( child is ITouchable )
{
_manager.removeFromTouchables( child as ITouchable );
//child.manager.removeFromTouchables(child as ITouchable );
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions Assets/Plugins/UIToolkit/BaseElements/UIObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public GameObject client
private UIObject _parentUIObject;
public virtual Color color { get; set; } // hack that is overridden in UISprite just for animation support
protected UIAnchorInfo _anchorInfo;
public bool autoRefreshPositionOnScaling = true;
public bool autoRefreshPositionOnScaling = false; //true;
protected float _width, _height;

/// <summary>
Expand All @@ -27,8 +27,7 @@ public GameObject client
/// evaluated by event handlers.
/// </value>
public object userData;



/// <summary>
/// Sets up the client GameObject along with it's layer and caches the transform
/// </summary>
Expand Down
37 changes: 34 additions & 3 deletions Assets/Plugins/UIToolkit/BaseElements/UISprite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class UISprite : UIObject, IPositionable
{
public UIToolkit manager = null; // Reference to the sprite manager in which this sprite resides
public bool ___hidden = false; // Indicates whether this sprite is currently hidden (DO NOT ACCESS DIRECTLY)
private bool __inFocus = true;
public static readonly Rect _rectZero = new Rect( 0, 0, 0, 0 ); // used for disabled touch frames
private bool _suspendUpdates; // when true, updateTransform and updateVertPositions will do nothing until endUpdates is called

Expand Down Expand Up @@ -36,11 +37,11 @@ public class UISprite : UIObject, IPositionable
protected Vector3[] meshVerts; // Pointer to the array of vertices in the mesh
protected Vector2[] uvs; // Pointer to the array of UVs in the mesh
protected Dictionary<string, UISpriteAnimation> spriteAnimations;


protected List<UITextInstance> _children = new List<UITextInstance>();

public UISprite(){}



public UISprite( Rect frame, int depth, UIUVRect uvFrame ) : this( frame, depth, uvFrame, false )
{}

Expand Down Expand Up @@ -131,8 +132,24 @@ public virtual bool hidden
manager.hideSprite( this );
else
manager.showSprite( this );

// apply state to the children
foreach( var child in _children )
child.hidden = value;
}
}

public virtual bool inFocus
{
get
{
return(__inFocus);
}
set
{
__inFocus=value;
}
}


public bool clipped
Expand Down Expand Up @@ -388,9 +405,23 @@ public override Color color
// Removes the sprite from the mesh and destroys it's client GO
public virtual void destroy()
{
foreach( var child in _children )
{
child.destroy();
}
manager.removeElement( this );
}

public virtual void addText( params UITextInstance[] children )
{
foreach( var child in children )
{
//child.parentUIObject = this;
_children.Add( child );
}

//layoutChildren();
}

#region Sprite Animation methods

Expand Down
7 changes: 5 additions & 2 deletions Assets/Plugins/UIToolkit/BaseElements/UISpriteAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public IEnumerator play( UISprite sprite, int loopCount )
_isPlaying = true;

// loop while we are playing and we havent finished looping
while( _isPlaying && loopCount >= 0 )
while( _isPlaying && (loopCount > 0 || loopCount==-1))
{
// what frame are we on?
if( loopingForward )
Expand All @@ -45,7 +45,10 @@ public IEnumerator play( UISprite sprite, int loopCount )
if( currentFrame < 0 || currentFrame == totalFrames )
{
// finished a loop, increment loop counter, reverse loop direction if necessary and reset currentFrame
--loopCount;
if (loopCount>0)
{
--loopCount;
}

if( loopReverse )
loopingForward = !loopingForward;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Plugins/UIToolkit/BaseElements/UISpriteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public UISprite addSprite(string name, int xPos, int yPos, int depth, bool gameO
/// <summary>
/// Shortcut for adding a new sprite using the raw materials
/// </summary>
private UISprite addSprite(Rect frame, UIUVRect uvFrame, int depth, bool gameObjectOriginInCenter)
public UISprite addSprite(Rect frame, UIUVRect uvFrame, int depth, bool gameObjectOriginInCenter)
{
// Create and initialize the new sprite
UISprite newSprite = new UISprite(frame, depth, uvFrame, gameObjectOriginInCenter);
Expand Down
13 changes: 12 additions & 1 deletion Assets/Plugins/UIToolkit/Containers/UIBackgroundLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@

public class UIBackgroundLayout : UIAbstractContainer
{
public UISprite background;
public UIBackgroundLayout( string filename ) : this( UI.firstToolkit, filename ) {}


public UIBackgroundLayout( UIToolkit manager, string filename ) : base( UILayoutType.BackgroundLayout )
{
var background = manager.addSprite( filename, 0, 0, 2 );
background = manager.addSprite( filename, 0, 0, 2 );
addChild( background );

//set dimensions of container based on background texture dimensions
_width = background.width;
_height = background.height;
}

public UIBackgroundLayout(UIToolkit manager, string filename, Rect frame) : base(UILayoutType.BackgroundLayout)
{
background = manager.addSprite(frame,UIUVRect.zero,2,false);
background.setSpriteImage(filename);
addChild(background);

_width = background.width;
_height = background.height;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class UIScrollableHorizontalLayout : UIAbstractTouchableContainer
{
public UIScrollableHorizontalLayout( int spacing ) : base( UILayoutType.Horizontal, spacing )
{}
public UIScrollableHorizontalLayout( UIToolkit manager, int spacing ) : base(manager, UILayoutType.Horizontal, spacing )
{}


protected override void clipChild( UISprite child )
Expand Down Expand Up @@ -70,7 +72,9 @@ public override void onTouchMoved( Touch touch, Vector2 touchPos )
// once we move too far unhighlight and stop tracking the touchable
if( _activeTouchable != null && Mathf.Abs( _deltaTouch ) > TOUCH_MAX_DELTA_FOR_ACTIVATION )
{
_activeTouchable.onTouchEnded( touch, touchPos, true );
//this is broken and passes a touch through to the scrollable item even if scrolling
//_activeTouchable.onTouchEnded( touch, touchPos, true );
_activeTouchable.highlighted = false;
_activeTouchable = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class UIScrollableVerticalLayout : UIAbstractTouchableContainer
public UIScrollableVerticalLayout( int spacing ) : base( UILayoutType.Vertical, spacing )
{}

//add constructor so we can specify manager
public UIScrollableVerticalLayout( UIToolkit manager, int spacing ) : base( manager, UILayoutType.Vertical, spacing )
{}

protected override void clipChild( UISprite child )
{
Expand Down Expand Up @@ -71,7 +74,8 @@ public override void onTouchMoved( Touch touch, Vector2 touchPos )
// once we move too far unhighlight and stop tracking the touchable
if( _activeTouchable != null && Mathf.Abs( _deltaTouch ) > TOUCH_MAX_DELTA_FOR_ACTIVATION )
{
_activeTouchable.onTouchEnded( touch, touchPos, true );
//_activeTouchable.onTouchEnded( touch, touchPos, true );
_activeTouchable.highlighted = false;
_activeTouchable = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private static UIAnimation animate( UIObject sprite, bool animateTo, float durat
// Sets up and starts a new animation in a Coroutine - float version
private static UIAnimation animate( UIObject sprite, float duration, UIAnimationProperty aniProperty, float start, float target, UIEaseType ease )
{
UIAnimation ani = new UIAnimation( sprite, duration, aniProperty, start, target, ease );
UIAnimation ani = new UIAnimation( sprite, duration, aniProperty, start, target, ease, true );
UI.instance.StartCoroutine( ani.animate() );

return ani;
Expand All @@ -222,7 +222,7 @@ private static UIAnimation animate( UIObject sprite, bool animateTo, float durat
// Sets up and starts a new animation in a Coroutine - Color version
private static UIAnimation animate( UIObject sprite, float duration, UIAnimationProperty aniProperty, Color start, Color target, UIEaseType ease )
{
UIAnimation ani = new UIAnimation( sprite, duration, aniProperty, start, target, ease );
UIAnimation ani = new UIAnimation( sprite, duration, aniProperty, start, target, ease, true );
UI.instance.StartCoroutine( ani.animate() );

return ani;
Expand Down Expand Up @@ -261,7 +261,7 @@ private static UIAnimation animate( UIObject sprite, bool animateTo, float durat
// Sets up and starts a new animation in a Coroutine - Vector3 version
private static UIAnimation animate( UIObject sprite, float duration, UIAnimationProperty aniProperty, Vector3 start, Vector3 target, UIEaseType ease )
{
var ani = new UIAnimation( sprite, duration, aniProperty, start, target, ease );
var ani = new UIAnimation( sprite, duration, aniProperty, start, target, ease, true );
UI.instance.StartCoroutine( ani.animate() );

return ani;
Expand Down
23 changes: 12 additions & 11 deletions Assets/Plugins/UIToolkit/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,24 @@ private void Awake()

// setup the HD flag
// handle texture loading if required
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER || UNITY_ANDROID
var deviceAllowsHD = true;
#else
#else
var deviceAllowsHD = ( allowPod4GenHD && iPhone.generation == iPhoneGeneration.iPodTouch4Gen ) || iPhone.generation != iPhoneGeneration.iPodTouch4Gen;
#endif
#endif
if( autoTextureSelectionForHD && deviceAllowsHD )
{
// are we laoding up a 2x texture?
#if UNITY_EDITOR
if( Screen.width >= 500 || Screen.height >= 500 ) // for easier testing in the editor
#else
//plw comment out the editor test...wondered why it wasnt working
//#if UNITY_EDITOR
// if( Screen.width >= 500 || Screen.height >= 500 ) // for easier testing in the editor
//#else
if( Screen.width >= maxWidthOrHeightForSD || Screen.height >= maxWidthOrHeightForSD )
#endif
//#endif
{
#if UNITY_EDITOR
#if UNITY_EDITOR
Debug.Log( "switching to 2x GUI texture" );
#endif
#endif
isHD = true;
scaleFactor = 2;
}
Expand All @@ -100,10 +101,10 @@ private void Awake()
// grab all our child UIToolkits
_toolkitInstances = GetComponentsInChildren<UIToolkit>();
firstToolkit = _toolkitInstances[0];
#if UNITY_EDITOR
#if UNITY_EDITOR
if( _toolkitInstances.Length == 0 )
throw new System.Exception( "Could not find any UIToolkit instances in children of UI" );
#endif
#endif

// kick off the loading of texture for any UIToolkits we have
foreach( var toolkit in _toolkitInstances )
Expand Down
Loading