public RobotThoughtHint(string text, Vector2 startPosition, Vector2 endPosition, float msTime, uint fadeTime) { ThinkingBubbles = new List <HintBubble>(); Text = text; //TODO: rework this LinesCount = text.Split('\n').Length; Color = new Color(0.81f, 0.5f, 0.33f); _currentFadeOperation = 1; Layer = 0; _startPosition = startPosition; _finalPosition = endPosition; CurrentPosition = startPosition; _fadeTime = fadeTime; if (_fadeTime <= 0) { Alpha = 1.0f; } // total time contains the fade in and fade out times (besides the normal msTime) Time = msTime + fadeTime * 2 + ThinkingSpeed; _state = HintState.Thinking; }
/// <summary> /// Raises the pointer enter event. /// </summary> /// <param name="eventData">Event data.</param> public void OnPointerEnter(PointerEventData eventData) { if (this.m_HintText == null) { return; } // Check if we are dragging if (eventData.dragging) { // Try getting slot base component from the selected object UISlotBase slotBase = this.ExtractSlot(eventData); // If we have a slot, we should show the hint if (slotBase != null) { // Show the hint if (this.m_Fading) { this.m_HintText.CrossFadeAlpha(1f, this.m_FadeDuration, true); } else { this.m_HintText.canvasRenderer.SetAlpha(1f); } // Set the hint state this.m_HintState = HintState.Shown; } } }
public void StopHintAsync() { switch (_state) { case HintState.Playing: _timer = 0; _state = HintState.FadeOut; break; } }
public FadeHint(string text, Vector2 position, Color color, float timeToLive, float fadeIn, float fadeOut) { _fadeInMs = fadeIn; _fadeOutMs = fadeOut; _timeToLiveMs = timeToLive; Position = position; Text = text; _state = HintState.Stopped; Color = color; _color.A = 0; _timer = 0; }
/// <summary> /// Hides the hint text if it's visible. /// </summary> private void HideHint() { if (this.m_HintState == HintState.Hidden) { return; } // Hide the hint if (this.m_Fading) { this.m_HintText.CrossFadeAlpha(0f, this.m_FadeDuration, true); } else { this.m_HintText.canvasRenderer.SetAlpha(0f); } this.m_HintState = HintState.Hidden; }
public void StartAsync() { switch (_state) { case HintState.Playing: _timer = 0; break; case HintState.FadeIn: break; case HintState.FadeOut: break; default: _color.A = 0; _timer = 0; _state = HintState.FadeIn; break; } }
public void Update(GameTime time) { switch (_state) { case HintState.FadeIn: _timer += ( float )time.ElapsedGameTime.TotalMilliseconds; _color.A = ( byte )(255f * _timer / _fadeInMs); if (_timer > _fadeInMs) { _timer = 0; _color.A = 255; _state = HintState.Playing; } break; case HintState.Playing: _timer += ( float )time.ElapsedGameTime.TotalMilliseconds; if (_timer > _timeToLiveMs) { _timer = 0; _state = HintState.FadeOut; } break; case HintState.FadeOut: _timer += ( float )time.ElapsedGameTime.TotalMilliseconds; _color.A = ( byte )(255f * (1f - _timer / _fadeOutMs)); if (_timer > _fadeOutMs) { _color.A = 0; _timer = 0; _state = HintState.Stopped; } break; case HintState.Stopped: break; } }
public void SetHintHidden() { hintText.text = ""; hintState = HintState.Hidden; }
public void TransitionTo(HintState hintState) { this.currentState = hintState; this.currentState.SetHintManager(this); }
/// <summary> /// Hides the hint text if it's visible. /// </summary> private void HideHint() { if (this.m_HintState == HintState.Hidden) return; // Hide the hint if (this.m_Fading) { this.m_HintText.CrossFadeAlpha(0f, this.m_FadeDuration, true); } else { this.m_HintText.canvasRenderer.SetAlpha(0f); } this.m_HintState = HintState.Hidden; }
/// <summary> /// Raises the pointer enter event. /// </summary> /// <param name="eventData">Event data.</param> public void OnPointerEnter(PointerEventData eventData) { if (this.m_HintText == null) return; // Check if we are dragging if (eventData.dragging) { // Try getting slot base component from the selected object UISlotBase slotBase = this.ExtractSlot(eventData); // If we have a slot, we should show the hint if (slotBase != null) { // Show the hint if (this.m_Fading) { this.m_HintText.CrossFadeAlpha(1f, this.m_FadeDuration, true); } else { this.m_HintText.canvasRenderer.SetAlpha(1f); } // Set the hint state this.m_HintState = HintState.Shown; } } }
public void Update(GameTime gameTime) { Time -= gameTime.ElapsedGameTime.Milliseconds; for (int i = 0; i < ThinkingBubbles.Count; ++i) { var thinkingBubble = ThinkingBubbles[i]; thinkingBubble.Time -= gameTime.ElapsedGameTime.Milliseconds; if (thinkingBubble.Time <= HintBubble.TimeToLive / 2) { thinkingBubble.Alpha = thinkingBubble.Time / (HintBubble.TimeToLive / 2.0f); } else { thinkingBubble.Alpha = 1 - (thinkingBubble.Time - (HintBubble.TimeToLive / 2.0f)) / (HintBubble.TimeToLive / 2.0f); } if (thinkingBubble.Time <= 0) { ThinkingBubbles.RemoveAt(i); --i; } } if (_state == HintState.Thinking) { _thinkTime += gameTime.ElapsedGameTime.Milliseconds; float amount = ( float )_thinkTime / ThinkingSpeed; CurrentPosition = Vector2.Lerp(_startPosition, _finalPosition, amount); // finished yet? if (amount >= 1) { _state = HintState.FadeIn; } else { if (_thinkTime - _lastBubbleTime > ThinkingBubbleInterval) { ThinkingBubbles.Add(new HintBubble { Position = CurrentPosition + new Vector2(10, 50), Scale = ThinkingBubbles.Count > 0 ? ThinkingBubbles.Last().Scale + ThinkingBubbleScaleIncrement : ThinkingBubbleInitialScale, Time = HintBubble.TimeToLive }); _lastBubbleTime = _thinkTime; } } } else if (_state != HintState.Created) { if (_fadeTime > 0) { _currentFadeTime += _currentFadeOperation * gameTime.ElapsedGameTime.Milliseconds; // fade time is done, stop the fading op if (_currentFadeTime >= _fadeTime) { _state = HintState.InPlace; _currentFadeOperation = 0; } // last fade time of the hint's life, fade out if (Time <= _fadeTime) { _state = HintState.FadeOut; _currentFadeOperation = -1; } Alpha = MathHelper.Lerp(0, 1.0f, ( float )_currentFadeTime / _fadeTime); } } }
public RobotThoughtHint(string text, Vector2 finalPosition, float msTime, uint fadeTime) : this(text, finalPosition, finalPosition, msTime, fadeTime) { _state = HintState.FadeIn; }
public void SetIndefiniteHint(string hint) { hintText.text = hint; hintState = HintState.Indefinite; }
private void Update() { m_StopShowing = m_LaserBeam.HasLaserBeenTriggered(); if (m_StopShowing) { SetPanelAlpha(0.0f); m_CurrentState = HintState.Hide; m_NextState = HintState.Hide; m_HintTimer = k_WaitTimeS - 1.0f; return; } m_HintTimer -= Time.deltaTime; m_HintTimer = m_HintTimer < 0 ? 0 : m_HintTimer; if (m_CurrentState != m_NextState) { switch (m_NextState) { case HintState.Show: m_HintTimer = k_ShowHintTimeS; break; case HintState.Hide: m_HintTimer = k_WaitTimeS; break; } m_CurrentState = m_NextState; } switch (m_CurrentState) { case HintState.Show: { float panelAlpha = k_ShowHintTimeS - m_HintTimer; panelAlpha = Mathf.Clamp(panelAlpha, 0.0f, 1.0f); SetPanelAlpha(panelAlpha); if (m_HintTimer == 0) { m_NextState = HintState.Hide; } break; } case HintState.Hide: { float panelAlpha = k_WaitTimeS - m_HintTimer; panelAlpha = 1.0f - Mathf.Clamp(panelAlpha, 0.0f, 1.0f); SetPanelAlpha(panelAlpha); if (m_HintTimer == 0) { m_NextState = HintState.Show; } break; } } }
public void SetTimedHint(string hint, float time) { hintText.text = hint; hintState = HintState.Timed; timeout = time; }
public void StopHint() { _timer = 0; _state = HintState.Stopped; }