Beispiel #1
0
    //@todo: there must be things we don't need to do directly here!
    private void Update()
    {
        if (_timer.state == Timer.TimeState.Done || _timer.state == Timer.TimeState.Countdown)
        {
            if (Input.GetKeyDown("[3]"))
            {
                restart_run();
            }
            return;
        }

        if (_current_split_row != null && _timer.state == Timer.TimeState.Running)
        {
            float run_percent = (float)_timer.elapsed_ms / _model.run.split_meta[_model.run.split_meta.Count - 1].pb;

            long split_time = _previous_split == null ? 0 : _previous_split.split_time;
            long gold       = _current_split_row.model.gold;
            long ms         = _timer.elapsed_ms - split_time;

            if (ms < gold)
            {
                _current_split_row.delta_image.fillAmount = (float)ms / gold;
            }
            else if (_timer.elapsed_ms < _current_split_row.model.pb)
            {
                _current_split_row.delta_image.color = Color.green;
            }
            else
            {
                _current_split_row.delta_image.color = Color.red;
            }

            if (_timer.elapsed_ms < _current_split_row.model.pb)
            {
                _pb_compare.color = Color.green;
                float fill = (float)ms / (_current_split_row.model.pb - split_time);
                _pb_compare.fillAmount = fill;
                _current_split_row.progress(fill);
            }
            else
            {
                _current_split_row.progress(1.0f);
                _pb_compare.color = Color.red;
            }

            long            pb_time_left = _current_split_row.model.pb - _timer.elapsed_ms;
            System.TimeSpan ts           = System.TimeSpan.FromMilliseconds(pb_time_left);

            // ts = System.TimeSpan.FromHours(2.31f);
            string ts_string = @"hh\:mm\:ss";
            if (ts.Hours == 0)
            {
                if (ts.Minutes == 0)
                {
                    ts_string = @"s\.f";
                }
                else
                {
                    ts_string = @"mm\:ss";
                }
            }
            if (pb_time_left > 0)
            {
                _current_split_row.delta.color = Color.green;
                _current_split_row.delta.text  = "-" + ts.ToString(ts_string);
            }
            else
            {
                _current_split_row.delta.color = Color.red;
                _current_split_row.delta.text  = "+" + ts.ToString(ts_string);
            }

            _run_total.value = (float)_timer.elapsed_ms / _model.run.split_meta[_model.run.split_meta.Count - 1].pb;
        }

        if (Input.GetKeyDown("[1]"))
        {
            if (_timer.state == Timer.TimeState.Stopped)
            {
                if (_timer.elapsed_ms > 0)
                {
                    // reset();
                }
                else
                {
                    // we force the view back to PB when we start a run, at the moment at least I just want the
                    // details viewable when not in a run
                    _view_mode = ViewMode.PB;
                    change_view_mode(_view_mode);
                    start_run();
                }
            }
            else if (_timer.state != Timer.TimeState.Countdown)
            {
                split();
            }
        }
        else if (Input.GetKeyDown("[2]"))
        {
            if (_timer.state == Timer.TimeState.Running)
            {
                skip_split();
            }
        }
        else if (Input.GetKeyDown("[3]"))
        {
            if (_timer.state != Timer.TimeState.Stopped)
            {
                restart_run();
                if (_animator != null)
                {
                    _animator.SetTrigger("stop");
                }
            }
        }
        else if (Input.GetKeyDown("[8]"))
        {
            if (_timer.state == Timer.TimeState.Running)
            {
                unsplit();
            }
        }

        if (Input.GetKeyDown(KeyCode.N))
        {
            if (_timer.state == Timer.TimeState.Stopped)
            {
                _view_mode = (ViewMode)(((int)(_view_mode) + 1) % (int)ViewMode.COUNT);
                change_view_mode(_view_mode);
            }
        }
        if (Input.GetKeyDown(KeyCode.L))
        {
            limerick_mode = !_limerick_mode;
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            _timer.toggle_pause();
        }
    }