TrackManiaControl/libs/FML/CustomUI.php

193 lines
4.4 KiB
PHP
Raw Normal View History

2014-01-03 17:18:14 +01:00
<?php
namespace FML;
/**
* Class representing a Custom_UI
*
2014-05-14 23:24:00 +02:00
* @author steeffeen
2014-04-13 18:21:40 +02:00
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
2014-05-14 23:24:00 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2014-01-03 17:18:14 +01:00
*/
class CustomUI {
2014-01-21 20:30:40 +01:00
/*
2014-06-21 03:18:21 +02:00
* Protected properties
2014-01-03 17:18:14 +01:00
*/
protected $encoding = 'utf-8';
protected $tagName = 'custom_ui';
protected $noticeVisible = null;
protected $challengeInfoVisible = null;
protected $netInfosVisible = null;
protected $chatVisible = null;
protected $checkpointListVisible = null;
protected $roundScoresVisible = null;
protected $scoretableVisible = null;
protected $globalVisible = null;
2014-01-19 19:30:21 +01:00
/**
2014-06-21 03:18:21 +02:00
* Create a new CustomUI object
2014-01-19 19:30:21 +01:00
*
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public static function create() {
2014-06-21 03:18:21 +02:00
return new static();
2014-01-19 19:30:21 +01:00
}
/**
2014-06-21 03:18:21 +02:00
* Set XML encoding
2014-01-03 17:18:14 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $encoding XML encoding
2014-07-03 22:34:47 +02:00
* @return static
2014-01-03 17:18:14 +01:00
*/
public function setXMLEncoding($encoding) {
2014-05-14 23:24:00 +02:00
$this->encoding = (string)$encoding;
2014-01-03 17:18:14 +01:00
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set showing of notices
2014-01-03 17:18:14 +01:00
*
2014-06-21 03:18:21 +02:00
* @param bool $visible Whether notices should be shown
2014-07-03 22:34:47 +02:00
* @return static
2014-01-03 17:18:14 +01:00
*/
public function setNoticeVisible($visible) {
$this->noticeVisible = $visible;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set showing of the challenge info
2014-01-03 17:18:14 +01:00
*
2014-06-21 03:18:21 +02:00
* @param bool $visible Whether the challenge info should be shown
2014-07-03 22:34:47 +02:00
* @return static
2014-01-03 17:18:14 +01:00
*/
public function setChallengeInfoVisible($visible) {
$this->challengeInfoVisible = $visible;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set showing of the net infos
2014-01-03 17:18:14 +01:00
*
2014-06-21 03:18:21 +02:00
* @param bool $visible Whether the net infos should be shown
2014-07-03 22:34:47 +02:00
* @return static
2014-01-03 17:18:14 +01:00
*/
public function setNetInfosVisible($visible) {
$this->netInfosVisible = $visible;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set showing of the chat
2014-01-03 17:18:14 +01:00
*
2014-06-21 03:18:21 +02:00
* @param bool $visible Whether the chat should be shown
2014-07-03 22:34:47 +02:00
* @return static
2014-01-03 17:18:14 +01:00
*/
public function setChatVisible($visible) {
$this->chatVisible = $visible;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set showing of the checkpoint list
2014-01-03 17:18:14 +01:00
*
2014-06-21 03:18:21 +02:00
* @param bool $visible Whether the checkpoint should be shown
2014-07-03 22:34:47 +02:00
* @return static
2014-01-03 17:18:14 +01:00
*/
public function setCheckpointListVisible($visible) {
$this->checkpointListVisible = $visible;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set showing of round scores
2014-01-03 17:18:14 +01:00
*
2014-06-21 03:18:21 +02:00
* @param bool $visible Whether the round scores should be shown
2014-07-03 22:34:47 +02:00
* @return static
2014-01-03 17:18:14 +01:00
*/
public function setRoundScoresVisible($visible) {
$this->roundScoresVisible = $visible;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set showing of the scoretable
2014-01-03 17:18:14 +01:00
*
2014-06-21 03:18:21 +02:00
* @param bool $visible Whether the scoretable should be shown
2014-07-03 22:34:47 +02:00
* @return static
2014-01-03 17:18:14 +01:00
*/
public function setScoretableVisible($visible) {
$this->scoretableVisible = $visible;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set global showing
2014-01-03 17:18:14 +01:00
*
2014-05-14 23:24:00 +02:00
* @param bool $visible Whether the UI should be disabled completely
2014-07-03 22:34:47 +02:00
* @return static
2014-01-03 17:18:14 +01:00
*/
public function setGlobalVisible($visible) {
$this->globalVisible = $visible;
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Render the XML document
2014-01-03 17:18:14 +01:00
*
2014-06-21 03:18:21 +02:00
* @param \DOMDocument $domDocument (optional) DOMDocument for which the XML element should be rendered
2014-01-03 17:18:14 +01:00
* @return \DOMDocument
*/
public function render($domDocument = null) {
2014-05-14 23:24:00 +02:00
$isChild = (bool)$domDocument;
2014-01-03 17:18:14 +01:00
if (!$isChild) {
2014-05-14 23:24:00 +02:00
$domDocument = new \DOMDocument('1.0', $this->encoding);
2014-01-19 19:30:21 +01:00
$domDocument->xmlStandalone = true;
2014-01-03 17:18:14 +01:00
}
$xmlElement = $domDocument->createElement($this->tagName);
2014-01-12 00:51:46 +01:00
if (!$isChild) {
$domDocument->appendChild($xmlElement);
}
2014-01-03 17:18:14 +01:00
$settings = $this->getSettings();
foreach ($settings as $setting => $value) {
2014-08-11 23:15:53 +02:00
if ($value === null) {
2014-05-14 23:24:00 +02:00
continue;
}
2014-01-03 17:18:14 +01:00
$xmlSubElement = $domDocument->createElement($setting);
$xmlSubElement->setAttribute('visible', ($value ? 1 : 0));
$xmlElement->appendChild($xmlSubElement);
}
if ($isChild) {
return $xmlElement;
}
return $domDocument;
}
/**
2014-06-21 03:18:21 +02:00
* Get string representation
2014-01-03 17:18:14 +01:00
*
* @return string
*/
public function __toString() {
2014-06-21 03:18:21 +02:00
return $this->render()->saveXML();
2014-01-03 17:18:14 +01:00
}
/**
2014-06-21 03:18:21 +02:00
* Get associative array of all CustomUI settings
2014-01-03 17:18:14 +01:00
*
* @return array
*/
2014-04-27 14:44:40 +02:00
protected function getSettings() {
2014-05-14 23:24:00 +02:00
$settings = array();
$settings['challenge_info'] = $this->challengeInfoVisible;
$settings['chat'] = $this->chatVisible;
2014-01-03 17:18:14 +01:00
$settings['checkpoint_list'] = $this->checkpointListVisible;
2014-05-14 23:24:00 +02:00
$settings['global'] = $this->globalVisible;
$settings['net_infos'] = $this->netInfosVisible;
$settings['notice'] = $this->noticeVisible;
$settings['round_scores'] = $this->roundScoresVisible;
$settings['scoretable'] = $this->scoretableVisible;
2014-01-03 17:18:14 +01:00
return $settings;
}
2013-12-30 14:11:24 +01:00
}