improved karma plugin
This commit is contained in:
		@@ -130,27 +130,29 @@ class KarmaPlugin implements CallbackListener, Plugin {
 | 
				
			|||||||
		// Build karma manialink
 | 
							// Build karma manialink
 | 
				
			||||||
		$this->buildManialink();
 | 
							$this->buildManialink();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							// Update karma gauge & label
 | 
				
			||||||
		$karmaGauge = $this->manialink->karmaGauge;
 | 
							$karmaGauge = $this->manialink->karmaGauge;
 | 
				
			||||||
 | 
							$karmaLabel = $this->manialink->karmaLabel;
 | 
				
			||||||
		if (is_numeric($karma)) {
 | 
							if (is_numeric($karma)) {
 | 
				
			||||||
			$karma = floatval($karma);
 | 
								$karma = floatval($karma);
 | 
				
			||||||
			$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
 | 
								$karmaGauge->setRatio($karma + 0.15 - $karma * 0.15);
 | 
				
			||||||
			$karmaColor = ColorUtil::floatToStatusColor($karma);
 | 
								$karmaColor = ColorUtil::floatToStatusColor($karma);
 | 
				
			||||||
			$karmaGauge->setColor($karmaColor . '9');
 | 
								$karmaGauge->setColor($karmaColor . '9');
 | 
				
			||||||
 | 
								$karmaLabel->setText('  ' . round($karma * 100.) . '% (' . $votes['count'] . ')');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
 | 
								$karma = 0.;
 | 
				
			||||||
			$karmaGauge->setRatio(0.);
 | 
								$karmaGauge->setRatio(0.);
 | 
				
			||||||
			$karmaGauge->setColor('00fb');
 | 
								$karmaGauge->setColor('00fb');
 | 
				
			||||||
 | 
								$karmaLabel->setText('-');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		$width = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_WIDTH);
 | 
					 | 
				
			||||||
		$height = $this->maniaControl->settingManager->getSetting($this, self::SETTING_WIDGET_HEIGHT);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Loop players
 | 
							// Loop players
 | 
				
			||||||
		foreach ($players as $login => $player) {
 | 
							foreach ($players as $login => $player) {
 | 
				
			||||||
			// Get player vote
 | 
								// Get player vote
 | 
				
			||||||
			$vote = $this->getPlayerVote($player, $map);
 | 
								$vote = $this->getPlayerVote($player, $map);
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
			// Adjust manialink for vote
 | 
								// Adjust manialink for player's vote
 | 
				
			||||||
			$votesFrame = $this->manialink->votesFrame;
 | 
								$votesFrame = $this->manialink->votesFrame;
 | 
				
			||||||
			$votesFrame->removeChildren();
 | 
								$votesFrame->removeChildren();
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
@@ -392,9 +394,12 @@ class KarmaPlugin implements CallbackListener, Plugin {
 | 
				
			|||||||
			return false;
 | 
								return false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		$votes = array();
 | 
							$votes = array();
 | 
				
			||||||
 | 
							$count = 0;
 | 
				
			||||||
		while ($vote = $result->fetch_object()) {
 | 
							while ($vote = $result->fetch_object()) {
 | 
				
			||||||
			$votes[$vote->vote] = $vote;
 | 
								$votes[$vote->vote] = $vote;
 | 
				
			||||||
 | 
								$count += $vote->count;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							$votes['count'] = $count;
 | 
				
			||||||
		$result->free();
 | 
							$result->free();
 | 
				
			||||||
		return $votes;
 | 
							return $votes;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -443,6 +448,14 @@ class KarmaPlugin implements CallbackListener, Plugin {
 | 
				
			|||||||
		$karmaGauge->setDrawBg(false);
 | 
							$karmaGauge->setDrawBg(false);
 | 
				
			||||||
		$manialink->karmaGauge = $karmaGauge;
 | 
							$manialink->karmaGauge = $karmaGauge;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							$karmaLabel = new Label();
 | 
				
			||||||
 | 
							$frame->add($karmaLabel);
 | 
				
			||||||
 | 
							$karmaLabel->setPosition(0, -0.4, 1);
 | 
				
			||||||
 | 
							$karmaLabel->setSize($width * 0.9, $height * 0.9);
 | 
				
			||||||
 | 
							$karmaLabel->setStyle($labelStyle);
 | 
				
			||||||
 | 
							$karmaLabel->setTextSize(1);
 | 
				
			||||||
 | 
							$manialink->karmaLabel = $karmaLabel;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		$votesFrame = new Frame();
 | 
							$votesFrame = new Frame();
 | 
				
			||||||
		$frame->add($votesFrame);
 | 
							$frame->add($votesFrame);
 | 
				
			||||||
		$manialink->votesFrame = $votesFrame;
 | 
							$manialink->votesFrame = $votesFrame;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user