TrackManiaControl/application/core/Libs/FML/CustomUI.php

198 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
*
* @author steeffeen
*/
class CustomUI {
2014-01-21 20:30:40 +01:00
/*
2014-01-03 17:18:14 +01:00
* Protected Properties
*/
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
/**
* Create a new CustomUI Object
*
* @return \FML\CustomUI
*/
public static function create() {
$customUI = new CustomUI();
return $customUI;
}
/**
* Construct a new CustomUI Object
*/
public function __construct() {
}
2014-01-03 17:18:14 +01:00
/**
* Set XML Encoding
*
2014-01-12 00:51:46 +01:00
* @param string $encoding XML Encoding
2014-01-03 17:18:14 +01:00
* @return \FML\CustomUI
*/
public function setXMLEncoding($encoding) {
2014-01-12 00:51:46 +01:00
$this->encoding = (string) $encoding;
2014-01-03 17:18:14 +01:00
return $this;
}
/**
* Set Showing of Notices
*
2014-01-12 00:51:46 +01:00
* @param bool $visible Whether Notices should be shown
2014-01-03 17:18:14 +01:00
* @return \FML\CustomUI
*/
public function setNoticeVisible($visible) {
$this->noticeVisible = $visible;
return $this;
}
/**
* Set Showing of the Challenge Info
*
2014-01-12 00:51:46 +01:00
* @param bool $visible Whether the Challenge Info should be shown
2014-01-03 17:18:14 +01:00
* @return \FML\CustomUI
*/
public function setChallengeInfoVisible($visible) {
$this->challengeInfoVisible = $visible;
return $this;
}
/**
* Set Showing of the Net Infos
*
2014-01-12 00:51:46 +01:00
* @param bool $visible Whether the Net Infos should be shown
2014-01-03 17:18:14 +01:00
* @return \FML\CustomUI
*/
public function setNetInfosVisible($visible) {
$this->netInfosVisible = $visible;
return $this;
}
/**
* Set Showing of the Chat
*
2014-01-12 00:51:46 +01:00
* @param bool $visible Whether the Chat should be shown
2014-01-03 17:18:14 +01:00
* @return \FML\CustomUI
*/
public function setChatVisible($visible) {
$this->chatVisible = $visible;
return $this;
}
/**
* Set Showing of the Checkpoint List
*
2014-01-12 00:51:46 +01:00
* @param bool $visible Whether the Checkpoint should be shown
2014-01-03 17:18:14 +01:00
* @return \FML\CustomUI
*/
public function setCheckpointListVisible($visible) {
$this->checkpointListVisible = $visible;
return $this;
}
/**
* Set Showing of Round Scores
*
2014-01-12 00:51:46 +01:00
* @param bool $visible Whether the Round Scores should be shown
2014-01-03 17:18:14 +01:00
* @return \FML\CustomUI
*/
public function setRoundScoresVisible($visible) {
$this->roundScoresVisible = $visible;
return $this;
}
/**
* Set Showing of the Scoretable
*
2014-01-12 00:51:46 +01:00
* @param bool $visible Whether the Scoretable should be shown
2014-01-03 17:18:14 +01:00
* @return \FML\CustomUI
*/
public function setScoretableVisible($visible) {
$this->scoretableVisible = $visible;
return $this;
}
/**
* Set Global Showing
*
2014-01-12 00:51:46 +01:00
* @param bool $visible Wether the UI should be disabled completely
2014-01-03 17:18:14 +01:00
* @return \FML\CustomUI
*/
public function setGlobalVisible($visible) {
$this->globalVisible = $visible;
return $this;
}
/**
* Render the XML Document
*
2014-01-12 00:51:46 +01: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-01-12 00:51:46 +01:00
$isChild = (bool) $domDocument;
2014-01-03 17:18:14 +01:00
if (!$isChild) {
$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) {
if ($value === null) continue;
$xmlSubElement = $domDocument->createElement($setting);
$xmlSubElement->setAttribute('visible', ($value ? 1 : 0));
$xmlElement->appendChild($xmlSubElement);
}
if ($isChild) {
return $xmlElement;
}
return $domDocument;
}
/**
* Get String Representation
*
* @return string
*/
public function __toString() {
$domDocument = $this->render();
$xmlText = $domDocument->saveXML();
return $xmlText;
}
/**
* Get associative Array of all CustomUI Settings
*
* @return array
*/
private function getSettings() {
$settings = array();
$settings['challenge_info'] = $this->challengeInfoVisible;
$settings['chat'] = $this->chatVisible;
$settings['checkpoint_list'] = $this->checkpointListVisible;
$settings['global'] = $this->globalVisible;
$settings['net_infos'] = $this->netInfosVisible;
$settings['notice'] = $this->noticeVisible;
$settings['round_scores'] = $this->roundScoresVisible;
$settings['scoretable'] = $this->scoretableVisible;
return $settings;
}
2013-12-30 14:11:24 +01:00
}