Permalink
Browse files

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...
1 parent 4266944 commit e7540038696c5438d19dd5f7401bbf5bf1a496dc Yohann Ferreira committed Oct 4, 2012
Showing with 53 additions and 4 deletions.
  1. +36 −4 src/modes/battle/battle_indicators.cpp
  2. +17 −0 src/modes/battle/battle_indicators.h
@@ -345,7 +345,9 @@ IndicatorSupervisor::~IndicatorSupervisor() {
_active_queue.clear();
}
-
+static bool IndicatorCompare(IndicatorElement *one, IndicatorElement *another) {
+ return (one->GetXOrigin() > another->GetXOrigin());
+}
void IndicatorSupervisor::Update() {
// Update all active elements
@@ -364,16 +366,46 @@ void IndicatorSupervisor::Update() {
}
}
- // TODO: determine if there is enough space to insert the next element
+ bool must_sort = false;
+ while (!_wait_queue.empty()) {
+
+ // Update the element position if it is overlapping another one.
+ _wait_queue.front()->Start(); // Setup the indcator's coords
+ while (_FixPotentialIndicatorOverlapping(_wait_queue.front()))
+ {}
- if (_wait_queue.empty() == false && (_active_queue.empty() || _active_queue.back()->HasStarted())) {
_active_queue.push_back(_wait_queue.front());
- _active_queue.back()->Start();
_wait_queue.pop_front();
+ must_sort = true;
}
+
+ // Sort the indicator display in that case
+ if (must_sort)
+ std::sort(_active_queue.begin(), _active_queue.end(), IndicatorCompare);
}
+bool IndicatorSupervisor::_FixPotentialIndicatorOverlapping(IndicatorElement *element) {
+ if (!element)
+ return false; // No overlapping
+
+ IndicatorElement* overlapped_element = 0;
+ // Get potential overlapped indicators
+ for (std::deque<IndicatorElement*>::iterator it = _active_queue.begin(),
+ it_end = _active_queue.end(); it != it_end; ++it) {
+ if ((*it)->GetXOrigin() == element->GetXOrigin()) {
+ overlapped_element = *it;
+ break;
+ }
+ }
+
+ if (!overlapped_element)
+ return false; // No overlapping
+
+ // Move the next indicator a bit.
+ element->SetXOrigin(element->GetXOrigin() + 15.0f);
+ return true;
+}
void IndicatorSupervisor::Draw() {
for (uint32 i = 0; i < _active_queue.size(); i++) {
@@ -97,6 +97,18 @@ class IndicatorElement {
const hoa_system::SystemTimer& GetTimer() const
{ return _timer; }
+
+ float GetXOrigin() const
+ { return _x_absolute_position; }
+
+ float GetYOrigin() const
+ { return _y_absolute_position; }
+
+ void SetXOrigin(float x)
+ { _x_absolute_position = x; }
+
+ void SetYOrigin(float y)
+ { _y_absolute_position = y; }
//@}
protected:
@@ -374,6 +386,11 @@ class IndicatorSupervisor {
//! \brief A FIFO queue container of all elements that have begun and are going through their display sequence
std::deque<IndicatorElement*> _active_queue;
+
+ //! Check the waiting queue and fix potential overlaps depending on the element position and type.
+ //! \param element the Indicator Element which is about to be added.
+ //! \return whether there were overlappiong elements whose positions were fixed.
+ bool _FixPotentialIndicatorOverlapping(IndicatorElement *element);
}; // class IndicatorSupervisor
} // namespace private_battle

0 comments on commit e754003

Please sign in to comment.