Spells/Reagents

* fix reagents listing and spell tooltips for nonexistent reagents
This commit is contained in:
Sarjuuk 2025-10-27 17:02:30 +01:00
parent e8bc37f82f
commit 9741774683
4 changed files with 29 additions and 18 deletions

View file

@ -1384,10 +1384,9 @@ class SpellBaseResponse extends TemplateResponse implements ICache
if (!$reagents)
return;
foreach ($this->subject->relItems->iterate() as $iId => $__)
foreach ($reagents as [$iId, $num])
{
if (!in_array($iId, array_keys($reagents)))
continue;
$relItem = $this->subject->relItems->getEntry($iId);
$data = array(
'path' => Type::ITEM.'-'.$iId, // id of the html-element
@ -1396,11 +1395,12 @@ class SpellBaseResponse extends TemplateResponse implements ICache
'typeStr' => Type::getFileString(Type::ITEM),
'icon' => new IconElement(
Type::ITEM,
$iId,
$this->subject->relItems->getField('name', true),
$reagents[$iId][1],
quality: $this->subject->relItems->getField('quality'),
is_null($relItem) ? 0 : $iId,
is_null($relItem) ? 'Item #'.$iId : $this->subject->relItems->getField('name', true),
$num,
quality: $relItem['quality'] ?? 'q',
size: IconElement::SIZE_SMALL,
link: !is_null($relItem),
align: 'right',
element: 'iconlist-icon'
)

View file

@ -15,12 +15,12 @@ class IconElement
private const CREATE_ICON_TPL = "\$WH.ge('%s%d').appendChild(%s.createIcon(%s));\n";
private int $idx = 0;
private string $href = '';
private bool $noIcon = false;
public readonly string $quality;
public readonly ?string $align;
public readonly ?string $href;
public readonly int $size;
public readonly bool $noIcon;
public function __construct(
public readonly int $type,
@ -70,6 +70,8 @@ class IconElement
if ($link || $url)
$this->href = $url ?: '?'.Type::getFileString($this->type).'='.$this->typeId;
else
$this->href = null;
// see Spell/Tools having icon container but no actual icon and having to be inline with other IconElements
$this->noIcon = !$typeId || !Type::hasIcon($type);

View file

@ -1839,8 +1839,13 @@ class SpellList extends DBTypeList
// get reagents
$reagents = $this->getReagentsForCurrent();
foreach ($reagents as &$r)
$r[2] = ItemList::getName($r[0]);
foreach ($reagents as $k => $r)
{
if ($item = $this->relItems->getEntry($r[0]))
$reagents[$k] += [2 => new LocString($item), 3 => true];
else
$reagents[$k] += [2 => 'Item #'.$r[0], 3 => false];
}
$reagents = array_reverse($reagents);
@ -1940,11 +1945,11 @@ class SpellList extends DBTypeList
if ($reagents)
{
$_ = Lang::spell('reagents').':<br/><div class="indent q1">';
while ($reagent = array_pop($reagents))
while ([$iId, $qty, $text, $exists] = array_pop($reagents))
{
$_ .= '<a href="?item='.$reagent[0].'">'.$reagent[2].'</a>';
if ($reagent[1] > 1)
$_ .= ' ('.$reagent[1].')';
$_ .= $exists ? '<a href="?item='.$iId.'">'.$text.'</a>' : $text;
if ($qty > 1)
$_ .= ' ('.$qty.')';
$_ .= empty($reagents) ? '<br />' : ', ';
}

View file

@ -185,8 +185,12 @@ endif;
foreach ($reagents as $k => ['path' => $path, 'level' => $level, 'final' => $final, 'typeStr' => $typeStr, 'icon' => $icon]):
$icon->renderContainer(0, $k); // just to set offset
echo '<tr id="reagent-list-generic.'.$path.'"'.($level ? ' style="display: none"' : '').'><th align="right" id="iconlist-icon'.$k.'"></th>' .
'<td'.($level ? ' style="padding-left: '.$level.'em"' : '').'>';
if ($icon->noIcon):
echo '<tr><th><ul><li><var>&nbsp;</var></li></ul></th><td>';
else:
echo '<tr id="reagent-list-generic.'.$path.'"'.($level ? ' style="display: none"' : '').'><th align="right" id="iconlist-icon'.$k.'"></th>' .
'<td'.($level ? ' style="padding-left: '.$level.'em"' : '').'>';
endif;
if ($final && $enhanced):
echo '<div class="iconlist-tree" style="width: 15px; float: left">&nbsp;</div>';
@ -194,7 +198,7 @@ foreach ($reagents as $k => ['path' => $path, 'level' => $level, 'final' => $fin
echo '<div class="iconlist-tree disclosure-off" onclick="iconlist_showhide(this);" style="padding-left: 0; cursor: pointer; width: 15px; float: left" id="spn.reagent-list-generic.'.$path.'">&nbsp;</div>';
endif;
echo '<span class="'.$icon->quality.'"><a href="?'.$typeStr.'='.$icon->typeId.'">'.$icon->text.'</a></span>'.($icon->num > 1 ? '&nbsp;('.$icon->num.')' : '')."</td></tr>\n";
echo '<span class="'.$icon->quality.'">'.($icon->href ? '<a href="?'.$typeStr.'='.$icon->typeId.'">'.$icon->text.'</a>' : $icon->text).'</span>'.($icon->num > 1 ? '&nbsp;('.$icon->num.')' : '')."</td></tr>\n";
endforeach;
?>
</table>