added ability to prohibit automatic timer disable
This commit is contained in:
parent
b904566977
commit
41ff6e2bf7
4 changed files with 82 additions and 21 deletions
|
@ -77,17 +77,16 @@ protected:
|
|||
private:
|
||||
RaceState state;
|
||||
|
||||
QList<ScStwTimer*> timerEnableQueque;
|
||||
|
||||
QTimer *nextActionTimer;
|
||||
QEventLoop *nextActionLoop;
|
||||
|
||||
// sounds
|
||||
ScStwSoundPlayer * soundPlayer;
|
||||
|
||||
|
||||
// some settings
|
||||
double soundVolume;
|
||||
bool allowAutomaticTimerDisable;
|
||||
bool allowAutomaticTimerDisableChanged;
|
||||
|
||||
/*!
|
||||
* \brief stores the start action settings
|
||||
|
@ -125,6 +124,7 @@ public slots:
|
|||
bool writeStartActionSetting(StartAction action, bool enabled, int delay);
|
||||
bool setSoundVolume(double volume);
|
||||
virtual bool addTimer(ScStwTimer *timer);
|
||||
void setAllowAutomaticTimerDisable(bool allow);
|
||||
|
||||
// getters
|
||||
RaceState getState();
|
||||
|
@ -138,10 +138,10 @@ protected slots:
|
|||
|
||||
private slots:
|
||||
void refreshTimerStates();
|
||||
void handleTimerEnable(ScStwTimer* timer);
|
||||
void handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled);
|
||||
int handleFalseStart();
|
||||
bool playSoundsAndStartTimers(StartAction thisAction);
|
||||
|
||||
void enableAllTimers();
|
||||
|
||||
/**
|
||||
* \brief Function to declare the winner and looser timers after a timer has been stopped
|
||||
|
|
|
@ -127,6 +127,11 @@ protected:
|
|||
*/
|
||||
QString letter;
|
||||
|
||||
/*!
|
||||
* \brief Defines if the timer currently wants to be disabled or not
|
||||
*/
|
||||
bool wantsToBeDisabled;
|
||||
|
||||
public slots:
|
||||
|
||||
/*!
|
||||
|
@ -294,6 +299,12 @@ public slots:
|
|||
*/
|
||||
bool setLetter(QString newLetter);
|
||||
|
||||
/*!
|
||||
* \brief Function to check if the timer currently wants to be disabled
|
||||
* \return true or false
|
||||
*/
|
||||
bool getWantsToBeDisabled();
|
||||
|
||||
protected slots:
|
||||
|
||||
/*!
|
||||
|
@ -338,6 +349,12 @@ protected slots:
|
|||
*/
|
||||
void setState(TimerState newState);
|
||||
|
||||
/*!
|
||||
* \brief Function to set whether the timer currently wants to be disabled
|
||||
* \param wantsToBeDisabled true or false
|
||||
*/
|
||||
void setWantsToBeDisabled(bool wantsToBeDisabled);
|
||||
|
||||
|
||||
signals:
|
||||
/*!
|
||||
|
@ -354,7 +371,7 @@ signals:
|
|||
* \brief Emitted when the timer wants its state to be changed by the external handler
|
||||
* \param timer the timer object
|
||||
*/
|
||||
void requestEnableChange(ScStwTimer* timer);
|
||||
void wantsToBeDisabledChanged(ScStwTimer* timer, bool wantsToBeDisabled);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/****************************************************************************
|
||||
/****************************************************************************
|
||||
** ScStw Libraries
|
||||
** Copyright (C) 2020 Itsblue development
|
||||
**
|
||||
|
@ -39,6 +39,7 @@ ScStwRace::ScStwRace(QObject *parent) : QObject(parent)
|
|||
this->writeStartActionSetting(AtYourMarks, false, 0);
|
||||
this->writeStartActionSetting(Ready, false, 0);
|
||||
this->setSoundVolume(1.0);
|
||||
this->allowAutomaticTimerDisable = false;
|
||||
}
|
||||
|
||||
// --------------------------
|
||||
|
@ -256,12 +257,18 @@ void ScStwRace::setState(RaceState newState) {
|
|||
emit this->stateChanged(newState);
|
||||
|
||||
if(this->state == IDLE) {
|
||||
// if we changed to IDLE -> enable timers
|
||||
foreach(ScStwTimer* timer, this->timerEnableQueque) {
|
||||
this->handleTimerEnable(timer);
|
||||
// if we changed to IDLE -> handle timer enable / disable
|
||||
if(this->allowAutomaticTimerDisableChanged && !this->allowAutomaticTimerDisable) {
|
||||
this->enableAllTimers();
|
||||
this->allowAutomaticTimerDisableChanged = false;
|
||||
}
|
||||
|
||||
this->timerEnableQueque.clear();
|
||||
if(this->allowAutomaticTimerDisable) {
|
||||
foreach(ScStwTimer* timer, this->timers) {
|
||||
if(timer->getWantsToBeDisabled() && timer->getState() != ScStwTimer::DISABLED)
|
||||
this->handleTimerWantsToBeDisabledChange(timer, timer->getWantsToBeDisabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -299,17 +306,38 @@ void ScStwRace::refreshTimerStates() {
|
|||
* @brief ScStwRace::handleTimerEnable function to enable timers at the right moment to prevent them from bricking the state machine
|
||||
* @param {ScStwExtensionControlledTimer*} timer timer to be enabled
|
||||
*/
|
||||
void ScStwRace::handleTimerEnable(ScStwTimer* timer) {
|
||||
void ScStwRace::handleTimerWantsToBeDisabledChange(ScStwTimer* timer, bool wantsToBeDisabled) {
|
||||
if(!this->allowAutomaticTimerDisable)
|
||||
return;
|
||||
|
||||
if(this->state == IDLE) {
|
||||
if(timer->getState() == ScStwTimer::DISABLED) {
|
||||
timer->setDisabled(false);
|
||||
}
|
||||
else {
|
||||
timer->setDisabled(true);
|
||||
}
|
||||
timer->setDisabled(wantsToBeDisabled);
|
||||
}
|
||||
else {
|
||||
this->timerEnableQueque.append(timer);
|
||||
}
|
||||
|
||||
|
||||
void ScStwRace::setAllowAutomaticTimerDisable(bool allow) {
|
||||
if(this->allowAutomaticTimerDisable == allow)
|
||||
return;
|
||||
|
||||
qDebug() << "Setting allow automatic timer disable to " << allow;
|
||||
|
||||
this->allowAutomaticTimerDisable = allow;
|
||||
|
||||
if(this->state != IDLE)
|
||||
this->allowAutomaticTimerDisableChanged = true;
|
||||
else if(!this->allowAutomaticTimerDisable)
|
||||
this->enableAllTimers();
|
||||
}
|
||||
|
||||
void ScStwRace::enableAllTimers() {
|
||||
if(this->state != IDLE)
|
||||
return;
|
||||
|
||||
qDebug() << "ENABLING ALL TIMERS";
|
||||
|
||||
foreach (ScStwTimer *timer, this->timers) {
|
||||
timer->setDisabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -370,10 +398,13 @@ bool ScStwRace::addTimer(ScStwTimer *timer) {
|
|||
this->timers.append(timer);
|
||||
|
||||
connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::refreshTimerStates);
|
||||
connect(timer, &ScStwTimer::requestEnableChange, this, &ScStwRace::handleTimerEnable);
|
||||
connect(timer, &ScStwTimer::wantsToBeDisabledChanged, this, &ScStwRace::handleTimerWantsToBeDisabledChange);
|
||||
connect(timer, &ScStwTimer::stateChanged, this, &ScStwRace::timersChanged);
|
||||
connect(timer, &ScStwTimer::reactionTimeChanged, this, &ScStwRace::timersChanged);
|
||||
|
||||
if(!this->allowAutomaticTimerDisable && timer->getState() == ScStwTimer::DISABLED)
|
||||
timer->setDisabled(false);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
|
|
@ -283,3 +283,16 @@ void ScStwTimer::setDisabled(bool disabled) {
|
|||
else
|
||||
this->setState(IDLE);
|
||||
}
|
||||
|
||||
void ScStwTimer::setWantsToBeDisabled(bool wantsToBeDisabled) {
|
||||
if(this->wantsToBeDisabled == wantsToBeDisabled)
|
||||
return;
|
||||
|
||||
this->wantsToBeDisabled = wantsToBeDisabled;
|
||||
|
||||
emit this->wantsToBeDisabledChanged(this, wantsToBeDisabled);
|
||||
}
|
||||
|
||||
bool ScStwTimer::getWantsToBeDisabled() {
|
||||
return this->wantsToBeDisabled;
|
||||
}
|
||||
|
|
Reference in a new issue