Allow text box widget to listen enter event
This commit is contained in:
parent
b72cf4f406
commit
a33a9a040b
@ -63,7 +63,14 @@ public:
|
||||
m_listeners[n].onTextUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Key == IRR_KEY_RETURN)
|
||||
{
|
||||
for (unsigned int n=0; n<m_listeners.size(); n++)
|
||||
{
|
||||
if (m_listeners[n].onEnterPressed(Text))
|
||||
Text = L"";
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,7 @@ namespace GUIEngine
|
||||
public:
|
||||
virtual ~ITextBoxWidgetListener() {}
|
||||
virtual void onTextUpdated() = 0;
|
||||
virtual bool onEnterPressed(const irr::core::stringw& text) { return false; }
|
||||
};
|
||||
|
||||
/** \brief A text field widget.
|
||||
|
@ -23,12 +23,12 @@
|
||||
#include "config/player_manager.hpp"
|
||||
#include "guiengine/CGUISpriteBank.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "guiengine/widgets/CGUIEditBox.hpp"
|
||||
#include "guiengine/widgets/button_widget.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
#include "guiengine/widgets/list_widget.hpp"
|
||||
#include "guiengine/widgets/ribbon_widget.hpp"
|
||||
#include "guiengine/widgets/text_box_widget.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
@ -136,6 +136,7 @@ void NetworkingLobby::init()
|
||||
input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||
PlayerProfile* profile = PlayerManager::getCurrentPlayer();
|
||||
StateManager::get()->createActivePlayer(profile, device);
|
||||
m_chat_box->addListener(this);
|
||||
} // init
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -240,6 +241,29 @@ void NetworkingLobby::onUpdate(float delta)
|
||||
|
||||
} // onUpdate
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void NetworkingLobby::sendChat(irr::core::stringw text)
|
||||
{
|
||||
// Max 80 words
|
||||
text = text.subString(0, 80).trim();
|
||||
if (text.size() > 0)
|
||||
{
|
||||
NetworkString chat(PROTOCOL_LOBBY_ROOM);
|
||||
chat.addUInt8(LobbyProtocol::LE_CHAT);
|
||||
|
||||
core::stringw name;
|
||||
PlayerProfile* player = PlayerManager::getCurrentPlayer();
|
||||
if (PlayerManager::getCurrentOnlineState() ==
|
||||
PlayerProfile::OS_SIGNED_IN)
|
||||
name = PlayerManager::getCurrentOnlineUserName();
|
||||
else
|
||||
name = player->getName();
|
||||
chat.encodeString(name + L": " + text);
|
||||
|
||||
STKHost::get()->sendToServer(&chat, true);
|
||||
}
|
||||
} // sendChat
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void NetworkingLobby::eventCallback(Widget* widget, const std::string& name,
|
||||
const int playerID)
|
||||
@ -263,25 +287,7 @@ void NetworkingLobby::eventCallback(Widget* widget, const std::string& name,
|
||||
} // click on a user
|
||||
else if (name == m_send_button->m_properties[PROP_ID])
|
||||
{
|
||||
core::stringw text = m_chat_box->getText();
|
||||
// Max 80 words
|
||||
text = text.subString(0, 80).trim();
|
||||
if (text.size() > 0)
|
||||
{
|
||||
NetworkString chat(PROTOCOL_LOBBY_ROOM);
|
||||
chat.addUInt8(LobbyProtocol::LE_CHAT);
|
||||
|
||||
core::stringw name;
|
||||
PlayerProfile* player = PlayerManager::getCurrentPlayer();
|
||||
if (PlayerManager::getCurrentOnlineState() ==
|
||||
PlayerProfile::OS_SIGNED_IN)
|
||||
name = PlayerManager::getCurrentOnlineUserName();
|
||||
else
|
||||
name = player->getName();
|
||||
chat.encodeString(name + L": " + text);
|
||||
|
||||
STKHost::get()->sendToServer(&chat, true);
|
||||
}
|
||||
sendChat(m_chat_box->getText());
|
||||
m_chat_box->setText("");
|
||||
} // send chat message
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define HEADER_NETWORKING_LOBBY_HPP
|
||||
|
||||
#include "guiengine/screen.hpp"
|
||||
#include "guiengine/widgets/text_box_widget.hpp"
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
@ -46,7 +47,8 @@ namespace irr
|
||||
* \ingroup states_screens
|
||||
*/
|
||||
class NetworkingLobby : public GUIEngine::Screen,
|
||||
public GUIEngine::ScreenSingleton<NetworkingLobby>
|
||||
public GUIEngine::ScreenSingleton<NetworkingLobby>,
|
||||
public GUIEngine::ITextBoxWidgetListener
|
||||
{
|
||||
private:
|
||||
friend class GUIEngine::ScreenSingleton<NetworkingLobby>;
|
||||
@ -70,6 +72,15 @@ private:
|
||||
/** \brief implement optional callback from parent class GUIEngine::Screen */
|
||||
virtual void unloaded();
|
||||
|
||||
virtual void onTextUpdated() {}
|
||||
virtual bool onEnterPressed(const irr::core::stringw& text) OVERRIDE
|
||||
{
|
||||
sendChat(text);
|
||||
return true;
|
||||
}
|
||||
|
||||
void sendChat(irr::core::stringw text);
|
||||
|
||||
public:
|
||||
|
||||
virtual void onUpdate(float delta) OVERRIDE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user