mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-23 08:41:47 -05:00
Text and animation UI elements
This commit is contained in:
parent
bb797ad81c
commit
2e828e0b61
11 changed files with 173 additions and 0 deletions
8
Assets/Addressables.meta
generated
Normal file
8
Assets/Addressables.meta
generated
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3fc8dc903d156324b8ffac5dee10ef83
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/Addressables/Roboto.ttf
Normal file
BIN
Assets/Addressables/Roboto.ttf
Normal file
Binary file not shown.
21
Assets/Addressables/Roboto.ttf.meta
generated
Normal file
21
Assets/Addressables/Roboto.ttf.meta
generated
Normal 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:
|
|
@ -36,6 +36,7 @@ namespace OpenTS2.Engine.Tests
|
|||
// Neighborhood View
|
||||
//var key = new ResourceKey(0x49000000, 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);
|
||||
mainMenuUILayout.Instantiate(Canvas);
|
||||
}
|
||||
|
|
62
Assets/Scripts/OpenTS2/UI/UIAnimationComponent.cs
Normal file
62
Assets/Scripts/OpenTS2/UI/UIAnimationComponent.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/OpenTS2/UI/UIAnimationComponent.cs.meta
generated
Normal file
11
Assets/Scripts/OpenTS2/UI/UIAnimationComponent.cs.meta
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e73ee12affcd6f147a9769ecba90540f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Assets/Scripts/OpenTS2/UI/UIAnimationElement.cs
Normal file
20
Assets/Scripts/OpenTS2/UI/UIAnimationElement.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/OpenTS2/UI/UIAnimationElement.cs.meta
generated
Normal file
11
Assets/Scripts/OpenTS2/UI/UIAnimationElement.cs.meta
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b3f95030b1c40c74ca9979eaa2eae0f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -17,9 +17,16 @@ namespace OpenTS2.UI
|
|||
case "GZWinBMP":
|
||||
element = new UIBMPElement();
|
||||
break;
|
||||
case "GZWinText":
|
||||
element = new UITextElement();
|
||||
break;
|
||||
case "GZWinBtn":
|
||||
element = new UIButtonElement();
|
||||
break;
|
||||
// Animated elements use this.
|
||||
case "0x4d9ccdb1":
|
||||
element = new UIAnimationElement();
|
||||
break;
|
||||
default:
|
||||
element = new UIElement();
|
||||
break;
|
||||
|
|
21
Assets/Scripts/OpenTS2/UI/UITextElement.cs
Normal file
21
Assets/Scripts/OpenTS2/UI/UITextElement.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/OpenTS2/UI/UITextElement.cs.meta
generated
Normal file
11
Assets/Scripts/OpenTS2/UI/UITextElement.cs.meta
generated
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 94e32f3663daac140b399831addf8c65
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in a new issue