diff --git a/endpoints/spell/spell.php b/endpoints/spell/spell.php index e4f1a206..67a7e2d0 100644 --- a/endpoints/spell/spell.php +++ b/endpoints/spell/spell.php @@ -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' ) diff --git a/includes/components/frontend/iconelement.class.php b/includes/components/frontend/iconelement.class.php index 435e1a28..6014bd31 100644 --- a/includes/components/frontend/iconelement.class.php +++ b/includes/components/frontend/iconelement.class.php @@ -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); diff --git a/includes/dbtypes/spell.class.php b/includes/dbtypes/spell.class.php index 924c1386..d7e44cd0 100644 --- a/includes/dbtypes/spell.class.php +++ b/includes/dbtypes/spell.class.php @@ -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').':
'; - while ($reagent = array_pop($reagents)) + while ([$iId, $qty, $text, $exists] = array_pop($reagents)) { - $_ .= ''.$reagent[2].''; - if ($reagent[1] > 1) - $_ .= ' ('.$reagent[1].')'; + $_ .= $exists ? ''.$text.'' : $text; + if ($qty > 1) + $_ .= ' ('.$qty.')'; $_ .= empty($reagents) ? '
' : ', '; } diff --git a/template/bricks/reagentList.tpl.php b/template/bricks/reagentList.tpl.php index b512ee44..0bdd4a13 100644 --- a/template/bricks/reagentList.tpl.php +++ b/template/bricks/reagentList.tpl.php @@ -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 '' . - ''; + if ($icon->noIcon): + echo ''; + else: + echo '' . + ''; + endif; if ($final && $enhanced): echo '
 
'; @@ -194,7 +198,7 @@ foreach ($reagents as $k => ['path' => $path, 'level' => $level, 'final' => $fin echo '
 
'; endif; - echo ''.$icon->text.''.($icon->num > 1 ? ' ('.$icon->num.')' : '')."\n"; + echo ''.($icon->href ? ''.$icon->text.'' : $icon->text).''.($icon->num > 1 ? ' ('.$icon->num.')' : '')."\n"; endforeach; ?>