예제 #1
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.");
	}
}
예제 #2
0
void DebugOverlayHandler::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
    if (value == "load_debug_overlay")
    {   
        gFpsField = event.GetTargetElement()->GetElementById("fps");
        gPos0Field = event.GetTargetElement()->GetElementById("pos0");
        gPos1Field = event.GetTargetElement()->GetElementById("pos1");
    }
}
예제 #3
0
// Processes an event coming through from Rocket.
void EventManager::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
	Rocket::Core::StringList commands;
	Rocket::Core::StringUtilities::ExpandString(commands, value, ';');
	for (size_t i = 0; i < commands.size(); ++i)
	{
		// Check for a generic 'load' or 'exit' command.
		Rocket::Core::StringList values;
		Rocket::Core::StringUtilities::ExpandString(values, commands[i], ' ');

		if (values.empty())
			return;

		if (values[0] == "goto" &&
 			values.size() > 1)
		{
			// Load the window, and if successful close the old window.
			if (LoadWindow(values[1]))
				event.GetTargetElement()->GetOwnerDocument()->Close();
		}
		else if (values[0] == "load" &&
 			values.size() > 1)
		{
			// Load the window.
			LoadWindow(values[1]);
		}
		else if (values[0] == "close")
		{
			Rocket::Core::ElementDocument* target_document = NULL;

			if (values.size() > 1)
				target_document = context->GetDocument(values[1].CString());
			else
				target_document = event.GetTargetElement()->GetOwnerDocument();

			if (target_document != NULL)
				target_document->Close();
		}
		else if (values[0] == "exit")
		{
			Shell::RequestExit();
		}
		else if (values[0] == "pause")
		{
			GameDetails::SetPaused(true);
		}
		else if (values[0] == "unpause")
		{
			GameDetails::SetPaused(false);
		}
		else
		{
			if (event_handler != NULL)
				event_handler->ProcessEvent(event, commands[i]);
		}
	}
}
예제 #4
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();
						}
					}
예제 #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);
    });
}
예제 #6
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 ;
        }
    }
}
예제 #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);
        }
    }
}
예제 #8
0
파일: ShortcutBar.cpp 프로젝트: noam-c/EDEn
void ShortcutBar::shortcutClicked(Rocket::Core::Event& event)
{
   Rocket::Core::Element* shortcutElement = event.GetTargetElement();

   while(shortcutElement != nullptr && shortcutElement->GetParentNode() != m_shortcutContainer)
   {
      shortcutElement = shortcutElement->GetParentNode();
   }

   // Only handle the click if it went to a shortcut
   // (direct child of the shortcut bar container)
   if (shortcutElement != nullptr)
   {
      // Find the index of the shortcut
      int shortcutIndex = 0;

      for(;;)
      {
         shortcutElement = shortcutElement->GetPreviousSibling();
         if (shortcutElement == nullptr) break;
         ++shortcutIndex;
      }

      bool shortcutInvoked = invokeShortcut(shortcutIndex);
      if (shortcutInvoked)
      {
         refresh();
      }
   }
}
예제 #9
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();
    }
}
예제 #10
0
void MainMenu::processSingleplayerLoad(Rocket::Core::Event& event)
{
    const Rocket::Core::String& id = event.GetCurrentElement()->GetId();
    if (id == "back") {
        m_mainMenuSingleplayerLoad->Hide();
    }
}
예제 #11
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();
    }
}
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);
}
예제 #13
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);
		}
	}
}
예제 #14
0
파일: ui_image.cpp 프로젝트: cfr/qfusion
// Regenerates the element's geometry.
void ElementImage::ProcessEvent(Rocket::Core::Event& event)
{
	Element::ProcessEvent(event);

	if (event.GetTargetElement() == this &&
		event == "resize")
	{
		GenerateGeometry();
	}
}
예제 #15
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());
    }
}
void FormSignalListener::ProcessEvent(Rocket::Core::Event& event) {
    const Rocket::Core::Dictionary *d = event.GetParameters();
    UISignalData *data = new UISignalData();
    Rocket::Core::String s;
    Rocket::Core::Variant *v;
    int n;
    while (d->Iterate(n, s, v)) {
        Rocket::Core::String val = v->Get<Rocket::Core::String>();
        data->set(string(s.CString()), string(val.CString()));        
    }

    PyScripting::getInstance()->broadcast(signal_name,{data}, true, true);
}
예제 #17
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));
							}
						}*/
					}
