Spells/Tooltips

* fix level slider for spells with buffs but without tooltips
This commit is contained in:
Sarjuuk
2022-08-21 20:28:56 +02:00
parent 2b15c13e88
commit f05fe60030
3 changed files with 65 additions and 36 deletions

View File

@@ -51,6 +51,8 @@ class SpellList extends BaseType
private $tools = []; private $tools = [];
private $interactive = false; private $interactive = false;
private $charLevel = MAX_LEVEL; private $charLevel = MAX_LEVEL;
private $scaling = [];
private $parsedText = [];
protected $queryBase = 'SELECT s.*, s.id AS ARRAY_KEY FROM ?_spell s'; protected $queryBase = 'SELECT s.*, s.id AS ARRAY_KEY FROM ?_spell s';
protected $queryOpts = array( protected $queryOpts = array(
@@ -61,13 +63,19 @@ class SpellList extends BaseType
'src' => ['j' => ['?_source src ON type = 6 AND typeId = s.id', true], 's' => ', src1, src2, src3, src4, src5, src6, src7, src8, src9, src10, src11, src12, src13, src14, src15, src16, src17, src18, src19, src20, src21, src22, src23, src24'] 'src' => ['j' => ['?_source src ON type = 6 AND typeId = s.id', true], 's' => ', src1, src2, src3, src4, src5, src6, src7, src8, src9, src10, src11, src12, src13, src14, src15, src16, src17, src18, src19, src20, src21, src22, src23, src24']
); );
public function __construct($conditions = []) public function __construct($conditions = [], $miscData = [])
{ {
parent::__construct($conditions); parent::__construct($conditions);
if ($this->error) if ($this->error)
return; return;
if (isset($miscData['interactive']))
$this->interactive = $miscData['interactive'];
if (isset($miscData['charLevel']))
$this->charLevel = $miscData['charLevel'];
// post processing // post processing
$foo = DB::World()->selectCol('SELECT perfectItemType FROM skill_perfect_item_template WHERE spellId IN (?a)', $this->getFoundIDs()); $foo = DB::World()->selectCol('SELECT perfectItemType FROM skill_perfect_item_template WHERE spellId IN (?a)', $this->getFoundIDs());
foreach ($this->iterate() as &$_curTpl) foreach ($this->iterate() as &$_curTpl)
@@ -129,6 +137,8 @@ class SpellList extends BaseType
if (!$_curTpl['iconString']) if (!$_curTpl['iconString'])
$_curTpl['iconString'] = 'inv_misc_questionmark'; $_curTpl['iconString'] = 'inv_misc_questionmark';
$this->scaling[$this->id] = false;
} }
if ($foo) if ($foo)
@@ -1066,7 +1076,7 @@ class SpellList extends BaseType
// description-, buff-parsing component // description-, buff-parsing component
// returns [min, max, minFulltext, maxFulltext, ratingId] // returns [min, max, minFulltext, maxFulltext, ratingId]
private function resolveVariableString($varParts, &$usesScalingRating) private function resolveVariableString($varParts)
{ {
$signs = ['+', '-', '/', '*', '%', '^']; $signs = ['+', '-', '/', '*', '%', '^'];
@@ -1187,7 +1197,7 @@ class SpellList extends BaseType
$rType = 0; $rType = 0;
if ($aura == 189) if ($aura == 189)
if ($rType = Game::itemModByRatingMask($mv)) if ($rType = Game::itemModByRatingMask($mv))
$usesScalingRating = true; $this->scaling[$this->id] = true;
// Aura end // Aura end
if ($rType) if ($rType)
@@ -1274,7 +1284,7 @@ class SpellList extends BaseType
$rType = 0; $rType = 0;
if ($aura == 189) if ($aura == 189)
if ($rType = Game::itemModByRatingMask($mv)) if ($rType = Game::itemModByRatingMask($mv))
$usesScalingRating = true; $this->scaling[$this->id] = true;
// Aura end // Aura end
if ($rType) if ($rType)
@@ -1342,7 +1352,7 @@ class SpellList extends BaseType
} }
// description-, buff-parsing component // description-, buff-parsing component
private function resolveFormulaString($formula, $precision = 0, &$scaling) private function resolveFormulaString($formula, $precision = 0)
{ {
$fSuffix = '%s'; $fSuffix = '%s';
$fRating = 0; $fRating = 0;
@@ -1381,7 +1391,7 @@ class SpellList extends BaseType
++$formCurPos; // for some odd reason the precision decimal survives if we dont increment further.. ++$formCurPos; // for some odd reason the precision decimal survives if we dont increment further..
} }
[$formOutStr, $fSuffix, $fRating] = $this->resolveFormulaString($formOutStr, $formPrecision, $scaling); [$formOutStr, $fSuffix, $fRating] = $this->resolveFormulaString($formOutStr, $formPrecision);
$formula = substr_replace($formula, $formOutStr, $formStartPos, ($formCurPos - $formStartPos)); $formula = substr_replace($formula, $formOutStr, $formStartPos, ($formCurPos - $formStartPos));
} }
@@ -1415,7 +1425,7 @@ class SpellList extends BaseType
$pos += $len; $pos += $len;
// we are resolving a formula -> omit ranges // we are resolving a formula -> omit ranges
$var = $this->resolveVariableString($varParts, $scaling); $var = $this->resolveVariableString($varParts);
// time within formula -> rebase to seconds and omit timeUnit // time within formula -> rebase to seconds and omit timeUnit
if (strtolower($varParts['var']) == 'd') if (strtolower($varParts['var']) == 'd')
@@ -1447,7 +1457,7 @@ class SpellList extends BaseType
// should probably used only once to create ?_spell. come to think of it, it yields the same results every time.. it absolutely has to! // should probably used only once to create ?_spell. come to think of it, it yields the same results every time.. it absolutely has to!
// although it seems to be pretty fast, even on those pesky test-spells with extra complex tooltips (Ron Test Spell X)) // although it seems to be pretty fast, even on those pesky test-spells with extra complex tooltips (Ron Test Spell X))
public function parseText($type = 'description', $level = MAX_LEVEL, $interactive = false, &$scaling = false) public function parseText($type = 'description', $level = MAX_LEVEL, $interactive = false)
{ {
// oooo..kaaayy.. parsing text in 6 or 7 easy steps // oooo..kaaayy.. parsing text in 6 or 7 easy steps
// we don't use the internal iterator here. This func has to be called for the individual template. // we don't use the internal iterator here. This func has to be called for the individual template.
@@ -1533,6 +1543,10 @@ class SpellList extends BaseType
$this->interactive = $interactive; $this->interactive = $interactive;
$this->charLevel = $level; $this->charLevel = $level;
// step -1: already handled?
if (isset($this->parsedText[$this->id][$type][$this->charLevel][(int)$this->interactive]))
return $this->parsedText[$this->id][$type][$this->charLevel][(int)$this->interactive];
// step 0: get text // step 0: get text
$data = $this->getField($type, true); $data = $this->getField($type, true);
if (empty($data) || $data == "[]") // empty tooltip shouldn't be displayed anyway if (empty($data) || $data == "[]") // empty tooltip shouldn't be displayed anyway
@@ -1582,13 +1596,13 @@ class SpellList extends BaseType
*/ */
$relSpells = []; $relSpells = [];
$data = $this->handleConditions($data, $scaling, $relSpells, true); $data = $this->handleConditions($data, $relSpells, true);
// step 3: unpack formulas ${ .. }.X // step 3: unpack formulas ${ .. }.X
$data = $this->handleFormulas($data, $scaling, true); $data = $this->handleFormulas($data, true);
// step 4: find and eliminate regular variables // step 4: find and eliminate regular variables
$data = $this->handleVariables($data, $scaling, true); $data = $this->handleVariables($data, true);
// step 5: variable-dependant variable-text // step 5: variable-dependant variable-text
// special case $lONE:ELSE[:ELSE2]; or $|ONE:ELSE[:ELSE2]; // special case $lONE:ELSE[:ELSE2]; or $|ONE:ELSE[:ELSE2];
@@ -1636,10 +1650,13 @@ class SpellList extends BaseType
// line endings // line endings
$data = strtr($data, ["\r" => '', "\n" => '<br />']); $data = strtr($data, ["\r" => '', "\n" => '<br />']);
// cache result
$this->parsedText[$this->id][$type][$this->charLevel][(int)$this->interactive] = [$data, $relSpells];
return [$data, $relSpells]; return [$data, $relSpells];
} }
private function handleFormulas($data, &$scaling, $topLevel = false) private function handleFormulas($data, $topLevel = false)
{ {
// they are stacked recursively but should be balanced .. hf // they are stacked recursively but should be balanced .. hf
while (($formStartPos = strpos($data, '${')) !== false) while (($formStartPos = strpos($data, '${')) !== false)
@@ -1678,7 +1695,7 @@ class SpellList extends BaseType
$formPrecision = $data[$formCurPos + 1]; $formPrecision = $data[$formCurPos + 1];
$formCurPos += 2; $formCurPos += 2;
} }
[$formOutVal, $formOutStr, $ratingId] = $this->resolveFormulaString($formOutStr, $formPrecision ?: ($topLevel ? 0 : 10), $scaling); [$formOutVal, $formOutStr, $ratingId] = $this->resolveFormulaString($formOutStr, $formPrecision ?: ($topLevel ? 0 : 10));
if ($ratingId && Util::checkNumeric($formOutVal) && $this->interactive) if ($ratingId && Util::checkNumeric($formOutVal) && $this->interactive)
$resolved = sprintf($formOutStr, $ratingId, abs($formOutVal), sprintf(Util::$setRatingLevelString, $this->charLevel, $ratingId, abs($formOutVal), Util::setRatingLevel($this->charLevel, $ratingId, abs($formOutVal)))); $resolved = sprintf($formOutStr, $ratingId, abs($formOutVal), sprintf(Util::$setRatingLevelString, $this->charLevel, $ratingId, abs($formOutVal), Util::setRatingLevel($this->charLevel, $ratingId, abs($formOutVal))));
@@ -1693,7 +1710,7 @@ class SpellList extends BaseType
return $data; return $data;
} }
private function handleVariables($data, &$scaling, $topLevel = false) private function handleVariables($data, $topLevel = false)
{ {
$pos = 0; // continue strpos-search from this offset $pos = 0; // continue strpos-search from this offset
$str = ''; $str = '';
@@ -1716,7 +1733,7 @@ class SpellList extends BaseType
$pos += $len; $pos += $len;
$var = $this->resolveVariableString($varParts, $scaling); $var = $this->resolveVariableString($varParts);
$resolved = is_numeric($var[0]) ? abs($var[0]) : $var[0]; $resolved = is_numeric($var[0]) ? abs($var[0]) : $var[0];
if (isset($var[2])) if (isset($var[2]))
{ {
@@ -1743,7 +1760,7 @@ class SpellList extends BaseType
return $str; return $str;
} }
private function handleConditions($data, &$scaling, &$relSpells, $topLevel = false) private function handleConditions($data, &$relSpells, $topLevel = false)
{ {
while (($condStartPos = strpos($data, '$?')) !== false) while (($condStartPos = strpos($data, '$?')) !== false)
{ {
@@ -1830,17 +1847,17 @@ class SpellList extends BaseType
// recursive conditions // recursive conditions
if (strstr($condParts[$targetPart], '$?')) if (strstr($condParts[$targetPart], '$?'))
$condParts[$targetPart] = $this->handleConditions($condParts[$targetPart], $scaling, $relSpells); $condParts[$targetPart] = $this->handleConditions($condParts[$targetPart], $relSpells);
if ($know && $topLevel) if ($know && $topLevel)
{ {
foreach ([1, 3] as $pos) foreach ([1, 3] as $pos)
{ {
if (strstr($condParts[$pos], '${')) if (strstr($condParts[$pos], '${'))
$condParts[$pos] = $this->handleFormulas($condParts[$pos], $scaling); $condParts[$pos] = $this->handleFormulas($condParts[$pos]);
if (strstr($condParts[$pos], '$')) if (strstr($condParts[$pos], '$'))
$condParts[$pos] = $this->handleVariables($condParts[$pos], $scaling); $condParts[$pos] = $this->handleVariables($condParts[$pos]);
} }
// false condition first // false condition first
@@ -1868,6 +1885,7 @@ class SpellList extends BaseType
return ['', []]; return ['', []];
$this->interactive = $interactive; $this->interactive = $interactive;
$this->charLevel = $level;
$x = '<table><tr>'; $x = '<table><tr>';
@@ -1884,7 +1902,7 @@ class SpellList extends BaseType
$x .= '<table><tr><td>'; $x .= '<table><tr><td>';
// parse Buff-Text // parse Buff-Text
$btt = $this->parseText('buff', $level, $this->interactive, $scaling); $btt = $this->parseText('buff');
$x .= $btt[0].'<br>'; $x .= $btt[0].'<br>';
// duration // duration
@@ -1894,7 +1912,7 @@ class SpellList extends BaseType
$x .= '</td></tr></table>'; $x .= '</td></tr></table>';
// scaling information - spellId:min:max:curr // scaling information - spellId:min:max:curr
$x .= '<!--?'.$this->id.':1:'.($scaling ? MAX_LEVEL : 1).':'.$level.'-->'; $x .= '<!--?'.$this->id.':1:'.($this->scaling[$this->id] ? MAX_LEVEL : 1).':'.$this->charLevel.'-->';
return [$x, Util::parseHtmlText($btt[1])]; return [$x, Util::parseHtmlText($btt[1])];
} }
@@ -1905,11 +1923,12 @@ class SpellList extends BaseType
return ['', []]; return ['', []];
$this->interactive = $interactive; $this->interactive = $interactive;
$this->charLevel = $level;
// fetch needed texts // fetch needed texts
$name = $this->getField('name', true); $name = $this->getField('name', true);
$rank = $this->getField('rank', true); $rank = $this->getField('rank', true);
$desc = $this->parseText('description', $level, $this->interactive, $scaling); $desc = $this->parseText('description');
$tools = $this->getToolsForCurrent(); $tools = $this->getToolsForCurrent();
$cool = $this->createCooldownForCurrent(); $cool = $this->createCooldownForCurrent();
$cast = $this->createCastTimeForCurrent(); $cast = $this->createCastTimeForCurrent();
@@ -2043,7 +2062,7 @@ class SpellList extends BaseType
$x .= '<table><tr><td>'.implode('<br />', $xTmp).'</td></tr></table>'; $x .= '<table><tr><td>'.implode('<br />', $xTmp).'</td></tr></table>';
// scaling information - spellId:min:max:curr // scaling information - spellId:min:max:curr
$x .= '<!--?'.$this->id.':1:'.($scaling ? MAX_LEVEL : 1).':'.$level.'-->'; $x .= '<!--?'.$this->id.':1:'.($this->scaling[$this->id] ? MAX_LEVEL : 1).':'.$this->charLevel.'-->';
return [$x, Util::parseHtmlText($desc[1])]; return [$x, Util::parseHtmlText($desc[1])];
} }

View File

@@ -1852,6 +1852,13 @@ $WH.Tooltip = {
Slider.setSize(tooltip.slider, m - 6); Slider.setSize(tooltip.slider, m - 6);
tooltip.className += ' tooltip-slider'; tooltip.className += ' tooltip-slider';
} }
// btt<typeId> empty, try to find tt<typeId>
else if (tt = $WH.ge(tooltip.id.substr(1))) { // aowow - added for spells with buff, but w/o tooltip
if (tt.slider) {
Slider.setSize(tt.slider, tt.offsetWidth - 6);
tooltip.className += ' tooltip-slider';
}
}
if (!noShrink && tooltip.offsetHeight > document.body.clientHeight) { if (!noShrink && tooltip.offsetHeight > document.body.clientHeight) {
table.className = 'shrink'; table.className = 'shrink';

View File

@@ -1,16 +1,16 @@
<div id="ic<?php echo $this->typeId; ?>" style="float: left"></div> <div id="ic<?=$this->typeId; ?>" style="float: left"></div>
<div id="tt<?php echo $this->typeId; ?>" class="wowhead-tooltip" style="float: left; padding-top: 1px"></div> <div id="tt<?=$this->typeId; ?>" class="wowhead-tooltip" style="float: left; padding-top: 1px"></div>
<div style="clear: left"></div> <div style="clear: left"></div>
<div id="sl<?php echo $this->typeId; ?>" style="margin-left: 70px; margin-top: 4px;"></div> <div id="sl<?=$this->typeId; ?>" style="margin-left: 70px; margin-top: 4px;"></div>
<div id="ks<?php echo $this->typeId; ?>" style="margin-left: 70px; margin-top: 4px;"></div> <div id="ks<?=$this->typeId; ?>" style="margin-left: 70px; margin-top: 4px;"></div>
<?php <?php
$hasBuff = !empty($this->jsGlobals[6][2][$this->typeId]['buff']); // not set with items $hasBuff = !empty($this->jsGlobals[Type::SPELL][2][$this->typeId]['buff']); // not set with items
if ($hasBuff): if ($hasBuff):
?> ?>
<h3><?php echo Lang::spell('_aura'); ?></h3> <h3><?php echo Lang::spell('_aura'); ?></h3>
<div id="btt<?php echo $this->typeId; ?>" class="wowhead-tooltip"></div> <div id="btt<?=$this->typeId; ?>" class="wowhead-tooltip"></div>
<?php <?php
endif; endif;
@@ -23,19 +23,22 @@ endif;
?> ?>
<script type="text/javascript">//<![CDATA[ <script type="text/javascript">//<![CDATA[
$WH.ge('ic<?php echo $this->typeId; ?>').appendChild(Icon.create('<?php echo $this->headIcons[0]; ?>', 2, null, 0, <?php echo $this->headIcons[1]; ?>)); $WH.ge('ic<?=$this->typeId; ?>').appendChild(Icon.create('<?php echo $this->headIcons[0]; ?>', 2, null, 0, <?php echo $this->headIcons[1]; ?>));
var var
tt = $WH.ge('tt<?php echo $this->typeId; ?>'), tt = $WH.ge('tt<?=$this->typeId; ?>'),
<?php if ($hasBuff): ?> <?php if ($hasBuff): ?>
btt = $WH.ge('btt<?php echo $this->typeId; ?>'), btt = $WH.ge('btt<?=$this->typeId; ?>'),
<?php endif; ?>
sl = $WH.ge('sl<?=$this->typeId; ?>'),
ks = $WH.ge('ks<?=$this->typeId; ?>');
tt.innerHTML = '<table><tr><td>' + ($WH.g_enhanceTooltip.bind(tt))(<?=$this->typeId; ?>, true, true, sl, null, [<?=$this->typeId; ?>], ks) + '</td><th style="background-position: top right"></th></tr><tr><th style="background-position: bottom left"></th><th style="background-position: bottom right"></th></tr></table>';
<?php if ($hasBuff): ?>
btt.innerHTML = '<table><tr><td>' + ($WH.g_enhanceTooltip.bind(btt))(<?=$this->typeId; ?>, true, true, sl, tt, [<?=$this->typeId; ?>], ks) + '</td><th style="background-position: top right"></th></tr><tr><th style="background-position: bottom left"></th><th style="background-position: bottom right"></th></tr></table>';
<?php endif; ?> <?php endif; ?>
sl = $WH.ge('sl<?php echo $this->typeId; ?>'),
ks = $WH.ge('ks<?php echo $this->typeId; ?>');
tt.innerHTML = '<table><tr><td>' + ($WH.g_enhanceTooltip.bind(tt))(<?php echo $this->typeId; ?>, true, true, sl, null, [<?php echo $this->typeId; ?>], ks, null) + '</td><th style="background-position: top right"></th></tr><tr><th style="background-position: bottom left"></th><th style="background-position: bottom right"></th></tr></table>';
$WH.Tooltip.fixSafe(tt, 1, 1); $WH.Tooltip.fixSafe(tt, 1, 1);
<?php if ($hasBuff): ?> <?php if ($hasBuff): ?>
btt.innerHTML = '<table><tr><td>' + ($WH.g_enhanceTooltip.bind(btt))(<?php echo $this->typeId; ?>, true, true, sl, tt, [<?php echo $this->typeId; ?>], ks) + '</td><th style="background-position: top right"></th></tr><tr><th style="background-position: bottom left"></th><th style="background-position: bottom right"></th></tr></table>';
$WH.Tooltip.fixSafe(btt, 1, 1); $WH.Tooltip.fixSafe(btt, 1, 1);
<?php endif; ?> <?php endif; ?>
//]]></script> //]]></script>