fixed setting changed callback + added use of it in widgets plugin

This commit is contained in:
kremsy 2014-07-04 18:48:39 +02:00
parent 40fa025317
commit eca5dcc2de
2 changed files with 18 additions and 3 deletions

View File

@ -173,6 +173,7 @@ class SettingManager implements CallbackListener {
* @return bool * @return bool
*/ */
public function setSetting($object, $settingName, $value) { public function setSetting($object, $settingName, $value) {
//TODO nowhere used, everywhere saveSettings used, is it depreciated?
$setting = $this->getSettingObject($object, $settingName); $setting = $this->getSettingObject($object, $settingName);
if ($setting) { if ($setting) {
$setting->value = $value; $setting->value = $value;
@ -190,9 +191,6 @@ class SettingManager implements CallbackListener {
$this->storeSetting($setting); $this->storeSetting($setting);
// Trigger Settings Changed Callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_SETTING_CHANGED, $setting);
return true; return true;
} }
@ -321,6 +319,9 @@ class SettingManager implements CallbackListener {
return false; return false;
} }
$settingStatement->close(); $settingStatement->close();
// Trigger Settings Changed Callback
$this->maniaControl->callbackManager->triggerCallback(self::CB_SETTING_CHANGED, $setting);
return true; return true;
} }

View File

@ -17,6 +17,8 @@ use ManiaControl\Manialinks\IconManager;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager; use ManiaControl\Players\PlayerManager;
use ManiaControl\Plugins\Plugin; use ManiaControl\Plugins\Plugin;
use ManiaControl\Settings\Setting;
use ManiaControl\Settings\SettingManager;
use ManiaControl\Utils\Formatter; use ManiaControl\Utils\Formatter;
/** /**
@ -129,6 +131,7 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidgets'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'updateWidgets');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidgets'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERINFOCHANGED, $this, 'updateWidgets');
$this->maniaControl->callbackManager->registerCallbackListener(SettingManager::CB_SETTING_CHANGED, $this, 'updateSettings');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_ACTIVATED, true);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20); $this->maniaControl->settingManager->initSetting($this, self::SETTING_MAP_WIDGET_POSX, 160 - 20);
@ -512,6 +515,17 @@ class WidgetPlugin implements CallbackListener, TimerListener, Plugin {
} }
} }
/**
* Update Widgets on Setting Changes
*
* @param Setting $setting
*/
public function updateSettings(Setting $setting){
if($setting->belongsToClass($this)){
$this->displayWIdgets();
}
}
/** /**
* Update Widget on certain callbacks * Update Widget on certain callbacks
*/ */