DayZ 1.24
Loading...
Searching...
No Matches
TimerBase Class Reference

Simple class for fading Widgets. More...

Inheritance diagram for TimerBase:
[legend]
Collaboration diagram for TimerBase:
[legend]

Protected Member Functions

void Timer (int category=CALL_CATEGORY_SYSTEM)
 
void Run (float duration, Managed obj, string fn_name, Param params=NULL, bool loop=false)
 Starts timer.
 
void OnTimer ()
 
override void Stop ()
 

Protected Attributes

Managed m_target
 
string m_function
 
ref Param m_params
 

Private Member Functions

void WidgetFadeTimer ()
 
void FadeIn (Widget w, float time, bool continue_=false)
 Make "fade in" effect on Widget (transparency goes from 0.0 to 1.0)
 
void FadeOut (Widget w, float time, bool continue_=false)
 Make "fade out" effect on Widget (transparency goes from 1.0 to 0.0)
 
void OnTimer ()
 
void OnUpdate ()
 

Private Attributes

Widget m_widget
 
bool m_fadeIn
 
float m_alpha
 

Detailed Description

Simple class for fading Widgets.

Timer class. Use when you want call function after some time, or repeatedly in time intervals. Call is not executed after the Timer object is deleted.
usage:

class MyObject
{
void MyObject()
{
myTimer1 = new Timer();
myTimer1.Run(10, this, "Refresh"); // calls "Refresh" on "this" after 10 seconds
myTimer2 = new Timer();
myTimer2.Run(10, this, "Refresh", NULL, true); // calls "Refresh" on "this" every 10 seconds, until Pause or Stop is called
myTimer3 = new Timer();
myTimer3.Run(15, this, "Show", new Param1<bool>(false)); // calls "Show" on "this" with one bool argument after 15 seconds
}
void Refresh();
void Show(bool visible);
}
void Show()
Definition DayZGame.c:155
ref Timer myTimer1
void Refresh()

Definition at line 405 of file tools.c.

Member Function Documentation

◆ FadeIn()

void TimerBase::FadeIn ( Widget w,
float time,
bool continue_ = false )
inlineprivate

Make "fade in" effect on Widget (transparency goes from 0.0 to 1.0)

Parameters
wwidget which will be faded
timeduration of effect
continue- if True continue from current alpha value, otherwise always begin from 0.0 alpha

Definition at line 423 of file tools.c.

424 {
425 m_alpha = w.GetAlpha();
426
427 if (continue_ && m_alpha > 0.95)
428 {
429 w.SetAlpha(1.0);
430 w.Show(true);
431 return;
432 }
433
434 m_widget = w;
435 m_fadeIn = true;
436
437 OnStart(time, false);
438
439 if (m_widget)
440 {
441 m_alpha = m_widget.GetAlpha();
442 m_widget.SetAlpha(0);
443 m_widget.Show(true);
444 }
445
446 if (continue_)
447 m_time = m_alpha * time;
448 }
float m_alpha
Definition tools.c:409
bool m_fadeIn
Definition tools.c:408
Widget m_widget
Definition tools.c:407
float m_time
Definition tools.c:212
void OnStart(float duration, bool loop)
Definition tools.c:324

References m_time, and OnStart().

◆ FadeOut()

void TimerBase::FadeOut ( Widget w,
float time,
bool continue_ = false )
inlineprivate

Make "fade out" effect on Widget (transparency goes from 1.0 to 0.0)

Parameters
wwidget which will be faded
timeduration of effect
continue- if True continue from current alpha value, otherwise always begin from 1.0 alpha

Definition at line 456 of file tools.c.

457 {
458 m_alpha = w.GetAlpha();
459
460 if (continue_ && m_alpha < 0.05)
461 {
462 w.SetAlpha(0);
463 w.Show(false);
464 return;
465 }
466
467 m_widget = w;
468 m_fadeIn = false;
469
470 OnStart(time, false);
471
472 if (m_widget && !continue_)
473 {
474 m_alpha = 1.0;
475 m_widget.SetAlpha(m_alpha);
476 m_widget.Show(true);
477 }
478
479 if (continue_)
480 m_time = (1.0 - m_alpha) * time;
481 }

