1: <?php
2: /**
3: * ManiaLive - TrackMania dedicated server manager in PHP
4: *
5: * @copyright Copyright (c) 2009-2011 NADEO (http://www.nadeo.com)
6: * @license http://www.gnu.org/licenses/lgpl.html LGPL License 3
7: * @version $Revision: 294 $:
8: * @author $Author: martin.gwendal $:
9: * @date $Date: 2011-12-08 19:20:04 +0100 (jeu., 08 déc. 2011) $:
10: */
11:
12: namespace ManiaLive\Gui;
13:
14: /**
15: * Set the custom appearance for the game UI here.
16: */
17: final class CustomUI
18: {
19: const NOTICE = 1;
20: const CHALLENGE_INFO = 2;
21: const CHAT = 4;
22: const CHECKPOINT_LIST = 8;
23: const ROUND_SCORES = 16;
24: const SCORETABLE = 32;
25: const GLOBAL_UI = 64;
26: const ALL = 127;
27:
28: private static $instances = array();
29: private static $fieldNames = array(
30: self::NOTICE => 'notice',
31: self::CHALLENGE_INFO => 'challenge_info',
32: self::CHAT => 'chat',
33: self::CHECKPOINT_LIST => 'checkpoint_list',
34: self::ROUND_SCORES => 'round_scores',
35: self::SCORETABLE => 'scoretable',
36: self::GLOBAL_UI => 'global'
37: );
38: private static $defaultState = self::ALL;
39:
40: private $currentState = self::ALL;
41: private $nextState;
42:
43: private function __construct()
44: {
45: $this->nextState = self::$defaultState;
46: }
47:
48: static function Create($login)
49: {
50: if(!isset(self::$instances[$login]))
51: self::$instances[$login] = new self();
52: return self::$instances[$login];
53: }
54:
55: static function GetAll()
56: {
57: return self::$instances;
58: }
59:
60: static function Erase($login)
61: {
62: unset(self::$instances[$login]);
63: }
64:
65: static function ShowForAll($fields)
66: {
67: $fields &= self::ALL;
68: foreach(self::$instances as $customUI)
69: $customUI->nextState |= $fields;
70: self::$defaultState |= $fields;
71: }
72:
73: static function HideForAll($fields)
74: {
75: $fields = ~$fields;
76: foreach(self::$instances as $customUI)
77: $customUI->nextState &= $fields;
78: self::$defaultState &= $fields;
79: }
80:
81: function show($fields)
82: {
83: $this->nextState |= ($fields & self::ALL);
84: }
85:
86: function hide($fields)
87: {
88: $this->nextState &= ~$fields;
89: }
90:
91: function getDiff()
92: {
93: return $this->currentState ^ $this->nextState;
94: }
95:
96: function save()
97: {
98: if($this->nextState == $this->currentState)
99: return;
100:
101: Manialinks::beginCustomUi();
102: $diff = $this->currentState ^ $this->nextState;
103: foreach(self::$fieldNames as $field => $name)
104: if($diff & $field)
105: Manialinks::setVisibility($name, (bool)($this->nextState & $field));
106: Manialinks::endCustomUi();
107:
108: $this->hasBeenSaved();
109: }
110:
111: function saveToDefault()
112: {
113: $oldNextState = $this->nextState;
114: $this->nextState = self::ALL;
115: $this->save();
116: $this->nextState = $oldNextState;
117: }
118:
119: function hasBeenSaved()
120: {
121: $this->currentState = $this->nextState;
122: }
123: }
124: ?>