Ejemplo n.º 1
0
					virtual void ProcessEvent(Rocket::Core::Event& event)
					{
						if(event.GetCurrentElement()->GetId() == "loadForm")
						{
							LevelSelector::GetInstance().OnLoadButtonClick();
						}
						else if(event.GetCurrentElement()->GetId() == "quitForm")
						{
							LevelSelector::GetInstance().OnQuitButtonClick();
						}
					}
Ejemplo n.º 2
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);
    });
}
Ejemplo n.º 3
0
void EventHandlerHighScore::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
	if (value == "add_score")
	{
		int score = GameDetails::GetScore();
		if (score > 0)
		{
			// Submit the score the player just got to the high scores chart.
			HighScores::SubmitScore(GameDetails::GetDefenderColour(), GameDetails::GetWave(), GameDetails::GetScore());
			// Reset the score so the chart won't get confused next time we enter.
			GameDetails::ResetScore();
		}
	}
	else if (value == "enter_name")
	{
		if (event.GetParameter< int >("key_identifier", Rocket::Core::Input::KI_UNKNOWN) == Rocket::Core::Input::KI_RETURN)
		{
			Rocket::Core::String name = event.GetCurrentElement()->GetAttribute< Rocket::Core::String >("value", "Anon.");
			HighScores::SubmitName(name);
		}
	}
	else if (value == "check_input")
	{
		Rocket::Core::Element* name_input_field = event.GetTargetElement()->GetElementById("player_input");
		if (name_input_field)
		{
			name_input_field->Focus();
		}
	}
	else if (value == "check_name")
	{
		/* TODO: Check if the player hasn't set their name first. */
		HighScores::SubmitName("Anon.");
	}
}
Ejemplo n.º 4
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();
    }
}
Ejemplo n.º 5
0
void MainMenu::processSingleplayerLoad(Rocket::Core::Event& event)
{
    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();
    if (id == "back") {
        m_mainMenuSingleplayerLoad->Hide();
    }
}
Ejemplo n.º 6
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();
    }
}
Ejemplo n.º 7
0
void Console::ProcessEvent(Rocket::Core::Event& event)
{
    String controlId(event.GetCurrentElement()->GetId().CString());
    if (controlId == "cmd")
    {
        int key = event.GetParameters()->Get<int>("key_identifier", 0);
        Rocket::Controls::ElementFormControl* inputBox =
            static_cast<Rocket::Controls::ElementFormControl*>(event.GetCurrentElement());
        if (key == Rocket::Core::Input::KI_RETURN)
        {
            String command = inputBox->GetValue().CString();
            inputBox->SetValue("");
            Execute(command);
        }
    }
}
void UiObjectQuantityPicker::Increment(Rocket::Core::Event& event)
{
  const short                           value_change = (event.GetCurrentElement()->GetId() == "item_plus" ? 1 : -1);
  const unsigned short                  quantity     = GetQuantity();

  if (quantity > 0 || value_change != -1)
    SetQuantity(quantity + value_change);
}
Ejemplo n.º 9
0
void MainMenu::processSingleplayerCreate(Rocket::Core::Event& event)
{
    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();
    if (id == "back") {
        m_mainMenuSingleplayerCreate->Hide();
    } else if (id == "start") {
        Rocket::Core::Element* playerNameInput = m_mainMenuSingleplayerCreate->GetElementById("playerName");
        Rocket::Core::String playerName = playerNameInput->GetAttribute("value")->Get<Rocket::Core::String>();
        hideSubmenus();
        m_client->startSinglePlayer(playerName.CString());
    }
}
Ejemplo n.º 10
0
					void ProcessEvent(Rocket::Core::Event& event)
					{
						if(event.GetType() == "rowadd")
						{						
							Rocket::Controls::ElementDataGrid *dataGrid = dynamic_cast<Rocket::Controls::ElementDataGrid*>(event.GetCurrentElement());

							for(int i = 0, len = dataGrid->GetNumRows();i < len; ++i)
							{
								Rocket::Controls::ElementDataGridRow *row = dataGrid->GetRow(i);

								//Remove to make sure we did not add it twice
								row->RemoveEventListener("click", this);
								row->RemoveEventListener("dblclick", this);
								row->AddEventListener("click", this);
								row->AddEventListener("dblclick", this);
							}
						}
						else if(event.GetType() == "click")
						{
							this->SetSelectedRow(event.GetCurrentElement());
						}
						else if(event.GetType() == "dblclick")
						{
							this->SetSelectedRow(event.GetCurrentElement());
						}
						/*
						else if(event.GetType() == "keydown")
						{
							Rocket::Controls::ElementDataGrid *dataGrid = dynamic_cast<Rocket::Controls::ElementDataGrid*>(event.GetCurrentElement());
							if(dataGrid->GetNumRows() == 0)
									return;

							if(pclSelectedRow == NULL)
							{
								event.GetParameter<int>("key_identifier", 
								this->SetSelectedRow(dataGrid->GetRow(0));
							}
						}*/
					}
Ejemplo n.º 11
0
void InteractMenu::ButtonClicked(Rocket::Core::Event& event)
{
    if (_done) return;
    for (unsigned int i = 0 ; i < _listeners.size() ; ++i)
    {
        if (event.GetCurrentElement()->GetId() == _listeners[i]->name.c_str())
        {
            _listeners[i]->signal->Emit(_listeners[i]->instance);
            _done = true;
            Done.Emit();
            break ;
        }
    }
}
Ejemplo n.º 12
0
void MainMenu::processMainMenu(Rocket::Core::Event& event)
{
    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();
    if (id == "singleplayer") {
        m_mainMenuSingleplayer->Show();
    } else if (id == "multiplayer") {
        m_mainMenuMultiplayer->Show();
    } else if (id == "options") {
        showOptionsDialog();
    } else if (id == "quit") {
        // no prompt needed for save, no active connection.
        m_client->shutdown();
    }
}
Ejemplo n.º 13
0
void InteractMenu::ExecuteForButtonId(Rocket::Core::Event& event, std::function<bool (Rocket::Core::Event&, const std::string&, Interactions::Interaction*)> callback)
{
    if (!_done)
    {
        string id         = event.GetCurrentElement()->GetId().CString();
        string event_type = event.GetType().CString();

        for (unsigned int i = 0 ; i < _listeners.size() ; ++i)
        {
            if (id == _listeners[i]->name && (callback(event, event_type, _listeners[i])))
                break ;
        }
    }
}
Ejemplo n.º 14
0
void MainMenu::processEscapeMenu(Rocket::Core::Event& event)
{
    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();

    if (id == "resume") {
        hideEscapeMenu();
    } else if (id == "disconnect") {
        m_client->disconnect();
    } else if (id == "options") {
        showOptionsDialog();
    } else if (id == "quit") {
        //FIXME: prompt dialog to disconnect, as we clearly are connected.
        m_client->shutdown();
    }
}
Ejemplo n.º 15
0
void MainMenu::processMultiplayerHost(Rocket::Core::Event& event)
{
    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();
    if (id == "back") {
        m_mainMenuMultiplayerHost->Hide();
    } if (id == "host") {
        Rocket::Core::Element* playerNameInput = m_mainMenuMultiplayerHost->GetElementById("playerName");
        Rocket::Core::String playerName = playerNameInput->GetAttribute("value")->Get<Rocket::Core::String>();
        Rocket::Core::Element* portInput = m_mainMenuMultiplayerHost->GetElementById("port");
        Rocket::Core::String port = portInput->GetAttribute("value")->Get<Rocket::Core::String>();

        hideSubmenus();

        m_client->startMultiplayerHost(playerName.CString(), atoi(port.CString()));
    }
}
Ejemplo n.º 16
0
void DragListener::ProcessEvent(Rocket::Core::Event& event)
{
	if (event == "dragdrop")
	{
		Rocket::Core::Element* dest_container = event.GetCurrentElement();
		Rocket::Core::Element* dest_element = event.GetTargetElement();
		Rocket::Core::Element* drag_element = static_cast< Rocket::Core::Element* >(event.GetParameter< void* >("drag_element", NULL));

		if (dest_container == dest_element)
		{
			// The dragged element was dragged directly onto a container.
			drag_element->GetParentNode()->RemoveChild(drag_element);
			dest_container->AppendChild(drag_element);
		}
		else
		{
			// The dragged element was dragged onto an item inside a container. In order to get the
			// element in the right place, it will be inserted into the container before the item
			// it was dragged on top of.
			Rocket::Core::Element* insert_before = dest_element;

			// Unless of course if it was dragged on top of an item in its own container; we need
			// to check then if it was moved up or down with the container.
			if (drag_element->GetParentNode() == dest_container)
			{
				// Check whether we're moving this icon from the left or the right.

				Rocket::Core::Element* previous_icon = insert_before->GetPreviousSibling();
				while (previous_icon != NULL)
				{
					if (previous_icon == drag_element)
					{
						insert_before = insert_before->GetNextSibling();
						break;
					}

					previous_icon = previous_icon->GetPreviousSibling();
				}
			}

			drag_element->GetParentNode()->RemoveChild(drag_element);
			dest_container->InsertBefore(drag_element, insert_before);
		}
	}
}
Ejemplo n.º 17
0
void MainMenu::ProcessEvent(Rocket::Core::Event& event)
{
    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();

    //process submenus first since those are on top, obviously..
    if (m_mainMenuSingleplayerCreate->IsVisible()) {
        processSingleplayerCreate(event);
        return;
    } else if (m_mainMenuSingleplayerLoad->IsVisible()) {
        processSingleplayerLoad(event);
        return;
    }

    if (m_mainMenuSingleplayer->IsVisible()) {
        processSingleplayer(event);
        return;
    }

    if (m_mainMenuMultiplayerHost->IsVisible()) {
        processMultiplayerHost(event);
        return;
    }

    if (m_mainMenuMultiplayerJoin->IsVisible()) {
        processMultiplayerJoin(event);
        return;
    }

    // process parent/non-submenus
    if (m_mainMenuMultiplayer->IsVisible()) {
        processMultiplayer(event);
        return;
    }

    if (m_escapeMenu->IsVisible()) {
        //user pressed escape, aka is in game with a connection (either SP or MP)
        processEscapeMenu(event);
        return;
    }

    if (m_menu->IsVisible()) {
        processMainMenu(event);
        return;
    }
}
Ejemplo n.º 18
0
void InventoryView::ProcessEvent(Rocket::Core::Event& event)
{
  if (event == "dragdrop")
  {
    Rocket::Core::Element* drag_element   = static_cast<Rocket::Core::Element*>(event.GetParameter< void* >("drag_element", NULL));

    if (drag_element->GetParentNode() != &_element)
      ObjectDropped.Emit(this, drag_element);
  }
  else
  {
    Rocket::Core::Element* currentElement = event.GetCurrentElement();
    InventoryObject*       object         = GetObjectFromId(currentElement->GetId().CString());

    if (event == "dblclick")
      ObjectSelected.Emit(object);
    else if (event == "mouseover")
      ObjectFocused.Emit(object);
  }
}
Ejemplo n.º 19
0
void MainMenu::processMultiplayerJoin(Rocket::Core::Event& event)
{
    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();
    if (id == "back") {
        m_mainMenuMultiplayerJoin->Hide();
    } else if (id == "join") {
        Rocket::Core::Element* playerNameInput = m_mainMenuMultiplayerJoin->GetElementById("playerName");
        Rocket::Core::String playerName = playerNameInput->GetAttribute("value")->Get<Rocket::Core::String>();
        Rocket::Core::Element* ipInput = m_mainMenuMultiplayerJoin->GetElementById("ip");
        Rocket::Core::String ip = ipInput->GetAttribute("value")->Get<Rocket::Core::String>();
        Rocket::Core::Element* portInput = m_mainMenuMultiplayerJoin->GetElementById("port");
        Rocket::Core::String port = portInput->GetAttribute("value")->Get<Rocket::Core::String>();

        Debug::log(Debug::Area::NetworkClientInitialArea) << "joining multiplayer session with player: " << playerName.CString() << " ip: " << ip.CString() << " port: " << atoi(port.CString());

        if (m_client->startMultiplayerClientConnection(playerName.CString(), ip.CString(), atoi(port.CString()))) {
            hideSubmenus();
        } else {
            //failure
        }
    }
}
Ejemplo n.º 20
0
void RocketMenuPlugin::ProcessEvent(Rocket::Core::Event& event) {
    Rocket::Core::Element *element = event.GetCurrentElement();

    if (event.GetType() == "click") {
        if (element->GetTagName() == "ftr") {
            SetNextItemValue(element->GetParentNode()->GetParentNode());
            event.StopPropagation();
        } else if (element->GetTagName() == "hdr") {
            SetPreviousItemValue(element->GetParentNode()->GetParentNode());
            event.StopPropagation();
        } else {
            DoItemAction(ItemActionEnter, element);
        }
    } else if (event.GetType() == "mousemove") {
        if (element->GetTagName() == "div") {
            HighlightItem(element);
        } else if (element->GetTagName() == "key1") {
            Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode();
            SetActiveKeySlot(menu_item, 0);
        } else if (element->GetTagName() == "key2") {
            Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode();
            SetActiveKeySlot(menu_item, 1);
        }
    } else if (event.GetType() == "change") {
        if (m_delegate != NULL && element->GetOwnerDocument()->IsVisible()) {
            Rocket::Core::Element *menu_item = element->GetParentNode()->GetParentNode();
            RangeData *data = GetRangeData(menu_item);
            const Rocket::Core::Dictionary  *p = event.GetParameters();
            float v = p->Get("value")->Get<float>();
            float new_value = data->min + v*(data->max - data->min);
            if (fabs(new_value-data->value) > 0.001f) {
                data->value = new_value;
                m_delegate->DidChangeRangeValue(menu_item, data->value);
            }
        }
    }
}