Merge pull request #21 from TES3MP/tes3mp-gui

Tes3mp gui
coverity_scan^2 tes3mp-0.0.1b
Stanislav Zhukov 9 years ago committed by GitHub
commit 4316d4d1bf

@ -50,7 +50,7 @@ set(SERVER
Script/Script.cpp Script/ScriptFunction.cpp
Script/ScriptFunctions.cpp
Script/Functions/Translocations.cpp Script/Functions/Stats.cpp Script/Functions/Items.cpp
Script/Functions/Timer.cpp Script/Functions/Chat.cpp
Script/Functions/Timer.cpp Script/Functions/Chat.cpp Script/Functions/GUI.cpp
Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp
${PawnScript_Sources}
${LuaScript_Sources}

@ -270,6 +270,16 @@ void Networking::Update(RakNet::Packet *packet)
break;
}
case ID_GUI_MESSAGEBOX:
{
DEBUG_PRINTF("ID_GUI_MESSAGEBOX\n");
myPacket->Read(player);
Script::Call<Script::CallbackIdentity("OnGUIAction")>(player->GetID(), (int)player->guiMessageBox.id,
player->guiMessageBox.data.c_str());
break;
}
default:
printf("Message with identifier %i has arrived.\n", packet->data[1]);
break;

@ -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);
}

@ -129,6 +129,10 @@ public:
static void Kick(unsigned short pid) noexcept;
static void MessageBox(unsigned short pid, int id, const char *label) noexcept;
static void CustomMessageBox(unsigned short pid, int id, const char *label, const char *buttons) noexcept;
static void InputDialog(unsigned short pid, int id, const char *label) noexcept;
static constexpr ScriptFunctionData functions[]{
{"CreateTimer", ScriptFunctions::CreateTimer},
{"CreateTimerEx", reinterpret_cast<Function<void>>(ScriptFunctions::CreateTimerEx)},
@ -219,6 +223,9 @@ public:
{"SendMessage", ScriptFunctions::SendMessage},
{"SetCharGenStage", ScriptFunctions::SetCharGenStage},
{"Resurrect", ScriptFunctions::Resurrect},
{"MessageBox", ScriptFunctions::MessageBox},
{"CustomMessageBox", ScriptFunctions::CustomMessageBox},
{"InputDialog", ScriptFunctions::InputDialog},
{"Kick", ScriptFunctions::Kick},
};
@ -234,7 +241,8 @@ public:
{"OnPlayerChangeCell", Function<void, unsigned short>()},
{"OnPlayerUpdateEquiped", Function<void, unsigned short>()},
{"OnPlayerSendMessage", Function<bool, unsigned short, const char*>()},
{"OnPlayerEndCharGen", Function<void, unsigned short>()}
{"OnPlayerEndCharGen", Function<void, unsigned short>()},
{"OnGUIAction", Function<void, unsigned short, int, const char*>()}
};
};

@ -96,7 +96,7 @@ add_openmw_dir (mwbase
inputmanager windowmanager statemanager
)
add_openmw_dir (mwmp DedicatedPlayer LocalPlayer Networking Main GUIChat GUILogin)
add_openmw_dir (mwmp DedicatedPlayer LocalPlayer Networking Main GUIChat GUILogin GUIController)
# Main executable

