Overview

Classes

  • Card
  • CardRegular
  • Component
  • ComponentAvatar
  • ComponentFlag
  • ComponentImage
  • ComponentLabel
  • ComponentXPBar
  • ErrorImage
  • OsuAPI
  • OsuSignature
  • PredefinedColours
  • Signature
  • Template
  • TemplateNormal
  • Utils
  • Overview
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 
<?php
/**
 * The original osu!nextsig signature card. This is the design that followed through from v1 to v3. This is a pretty
 * messy class.
 *
 * @author Lemmmy
 */
class TemplateNormal extends Template
{
    private static function getGDFontSize ($size) {
        return ($size * 3) / 4;
    }

    public function __construct(OsuSignature $signature) {
        parent::__construct($signature);

        $user = $signature->getUser();

        $this->setCard(new CardRegular($user));

        $isCountryRank = isset($_GET['countryrank']);
        $removeAvatarMargin = isset($_GET['removeavmargin']);
        $showPP = isset($_GET['pp']);
        $pp = $showPP ? $_GET['pp'] : -1;
        $darkHeader = isset($_GET['darkheader']);
        $showRankedScore = isset($_GET['rankedscore']);
        $showXPBar = isset($_GET['xpbar']);

        if ($showPP && ($pp < 0 || $pp > 3)) {
            $errorImage = new ErrorImage();
            $errorImage->generate("Invalid parameter", "Parameter 'pp' has an\ninvalid value");
        }

        $userRank = $user['pp_rank'];
        $userRank = $userRank ? $userRank : '?';
        $userCountryRank = $user['pp_country_rank'];
        $userCountryRank = $userCountryRank ? $userCountryRank : '?';
        $mode = isset($_GET['mode']) ? $_GET['mode'] : 'osu';
        $iconmode = 0;
        switch ($mode) {
            case 0:
                $mode = 'osu';
                $iconmode = 0;
                break;
            case 1:
                $mode = 'taiko';
                $iconmode = 3;
                break;
            case 2:
                $mode = 'ctb';
                $iconmode = 2;
                break;
            case 3:
                $mode = 'mania';
                $iconmode = 1;
                break;
        }
        $username = $user['username'];
        $ppText = $user['pp_raw'];
        $accuracy = $user['accuracy'];
        $playcount = $user['playcount'];
        $level = $user['level'];

        $headerTextColour = $darkHeader ? '#555555' : '#FFFFFF';

        $avatar = new ComponentAvatar(
            $signature,
            CardRegular::SIG_MARGIN + ($removeAvatarMargin ? 4 : 6),
            CardRegular::SIG_MARGIN + ($removeAvatarMargin ? 4 : 6),
            $removeAvatarMargin ? 80 : 76,
            $removeAvatarMargin ? 80 : 76
        );

        $rank = new ComponentLabel(
            $signature,
            $isCountryRank ? 325 : 287,
            32,
            '#' . number_format($userRank) . ($isCountryRank ? " (" . '#' . number_format($userCountryRank) . ')' : ""),
            ComponentLabel::FONT_REGULAR,
            $headerTextColour,
            $isCountryRank ? 12 : 14,
            \Imagick::ALIGN_RIGHT,
            0
        );

        $mode = new ComponentLabel(
            $signature,
            $isCountryRank ? 313 : 290,
            $isCountryRank ? 18 : 31,
            json_decode('"\\ue00' . $iconmode . '"'),
            ComponentLabel::FONT_OSU,
            $headerTextColour,
            $isCountryRank ? 12 : 14,
            \Imagick::ALIGN_LEFT,
            $isCountryRank ? 12 : 14
        );

        $flag = new ComponentFlag(
            $signature,
            $isCountryRank ? 294 : 307,
            $isCountryRank ? 10 : 21,
            $isCountryRank ? 13 : 18,
            $isCountryRank ? 9 : 12
        );

        $nameFontSize = 24;
        $nameFont = ComponentLabel::FONT_DIRECTORY . ComponentLabel::FONT_MEDIUM;

        $nameDimensions = imagettfbbox(static::getGDFontSize($nameFontSize), 0, $nameFont, $username);
        $nameTextWidth = abs($nameDimensions[4] - $nameDimensions[0]);

        while ($nameTextWidth > ($isCountryRank ? 235 : 198) - $rank->getActualWidth()) {
            $nameDimensions = imagettfbbox(static::getGDFontSize($nameFontSize), 0, $nameFont, $username);
            $nameTextWidth = abs($nameDimensions[4] - $nameDimensions[0]);

            $nameFontSize -= 0.5;
        }

        $name = new ComponentLabel(
            $signature,
            90,
            32,
            $username,
            ComponentLabel::FONT_MEDIUM,
            $headerTextColour,
            $nameFontSize,
            \Imagick::ALIGN_LEFT,
            -2
        );

        $accuracyLabel = new ComponentLabel(
            $signature,
            91,
            56,
            "Accuracy",
            ComponentLabel::FONT_REGULAR,
            '#555555',
            14,
            \Imagick::ALIGN_LEFT
        );

        $playCountLabel = new ComponentLabel(
            $signature,
            91,
            73,
            $showRankedScore ? "Ranked Score" : "Play Count",
            ComponentLabel::FONT_REGULAR,
            '#555555',
            14,
            \Imagick::ALIGN_LEFT
        );

        $accuracyText = round($accuracy, 2) . '%' . ($showPP && $pp == 1 ? ' (' . number_format(floor($ppText)) . 'pp)' : '');
        $accuracyValueLabel = new ComponentLabel(
            $signature,
            325,
            56,
            $accuracyText,
            ComponentLabel::FONT_BOLD,
            '#555555',
            14,
            \Imagick::ALIGN_RIGHT,
            -2
        );

        $playCountText = number_format($playcount) . ($showPP && $pp == 0 ? ' (' . number_format(floor($ppText)) . 'pp)' : ($showXPBar ? '' : ' (lv' . floor($level) . ')'));
        $playCountValueLabel = new ComponentLabel(
            $signature,
            325,
            73,
            $showRankedScore ? Utils::largeNumberFormat($user['ranked_score']) : $playCountText,
            ComponentLabel::FONT_BOLD,
            '#555555',
            14,
            \Imagick::ALIGN_RIGHT,
            -2
        );

        $this->addComponent($avatar);
        $this->addComponent($rank);
        $this->addComponent($mode);
        $this->addComponent($flag);
        $this->addComponent($name);
        $this->addComponent($accuracyLabel);
        $this->addComponent($playCountLabel);
        $this->addComponent($accuracyValueLabel);
        $this->addComponent($playCountValueLabel);

        if ($showPP && $pp == 2) {
            $ppLabel = new ComponentLabel(
                $signature,
                $isCountryRank ? 290 : 326,
                18,
                number_format(floor($ppText)) . 'pp',
                ComponentLabel::FONT_REGULAR,
                $headerTextColour,
                10,
                \Imagick::ALIGN_RIGHT,
                -2
            );

            $this->addComponent($ppLabel);
        }

        $onlineIndicator = isset($_GET['onlineindicator']) ? $_GET['onlineindicator'] : false;
        $online = $onlineIndicator == 2 || $onlineIndicator == 3 ? Utils::isUserOnline($user['username']) : false;

        if ($online) {
            $onlineIndicatorImage = new ComponentImage(
                $signature,
                $avatar->x + $avatar->getWidth() - 17,
                $avatar->y + $avatar->getHeight() - 17,
                ComponentImage::IMG_DIRECTORY . 'online_indicator.png'
            );

            $this->addComponent($onlineIndicatorImage);
        }

        if ($showXPBar) {
            $xpBar = new ComponentXPBar(
                $signature,
                92,
                79,
                isset($_GET['xpbarhex']) ? '' : '#ffa200',
                233,
                4
            );

            $this->addComponent($xpBar);
        }

        // I don't know either.
        $this->extraWidth = CardRegular::SIG_MARGIN * 2 + 1;
        $this->extraHeight = $removeAvatarMargin ? 1 : 3;
    }

    /**
     * @return int The width to be added to the image.
     */
    public function getImageMarginWidth()
    {
        return CardRegular::SIG_MARGIN * 2;
    }

    /**
     * @return int The height to be added to the image.
     */
    public function getImageMarginHeight()
    {
        return CardRegular::SIG_MARGIN * 2;
    }
}
API documentation generated by ApiGen