Text and animation UI elements

This commit is contained in:
Nahuel Rocchetti 2023-05-28 16:09:20 -03:00
parent bb797ad81c
commit 2e828e0b61
11 changed files with 173 additions and 0 deletions

8
Assets/Addressables.meta generated Normal file
View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3fc8dc903d156324b8ffac5dee10ef83
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

21
Assets/Addressables/Roboto.ttf.meta generated Normal file
View file

@ -0,0 +1,21 @@
fileFormatVersion: 2
guid: 0b89e5cf40aeb5041b1628fc5265cadb
TrueTypeFontImporter:
externalObjects: {}
serializedVersion: 4
fontSize: 16
forceTextureCase: -2
characterSpacing: 0
characterPadding: 1
includeFontData: 1
fontNames:
- Roboto Black
fallbackFontReferences: []
customCharacters:
fontRenderingMode: 0
ascentCalculationMode: 1
useLegacyBoundsCalculation: 0
shouldRoundAdvanceValue: 1
userData:
assetBundleName:
assetBundleVariant:

View file

@ -36,6 +36,7 @@ namespace OpenTS2.Engine.Tests
// Neighborhood View // Neighborhood View
//var key = new ResourceKey(0x49000000, 0xA99D8A11, TypeIDs.UI); //var key = new ResourceKey(0x49000000, 0xA99D8A11, TypeIDs.UI);
//var key = new ResourceKey(0x49001010, 0xA99D8A11, TypeIDs.UI); //var key = new ResourceKey(0x49001010, 0xA99D8A11, TypeIDs.UI);
//var key = new ResourceKey(0x49060005, 0xA99D8A11, TypeIDs.UI);
var mainMenuUILayout = contentProvider.GetAsset<UILayout>(key); var mainMenuUILayout = contentProvider.GetAsset<UILayout>(key);
mainMenuUILayout.Instantiate(Canvas); mainMenuUILayout.Instantiate(Canvas);
} }

View file

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace OpenTS2.UI
{
public class UIAnimationComponent : UIBMPComponent
{
public float Speed = 0.04f;
public int CurrentFrame { get
{
return _currentFrame;
}
set
{
_currentFrame = value;
UpdateFrame();
}
}
private int _currentFrame = 0;
private Texture2D[] _frames;
private float _timer = 0f;
public void SetTexture(Texture2D texture, int width)
{
_frames = UIUtils.SplitTextureHorizontalSequence(texture, width);
_currentFrame = 0;
_timer = 0f;
UpdateFrame();
var rawImage = RawImageComponent;
rawImage.SetNativeSize();
}
protected void UpdateFrame()
{
if (_currentFrame >= _frames.Length)
_currentFrame = _frames.Length - 1;
if (_currentFrame < 0)
_currentFrame = 0;
var rawImage = RawImageComponent;
rawImage.texture = _frames[_currentFrame];
}
private void Update()
{
UpdateFrame();
if (Speed <= 0f)
return;
_timer += Time.deltaTime;
if (_timer >= Speed)
{
var amountPassed = Mathf.FloorToInt(_timer / Speed);
_currentFrame += amountPassed;
_timer -= amountPassed * Speed;
}
if (_currentFrame >= _frames.Length)
_currentFrame -= Mathf.FloorToInt(_currentFrame / _frames.Length) * _frames.Length;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e73ee12affcd6f147a9769ecba90540f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace OpenTS2.UI
{
public class UIAnimationElement : UIBMPElement
{
protected override Type UIComponentType => typeof(UIAnimationComponent);
public override UIComponent Instantiate(Transform parent)
{
var uiComponent = base.Instantiate(parent) as UIAnimationComponent;
uiComponent.SetTexture(uiComponent.RawImageComponent.texture as Texture2D, (int)Area.width);
return uiComponent;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b3f95030b1c40c74ca9979eaa2eae0f6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -17,9 +17,16 @@ namespace OpenTS2.UI
case "GZWinBMP": case "GZWinBMP":
element = new UIBMPElement(); element = new UIBMPElement();
break; break;
case "GZWinText":
element = new UITextElement();
break;
case "GZWinBtn": case "GZWinBtn":
element = new UIButtonElement(); element = new UIButtonElement();
break; break;
// Animated elements use this.
case "0x4d9ccdb1":
element = new UIAnimationElement();
break;
default: default:
element = new UIElement(); element = new UIElement();
break; break;

View file

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace OpenTS2.UI
{
public class UITextElement : UIElement
{
public override UIComponent Instantiate(Transform parent)
{
var uiComponent = base.Instantiate(parent);
var text = uiComponent.gameObject.AddComponent<Text>();
text.text = Caption;
return uiComponent;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 94e32f3663daac140b399831addf8c65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: