Inventory.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include "Inventory.h"
  2. #include <Rocket/Core/Factory.h>
  3. // Constructs a new inventory and opens its window.
  4. Inventory::Inventory(const Rocket::Core::String& title, const Rocket::Core::Vector2f& position, Rocket::Core::Context* context)
  5. {
  6. document = context->LoadDocument("data/inventory.rml");
  7. if (document != NULL)
  8. {
  9. document->GetElementById("title")->SetInnerRML(title);
  10. document->SetProperty(Rocket::Core::PropertyId::Left, Rocket::Core::Property(position.x, Rocket::Core::Property::PX));
  11. document->SetProperty(Rocket::Core::PropertyId::Top, Rocket::Core::Property(position.y, Rocket::Core::Property::PX));
  12. document->Show();
  13. }
  14. }
  15. // Destroys the inventory and closes its window.
  16. Inventory::~Inventory()
  17. {
  18. if (document != NULL)
  19. {
  20. document->RemoveReference();
  21. document->Close();
  22. }
  23. }
  24. // Adds a brand-new item into this inventory.
  25. void Inventory::AddItem(const Rocket::Core::String& name)
  26. {
  27. if (document == NULL)
  28. return;
  29. Rocket::Core::Element* content = document->GetElementById("content");
  30. if (content == NULL)
  31. return;
  32. // Create the new 'icon' element.
  33. Rocket::Core::Element* icon = Rocket::Core::Factory::InstanceElement(content, "icon", "icon", Rocket::Core::XMLAttributes());
  34. icon->SetInnerRML(name);
  35. content->AppendChild(icon);
  36. // Release the initial reference on the element now that the document has it.
  37. icon->RemoveReference();
  38. }