improved player detailed
This commit is contained in:
		
				
					committed by
					
						
						Steffen Schröder
					
				
			
			
				
	
			
			
			
						parent
						
							05eb8b96a7
						
					
				
				
					commit
					b0b6e6ef17
				
			@@ -8,7 +8,6 @@ use FML\Controls\Labels\Label_Button;
 | 
			
		||||
use FML\Controls\Labels\Label_Text;
 | 
			
		||||
use FML\Controls\Quad;
 | 
			
		||||
use FML\Controls\Quads\Quad_BgsPlayerCard;
 | 
			
		||||
use FML\Controls\Quads\Quad_Icons64x64_1;
 | 
			
		||||
use FML\ManiaLink;
 | 
			
		||||
use FML\Script\Script;
 | 
			
		||||
use ManiaControl\Formatter;
 | 
			
		||||
@@ -22,7 +21,10 @@ use ManiaControl\Statistics\StatisticManager;
 | 
			
		||||
 * @author steeffeen & kremsy
 | 
			
		||||
 */
 | 
			
		||||
class PlayerDetailed {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Constants
 | 
			
		||||
	 */
 | 
			
		||||
	const STATS_PER_COLUMN = 13;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Private properties
 | 
			
		||||
@@ -42,40 +44,25 @@ class PlayerDetailed {
 | 
			
		||||
		$this->height       = $this->maniaControl->manialinkManager->styleManager->getListWidgetsHeight();
 | 
			
		||||
		$this->quadStyle    = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowStyle();
 | 
			
		||||
		$this->quadSubstyle = $this->maniaControl->manialinkManager->styleManager->getDefaultMainWindowSubStyle();
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	public function showPlayerDetailed(Player $player, $targetLogin) {
 | 
			
		||||
		$target = $this->maniaControl->playerManager->getPlayer($targetLogin);
 | 
			
		||||
 | 
			
		||||
		//Create ManiaLink
 | 
			
		||||
		$maniaLink = new ManiaLink(ManialinkManager::MAIN_MLID);
 | 
			
		||||
		$script    = $maniaLink->getScript();
 | 
			
		||||
 | 
			
		||||
		// Main frame
 | 
			
		||||
		$frame = $this->maniaControl->manialinkManager->styleManager->defaultListFrame($script);
 | 
			
		||||
		$maniaLink->add($frame);
 | 
			
		||||
 | 
			
		||||
		// Create script and features
 | 
			
		||||
		$script = new Script();
 | 
			
		||||
		$maniaLink->setScript($script);
 | 
			
		||||
 | 
			
		||||
		// mainframe
 | 
			
		||||
		$frame = new Frame();
 | 
			
		||||
		$maniaLink->add($frame);
 | 
			
		||||
		$frame->setSize($this->width, $this->height);
 | 
			
		||||
		$frame->setPosition(0, 0);
 | 
			
		||||
 | 
			
		||||
		// Background Quad
 | 
			
		||||
		$backgroundQuad = new Quad();
 | 
			
		||||
		$frame->add($backgroundQuad);
 | 
			
		||||
		$backgroundQuad->setSize($this->width, $this->height);
 | 
			
		||||
		$backgroundQuad->setStyles($this->quadStyle, $this->quadSubstyle);
 | 
			
		||||
 | 
			
		||||
		// Add Close Quad (X)
 | 
			
		||||
		$closeQuad = new Quad_Icons64x64_1();
 | 
			
		||||
		$frame->add($closeQuad);
 | 
			
		||||
		$closeQuad->setPosition($this->width * 0.483, $this->height * 0.467, 3);
 | 
			
		||||
		$closeQuad->setSize(6, 6);
 | 
			
		||||
		$closeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_QuitRace);
 | 
			
		||||
		$closeQuad->setAction(ManialinkManager::ACTION_CLOSEWIDGET);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		$y = $this->height / 2 - 10;
 | 
			
		||||
		$y = $this->height / 2 - 7;
 | 
			
		||||
 | 
			
		||||
		//Nation Quad
 | 
			
		||||
		$countryQuad = new Quad();
 | 
			
		||||
@@ -88,7 +75,6 @@ class PlayerDetailed {
 | 
			
		||||
		$countryQuad->setHAlign(Control::LEFT);
 | 
			
		||||
 | 
			
		||||
		//Nickname
 | 
			
		||||
 | 
			
		||||
		$label = new Label_Text();
 | 
			
		||||
		$frame->add($label);
 | 
			
		||||
		$label->setPosition(-$this->width / 2 + 15, $y);
 | 
			
		||||
@@ -97,7 +83,7 @@ class PlayerDetailed {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		//Define MainLabel (Login)
 | 
			
		||||
		$y -= 5;
 | 
			
		||||
		$y -= 8;
 | 
			
		||||
		$mainLabel = new Label_Text();
 | 
			
		||||
		$frame->add($mainLabel);
 | 
			
		||||
		$mainLabel->setPosition(-$this->width / 2 + 10, $y);
 | 
			
		||||
@@ -139,7 +125,13 @@ class PlayerDetailed {
 | 
			
		||||
		$label = clone $mainLabel;
 | 
			
		||||
		$frame->add($label);
 | 
			
		||||
		$label->setY($y);
 | 
			
		||||
		$label->setText("Plays since:");
 | 
			
		||||
		$label->setText("Inscribed Zone:");
 | 
			
		||||
 | 
			
		||||
		$y -= 5;
 | 
			
		||||
		$label = clone $mainLabel;
 | 
			
		||||
		$frame->add($label);
 | 
			
		||||
		$label->setY($y);
 | 
			
		||||
		$label->setText('Avatar');
 | 
			
		||||
 | 
			
		||||
		//Login
 | 
			
		||||
		$y         = $this->height / 2 - 15;
 | 
			
		||||
@@ -192,18 +184,10 @@ class PlayerDetailed {
 | 
			
		||||
		$label->setY($y);
 | 
			
		||||
		$label->setText(date("d M Y", time() - 3600 * 24 * $target->maniaPlanetPlayDays));
 | 
			
		||||
 | 
			
		||||
		//Avatar
 | 
			
		||||
		$label = new Label_Text();
 | 
			
		||||
		$frame->add($label);
 | 
			
		||||
		$label->setPosition($this->width / 2 - 10, $this->height / 2 - 10);
 | 
			
		||||
		$label->setText("Avatar");
 | 
			
		||||
		$label->setTextSize(1.3);
 | 
			
		||||
		$label->setHAlign(Control::RIGHT);
 | 
			
		||||
 | 
			
		||||
		$quad = new Quad();
 | 
			
		||||
		$frame->add($quad);
 | 
			
		||||
		$quad->setImage('file://' . $target->avatar);
 | 
			
		||||
		$quad->setPosition($this->width / 2 - 10, $this->height / 2 - 10);
 | 
			
		||||
		$quad->setPosition(-$this->width / 2 + 50, -$this->height / 2 + 34);
 | 
			
		||||
		$quad->setAlign(Control::RIGHT, Control::TOP);
 | 
			
		||||
		$quad->setSize(20, 20);
 | 
			
		||||
 | 
			
		||||
@@ -216,7 +200,7 @@ class PlayerDetailed {
 | 
			
		||||
		$quad->setStyle($quad::STYLE_CardMain_Quit);
 | 
			
		||||
		$quad->setHAlign(Control::LEFT);
 | 
			
		||||
		$quad->setScale(0.75);
 | 
			
		||||
		$quad->setText("Back to Playerlist");
 | 
			
		||||
		$quad->setText("Back");
 | 
			
		||||
		$quad->setPosition(-$this->width / 2 + 7, -$this->height / 2 + 7);
 | 
			
		||||
		$quad->setAction(PlayerCommands::ACTION_OPEN_PLAYERLIST);
 | 
			
		||||
 | 
			
		||||
@@ -227,50 +211,54 @@ class PlayerDetailed {
 | 
			
		||||
	public function statisticsFrame($player) {
 | 
			
		||||
		$frame = new Frame();
 | 
			
		||||
 | 
			
		||||
		/*$mainLabel = new Label_Text();
 | 
			
		||||
		$frame->add($mainLabel);
 | 
			
		||||
		$mainLabel->setPosition(-$this->width / 2 + 50, $this->height / 2 - 10);
 | 
			
		||||
		$mainLabel->setTextSize(1.2);
 | 
			
		||||
		$mainLabel->setHAlign(Control::LEFT);
 | 
			
		||||
		$mainLabel->setText("Statistics");*/
 | 
			
		||||
 | 
			
		||||
		$playerStats = $this->maniaControl->statisticManager->getAllPlayerStats($player);
 | 
			
		||||
 | 
			
		||||
		$y  = $this->height / 2 - 15;
 | 
			
		||||
		$x  = -$this->width / 2 + 52;
 | 
			
		||||
		$id = 1;
 | 
			
		||||
		foreach($playerStats as $stat) {
 | 
			
		||||
			$statProperties = $stat[0];
 | 
			
		||||
			$value          = $stat[1];
 | 
			
		||||
 | 
			
		||||
			if($statProperties->type == StatisticManager::STAT_TYPE_TIME) {
 | 
			
		||||
			if ((int)$value == 0) {
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if ($statProperties->type == StatisticManager::STAT_TYPE_TIME) {
 | 
			
		||||
				$value = Formatter::formatTimeH($value);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if($id % 2 != 0) {
 | 
			
		||||
			if ($id % 2 != 0) {
 | 
			
		||||
				$lineQuad = new Quad_BgsPlayerCard();
 | 
			
		||||
				$frame->add($lineQuad);
 | 
			
		||||
				$lineQuad->setSize(49, 4);
 | 
			
		||||
				$lineQuad->setSubStyle($lineQuad::SUBSTYLE_BgPlayerCardBig);
 | 
			
		||||
				$lineQuad->setPosition(-$this->width / 2 + 66, $y, 0.001);
 | 
			
		||||
				$lineQuad->setPosition($x, $y, 0.001);
 | 
			
		||||
				$lineQuad->setHAlign(Control::LEFT);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			$label = new Label_Text();
 | 
			
		||||
			$frame->add($label);
 | 
			
		||||
			$label->setPosition(-$this->width / 2 + 70, $y);
 | 
			
		||||
			$label->setPosition($x + 4, $y);
 | 
			
		||||
			$label->setText($statProperties->name);
 | 
			
		||||
			$label->setHAlign(Control::LEFT);
 | 
			
		||||
			$label->setTextSize(1.5);
 | 
			
		||||
 | 
			
		||||
			$label = new Label_Text();
 | 
			
		||||
			$frame->add($label);
 | 
			
		||||
			$label->setPosition(-$this->width / 2 + 100, $y);
 | 
			
		||||
			$label->setPosition($x + 40, $y);
 | 
			
		||||
			$label->setText($value);
 | 
			
		||||
			$label->setHAlign(Control::LEFT);
 | 
			
		||||
			$label->setVAlign(Control::CENTER2);
 | 
			
		||||
			$label->setTextSize(1.5);
 | 
			
		||||
 | 
			
		||||
			$y -= 4;
 | 
			
		||||
			$id++;
 | 
			
		||||
 | 
			
		||||
			if ($id > self::STATS_PER_COLUMN) {
 | 
			
		||||
				$y = $this->height / 2 - 15;
 | 
			
		||||
				$x += 47;
 | 
			
		||||
				$id = 0;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return $frame;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -32,13 +32,13 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
	const STAT_ON_PLAYER_REQUEST_RESPAWN = 'Respawns';
 | 
			
		||||
	const STAT_ON_KILL                   = 'Kills';
 | 
			
		||||
	const STAT_LASER_SHOT                = 'Laser Shots';
 | 
			
		||||
	const STAT_LASER_HIT                 = 'Laser Hit';
 | 
			
		||||
	const STAT_LASER_HIT                 = 'Laser Hits';
 | 
			
		||||
	const STAT_ROCKET_SHOT               = 'Rocket Shots';
 | 
			
		||||
	const STAT_ROCKET_HIT                = 'Rocket Hit';
 | 
			
		||||
	const STAT_ROCKET_HIT                = 'Rocket Hits';
 | 
			
		||||
	const STAT_ARROW_SHOT                = 'Arrow Shots';
 | 
			
		||||
	const STAT_ARROW_HIT                 = 'Arrow Hit';
 | 
			
		||||
	const STAT_ARROW_HIT                 = 'Arrow Hits';
 | 
			
		||||
	const STAT_NUCLEUS_SHOT              = 'Nucleus Shots';
 | 
			
		||||
	const STAT_NUCLEUS_HIT               = 'Nucleus Hit';
 | 
			
		||||
	const STAT_NUCLEUS_HIT               = 'Nucleus Hits';
 | 
			
		||||
 | 
			
		||||
	const SPECIAL_STAT_KILL_DEATH_RATIO = 'Kill / Death';
 | 
			
		||||
 | 
			
		||||
@@ -105,7 +105,7 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
	 * @param $login
 | 
			
		||||
	 */
 | 
			
		||||
	private function handleOnShoot($login, $weaponNumber) {
 | 
			
		||||
		if(!isset($this->onShootArray[$login])) {
 | 
			
		||||
		if (!isset($this->onShootArray[$login])) {
 | 
			
		||||
			$this->onShootArray[$login] = array(self::WEAPON_ROCKET => 0, self::WEAPON_ARROW => 0, self::WEAPON_NUCLEUS => 0, self::WEAPON_LASER => 0);
 | 
			
		||||
			$this->onShootArray[$login][$weaponNumber]++;
 | 
			
		||||
		} else {
 | 
			
		||||
@@ -113,7 +113,7 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Write Shoot Data into database
 | 
			
		||||
		if(array_sum($this->onShootArray[$login]) > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) {
 | 
			
		||||
		if (array_sum($this->onShootArray[$login]) > $this->maniaControl->settingManager->getSetting($this, self::SETTING_ON_SHOOT_PRESTORE)) {
 | 
			
		||||
			$player = $this->maniaControl->playerManager->getPlayer($login);
 | 
			
		||||
 | 
			
		||||
			$rocketShots  = $this->onShootArray[$login][self::WEAPON_ROCKET];
 | 
			
		||||
@@ -121,19 +121,19 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
			$arrowShots   = $this->onShootArray[$login][self::WEAPON_ARROW];
 | 
			
		||||
			$nucleusShots = $this->onShootArray[$login][self::WEAPON_NUCLEUS];
 | 
			
		||||
 | 
			
		||||
			if($rocketShots > 0) {
 | 
			
		||||
			if ($rocketShots > 0) {
 | 
			
		||||
				$this->maniaControl->statisticManager->insertStat(self::STAT_ROCKET_SHOT, $player, $this->maniaControl->server->index, $rocketShots);
 | 
			
		||||
				$this->onShootArray[$login][self::WEAPON_ROCKET] = 0;
 | 
			
		||||
			}
 | 
			
		||||
			if($laserShots > 0) {
 | 
			
		||||
			if ($laserShots > 0) {
 | 
			
		||||
				$this->maniaControl->statisticManager->insertStat(self::STAT_LASER_SHOT, $player, $this->maniaControl->server->index, $laserShots);
 | 
			
		||||
				$this->onShootArray[$login][self::WEAPON_LASER] = 0;
 | 
			
		||||
			}
 | 
			
		||||
			if($arrowShots > 0) {
 | 
			
		||||
			if ($arrowShots > 0) {
 | 
			
		||||
				$this->maniaControl->statisticManager->insertStat(self::STAT_ARROW_SHOT, $player, $this->maniaControl->server->index, $arrowShots);
 | 
			
		||||
				$this->onShootArray[$login][self::WEAPON_ARROW] = 0;
 | 
			
		||||
			}
 | 
			
		||||
			if($nucleusShots > 0) {
 | 
			
		||||
			if ($nucleusShots > 0) {
 | 
			
		||||
				$this->maniaControl->statisticManager->insertStat(self::STAT_NUCLEUS_SHOT, $player, $this->maniaControl->server->index, $nucleusShots);
 | 
			
		||||
				$this->onShootArray[$login][self::WEAPON_NUCLEUS] = 0;
 | 
			
		||||
			}
 | 
			
		||||
@@ -150,7 +150,7 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
	 * @return string
 | 
			
		||||
	 */
 | 
			
		||||
	private function getWeaponStat($weaponNumber, $shot = true) {
 | 
			
		||||
		if($shot) {
 | 
			
		||||
		if ($shot) {
 | 
			
		||||
			switch($weaponNumber) {
 | 
			
		||||
				case self::WEAPON_ROCKET:
 | 
			
		||||
					return self::STAT_ROCKET_SHOT;
 | 
			
		||||
@@ -189,13 +189,13 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
		$player = $callback[1];
 | 
			
		||||
 | 
			
		||||
		//Check if Stat Collecting is enabled
 | 
			
		||||
		if(!$this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_ENABLED)) {
 | 
			
		||||
		if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_ENABLED)) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Insert Data into Database, and destroy player
 | 
			
		||||
		if(isset($this->onShootArray[$player->login])) {
 | 
			
		||||
			if($this->onShootArray[$player->login] > 0) {
 | 
			
		||||
		if (isset($this->onShootArray[$player->login])) {
 | 
			
		||||
			if ($this->onShootArray[$player->login] > 0) {
 | 
			
		||||
				$this->maniaControl->statisticManager->insertStat(self::STAT_ON_SHOOT, $player, $this->maniaControl->server->index, $this->onShootArray[$player->login]);
 | 
			
		||||
			}
 | 
			
		||||
			unset($this->onShootArray[$player->login]);
 | 
			
		||||
@@ -209,12 +209,12 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
	 */
 | 
			
		||||
	public function handleCallbacks(array $callback) {
 | 
			
		||||
		//Check if Stat Collecting is enabled
 | 
			
		||||
		if(!$this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_ENABLED)) {
 | 
			
		||||
		if (!$this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_ENABLED)) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Check for Minplayer
 | 
			
		||||
		if(count($this->maniaControl->playerManager->getPlayers()) < $this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS)) {
 | 
			
		||||
		if (count($this->maniaControl->playerManager->getPlayers()) < $this->maniaControl->settingManager->getSetting($this, self::SETTING_COLLECT_STATS_MINPLAYERS)) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@@ -241,7 +241,7 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
				$logins = explode(';', $logins);
 | 
			
		||||
				foreach($logins as $login) {
 | 
			
		||||
					$player = $this->maniaControl->playerManager->getPlayer($login);
 | 
			
		||||
					if(!$player) {
 | 
			
		||||
					if (!$player) {
 | 
			
		||||
						continue;
 | 
			
		||||
					}
 | 
			
		||||
					$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_CAPTURE, $player);
 | 
			
		||||
@@ -250,7 +250,7 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
			case 'LibXmlRpc_OnArmorEmpty':
 | 
			
		||||
				$shooter = $this->maniaControl->playerManager->getPlayer($callback[1][1][0]);
 | 
			
		||||
				$victim  = $this->maniaControl->playerManager->getPlayer($callback[1][1][1]);
 | 
			
		||||
				if($shooter != null) {
 | 
			
		||||
				if ($shooter != null) {
 | 
			
		||||
					$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_KILL, $shooter);
 | 
			
		||||
				}
 | 
			
		||||
				$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_DEATH, $victim);
 | 
			
		||||
@@ -287,7 +287,7 @@ class StatisticCollector implements CallbackListener {
 | 
			
		||||
				$victim       = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Victim->Login);
 | 
			
		||||
				$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_DEATH, $victim);
 | 
			
		||||
				$shooter = $this->maniaControl->playerManager->getPlayer($paramsObject->Event->Shooter->Login);
 | 
			
		||||
				if($shooter != null) {
 | 
			
		||||
				if ($shooter != null) {
 | 
			
		||||
					$this->maniaControl->statisticManager->incrementStat(self::STAT_ON_KILL, $shooter);
 | 
			
		||||
				}
 | 
			
		||||
				break;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user