Skip to content
This repository
Browse code

Made the indicators not overlap when several are triggered at the sam…

…e time.

This fixes the Minor Elixir battle indicator display.
  • Loading branch information...
commit e7540038696c5438d19dd5f7401bbf5bf1a496dc 1 parent 4266944
Yohann Ferreira authored
40 src/modes/battle/battle_indicators.cpp
@@ -345,7 +345,9 @@ IndicatorSupervisor::~IndicatorSupervisor() {
345 345 _active_queue.clear();
346 346 }
347 347
348   -
  348 +static bool IndicatorCompare(IndicatorElement *one, IndicatorElement *another) {
  349 + return (one->GetXOrigin() > another->GetXOrigin());
  350 +}
349 351
350 352 void IndicatorSupervisor::Update() {
351 353 // Update all active elements
@@ -364,16 +366,46 @@ void IndicatorSupervisor::Update() {
364 366 }
365 367 }
366 368
367   - // TODO: determine if there is enough space to insert the next element
  369 + bool must_sort = false;
  370 + while (!_wait_queue.empty()) {
  371 +
  372 + // Update the element position if it is overlapping another one.
  373 + _wait_queue.front()->Start(); // Setup the indcator's coords
  374 + while (_FixPotentialIndicatorOverlapping(_wait_queue.front()))
  375 + {}
368 376
369   - if (_wait_queue.empty() == false && (_active_queue.empty() || _active_queue.back()->HasStarted())) {
370 377 _active_queue.push_back(_wait_queue.front());
371   - _active_queue.back()->Start();
372 378 _wait_queue.pop_front();
  379 + must_sort = true;
373 380 }
  381 +
  382 + // Sort the indicator display in that case
  383 + if (must_sort)
  384 + std::sort(_active_queue.begin(), _active_queue.end(), IndicatorCompare);
374 385 }
375 386
  387 +bool IndicatorSupervisor::_FixPotentialIndicatorOverlapping(IndicatorElement *element) {
  388 + if (!element)
  389 + return false; // No overlapping
  390 +
  391 + IndicatorElement* overlapped_element = 0;
376 392
  393 + // Get potential overlapped indicators
  394 + for (std::deque<IndicatorElement*>::iterator it = _active_queue.begin(),
  395 + it_end = _active_queue.end(); it != it_end; ++it) {
  396 + if ((*it)->GetXOrigin() == element->GetXOrigin()) {
  397 + overlapped_element = *it;
  398 + break;
  399 + }
  400 + }
  401 +
  402 + if (!overlapped_element)
  403 + return false; // No overlapping
  404 +
  405 + // Move the next indicator a bit.
  406 + element->SetXOrigin(element->GetXOrigin() + 15.0f);
  407 + return true;
  408 +}
377 409
378 410 void IndicatorSupervisor::Draw() {
379 411 for (uint32 i = 0; i < _active_queue.size(); i++) {
17 src/modes/battle/battle_indicators.h
@@ -97,6 +97,18 @@ class IndicatorElement {
97 97
98 98 const hoa_system::SystemTimer& GetTimer() const
99 99 { return _timer; }
  100 +
  101 + float GetXOrigin() const
  102 + { return _x_absolute_position; }
  103 +
  104 + float GetYOrigin() const
  105 + { return _y_absolute_position; }
  106 +
  107 + void SetXOrigin(float x)
  108 + { _x_absolute_position = x; }
  109 +
  110 + void SetYOrigin(float y)
  111 + { _y_absolute_position = y; }
100 112 //@}
101 113
102 114 protected:
@@ -374,6 +386,11 @@ class IndicatorSupervisor {
374 386
375 387 //! \brief A FIFO queue container of all elements that have begun and are going through their display sequence
376 388 std::deque<IndicatorElement*> _active_queue;
  389 +
  390 + //! Check the waiting queue and fix potential overlaps depending on the element position and type.
  391 + //! \param element the Indicator Element which is about to be added.
  392 + //! \return whether there were overlappiong elements whose positions were fixed.
  393 + bool _FixPotentialIndicatorOverlapping(IndicatorElement *element);
377 394 }; // class IndicatorSupervisor
378 395
379 396 } // namespace private_battle

0 comments on commit e754003

Please sign in to comment.
Something went wrong with that request. Please try again.