Exemplo n.º 1
0
void MainMenu::processMultiplayer(Rocket::Core::Event& event)
{
    std::random_device device;
    std::mt19937 rand(device());
    std::uniform_int_distribution<> distribution(0, INT_MAX);

    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();
    if (id == "back") {
        m_mainMenuMultiplayer->Hide();
    } else if (id == "host") {
        Rocket::Core::Element* playerNameInput = m_mainMenuMultiplayerHost->GetElementById("playerName");
        //HACK: pick a random useless name
        std::stringstream ss;
        ss << "Player";
        ss << distribution(rand);

        playerNameInput->SetAttribute("value", ss.str().c_str());

        m_mainMenuMultiplayerHost->Show();
    } else if (id == "join") {
        Rocket::Core::Element* playerNameInput = m_mainMenuMultiplayerJoin->GetElementById("playerName");
        //HACK: pick a random useless name
        std::stringstream ss;
        ss << "Player";
        ss << distribution(rand);

        playerNameInput->SetAttribute("value", ss.str().c_str());

        m_mainMenuMultiplayerJoin->Show();
    }
}
Exemplo n.º 2
0
void MainMenu::processSingleplayer(Rocket::Core::Event& event)
{
    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();
    //just at the singleplayer sub menu
    if (id == "create") {
        // FIXME: populate the singleplayer create with values from settings
        Rocket::Core::Element* playerNameInput = m_mainMenuSingleplayerCreate->GetElementById("playerName");
        //HACK: pick a random useless name
        std::stringstream ss;
        ss << "Player";
        std::random_device device;
        std::mt19937 rand(device());
        std::uniform_int_distribution<> distribution(0, INT_MAX);

        ss << distribution(rand);

        playerNameInput->SetAttribute("value", ss.str().c_str());

        m_mainMenuSingleplayerCreate->Show();
    } else if (id == "load") {
        m_mainMenuSingleplayerLoad->Show();
    } else if (id == "back") {
        m_mainMenuSingleplayer->Hide();
    }
}
UiObjectQuantityPicker::UiObjectQuantityPicker(WindowFramework* window, Rocket::Core::Context* context, const Inventory& inventory, const InventoryObject* object) : UiBase(window, context)
{
  _max_quantity = inventory.ContainsHowMany(object->GetName());
  root         = context->LoadDocument("data/object_quantity_picker.rml");
  if (root)
  {
    Rocket::Core::Element* icon = root->GetElementById("item_icon");

    _line_edit  = root->GetElementById("item_quantity");
    if (_line_edit)
    {
      ToggleEventListener(true, "button_confirm", "click", EventAccepted);
      EventAccepted.EventReceived.Connect(*this, &UiObjectQuantityPicker::Accepted);
    }
    if (icon)
    {
      Rocket::Core::String src("../textures/itemIcons/");

      src += object->GetIcon().c_str();
      icon->SetAttribute("src", src);
    }
    ToggleEventListener(true, "item_minus",    "click",  EventIncrement);
    ToggleEventListener(true, "item_plus",     "click",  EventIncrement);
    ToggleEventListener(true, "item_quantity", "change", EventValueChanged);
    ToggleEventListener(true, "button_cancel", "click",  EventCanceled);
    EventIncrement.EventReceived.Connect(*this, &UiObjectQuantityPicker::Increment);
    EventValueChanged.EventReceived.Connect([this](Rocket::Core::Event&) { SetQuantity(GetQuantity()); });
    EventCanceled.EventReceived.Connect(    [this](Rocket::Core::Event&) { Canceled.Emit();            });
    Canceled.Connect(*this, &UiBase::Hide);
    SetModal(true);
  }
}
Exemplo n.º 4
0
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);
   }
}
Exemplo n.º 5
0
void InteractMenu::MouseButton(Rocket::Core::Event& event)
{
    ExecuteForButtonId(event, [this](Rocket::Core::Event& event, const string& event_type, Interactions::Interaction* interaction) -> bool
    {
        bool                   mouse_over = event_type == "mousedown";
        Rocket::Core::Element* img        = event.GetCurrentElement()->GetChild(0);
        string                 id         = event.GetCurrentElement()->GetId().CString();
        string                 src        = "../textures/buttons/" + id + '-' + (mouse_over ? "pressed" : "normal") + ".png";

        img->SetAttribute("src", src.c_str());
        return (true);
    });
}
Exemplo n.º 6
0
void Rocket_SetAttribute( const char *name, const char *id, const char *attribute, const char *value )
{
    if ( ( !*name && !*id ) && activeElement )
    {
        activeElement->SetAttribute( attribute, value );
    }

    else
    {
        Rocket::Core::ElementDocument *document = name[0] ? menuContext->GetDocument( name ) : menuContext->GetFocusElement()->GetOwnerDocument();

        if ( document )
        {
            Rocket::Core::Element *element = document->GetElementById( id );

            if ( element )
            {
                element->SetAttribute( attribute, value );
            }
        }
    }
}