2014-05-03 21:57:38 +02:00
< ? php
namespace MCTeam ;
use FML\Controls\Frame ;
use FML\Controls\Label ;
use FML\Controls\Labels\Label_Text ;
use FML\Controls\Quad ;
2014-07-04 18:29:30 +02:00
use FML\Controls\Quads\Quad_BgRaceScore2 ;
2014-05-03 21:57:38 +02:00
use FML\Controls\Quads\Quad_BgsPlayerCard ;
use FML\ManiaLink ;
use FML\Script\Features\Paging ;
use ManiaControl\Admin\AuthenticationManager ;
use ManiaControl\Bills\BillManager ;
use ManiaControl\Callbacks\CallbackListener ;
use ManiaControl\Callbacks\CallbackManager ;
use ManiaControl\Commands\CommandListener ;
use ManiaControl\ManiaControl ;
use ManiaControl\Manialinks\ManialinkManager ;
use ManiaControl\Players\Player ;
use ManiaControl\Players\PlayerManager ;
use ManiaControl\Plugins\Plugin ;
/**
* ManiaControl Donation Plugin
*
2014-05-03 23:49:58 +02:00
* @ author ManiaControl Team < mail @ maniacontrol . com >
* @ copyright 2014 ManiaControl Team
* @ license http :// www . gnu . org / licenses / GNU General Public License , Version 3
2014-05-03 21:57:38 +02:00
*/
class DonationPlugin implements CallbackListener , CommandListener , Plugin {
2014-05-03 23:49:58 +02:00
/*
2014-05-03 21:57:38 +02:00
* Constants
*/
2014-06-17 23:35:56 +02:00
const ID = 3 ;
const VERSION = 0.1 ;
const AUTHOR = 'MCTeam' ;
const NAME = 'Donation Plugin' ;
const SETTING_ANNOUNCE_SERVER_DONATION = 'Enable Server-Donation Announcements' ;
const STAT_PLAYER_DONATIONS = 'Donated Planets' ;
const ACTION_DONATE_VALUE = 'Donate.DonateValue' ;
2014-05-03 21:57:38 +02:00
// DonateWidget Properties
const MLID_DONATE_WIDGET = 'DonationPlugin.DonateWidget' ;
const SETTING_DONATE_WIDGET_ACTIVATED = 'Donate-Widget Activated' ;
const SETTING_DONATE_WIDGET_POSX = 'Donate-Widget-Position: X' ;
const SETTING_DONATE_WIDGET_POSY = 'Donate-Widget-Position: Y' ;
const SETTING_DONATE_WIDGET_WIDTH = 'Donate-Widget-Size: Width' ;
const SETTING_DONATE_WIDGET_HEIGHT = 'Donate-Widget-Size: Height' ;
const SETTING_DONATION_VALUES = 'Donation Values' ;
const SETTING_MIN_AMOUNT_SHOWN = 'Minimum Donation amount to get shown' ;
2014-05-03 23:49:58 +02:00
/*
2014-08-02 22:31:46 +02:00
* Private properties
2014-05-03 21:57:38 +02:00
*/
2014-05-07 22:59:09 +02:00
/** @var ManiaControl $maniaControl */
2014-05-03 21:57:38 +02:00
private $maniaControl = null ;
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: prepare ()
2014-05-03 21:57:38 +02:00
*/
public static function prepare ( ManiaControl $maniaControl ) {
}
2014-05-03 23:49:58 +02:00
/**
* @ see \ManiaControl\Plugins\Plugin :: getId ()
*/
public static function getId () {
return self :: ID ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getName ()
*/
public static function getName () {
return self :: NAME ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getVersion ()
*/
public static function getVersion () {
return self :: VERSION ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getAuthor ()
*/
public static function getAuthor () {
return self :: AUTHOR ;
}
/**
* @ see \ManiaControl\Plugins\Plugin :: getDescription ()
*/
public static function getDescription () {
2014-05-07 22:59:09 +02:00
return 'Plugin offering Commands like /donate, /pay and /planets and a Donation Widget.' ;
2014-05-03 23:49:58 +02:00
}
2014-05-03 21:57:38 +02:00
/**
* @ see \ManiaControl\Plugins\Plugin :: load ()
*/
public function load ( ManiaControl $maniaControl ) {
$this -> maniaControl = $maniaControl ;
// Register for commands
$this -> maniaControl -> commandManager -> registerCommandListener ( 'donate' , $this , 'command_Donate' , false , 'Donate some planets to the server.' );
$this -> maniaControl -> commandManager -> registerCommandListener ( 'pay' , $this , 'command_Pay' , true , 'Pays planets from the server to a player.' );
2014-05-20 14:59:17 +02:00
$this -> maniaControl -> commandManager -> registerCommandListener ( array ( 'getplanets' , 'planets' ), $this , 'command_GetPlanets' , true , 'Checks the planets-balance of the server.' );
2014-05-13 16:03:26 +02:00
$this -> maniaControl -> commandManager -> registerCommandListener ( 'topdons' , $this , 'command_TopDons' , false , 'Provides an overview of who donated the most planets.' );
2014-05-03 21:57:38 +02:00
// Register for callbacks
$this -> maniaControl -> callbackManager -> registerCallbackListener ( PlayerManager :: CB_PLAYERCONNECT , $this , 'handlePlayerConnect' );
$this -> maniaControl -> callbackManager -> registerCallbackListener ( CallbackManager :: CB_MP_PLAYERMANIALINKPAGEANSWER , $this , 'handleManialinkPageAnswer' );
// Define player stats
$this -> maniaControl -> statisticManager -> defineStatMetaData ( self :: STAT_PLAYER_DONATIONS );
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_ACTIVATED , true );
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_POSX , 156. );
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_POSY , - 31.4 );
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_WIDTH , 6 );
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATE_WIDGET_HEIGHT , 6 );
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_DONATION_VALUES , " 20,50,100,500,1000,2000 " );
$this -> maniaControl -> settingManager -> initSetting ( $this , self :: SETTING_MIN_AMOUNT_SHOWN , 100 );
// Register Stat in Simple StatsList
2014-08-02 22:31:46 +02:00
$this -> maniaControl -> statisticManager -> getSimpleStatsList () -> registerStat ( self :: STAT_PLAYER_DONATIONS , 90 , " DP " , 15 );
2014-05-03 21:57:38 +02:00
$this -> displayWidget ();
return true ;
}
/**
2014-05-07 22:59:09 +02:00
* Display the widget
2014-05-03 21:57:38 +02:00
*/
public function displayWidget () {
2014-05-13 16:03:26 +02:00
if ( $this -> maniaControl -> settingManager -> getSettingValue ( $this , self :: SETTING_DONATE_WIDGET_ACTIVATED )) {
2014-05-03 21:57:38 +02:00
$this -> displayDonateWidget ();
}
}
/**
2014-05-09 17:31:29 +02:00
* Display the Donation Widget
2014-05-03 21:57:38 +02:00
*
2014-05-07 22:59:09 +02:00
* @ param string $login
2014-05-03 21:57:38 +02:00
*/
2014-05-09 17:31:29 +02:00
public function displayDonateWidget ( $login = null ) {
2014-05-13 16:03:26 +02:00
$posX = $this -> maniaControl -> settingManager -> getSettingValue ( $this , self :: SETTING_DONATE_WIDGET_POSX );
$posY = $this -> maniaControl -> settingManager -> getSettingValue ( $this , self :: SETTING_DONATE_WIDGET_POSY );
$width = $this -> maniaControl -> settingManager -> getSettingValue ( $this , self :: SETTING_DONATE_WIDGET_WIDTH );
$height = $this -> maniaControl -> settingManager -> getSettingValue ( $this , self :: SETTING_DONATE_WIDGET_HEIGHT );
$values = $this -> maniaControl -> settingManager -> getSettingValue ( $this , self :: SETTING_DONATION_VALUES );
2014-08-02 22:31:46 +02:00
$shootManiaOffset = $this -> maniaControl -> manialinkManager -> getStyleManager () -> getDefaultIconOffsetSM ();
$quadStyle = $this -> maniaControl -> manialinkManager -> getStyleManager () -> getDefaultQuadStyle ();
$quadSubstyle = $this -> maniaControl -> manialinkManager -> getStyleManager () -> getDefaultQuadSubstyle ();
2014-05-03 21:57:38 +02:00
$itemMarginFactorX = 1.3 ;
$itemMarginFactorY = 1.2 ;
//If game is shootmania lower the icons position by 20
2014-06-22 19:02:18 +02:00
if ( $this -> maniaControl -> mapManager -> getCurrentMap ()
-> getGame () === 'sm'
) {
2014-05-03 21:57:38 +02:00
$posY -= $shootManiaOffset ;
}
$itemSize = $width ;
$maniaLink = new ManiaLink ( self :: MLID_DONATE_WIDGET );
// Donate Menu Icon Frame
$frame = new Frame ();
$maniaLink -> add ( $frame );
$frame -> setPosition ( $posX , $posY );
$backgroundQuad = new Quad ();
$frame -> add ( $backgroundQuad );
$backgroundQuad -> setSize ( $width * $itemMarginFactorX , $height * $itemMarginFactorY );
$backgroundQuad -> setStyles ( $quadStyle , $quadSubstyle );
$iconFrame = new Frame ();
$frame -> add ( $iconFrame );
$iconFrame -> setSize ( $itemSize , $itemSize );
2014-07-04 18:29:30 +02:00
$itemQuad = new Quad_BgRaceScore2 ();
$itemQuad -> setSubStyle ( $itemQuad :: SUBSTYLE_Points );
2014-05-03 21:57:38 +02:00
$itemQuad -> setSize ( $itemSize , $itemSize );
$iconFrame -> add ( $itemQuad );
2014-06-22 19:02:18 +02:00
$valueArray = explode ( ',' , $values );
2014-05-03 21:57:38 +02:00
// Values Menu
$popoutFrame = new Frame ();
$maniaLink -> add ( $popoutFrame );
$popoutFrame -> setPosition ( $posX - $itemSize * 0.5 , $posY );
2014-06-22 19:02:18 +02:00
$popoutFrame -> setHAlign ( $popoutFrame :: RIGHT );
2014-05-03 21:57:38 +02:00
$popoutFrame -> setSize ( 4 * $itemSize * $itemMarginFactorX , $itemSize * $itemMarginFactorY );
$popoutFrame -> setVisible ( false );
$quad = new Quad ();
$popoutFrame -> add ( $quad );
2014-06-22 19:02:18 +02:00
$quad -> setHAlign ( $quad :: RIGHT );
2014-05-03 21:57:38 +02:00
$quad -> setStyles ( $quadStyle , $quadSubstyle );
$quad -> setSize ( strlen ( $values ) * 2 + count ( $valueArray ) * 1 , $itemSize * $itemMarginFactorY );
$popoutFrame -> add ( $quad );
2014-05-03 23:49:58 +02:00
$itemQuad -> addToggleFeature ( $popoutFrame );
2014-05-03 21:57:38 +02:00
// Description Label
$descriptionFrame = new Frame ();
$maniaLink -> add ( $descriptionFrame );
$descriptionFrame -> setPosition ( $posX - 50 , $posY - 5 );
2014-06-22 19:02:18 +02:00
$descriptionFrame -> setHAlign ( $descriptionFrame :: RIGHT );
2014-05-03 21:57:38 +02:00
$descriptionLabel = new Label ();
$descriptionFrame -> add ( $descriptionLabel );
2014-06-22 19:02:18 +02:00
$descriptionLabel -> setAlign ( $descriptionLabel :: LEFT , $descriptionLabel :: TOP );
2014-05-03 21:57:38 +02:00
$descriptionLabel -> setSize ( 40 , 4 );
$descriptionLabel -> setTextSize ( 2 );
$descriptionLabel -> setVisible ( true );
2014-06-22 19:02:18 +02:00
$descriptionLabel -> setTextColor ( '0f0' );
2014-05-03 21:57:38 +02:00
// Add items
2014-06-14 15:48:27 +02:00
$posX = - 2 ;
2014-05-03 23:49:58 +02:00
foreach ( array_reverse ( $valueArray ) as $value ) {
2014-06-22 19:02:18 +02:00
$label = new Label_Text ();
2014-05-03 21:57:38 +02:00
$popoutFrame -> add ( $label );
2014-06-14 15:48:27 +02:00
$label -> setX ( $posX );
2014-06-22 19:02:18 +02:00
$label -> setHAlign ( $label :: RIGHT );
2014-05-03 21:57:38 +02:00
$label -> setText ( '$s$FFF' . $value . '$09FP' );
$label -> setTextSize ( 1.2 );
$label -> setAction ( self :: ACTION_DONATE_VALUE . " . " . $value );
2014-06-22 19:02:18 +02:00
$label -> setStyle ( $label :: STYLE_TextCardSmall );
2014-05-03 23:49:58 +02:00
$description = " Donate { $value } Planets " ;
$label -> addTooltipLabelFeature ( $descriptionLabel , $description );
2014-05-03 21:57:38 +02:00
2014-06-14 15:48:27 +02:00
$posX -= strlen ( $value ) * 2 + 1.7 ;
2014-05-03 21:57:38 +02:00
}
// Send manialink
$this -> maniaControl -> manialinkManager -> sendManialink ( $maniaLink , $login );
}
/**
2014-05-03 23:49:58 +02:00
* @ see \ManiaControl\Plugins\Plugin :: unload ()
*/
public function unload () {
$this -> maniaControl -> manialinkManager -> hideManialink ( self :: MLID_DONATE_WIDGET );
}
/**
* Handle ManialinkPageAnswer Callback
2014-05-03 21:57:38 +02:00
*
2014-05-03 23:49:58 +02:00
* @ param array $callback
2014-05-03 21:57:38 +02:00
*/
2014-05-03 23:49:58 +02:00
public function handleManialinkPageAnswer ( array $callback ) {
$actionId = $callback [ 1 ][ 2 ];
$boolSetting = ( strpos ( $actionId , self :: ACTION_DONATE_VALUE ) === 0 );
if ( ! $boolSetting ) {
return ;
2014-05-03 21:57:38 +02:00
}
2014-05-03 23:49:58 +02:00
$login = $callback [ 1 ][ 1 ];
$player = $this -> maniaControl -> playerManager -> getPlayer ( $login );
$actionArray = explode ( " . " , $callback [ 1 ][ 2 ]);
$this -> handleDonation ( $player , intval ( $actionArray [ 2 ]));
2014-05-03 21:57:38 +02:00
}
/**
2014-05-09 17:31:29 +02:00
* Handle a Player Donation
2014-05-03 21:57:38 +02:00
*
* @ param Player $player
2014-05-09 17:31:29 +02:00
* @ param int $amount
* @ param string $receiver
* @ param string $receiverName
2014-05-03 21:57:38 +02:00
*/
2014-05-09 17:31:29 +02:00
private function handleDonation ( Player $player , $amount , $receiver = '' , $receiverName = null ) {
2014-07-20 00:12:28 +02:00
if ( $amount > 1000000 ) {
// Prevent too huge donation amounts that would cause xmlrpc parsing errors
$message = " You can only donate 1.000.000 Planets at a time! " ;
$this -> maniaControl -> chat -> sendError ( $message , $player );
return ;
}
2014-05-03 21:57:38 +02:00
if ( ! $receiverName ) {
$serverName = $this -> maniaControl -> client -> getServerName ();
$message = 'Donate ' . $amount . ' Planets to $<' . $serverName . '$>?' ;
} else {
$message = 'Donate ' . $amount . ' Planets to $<' . $receiverName . '$>?' ;
}
//Send and Handle the Bill
2014-06-17 23:27:28 +02:00
$this -> maniaControl -> billManager -> sendBill ( function ( $data , $status ) use ( & $player , $amount , $receiver ) {
2014-05-03 23:49:58 +02:00
switch ( $status ) {
2014-05-03 21:57:38 +02:00
case BillManager :: DONATED_TO_SERVER :
2014-06-17 23:35:56 +02:00
if ( $this -> maniaControl -> settingManager -> getSettingValue ( $this , DonationPlugin :: SETTING_ANNOUNCE_SERVER_DONATION , true ) && $amount >= $this -> maniaControl -> settingManager -> getSettingValue ( $this , DonationPlugin :: SETTING_MIN_AMOUNT_SHOWN , true )) {
2014-05-03 21:57:38 +02:00
$login = null ;
$message = '$<' . $player -> nickname . '$> donated ' . $amount . ' Planets! Thanks.' ;
} else {
2014-05-03 23:49:58 +02:00
$login = $player -> login ;
2014-05-03 21:57:38 +02:00
$message = 'Donation successful! Thanks.' ;
}
2014-06-17 23:27:28 +02:00
$this -> maniaControl -> chat -> sendSuccess ( $message , $login );
$this -> maniaControl -> statisticManager -> insertStat ( DonationPlugin :: STAT_PLAYER_DONATIONS , $player , $this -> maniaControl -> server -> index , $amount );
2014-05-03 21:57:38 +02:00
break ;
case BillManager :: DONATED_TO_RECEIVER :
$message = " Successfully donated { $amount } to ' { $receiver } '! " ;
2014-06-17 23:27:28 +02:00
$this -> maniaControl -> chat -> sendSuccess ( $message , $player -> login );
2014-05-03 21:57:38 +02:00
break ;
case BillManager :: PLAYER_REFUSED_DONATION :
$message = 'Transaction cancelled.' ;
2014-06-17 23:27:28 +02:00
$this -> maniaControl -> chat -> sendError ( $message , $player -> login );
2014-05-03 21:57:38 +02:00
break ;
case BillManager :: ERROR_WHILE_TRANSACTION :
$message = $data ;
2014-06-17 23:27:28 +02:00
$this -> maniaControl -> chat -> sendError ( $message , $player -> login );
2014-05-03 21:57:38 +02:00
break ;
}
}, $player , $amount , $message );
}
2014-05-03 23:49:58 +02:00
/**
* Handle PlayerConnect callback
*
* @ param Player $player
*/
public function handlePlayerConnect ( Player $player ) {
// Display Map Widget
2014-05-13 16:03:26 +02:00
if ( $this -> maniaControl -> settingManager -> getSettingValue ( $this , self :: SETTING_DONATE_WIDGET_ACTIVATED )) {
2014-05-03 23:49:58 +02:00
$this -> displayDonateWidget ( $player -> login );
}
}
/**
* Handle / donate command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_Donate ( array $chatCallback , Player $player ) {
$text = $chatCallback [ 1 ][ 2 ];
$params = explode ( ' ' , $text );
if ( count ( $params ) < 2 ) {
$this -> sendDonateUsageExample ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 23:49:58 +02:00
}
$amount = ( int ) $params [ 1 ];
if ( ! $amount || $amount <= 0 ) {
$this -> sendDonateUsageExample ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 23:49:58 +02:00
}
if ( count ( $params ) >= 3 ) {
$receiver = $params [ 2 ];
$receiverPlayer = $this -> maniaControl -> playerManager -> getPlayer ( $receiver );
$receiverName = ( $receiverPlayer ? $receiverPlayer -> nickname : $receiver );
} else {
$receiver = '' ;
$receiverName = $this -> maniaControl -> client -> getServerName ();
}
2014-05-07 22:59:09 +02:00
$this -> handleDonation ( $player , $amount , $receiver , $receiverName );
2014-05-03 23:49:58 +02:00
}
/**
* Send an usage example for / donate to the player
*
* @ param Player $player
*/
private function sendDonateUsageExample ( Player $player ) {
$message = " Usage Example: '/donate 100' " ;
2014-05-07 22:59:09 +02:00
$this -> maniaControl -> chat -> sendChat ( $message , $player -> login );
2014-05-03 23:49:58 +02:00
}
2014-05-03 21:57:38 +02:00
/**
* Handle //pay command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_Pay ( array $chatCallback , Player $player ) {
if ( ! $this -> maniaControl -> authenticationManager -> checkRight ( $player , AuthenticationManager :: AUTH_LEVEL_SUPERADMIN )) {
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 21:57:38 +02:00
}
$text = $chatCallback [ 1 ][ 2 ];
$params = explode ( ' ' , $text );
if ( count ( $params ) < 2 ) {
$this -> sendPayUsageExample ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 21:57:38 +02:00
}
$amount = ( int ) $params [ 1 ];
if ( ! $amount || $amount <= 0 ) {
$this -> sendPayUsageExample ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 21:57:38 +02:00
}
if ( count ( $params ) >= 3 ) {
$receiver = $params [ 2 ];
} else {
$receiver = $player -> login ;
}
$message = 'Payout from $<' . $this -> maniaControl -> client -> getServerName () . '$>.' ;
2014-06-17 23:27:28 +02:00
$this -> maniaControl -> billManager -> sendPlanets ( function ( $data , $status ) use ( & $player , $amount , $receiver ) {
2014-05-03 23:49:58 +02:00
switch ( $status ) {
2014-05-03 21:57:38 +02:00
case BillManager :: PAYED_FROM_SERVER :
$message = " Successfully payed out { $amount } to ' { $receiver } '! " ;
2014-06-17 23:27:28 +02:00
$this -> maniaControl -> chat -> sendSuccess ( $message , $player -> login );
2014-05-03 21:57:38 +02:00
break ;
case BillManager :: PLAYER_REFUSED_DONATION :
$message = 'Transaction cancelled.' ;
2014-06-17 23:27:28 +02:00
$this -> maniaControl -> chat -> sendError ( $message , $player -> login );
2014-05-03 21:57:38 +02:00
break ;
case BillManager :: ERROR_WHILE_TRANSACTION :
$message = $data ;
2014-06-17 23:27:28 +02:00
$this -> maniaControl -> chat -> sendError ( $message , $player -> login );
2014-05-03 21:57:38 +02:00
break ;
}
}, $receiver , $amount , $message );
}
2014-05-03 23:49:58 +02:00
/**
* Send an usage example for / pay to the player
*
* @ param Player $player
*/
private function sendPayUsageExample ( Player $player ) {
2014-05-24 21:53:07 +02:00
$message = " Usage Example: '//pay 100 login' " ;
2014-05-07 22:59:09 +02:00
$this -> maniaControl -> chat -> sendChat ( $message , $player -> login );
2014-05-03 23:49:58 +02:00
}
2014-05-03 21:57:38 +02:00
/**
* Handle //getplanets command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_GetPlanets ( array $chatCallback , Player $player ) {
if ( ! $this -> maniaControl -> authenticationManager -> checkRight ( $player , AuthenticationManager :: AUTH_LEVEL_ADMIN )) {
$this -> maniaControl -> authenticationManager -> sendNotAllowed ( $player );
2014-05-07 22:59:09 +02:00
return ;
2014-05-03 21:57:38 +02:00
}
$planets = $this -> maniaControl -> client -> getServerPlanets ();
$message = " This Server has { $planets } Planets! " ;
2014-05-07 22:59:09 +02:00
$this -> maniaControl -> chat -> sendInformation ( $message , $player -> login );
2014-05-03 21:57:38 +02:00
}
/**
* Handles the / topdons command
*
* @ param array $chatCallback
* @ param Player $player
*/
public function command_TopDons ( array $chatCallback , Player $player ) {
$this -> showTopDonsList ( $player );
}
/**
2014-05-13 18:26:38 +02:00
* Provide an Overview ManiaLink with Donators
2014-05-03 21:57:38 +02:00
*
* @ param Player $player
*/
private function showTopDonsList ( Player $player ) {
$stats = $this -> maniaControl -> statisticManager -> getStatsRanking ( self :: STAT_PLAYER_DONATIONS );
2014-08-02 22:31:46 +02:00
$width = $this -> maniaControl -> manialinkManager -> getStyleManager () -> getListWidgetsWidth ();
$height = $this -> maniaControl -> manialinkManager -> getStyleManager () -> getListWidgetsHeight ();
2014-05-03 21:57:38 +02:00
// create manialink
$maniaLink = new ManiaLink ( ManialinkManager :: MAIN_MLID );
2014-05-03 23:49:58 +02:00
$script = $maniaLink -> getScript ();
$paging = new Paging ();
2014-05-03 21:57:38 +02:00
$script -> addFeature ( $paging );
// Main frame
2014-08-02 22:31:46 +02:00
$frame = $this -> maniaControl -> manialinkManager -> getStyleManager () -> getDefaultListFrame ( $script , $paging );
2014-05-03 21:57:38 +02:00
$maniaLink -> add ( $frame );
// Start offsets
2014-06-14 15:48:27 +02:00
$posX = - $width / 2 ;
$posY = $height / 2 ;
2014-05-03 21:57:38 +02:00
//Predefine description Label
2014-08-02 22:31:46 +02:00
$descriptionLabel = $this -> maniaControl -> manialinkManager -> getStyleManager () -> getDefaultDescriptionLabel ();
2014-05-03 21:57:38 +02:00
$frame -> add ( $descriptionLabel );
// Headline
$headFrame = new Frame ();
$frame -> add ( $headFrame );
2014-06-14 15:48:27 +02:00
$headFrame -> setY ( $posY - 5 );
$array = array ( '$oId' => $posX + 5 , '$oNickname' => $posX + 18 , '$oDonated planets' => $posX + 70 );
2014-05-03 21:57:38 +02:00
$this -> maniaControl -> manialinkManager -> labelLine ( $headFrame , $array );
2014-06-14 15:48:27 +02:00
$index = 1 ;
$posY = $posY - 10 ;
2014-05-15 17:45:08 +02:00
$pageFrame = null ;
2014-05-03 23:49:58 +02:00
foreach ( $stats as $playerIndex => $donations ) {
2014-06-14 15:48:27 +02:00
if ( $index % 15 === 1 ) {
2014-05-03 21:57:38 +02:00
$pageFrame = new Frame ();
$frame -> add ( $pageFrame );
2014-06-14 15:48:27 +02:00
$posY = $height / 2 - 10 ;
2014-05-03 21:57:38 +02:00
$paging -> addPage ( $pageFrame );
}
$playerFrame = new Frame ();
$pageFrame -> add ( $playerFrame );
2014-06-14 15:48:27 +02:00
$playerFrame -> setY ( $posY );
2014-05-03 21:57:38 +02:00
2014-06-14 15:48:27 +02:00
if ( $index % 2 !== 0 ) {
2014-05-03 21:57:38 +02:00
$lineQuad = new Quad_BgsPlayerCard ();
$playerFrame -> add ( $lineQuad );
$lineQuad -> setSize ( $width , 4 );
$lineQuad -> setSubStyle ( $lineQuad :: SUBSTYLE_BgPlayerCardBig );
$lineQuad -> setZ ( 0.001 );
}
$donatingPlayer = $this -> maniaControl -> playerManager -> getPlayerByIndex ( $playerIndex );
2014-06-14 15:48:27 +02:00
$array = array ( $index => $posX + 5 , $donatingPlayer -> nickname => $posX + 18 , $donations => $posX + 70 );
2014-05-03 21:57:38 +02:00
$this -> maniaControl -> manialinkManager -> labelLine ( $playerFrame , $array );
2014-06-14 15:48:27 +02:00
$posY -= 4 ;
$index ++ ;
2014-05-03 21:57:38 +02:00
2014-06-14 15:48:27 +02:00
if ( $index > 100 ) {
2014-05-03 21:57:38 +02:00
break ;
}
}
// Render and display xml
$this -> maniaControl -> manialinkManager -> displayWidget ( $maniaLink , $player , 'TopDons' );
}
}