- Karma plugin

- ColorUtil
- Minor improvements
This commit is contained in:
Steffen Schröder
2013-11-28 01:12:52 +01:00
parent c14c025df3
commit 80db4071ce
10 changed files with 586 additions and 22 deletions

View File

@ -0,0 +1,57 @@
<?php
namespace ManiaControl;
/**
* Utitlity class offering methods to convert and use ManiaPlanet colors
*
* @author steeffeen
*/
abstract class ColorUtil {
/**
* Convert the given float value to a color code from red to green
*
* @param float $value
* @return string
*/
public static function floatToStatusColor($value) {
$value = floatval($value);
$red = 1.;
$green = 1.;
if ($value < 0.5) {
$green = $value * 2.;
}
if ($value > 0.5) {
$red = 2. * (1. - $value);
}
$red = ColorUtil::floatToCode($red);
$green = ColorUtil::floatToCode($green);
return $red . $green . '0';
}
/**
* Get hex color representation of the float
*
* @param float $value
* @return string
*/
public static function floatToCode($value) {
$value = floatval($value);
if ($value < 0.) {
$value = 0.;
}
if ($value > 1.) {
$value = 1.;
}
$value *= 15.;
$value = round($value);
if ($value < 10) {
return (string) $value;
}
$codes = array(10 => 'a', 11 => 'b', 12 => 'c', 13 => 'd', 14 => 'e', 15 => 'f');
return $codes[$value];
}
}
?>

View File

@ -121,19 +121,37 @@ abstract class Control implements Renderable {
* @param real $z
* @return \FML\Controls\Control
*/
public function setPosition($x = null, $y = null, $z = null) {
if ($x !== null) {
$this->setX($x);
}
if ($y !== null) {
$this->setY($y);
}
public function setPosition($x, $y, $z = null) {
$this->setX($x);
$this->setY($y);
if ($z !== null) {
$this->setZ($z);
}
return $this;
}
/**
* Set width
*
* @param real $width
* @return \FML\Controls\Control
*/
public function setWidth($width) {
$this->width = $width;
return $this;
}
/**
* Set height
*
* @param real $height
* @return \FML\Controls\Control
*/
public function setHeight($height) {
$this->height = $height;
return $this;
}
/**
* Set size
*
@ -141,13 +159,9 @@ abstract class Control implements Renderable {
* @param real $height
* @return \FML\Controls\Control
*/
public function setSize($width = null, $height = null) {
if ($width !== null) {
$this->width = $width;
}
if ($height !== null) {
$this->height = $height;
}
public function setSize($width, $height) {
$this->setWidth($width);
$this->setHeight($height);
return $this;
}

View File

@ -2,6 +2,8 @@
namespace FML\Controls;
use FML\Types\Styleable;
/**
* Class representing CMlGauge
*
@ -13,11 +15,13 @@ class Gauge extends Control implements Styleable {
*/
protected $ratio = 1.;
protected $grading = 1.;
protected $color = '';
protected $rotation = 0.;
protected $centered = 0;
protected $clan = 0;
protected $drawBg = 1;
protected $drawBlockBg = 1;
protected $style = '';
/**
* Construct a new gauge control
@ -26,70 +30,104 @@ class Gauge extends Control implements Styleable {
*/
public function __construct($id = null) {
parent::__construct($id);
$this->name = 'gauge';
$this->tagName = 'gauge';
}
/**
* Set ratio
*
* @param real $ratio
* @return \FML\Controls\Gauge
*/
public function setRatio($ratio) {
$this->ratio = $ratio;
return $this;
}
/**
* Set grading
*
* @param real $grading
* @return \FML\Controls\Gauge
*/
public function setGrading($grading) {
$this->grading = $grading;
return $this;
}
/**
* Set color
*
* @param string $color
* @return \FML\Controls\Gauge
*/
public function setColor($color) {
$this->color = $color;
return $this;
}
/**
* Set rotation
*
* @param real $rotation
* @return \FML\Controls\Gauge
*/
public function setRotation($rotation) {
$this->rotation = $rotation;
return $this;
}
/**
* Set centered
*
* @param bool $centered
* @return \FML\Controls\Gauge
*/
public function setCentered($centered) {
$this->centered = ($centered ? 1 : 0);
return $this;
}
/**
* Set clan
*
* @param int $clan
* @return \FML\Controls\Gauge
*/
public function setClan($clan) {
$this->clan = $clan;
return $this;
}
/**
* Set draw background
*
* @param bool $drawBg
* @return \FML\Controls\Gauge
*/
public function setDrawBg($drawBg) {
$this->drawBg = ($drawBg ? 1 : 0);
return $this;
}
/**
* Set draw block background
*
* @param bool $drawBlockBg
* @return \FML\Controls\Gauge
*/
public function setDrawBlockBg($drawBlockBg) {
$this->drawBlockBg = ($drawBlockBg ? 1 : 0);
return $this;
}
/**
*
* @see \FML\Types\Styleable::setStyle()
*/
public function setStyle($style) {
$this->style = $style;
return $this;
}
/**
@ -100,11 +138,23 @@ class Gauge extends Control implements Styleable {
$xml = parent::render($domDocument);
$xml->setAttribute('ratio', $this->ratio);
$xml->setAttribute('grading', $this->grading);
$xml->setAttribute('rotation', $this->rotation);
$xml->setAttribute('centered', $this->centered);
$xml->setAttribute('clan', $this->clan);
if ($this->color) {
$xml->setAttribute('color', $this->color);
}
if ($this->rotation) {
$xml->setAttribute('rotation', $this->rotation);
}
if ($this->centered) {
$xml->setAttribute('centered', $this->centered);
}
if ($this->clan) {
$xml->setAttribute('clan', $this->clan);
}
$xml->setAttribute('drawbg', $this->drawBg);
$xml->setAttribute('drawblockbg', $this->drawBlockBg);
if ($this->style) {
$xml->setAttribute('style', $this->style);
}
return $xml;
}
}

View File

@ -20,6 +20,7 @@ class Label extends Control implements Linkable, NewLineable, Scriptable, Stylea
protected $text = '';
protected $textPrefix = '';
protected $textEmboss = 0;
protected $translate = 0;
protected $maxLines = 0;
protected $url = '';
protected $manialink = '';
@ -75,6 +76,17 @@ class Label extends Control implements Linkable, NewLineable, Scriptable, Stylea
return $this;
}
/**
* Set translate
*
* @param bool $translate
* @return \FML\Controls\Label
*/
public function setTranslate($translate) {
$this->translate = ($translate ? 1 : 0);
return $this;
}
/**
* Set max lines
*
@ -191,6 +203,9 @@ class Label extends Control implements Linkable, NewLineable, Scriptable, Stylea
if ($this->textEmboss) {
$xml->setAttribute('textemboss', $this->textEmboss);
}
if ($this->translate) {
$xml->setAttribute('translate', $this->translate);
}
if ($this->maxLines) {
$xml->setAttribute('maxlines', $this->maxLines);
}

View File

@ -31,6 +31,7 @@ require_once __DIR__ . '/Settings/SettingManager.php';
require_once __DIR__ . '/GbxDataFetcher/gbxdatafetcher.inc.php';
require_once __DIR__ . '/ManiaExchange/mxinfofetcher.inc.php';
require_once __DIR__ . '/ManiaExchange/mxinfosearcher.inc.php';
require_once __DIR__ . '/ColorUtil.php';
list($endiantest) = array_values(unpack('L1L', pack('V', 1)));
if ($endiantest == 1) {
require_once __DIR__ . '/PhpRemote/GbxRemote.inc.php';

View File

@ -9,19 +9,19 @@ require_once __DIR__ . '/../FML/autoload.php';
*
* @author steeffeen & kremsy
*/
class ManialinkUtil {
abstract class ManialinkUtil {
/**
* Send the given manialink to players
*
* @param \IXR_ClientMulticall_Gbx $client
* @param string $manialink
* @param array $logins
* @param mixed $logins
* @param int $timeout
* @param bool $hideOnClick
* @return bool
*/
public static function sendManialinkPage(\IXR_ClientMulticall_Gbx $client, $manialinkText, array $logins = null, $timeout = 0,
public static function sendManialinkPage(\IXR_ClientMulticall_Gbx $client, $manialinkText, $logins = null, $timeout = 0,
$hideOnClick = false) {
if (!$client || !$manialinkText) {
return false;

View File

@ -138,6 +138,15 @@ class PlayerManager implements CallbackListener {
$this->maniaControl->chat->sendChat('$<' . $player->nickname . '$> $ff0has left the game. Played:$fff ' . $played);
}
/**
* Get the complete PlayerList
*
* @return array
*/
public function getPlayers() {
return $this->playerList;
}
/**
* Get a Player from the PlayerList
*

View File

@ -133,7 +133,7 @@ class SettingManager {
return (int) $value;
}
if ($type === self::TYPE_REAL) {
return (real) $value;
return (float) $value;
}
if ($type === self::TYPE_BOOL) {
return (bool) $value;