Tooltips/TimeFMT

* use strings from globalstrings.lua to format time in item and spell tooltips
 * fixed item filter ItemCooldown
 * fixed timeAgo format
 * move item duration to correct position in tooltip
This commit is contained in:
Sarjuuk
2023-03-18 21:30:55 +01:00
parent 6ee0d63766
commit d77e459da3
11 changed files with 273 additions and 40 deletions

View File

@@ -942,7 +942,7 @@ abstract class Filter
public function getExtraCols()
{
return $this->formData['extraCols'];
return array_unique($this->formData['extraCols']);
}
public function getSetCriteria()

View File

@@ -604,16 +604,6 @@ class ItemList extends BaseType
$x .= '<br />'.sprintf(Lang::item($limit['isGem'] ? 'uniqueEquipped' : 'unique', 2), Util::localizedString($limit, 'name'), $limit['count']);
}
// max duration
if ($dur = $this->curTpl['duration'])
{
$rt = '';
if ($this->curTpl['flagsCustom'] & 0x1)
$rt = $interactive ? ' ('.sprintf(Util::$dfnString, 'LANG.tooltip_realduration', Lang::item('realTime')).')' : ' ('.Lang::item('realTime').')';
$x .= "<br />".Lang::game('duration').Lang::main('colon').Util::formatTime(abs($dur) * 1000).$rt;
}
// required holiday
if ($eId = $this->curTpl['eventId'])
if ($hName = DB::Aowow()->selectRow('SELECT h.* FROM ?_holidays h JOIN ?_events e ON e.holidayId = h.id WHERE e.id = ?d', $eId))
@@ -875,6 +865,16 @@ class ItemList extends BaseType
if ($dur = $this->curTpl['durability'])
$x .= sprintf(Lang::item('durability'), $dur, $dur).'<br />';
// max duration
if ($dur = $this->curTpl['duration'])
{
$rt = '';
if ($this->curTpl['flagsCustom'] & 0x1)
$rt = $interactive ? ' ('.sprintf(Util::$dfnString, 'LANG.tooltip_realduration', Lang::item('realTime')).')' : ' ('.Lang::item('realTime').')';
$x .= Lang::formatTime(abs($dur) * 1000, 'item', 'duration').$rt."<br />";
}
$jsg = [];
// required classes
if ($classes = Lang::getClassString($this->curTpl['requiredClass'], $jsg))
@@ -959,12 +959,18 @@ class ItemList extends BaseType
$extra = [];
if ($cd >= 5000)
$extra[] = Lang::game('cooldown', [Util::formatTime($cd, true)]);
{
$pt = Util::parseTime($cd);
if (count(array_filter($pt)) == 1) // simple time: use simple method
$extra[] = Lang::formatTime($cd, 'item', 'cooldown');
else // build block with generic time
$extra[] = Lang::item('cooldown', 0, [Lang::formatTime($cd, 'game', 'timeAbbrev', true)]);
}
if ($this->curTpl['spellTrigger'.$j] == 2)
if ($ppm = $this->curTpl['spellppmRate'.$j])
$extra[] = Lang::spell('ppm', [$ppm]);
$itemSpellsAndTrigger[$this->curTpl['spellId'.$j]] = [$this->curTpl['spellTrigger'.$j], $extra ? ' ('.implode(', ', $extra).')' : ''];
$itemSpellsAndTrigger[$this->curTpl['spellId'.$j]] = [$this->curTpl['spellTrigger'.$j], $extra ? ' '.implode(', ', $extra) : ''];
}
}
@@ -2437,7 +2443,7 @@ class ItemListFilter extends Filter
$cr[2] *= 1000; // field supplied in milliseconds
$this->formData['extraCols'][] = $cr[0];
$this->extraOpts['is']['s'][] = ', IF(spellCooldown1 > 1, spellCooldown1, IF(spellCooldown2 > 1, spellCooldown2, IF(spellCooldown3 > 1, spellCooldown3, IF(spellCooldown4 > 1, spellCooldown4, IF(spellCooldown5 > 1, spellCooldown5,))))) AS cooldown';
$this->extraOpts['is']['s'][] = ', GREATEST(spellCooldown1, spellCooldown2, spellCooldown3, spellCooldown4, spellCooldown5) AS cooldown';
return [
'OR',

View File

@@ -1123,10 +1123,7 @@ class SpellList extends BaseType
case 'D': // todo (med): min/max?; /w unit?
$base = $srcSpell->getField('duration');
if ($base <= 0)
$result[2] = Lang::spell('untilCanceled');
else
$result[2] = Util::formatTime($base, true);
$result[2] = Lang::formatTime($srcSpell->getField('duration'), 'spell', 'duration');
if (in_array($op, $signs) && is_numeric($oparg) && is_numeric($base))
eval("\$base = $base $op $oparg;");
@@ -1907,7 +1904,7 @@ class SpellList extends BaseType
// duration
if ($this->curTpl['duration'] > 0)
$x .= '<span class="q">'.sprintf(Lang::spell('remaining'), Util::formatTime($this->curTpl['duration'])).'<span>';
$x .= '<span class="q">'.Lang::formatTime($this->curTpl['duration'], 'spell', 'timeRemaining').'<span>';
$x .= '</td></tr></table>';

View File

@@ -573,7 +573,7 @@ abstract class Util
return $money;
}
private static function parseTime(int $msec) : array
public static function parseTime(int $msec) : array
{
$time = [0, 0, 0, 0, 0];
@@ -671,7 +671,7 @@ abstract class Util
else if ($h) // hours, minutes ago
return Lang::main('timeAgo', [$h . ' ' . Lang::timeUnits('ab', 4) . ' ' . $m . ' ' . Lang::timeUnits('ab', 5)]);
else if ($m) // minutes, seconds ago
return Lang::main('timeAgo', [$m . ' ' . Lang::timeUnits('ab', 5) . ' ' . $m . ' ' . Lang::timeUnits('ab', 6)]);
return Lang::main('timeAgo', [$m . ' ' . Lang::timeUnits('ab', 5) . ' ' . $s . ' ' . Lang::timeUnits('ab', 6)]);
else // seconds ago
return Lang::main('timeAgo', [$s . ' ' . Lang::timeUnits($s == 1 ? 'sg' : 'pl', 6)]);
}