예제 #18
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();
    }
}
예제 #19
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 ;
        }
    }
}
예제 #20
0
파일: chathandler.cpp 프로젝트: ktj007/mmo
void ChatHandler::ProcessEvent(Rocket::Core::Event& event, const Rocket::Core::String& value)
{
    if (value == "load_chat")
    {   
        gChatLogField = event.GetTargetElement()->GetElementById("chatlog");
    }

    if (value == "enter_key")
    {
        if (event.GetParameter< int >("key_identifier", Rocket::Core::Input::KI_UNKNOWN) == Rocket::Core::Input::KI_RETURN)
        {
            DoChat(event);
        }
    }
}
예제 #21
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();
    }
}
예제 #22
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()));
    }
}
예제 #23
0
파일: chathandler.cpp 프로젝트: ktj007/mmo
void ChatHandler::DoChat(Rocket::Core::Event& event)
{
    auto chatline = event.GetTargetElement()->GetElementById("chatline");
    if (chatline)
    {
        auto line = chatline->GetAttribute<Rocket::Core::String>("value", "");
        if (line.Length() > 0)
        {
            cl_player_chat(line.CString());
        }
    }
    else
    {
        // ASSERT
    }
    
}
예제 #24
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;
    }
}
예제 #25
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);
  }
}
예제 #26
0
파일: SaveMenu.cpp 프로젝트: noam-c/EDEn
void SaveMenu::saveGameClicked(Rocket::Core::Event& event)
{
   Rocket::Core::Element* target = event.GetTargetElement();

   // Move up the DOM to the datagridrow item holding this element
   while(target->GetParentNode() != nullptr && target->GetTagName() != "datagridrow")
   {
      target = target->GetParentNode();
   }

   if(target != nullptr)
   {
      // If we found a row element, cast it and get its index
      Rocket::Controls::ElementDataGridRow* rowElement = dynamic_cast<Rocket::Controls::ElementDataGridRow*>(target);
      if(rowElement != nullptr)
      {
         int saveGameIndex = rowElement->GetParentRelativeIndex();
         showConfirmDialog(saveGameIndex);
      }
   }
}
예제 #27
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
        }
    }
}
예제 #28
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);
            }
        }
    }
}
예제 #29
0
void UI_ScriptDocument::ProcessEvent( Rocket::Core::Event &event )
{
	if( event.GetType() == "afterLoad" && event.GetTargetElement() == this ) {
		if( module ) {
			owner = event.GetParameter<void *>( "owner", NULL );

			as->finishBuilding( module );
			as->setModuleUserData( module, owner );
		}

		isLoading = false;

		// handle postponed onload events (HOWTO handle these in cached documents?)
		for( PostponedList::iterator it = onloads.begin(); it != onloads.end(); ++it ) {
			Rocket::Core::Event *load = *it;
			this->DispatchEvent( load->GetType(), *(load->GetParameters()), true );
			load->RemoveReference();
		}

		// and clear the events
		onloads.clear();
		return;
	}

	if( event.GetType() == "beforeUnload" && event.GetTargetElement() == this ) {
		if( module ) {
			// FIXME: destroy script event listeners here somehow!

			// destroy the AS module by name to prevent crashes in case multiple document instances share the same module pointer
			as->buildReset( GetSourceURL().CString() );
			module = NULL;
		}
		return;
	}

	if( isLoading ) {
		Rocket::Core::Event *instanced = Rocket::Core::Factory::InstanceEvent( event.GetTargetElement(),
			event.GetType(), *event.GetParameters(), true );
		onloads.push_back( instanced );
		event.StopPropagation();
		return;
	}

	Rocket::Core::ElementDocument::ProcessEvent( event );
}
예제 #30
0
	void ProcessEvent( Rocket::Core::Event &ev )
	{
		if( ev.GetType() == "change" )
			setCvar( ev.GetTargetElement() );
	}