make click sound handling DRY
This commit is contained in:
@@ -877,13 +877,7 @@ void cDialog::process_keystroke(cKey keyHit){
|
||||
if(iter->second->isVisible() && iter->second->isClickable() && iter->second->getAttachedKey() == keyHit){
|
||||
iter->second->setActive(true);
|
||||
draw();
|
||||
if(get_bool_pref("PlaySounds", true)) {
|
||||
if(typeid(iter->second) == typeid(cLed*))
|
||||
play_sound(34);
|
||||
else play_sound(37);
|
||||
sf::sleep(time_in_ticks(6));
|
||||
}
|
||||
else sf::sleep(time_in_ticks(14));
|
||||
iter->second->playClickSound();
|
||||
iter->second->setActive(false);
|
||||
draw();
|
||||
sf::sleep(sf::milliseconds(8));
|
||||
|
@@ -210,6 +210,16 @@ void cControl::redraw() {
|
||||
if(parent) parent->draw();
|
||||
}
|
||||
|
||||
void cControl::playClickSound(){
|
||||
if(get_bool_pref("PlaySounds", true)) {
|
||||
if(typeid(this) == typeid(cLed*))
|
||||
play_sound(34);
|
||||
else play_sound(37);
|
||||
sf::sleep(time_in_ticks(6));
|
||||
}
|
||||
else sf::sleep(time_in_ticks(14));
|
||||
}
|
||||
|
||||
bool cControl::handleClick(location){
|
||||
sf::Event e;
|
||||
bool done = false, clicked = false;
|
||||
@@ -231,13 +241,8 @@ bool cControl::handleClick(location){
|
||||
depressed = frame.contains(toPos);
|
||||
}
|
||||
}
|
||||
if(get_bool_pref("PlaySounds", true)) {
|
||||
if(typeid(this) == typeid(cLed*))
|
||||
play_sound(34);
|
||||
else play_sound(37);
|
||||
sf::sleep(time_in_ticks(6));
|
||||
}
|
||||
else sf::sleep(time_in_ticks(14));
|
||||
playClickSound();
|
||||
|
||||
redraw();
|
||||
return clicked;
|
||||
}
|
||||
|
@@ -451,6 +451,8 @@ protected:
|
||||
/// Redraws the parent dialog, if any.
|
||||
/// Intended to be called from handleClick(), where there is usually a minor event loop happening.
|
||||
void redraw();
|
||||
/// Plays the proper sound for this control being clicked on
|
||||
void playClickSound();
|
||||
private:
|
||||
friend class cDialog; // TODO: This is only so it can access parseColour... hack!
|
||||
eControlType type;
|
||||
|
Reference in New Issue
Block a user