References m_alpha, m_time, and OnStart().

◆ OnTimer() [1/2]

void TimerBase::OnTimer ( )
inlineprivate

Definition at line 483 of file tools.c.

484 {
485 if (m_widget)
486 {
487 if (m_fadeIn)
488 m_widget.SetAlpha(1);
489 else
490 {
491 m_widget.SetAlpha(0);
492 m_widget.Show(false);
493 }
494 }
495 }

Referenced by Tick().

◆ OnTimer() [2/2]

void TimerBase::OnTimer ( )
inlineprotected

Definition at line 574 of file tools.c.

575 {
576 if (m_params)
577 {
578 GetGame().GameScript.CallFunctionParams(m_target, m_function, NULL, m_params);
579 m_params = NULL;
580 }
581 else
582 GetGame().GameScript.CallFunction(m_target, m_function, NULL, 0);
583 }
Managed m_target
Definition tools.c:548
ref Param m_params
Definition tools.c:550
string m_function
Definition tools.c:549
proto native CGame GetGame()

References GetGame().

◆ OnUpdate()

void TimerBase::OnUpdate ( )
inlineprivate

Definition at line 497 of file tools.c.

498 {
499 float timeDiff = m_time / m_duration;
500 float progress;
501 if (m_widget)
502 {
503 if (m_fadeIn)
505 else
506 {
508 progress = Math.Clamp(progress, 0, 1);
509 }
510
511 m_widget.SetAlpha(progress);
512 }
513 }
Definition EnMath.c:7
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
float m_duration
Definition tools.c:211

References Math::Clamp(), Math::Lerp(), m_duration, and m_time.

Referenced by Tick().

◆ Run()

void TimerBase::Run ( float duration,
Managed obj,
string fn_name,
Param params = NULL,
bool loop = false )
inlineprotected

Starts timer.

Parameters
durationfunction is executed after this time (in seconds).
objtarget object on which function will be executed
fn_namename of function (on object "obj") which will be executed
paramsfunction arguments see Param for usage, default NULL (no arguments)
loopwhen true, timer is looped endlessly and function is executed after every loop.

Definition at line 565 of file tools.c.

566 {
567 m_target = obj;
569
572 }

References OnStart().

◆ Stop()

override void TimerBase::Stop ( )
inlineprotected

Definition at line 585 of file tools.c.

586 {
587 super.Stop();
588 m_params = NULL;
589 }

◆ Timer()

void TimerBase::Timer ( int category = CALL_CATEGORY_SYSTEM)
inlineprotected

Definition at line 552 of file tools.c.

553 {
555 }
void OnInit()
Definition AIBehaviour.c:49

References OnInit().

◆ WidgetFadeTimer()

void TimerBase::WidgetFadeTimer ( )
inlineprivate

Definition at line 411 of file tools.c.

412 {
414 m_fadeIn = true;
415 }
const int CALL_CATEGORY_GUI
Definition tools.c:9

References CALL_CATEGORY_GUI, and OnInit().

Member Data Documentation

◆ m_alpha

float TimerBase::m_alpha
private

Definition at line 409 of file tools.c.

Referenced by FadeOut().

◆ m_fadeIn

bool TimerBase::m_fadeIn
private

Definition at line 408 of file tools.c.

◆ m_function

string TimerBase::m_function
protected

Definition at line 549 of file tools.c.

◆ m_params

ref Param TimerBase::m_params
protected

Definition at line 550 of file tools.c.

◆ m_target

Managed TimerBase::m_target
protected

Definition at line 548 of file tools.c.

◆ m_widget

Widget TimerBase::m_widget
private

Definition at line 407 of file tools.c.


The documentation for this class was generated from the following file: