forked from mirror/openmw-tes3mp
New API functions: MessageBox, CustomMessageBox, InputDialog
New Callback: OnGUIActioncoverity_scan^2
parent
78b1511b5e
commit
9ab77cb123
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Created by koncord on 23.07.16.
|
||||
//
|
||||
|
||||
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
||||
#include <apps/openmw-mp/Networking.hpp>
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
|
||||
|
||||
|
||||
void ScriptFunctions::MessageBox(unsigned short pid, int id, const char *label) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player,);
|
||||
|
||||
player->guiMessageBox.id = id;
|
||||
player->guiMessageBox.label = label;
|
||||
player->guiMessageBox.type = Player::GUIMessageBox::MessageBox;
|
||||
|
||||
mwmp::Networking::Get().GetController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false);
|
||||
}
|
||||
|
||||
void ScriptFunctions::CustomMessageBox(unsigned short pid, int id, const char *label, const char *buttons) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player,);
|
||||
|
||||
player->guiMessageBox.id = id;
|
||||
player->guiMessageBox.label = label;
|
||||
player->guiMessageBox.buttons = buttons;
|
||||
player->guiMessageBox.type = Player::GUIMessageBox::CustomMessageBox;
|
||||
|
||||
mwmp::Networking::Get().GetController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false);
|
||||
}
|
||||
|
||||
void ScriptFunctions::InputDialog(unsigned short pid, int id, const char *label) noexcept
|
||||
{
|
||||
Player *player;
|
||||
GET_PLAYER(pid, player,);
|
||||
|
||||
player->guiMessageBox.id = id;
|
||||
player->guiMessageBox.label = label;
|
||||
player->guiMessageBox.type = Player::GUIMessageBox::InputDialog;
|
||||
|
||||
mwmp::Networking::Get().GetController()->GetPacket(ID_GUI_MESSAGEBOX)->Send(player, false);
|
||||
}
|
@ -0,0 +1,158 @@
|
||||
//
|
||||
// Created by koncord on 20.07.16.
|
||||
//
|
||||
|
||||
#include <SDL_system.h>
|
||||
#include <MyGUI_InputManager.h>
|
||||
#include <apps/openmw/mwbase/windowmanager.hpp>
|
||||
#include <apps/openmw/mwbase/inputmanager.hpp>
|
||||
#include <apps/openmw/mwbase/environment.hpp>
|
||||
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||
|
||||
|
||||
#include "GUIController.hpp"
|
||||
#include "Main.hpp"
|
||||
|
||||
|
||||
mwmp::GUIController::GUIController(): mInputBox(0)
|
||||
{
|
||||
mChat = nullptr;
|
||||
keySay = SDLK_y;
|
||||
keyChatMode = SDLK_F2;
|
||||
calledMessageBox = false;
|
||||
}
|
||||
|
||||
mwmp::GUIController::~GUIController()
|
||||
{
|
||||
/* if(mChat != nullptr)
|
||||
delete mChat;
|
||||
mChat = nullptr;*/
|
||||
}
|
||||
|
||||
void mwmp::GUIController::setupChat(const Settings::Manager &mgr)
|
||||
{
|
||||
assert(mChat == nullptr);
|
||||
|
||||
float chatDelay = mgr.getFloat("delay", "Chat");
|
||||
int chatY = mgr.getInt("y", "Chat");
|
||||
int chatX = mgr.getInt("x", "Chat");
|
||||
int chatW = mgr.getInt("w", "Chat");
|
||||
int chatH = mgr.getInt("h", "Chat");
|
||||
|
||||
keySay = SDL_GetKeyFromName(mgr.getString("keySay", "Chat").c_str());
|
||||
keyChatMode = SDL_GetKeyFromName(mgr.getString("keyChatMode", "Chat").c_str());
|
||||
|
||||
mChat = new GUIChat(chatX, chatY, chatW, chatH);
|
||||
mChat->SetDelay(chatDelay);
|
||||
}
|
||||
|
||||
void mwmp::GUIController::PrintChatMessage(std::string &msg)
|
||||
{
|
||||
if(mChat != nullptr)
|
||||
mChat->print(msg);
|
||||
}
|
||||
|
||||
|
||||
void mwmp::GUIController::setChatVisible(bool chatVisible)
|
||||
{
|
||||
mChat->setVisible(chatVisible);
|
||||
}
|
||||
|
||||
void mwmp::GUIController::ShowMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox)
|
||||
{
|
||||
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
||||
std::vector<std::string> buttons;
|
||||
buttons.push_back("Ok");
|
||||
windowManager->interactiveMessageBox(guiMessageBox.label, buttons);
|
||||
calledMessageBox = true;
|
||||
}
|
||||
|
||||
std::vector<std::string> splitString(const std::string &str, char delim = ';')
|
||||
{
|
||||
std::istringstream ss(str);
|
||||
std::vector<std::string> result;
|
||||
std::string token;
|
||||
while(std::getline(ss, token, delim))
|
||||
result.push_back(token);
|
||||
return result;
|
||||
}
|
||||
|
||||
void mwmp::GUIController::ShowCustomMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox)
|
||||
{
|
||||
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
||||
std::vector<std::string> buttons = splitString(guiMessageBox.buttons);
|
||||
windowManager->interactiveMessageBox(guiMessageBox.label, buttons);
|
||||
calledMessageBox = true;
|
||||
}
|
||||
|
||||
void mwmp::GUIController::ShowInputBox(const BasePlayer::GUIMessageBox &guiMessageBox)
|
||||
{
|
||||
printf("test adf\n");
|
||||
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
||||
|
||||
windowManager->removeDialog(mInputBox);
|
||||
mInputBox = 0;
|
||||
mInputBox = new MWGui::TextInputDialog();
|
||||
mInputBox->setTextLabel(guiMessageBox.label);
|
||||
mInputBox->eventDone += MyGUI::newDelegate(this, &GUIController::OnInputBoxDone);
|
||||
mInputBox->setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
void mwmp::GUIController::OnInputBoxDone(MWGui::WindowBase *parWindow)
|
||||
{
|
||||
//MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
||||
printf("GUIController::OnInputBoxDone: %s.\n",mInputBox->getTextInput().c_str());
|
||||
|
||||
Main::get().getLocalPlayer()->guiMessageBox.data = mInputBox->getTextInput();
|
||||
Main::get().getNetworking()->GetPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer());
|
||||
|
||||
MWBase::Environment::get().getWindowManager()->removeDialog(mInputBox);
|
||||
mInputBox = 0;
|
||||
}
|
||||
|
||||
bool mwmp::GUIController::pressedKey(int key)
|
||||
{
|
||||
MWBase::WindowManager *windowManager = MWBase::Environment::get().getWindowManager();
|
||||
if(mChat == nullptr || windowManager->getMode() != MWGui::GM_None)
|
||||
return false;
|
||||
if(key == keyChatMode)
|
||||
{
|
||||
mChat->PressedChatMode();
|
||||
return true;
|
||||
}
|
||||
else if(key == keySay)
|
||||
{
|
||||
//MyGUI::Widget *oldFocus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
|
||||
mChat->PressedSay();
|
||||
/*MyGUI::Widget *newFocus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
|
||||
printf("mwmp::GUIController::pressedKey. oldFocus: %s.\n", oldFocus ? oldFocus->getName().c_str() : "nil");
|
||||
printf("mwmp::GUIController::pressedKey.newFocus: %s.\n", newFocus ? newFocus->getName().c_str() : "nil");*/
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool mwmp::GUIController::HaveFocusedElement()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void mwmp::GUIController::update(float dt)
|
||||
{
|
||||
if(mChat != nullptr)
|
||||
mChat->Update(dt);
|
||||
|
||||
int pressedButton = MWBase::Environment::get().getWindowManager()->readPressedButton();
|
||||
if(pressedButton != -1 && calledMessageBox)
|
||||
{
|
||||
printf("Pressed: %d\n", pressedButton);
|
||||
calledMessageBox = false;
|
||||
Main::get().getLocalPlayer()->guiMessageBox.data = MyGUI::utility::toString(pressedButton);
|
||||
Main::get().getNetworking()->GetPacket(ID_GUI_MESSAGEBOX)->Send(Main::get().getLocalPlayer());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
//
|
||||
// Created by koncord on 20.07.16.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_GUICONTROLLER_HPP
|
||||
#define OPENMW_GUICONTROLLER_HPP
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
#include <apps/openmw/mwgui/textinput.hpp>
|
||||
#include <components/openmw-mp/Base/BasePlayer.hpp>
|
||||
#include "GUIChat.hpp"
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class GUIController
|
||||
{
|
||||
public:
|
||||
GUIController();
|
||||
~GUIController();
|
||||
void setupChat(const Settings::Manager &manager);
|
||||
|
||||
void PrintChatMessage(std::string &msg);
|
||||
void setChatVisible(bool chatVisible);
|
||||
|
||||
void ShowMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox);
|
||||
void ShowCustomMessageBox(const BasePlayer::GUIMessageBox &guiMessageBox);
|
||||
void ShowInputBox(const BasePlayer::GUIMessageBox &guiMessageBox);
|
||||
|
||||
/// Return true if any tes3mp gui element in active state
|
||||
bool HaveFocusedElement();
|
||||
/// Returns 0 if there was no events
|
||||
bool pressedKey(int key);
|
||||
|
||||
void update(float dt);
|
||||
|
||||
private:
|
||||
GUIChat *mChat;
|
||||
int keySay;
|
||||
int keyChatMode;
|
||||
|
||||
long id;
|
||||
bool calledMessageBox;
|
||||
MWGui::TextInputDialog *mInputBox;
|
||||
void OnInputBoxDone(MWGui::WindowBase* parWindow);
|
||||
//MyGUI::Widget *oldFocusWidget, *currentFocusWidget;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_GUICONTROLLER_HPP
|
@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by koncord on 23.07.16.
|
||||
//
|
||||
|
||||
#include "PacketGUIBoxes.hpp"
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
|
||||
using namespace mwmp;
|
||||
|
||||
PacketGUIBoxes::PacketGUIBoxes(RakNet::RakPeerInterface *peer) : BasePacket(peer)
|
||||
{
|
||||
packetID = ID_GUI_MESSAGEBOX;
|
||||
}
|
||||
|
||||
void PacketGUIBoxes::Packet(RakNet::BitStream *bs, BasePlayer *player, bool send)
|
||||
{
|
||||
BasePacket::Packet(bs, player, send);
|
||||
|
||||
RW(player->guiMessageBox.id, send);
|
||||
RW(player->guiMessageBox.type, send);
|
||||
RW(player->guiMessageBox.label, send);
|
||||
|
||||
RW(player->guiMessageBox.data, send);
|
||||
|
||||
if(player->guiMessageBox.type == BasePlayer::GUIMessageBox::CustomMessageBox)
|
||||
RW(player->guiMessageBox.buttons, send);
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// Created by koncord on 23.07.16.
|
||||
//
|
||||
|
||||
#ifndef OPENMW_PACKETGUIBOXES_HPP
|
||||
#define OPENMW_PACKETGUIBOXES_HPP
|
||||
|
||||
|
||||
#include <components/openmw-mp/Packets/BasePacket.hpp>
|
||||
|
||||
namespace mwmp
|
||||
{
|
||||
class PacketGUIBoxes : public BasePacket
|
||||
{
|
||||
public:
|
||||
PacketGUIBoxes(RakNet::RakPeerInterface *peer);
|
||||
|
||||
virtual void Packet(RakNet::BitStream *bs, BasePlayer *player, bool send);
|
||||
};
|
||||
}
|
||||
|
||||
#endif //OPENMW_PACKETGUIBOXES_HPP
|
Loading…
Reference in New Issue