@ -17,6 +17,8 @@
#include "Networking.hpp"
#include "Main.hpp"
#include "GUIController.hpp"
namespace mwmp
{

@ -22,8 +22,10 @@
namespace mwmp
{
class GUIController;
class GUIChat : public MWGui::WindowBase, public MWGui::ReferenceInterface
{
friend class GUIController;
public:
enum
{

@ -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

@ -26,7 +26,6 @@
#include "DedicatedPlayer.hpp"
#include "LocalPlayer.hpp"
#include "GUIChat.hpp"
using namespace mwmp;
using namespace std;
@ -61,12 +60,11 @@ Main::Main()
std::cout << "Main::Main" << std::endl;
mNetworking = new Networking();
mLocalPlayer = new LocalPlayer();
mGUIController = new GUIController();
//mLocalPlayer->CharGen(0, 4);
server = "mp.tes3mp.com";
port = 25565;
keySay = SDLK_y;
keyChatMode = SDLK_F2;
}
Main::~Main()
@ -74,6 +72,7 @@ Main::~Main()
std::cout << "Main::~Main" << std::endl;
delete mNetworking;
delete mLocalPlayer;
delete mGUIController;
Players::CleanUp();
}
@ -94,17 +93,7 @@ void Main::Create()
pMain->server = mgr.getString("server", "General");
pMain->port = (unsigned short)mgr.getInt("port", "General");
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");
pMain->keySay = SDL_GetKeyFromName(mgr.getString("keySay", "Chat").c_str());
pMain->keyChatMode = SDL_GetKeyFromName(mgr.getString("keyChatMode", "Chat").c_str());
pMain->mChat = new GUIChat(chatX, chatY, chatW, chatH);
pMain->getChatBox()->SetDelay(chatDelay);
pMain->mGUIController->setupChat(mgr);
mgr.mUserSettings = saveUserSettings;
mgr.mDefaultSettings = saveDefaultSettings;
@ -119,7 +108,7 @@ void Main::Destroy()
{
assert(pMain);
delete pMain->mChat;
delete pMain->mGUIController;
delete pMain;
pMain = 0;
@ -138,7 +127,7 @@ void Main::Frame(float dt)
Players::Update(dt);
get().UpdateWorld(dt);
get().getChatBox()->Update(dt);
get().getGUIConroller()->update(dt);
}
@ -160,7 +149,7 @@ void Main::UpdateWorld(float dt) const
mNetworking->Connect(server, port);
player.getClass().getCreatureStats(player).getSpells().add("fireball");
mLocalPlayer->updateBaseStats(true);
mChat->setVisible(true);
get().getGUIConroller()->setChatVisible(true);
}
else
mLocalPlayer->Update();
@ -181,23 +170,15 @@ LocalPlayer *Main::getLocalPlayer() const
return mLocalPlayer;
}
GUIChat *Main::getChatBox() const
{
return mChat;
}
GUILogin *Main::getGUILogin() const
GUIController *Main::getGUIConroller() const
{
return mGUILogin;
return mGUIController;
}
void Main::PressedKey(int key)
{
if(pMain == nullptr || get().getChatBox() == nullptr) return;
if(key == get().keyChatMode)
get().getChatBox()->PressedChatMode();
else if(key == get().keySay)
get().getChatBox()->PressedSay();
if(pMain == nullptr) return;
if(get().getGUIConroller()->pressedKey(key))
return; // if any gui bind pressed
}

@ -1,8 +1,7 @@
#include <apps/openmw/mwworld/ptr.hpp>
#include "Networking.hpp"
#include "LocalPlayer.hpp"
#include "GUIChat.hpp"
#include "GUILogin.hpp"
#include "GUIController.hpp"
namespace mwmp
{
@ -20,8 +19,7 @@ namespace mwmp
Networking *getNetworking() const;
LocalPlayer *getLocalPlayer() const;
GUIChat *getChatBox() const;
GUILogin *getGUILogin() const;
GUIController *getGUIConroller() const;
void UpdateWorld(float dt) const;
@ -34,13 +32,9 @@ namespace mwmp
Networking *mNetworking;
LocalPlayer *mLocalPlayer;
GUIChat *mChat;
GUILogin *mGUILogin;
GUIController *mGUIController;
std::string server;
unsigned short port;
int keySay;
int keyChatMode;
};
}

