void ShortcutBar::refresh() { DEBUG("Refreshing shortcut bar..."); m_shortcutContainer->SetInnerRML(""); for (int i = 0; i < PlayerData::SHORTCUT_BAR_SIZE; ++i) { const Shortcut& shortcut = m_playerData.getShortcut(i); const Usable* usable = shortcut.usableType == Shortcut::UsableType::ITEM ? static_cast<const Usable*>(m_metadata.getItem(shortcut.usableId)) : static_cast<const Usable*>(m_metadata.getSkill(shortcut.usableId)); Rocket::Core::Element* shortcutElement = m_shortcutBarDocument->CreateElement("div"); Rocket::Core::ElementAttributes shortcutElementAttributes; shortcutElementAttributes.Set("class", "shortcut"); if(usable != nullptr) { if (shortcut.usableType == Shortcut::UsableType::ITEM) { DEBUG("Adding shortcut for item %d", shortcut.usableId); shortcutElementAttributes.Set("itemId", static_cast<int>(shortcut.usableId)); } else { DEBUG("Adding shortcut for skill %d", shortcut.usableId); shortcutElementAttributes.Set("skillId", static_cast<int>(shortcut.usableId)); shortcutElementAttributes.Set("characterId", shortcut.characterId.c_str()); } Rocket::Core::String shortcutIconPath("../../"); shortcutIconPath += usable->getIconPath().c_str(); Rocket::Core::Element* shortcutIconElement = m_shortcutBarDocument->CreateElement("img"); Rocket::Core::ElementAttributes shortcutIconElementAttributes; shortcutIconElementAttributes.Set("src", shortcutIconPath); shortcutIconElementAttributes.Set("class", "shortcutIcon"); if (shortcut.usableType == Shortcut::UsableType::ITEM) { const Rocket::Core::String shortcutQuantity(8, "%d", m_playerData.getInventory()->getItemQuantity(shortcut.usableId)); Rocket::Core::Element* shortcutQuantityElement = m_shortcutBarDocument->CreateElement("span"); shortcutQuantityElement->SetInnerRML(shortcutQuantity); shortcutQuantityElement->SetAttribute("class", "shortcutQuantity"); shortcutElement->AppendChild(shortcutQuantityElement); } shortcutIconElement->SetAttributes(&shortcutIconElementAttributes); shortcutElement->AppendChild(shortcutIconElement); } shortcutElement->SetAttributes(&shortcutElementAttributes); m_shortcutContainer->AppendChild(shortcutElement); } }
// Adds a brand-new item into this inventory. void Inventory::AddItem(const Rocket::Core::String& name) { if (document == NULL) return; Rocket::Core::Element* content = document->GetElementById("content"); if (content == NULL) return; // Create the new 'icon' element. Rocket::Core::Element* icon = Rocket::Core::Factory::InstanceElement(content, "icon", "icon", Rocket::Core::XMLAttributes()); icon->SetInnerRML(name); content->AppendChild(icon); // Release the initial reference on the element now that the document has it. icon->RemoveReference(); }