File size: 1,733 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class MainMenuButtonEffect : ScriptedWidgetEventHandler
{
	reference float speed;
	reference float amount;
	protected float m_textProportion;
	protected float m_textProportion2;
	protected ButtonWidget m_root;
	protected ref AnimatorTimer m_anim;
	
	// -----------------------------------------------------------
	void MainMenuButtonEffect()
	{
		if ( GetGame() )
		{
			GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Insert(this.Update);
		}
		m_anim = new AnimatorTimer();
	}
	
	// -----------------------------------------------------------
	void ~MainMenuButtonEffect()
	{
		if ( GetGame() && GetGame().GetUpdateQueue(CALL_CATEGORY_GUI) )
		{
			GetGame().GetUpdateQueue(CALL_CATEGORY_GUI).Remove(this.Update);
		}
	}
	
	// -----------------------------------------------------------
	void OnWidgetScriptInit(ButtonWidget w)
	{
		m_root = w;
		m_root.SetHandler(this);
	}
	
	// -----------------------------------------------------------
	protected void Update(float tDelta)
	{
		m_anim.Tick(tDelta);
		float p = amount * m_anim.GetValue();
		//m_root.SetTextProportion( m_textProportion + (p * 0.5) );
		m_root.SetTextOffset( p * 4, 0 );
	
		float c = 1.0 - m_anim.GetValue();
		m_root.SetTextColor(ARGBF(1, 1, c, c));
	}
	
	// -----------------------------------------------------------
	override bool OnFocus(Widget w, int x, int y)
	{
		//if ( !m_anim.IsRunning() ) m_textProportion = m_root.GetTextProportion();
		if ( !m_anim.IsRunning() )
		{
			m_root.GetPos( m_textProportion, m_textProportion2 );
		}
		m_anim.Animate(1.0, speed);

		return false;
	}
	
	// -----------------------------------------------------------
	override bool OnFocusLost(Widget w, int x, int y)
	{
		m_anim.Animate(0.0, speed);
		return false;
	}
};