@ -459,7 +459,7 @@ void Networking::ReciveMessage(RakNet::Packet *packet)
myPacket->Packet(&bsIn, pl, false);
message = *pl->ChatMessage();
}
Main::get().getChatBox()->print(message);
Main::get().getGUIConroller()->PrintChatMessage(message);
break;
}
case ID_GAME_CHARGEN:
@ -530,6 +530,23 @@ void Networking::ReciveMessage(RakNet::Packet *packet)
break;
}
case ID_GUI_MESSAGEBOX:
{
if(id == myid)
{
myPacket->Packet(&bsIn, getLocalPlayer(), false);
printf("ID_GUI_MESSAGEBOX, Type %d, MSG %s\n", getLocalPlayer()->guiMessageBox.type, getLocalPlayer()->guiMessageBox.label.c_str());
if(getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::MessageBox)
Main::get().getGUIConroller()->ShowMessageBox(getLocalPlayer()->guiMessageBox);
else if(getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::CustomMessageBox)
Main::get().getGUIConroller()->ShowCustomMessageBox(getLocalPlayer()->guiMessageBox);
else if(getLocalPlayer()->guiMessageBox.type == BasePlayer::GUIMessageBox::InputDialog)
Main::get().getGUIConroller()->ShowInputBox(getLocalPlayer()->guiMessageBox);
}
break;
}
default:
printf("Custom message with identifier %i has arrived in initialization.\n", packet->data[1]);
}

@ -145,7 +145,7 @@ add_component_dir (openmw-mp
PacketsController
Packets/BasePacket Packets/PacketBaseInfo Packets/PacketPosition Packets/PacketEquiped Packets/PacketAttributesAndStats
Packets/PacketAttack Packets/PacketMainStats Packets/PacketCell Packets/PacketDrawState Packets/PacketChatMessage
Packets/PacketCharGen Packets/PacketAttribute Packets/PacketSkill Packets/PacketHandshake)
Packets/PacketCharGen Packets/PacketAttribute Packets/PacketSkill Packets/PacketHandshake Packets/PacketGUIBoxes)
add_component_dir (fallback
fallback validate

@ -42,6 +42,23 @@ namespace mwmp
int current, end;
};
struct GUIMessageBox
{
int id;
int type;
enum GUI_TYPE
{
MessageBox = 0,
CustomMessageBox,
InputDialog,
PasswordDialog
};
std::string label;
std::string buttons;
std::string data;
};
BasePlayer(RakNet::RakNetGUID guid) : guid(guid)
{
@ -124,6 +141,7 @@ namespace mwmp
return &passw;
}
RakNet::RakNetGUID guid;
GUIMessageBox guiMessageBox;
protected:
ESM::Position pos;

@ -36,7 +36,8 @@ enum MyGameMesages
ID_GAME_SKILL,
ID_GAME_CHARCLASS,
ID_GAME_SKILLPRIORITY,
ID_HANDSHAKE
ID_HANDSHAKE,
ID_GUI_MESSAGEBOX
};

@ -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

@ -19,6 +19,7 @@
#include "Packets/PacketAttribute.hpp"
#include "Packets/PacketSkill.hpp"
#include "Packets/PacketHandshake.hpp"
#include "Packets/PacketGUIBoxes.hpp"
#include "PacketsController.hpp"
@ -46,6 +47,8 @@ mwmp::PacketsController::PacketsController(RakNet::RakPeerInterface *peer)
packetSkill = new PacketSkill(peer);
packetHandshake = new PacketHandshake(peer);
packetGUIBoxes = new PacketGUIBoxes(peer);
}
@ -105,6 +108,9 @@ mwmp::BasePacket *mwmp::PacketsController::GetPacket(RakNet::MessageID id)
case ID_HANDSHAKE:
packet = packetHandshake;
break;
case ID_GUI_MESSAGEBOX:
packet = packetGUIBoxes;
break;
default:
packet = 0;
}
@ -134,4 +140,6 @@ void mwmp::PacketsController::SetStream(RakNet::BitStream *inStream, RakNet::Bit
packetSkill->SetStreams(inStream, outStream);
packetHandshake->SetStreams(inStream, outStream);
packetGUIBoxes->SetStreams(inStream, outStream);
}

@ -32,6 +32,8 @@ namespace mwmp
class PacketSkill;
class PacketHandshake;
class PacketGUIBoxes;
class PacketsController
{
public:
@ -61,6 +63,7 @@ namespace mwmp
PacketAttribute *packetAttribute;
PacketSkill *packetSkill;
PacketHandshake *packetHandshake;
PacketGUIBoxes *packetGUIBoxes;
};
}

Loading…
Cancel
Save