TrackManiaControl/application/core/Manialinks/StyleManager.php

231 lines
6.8 KiB
PHP
Raw Normal View History

<?php
namespace ManiaControl\Manialinks;
2014-01-28 19:28:17 +01:00
use FML\Controls\Control;
2014-01-28 16:54:23 +01:00
use FML\Controls\Frame;
use FML\Controls\Label;
2014-01-28 19:28:17 +01:00
use FML\Controls\Labels\Label_Text;
2014-01-28 16:54:23 +01:00
use FML\Controls\Quad;
2013-12-29 10:03:58 +01:00
use FML\Controls\Quads\Quad_BgRaceScore2;
2014-01-28 16:54:23 +01:00
use FML\Controls\Quads\Quad_Icons64x64_1;
2014-04-27 16:22:12 +02:00
use FML\Script\Features\Paging;
2014-01-28 19:28:17 +01:00
use FML\Script\Script;
use ManiaControl\ManiaControl;
/**
* Class managing default Control Styles
*
2014-05-02 17:50:30 +02:00
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class StyleManager {
/*
* Constants
*/
2014-01-15 22:07:09 +01:00
const SETTING_LABEL_DEFAULT_STYLE = 'Default Label Style';
const SETTING_QUAD_DEFAULT_STYLE = 'Default Quad Style';
const SETTING_QUAD_DEFAULT_SUBSTYLE = 'Default Quad SubStyle';
2013-12-29 10:03:58 +01:00
2014-01-15 22:07:09 +01:00
const SETTING_MAIN_WIDGET_DEFAULT_STYLE = 'Main Widget Default Quad Style';
2013-12-29 10:03:58 +01:00
const SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE = 'Main Widget Default Quad SubStyle';
2014-01-15 22:07:09 +01:00
const SETTING_LIST_WIDGETS_WIDTH = 'List Widgets Width';
const SETTING_LIST_WIDGETS_HEIGHT = 'List Widgets Height';
const SETTING_ICON_DEFAULT_OFFSET_SM = 'Default Icon Offset in Shootmania';
/*
* Private Properties
*/
private $maniaControl = null;
/**
* Create a new style manager instance
*
2014-01-15 22:07:09 +01:00
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
2014-01-15 22:07:09 +01:00
// Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_LABEL_DEFAULT_STYLE, 'TextTitle1');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_QUAD_DEFAULT_STYLE, 'Bgs1InRace');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE, 'BgTitleShadow');
2013-12-29 10:03:58 +01:00
//Main Widget
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE, Quad_BgRaceScore2::STYLE);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE, Quad_BgRaceScore2::SUBSTYLE_HandleSelectable);
$this->maniaControl->settingManager->initSetting($this, self::SETTING_LIST_WIDGETS_WIDTH, '150');
$this->maniaControl->settingManager->initSetting($this, self::SETTING_LIST_WIDGETS_HEIGHT, '80');
2014-01-15 22:07:09 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ICON_DEFAULT_OFFSET_SM, '20');
}
/**
* Get the default Icon Offset for shootmania
*
* @return string
*/
public function getDefaultIconOffsetSM() {
2014-05-13 16:03:26 +02:00
return $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_ICON_DEFAULT_OFFSET_SM);
}
/**
* Get the default label style
*
* @return string
*/
public function getDefaultLabelStyle() {
2014-05-13 16:03:26 +02:00
return $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_LABEL_DEFAULT_STYLE);
}
/**
* Get the default quad style
*
* @return string
*/
public function getDefaultQuadStyle() {
2014-05-13 16:03:26 +02:00
return $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_QUAD_DEFAULT_STYLE);
}
/**
* Get the default quad substyle
*
* @return string
*/
public function getDefaultQuadSubstyle() {
2014-05-13 16:03:26 +02:00
return $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_QUAD_DEFAULT_SUBSTYLE);
}
2013-12-29 10:03:58 +01:00
/**
2014-05-02 17:50:30 +02:00
* Gets the Default Description Label
2013-12-29 10:03:58 +01:00
*
2014-05-02 17:50:30 +02:00
* @return Label
2013-12-29 10:03:58 +01:00
*/
2014-05-02 17:50:30 +02:00
public function getDefaultDescriptionLabel() {
$width = $this->getListWidgetsWidth();
$height = $this->getListWidgetsHeight();
2013-12-29 10:03:58 +01:00
2014-05-02 17:50:30 +02:00
// Predefine Description Label
$descriptionLabel = new Label();
$descriptionLabel->setAlign(Control::LEFT, Control::TOP);
$descriptionLabel->setPosition(-$width / 2 + 10, -$height / 2 + 5);
$descriptionLabel->setSize($width * 0.7, 4);
$descriptionLabel->setTextSize(2);
$descriptionLabel->setVisible(false);
return $descriptionLabel;
2013-12-29 10:03:58 +01:00
}
/**
* Get the Default List Widgets Width
2013-12-29 10:03:58 +01:00
*
* @return string
*/
2014-01-15 22:07:09 +01:00
public function getListWidgetsWidth() {
2014-05-13 16:03:26 +02:00
return $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_LIST_WIDGETS_WIDTH);
2013-12-29 10:03:58 +01:00
}
/**
* Get the default list widget height
*
* @return string
*/
2014-01-15 22:07:09 +01:00
public function getListWidgetsHeight() {
2014-05-13 16:03:26 +02:00
return $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_LIST_WIDGETS_HEIGHT);
2013-12-29 10:03:58 +01:00
}
2014-01-28 16:54:23 +01:00
/**
* Builds the Default List Frame
*
* @return Frame $frame
*/
2014-04-27 18:59:21 +02:00
public function getDefaultListFrame() {
2014-05-02 17:50:30 +02:00
$args = func_get_args();
2014-04-27 18:59:21 +02:00
$script = null;
$paging = null;
foreach ($args as $arg) {
if ($arg instanceof Script) {
$script = $arg;
}
if ($arg instanceof Paging) {
$paging = $arg;
}
}
2014-05-02 17:50:30 +02:00
2014-01-28 16:54:23 +01:00
$width = $this->getListWidgetsWidth();
$height = $this->getListWidgetsHeight();
$quadStyle = $this->getDefaultMainWindowStyle();
$quadSubstyle = $this->getDefaultMainWindowSubStyle();
// mainframe
$frame = new Frame();
$frame->setSize($width, $height);
2014-02-02 20:05:34 +01:00
$frame->setPosition(0, 0, 35); //TODO place before scoreboards
2014-01-28 16:54:23 +01:00
// Background Quad
$backgroundQuad = new Quad();
$frame->add($backgroundQuad);
$backgroundQuad->setSize($width, $height);
$backgroundQuad->setStyles($quadStyle, $quadSubstyle);
// Add Close Quad (X)
$closeQuad = new Quad_Icons64x64_1();
$frame->add($closeQuad);
$closeQuad->setPosition($width * 0.483, $height * 0.467, 3);
$closeQuad->setSize(6, 6);
$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
2014-04-27 18:59:21 +02:00
if ($script) {
2014-01-28 19:28:17 +01:00
$pagerSize = 6.;
$pagerPrev = new Quad_Icons64x64_1();
$frame->add($pagerPrev);
$pagerPrev->setPosition($width * 0.42, $height * -0.44, 2);
$pagerPrev->setSize($pagerSize, $pagerSize);
$pagerPrev->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowPrev);
$pagerNext = new Quad_Icons64x64_1();
$frame->add($pagerNext);
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
$pagerNext->setSize($pagerSize, $pagerSize);
$pagerNext->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_ArrowNext);
2014-05-02 17:50:30 +02:00
if ($paging) {
$paging->addButton($pagerNext);
$paging->addButton($pagerPrev);
}
2014-01-28 19:28:17 +01:00
$pageCountLabel = new Label_Text();
$frame->add($pageCountLabel);
$pageCountLabel->setHAlign(Control::RIGHT);
$pageCountLabel->setPosition($width * 0.40, $height * -0.44, 1);
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
$pageCountLabel->setTextSize(1.3);
2014-05-02 17:50:30 +02:00
if ($paging) {
$paging->setLabel($pageCountLabel);
}
2014-01-28 19:28:17 +01:00
}
2014-01-28 16:54:23 +01:00
return $frame;
}
2014-05-02 17:50:30 +02:00
/**
* Get the default main window style
*
* @return string
*/
public function getDefaultMainWindowStyle() {
2014-05-13 16:03:26 +02:00
return $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_STYLE);
2014-05-02 17:50:30 +02:00
}
/**
* Get the default main window substyle
*
* @return string
*/
public function getDefaultMainWindowSubStyle() {
2014-05-13 16:03:26 +02:00
return $this->maniaControl->settingManager->getSettingValue($this, self::SETTING_MAIN_WIDGET_DEFAULT_SUBSTYLE);
2014-05-02 17:50:30 +02:00
}
}