|
|
@ -30,129 +30,100 @@ GUI::GUI(Player *player): BaseMgr(player)
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::processUpdate()
|
|
|
|
void GUI::processUpdate()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
player->guiMessageBox = guiQueue.front().first;
|
|
|
|
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX);
|
|
|
|
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GUI_MESSAGEBOX);
|
|
|
|
packet->setPlayer(player);
|
|
|
|
packet->setPlayer(player);
|
|
|
|
packet->Send(false);
|
|
|
|
packet->Send(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int GUI::generateGuiId()
|
|
|
|
uint64_t GUI::generateGuiId()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int id = 0;
|
|
|
|
return RakNet::RakPeerInterface::Get64BitUniqueRandomNumber();
|
|
|
|
|
|
|
|
|
|
|
|
for (const auto &item: callbacks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (item.second == nullptr)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
id = item.first;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (id == 0)
|
|
|
|
|
|
|
|
id = lastGuiId++;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::messageBox(sol::function fn, const char *label, sol::this_environment te)
|
|
|
|
void GUI::messageBox(sol::function fn, const char *label, sol::this_environment te)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(fn.valid())
|
|
|
|
mwmp::BasePlayer::GUIMessageBox mbox;
|
|
|
|
{
|
|
|
|
|
|
|
|
int id = generateGuiId();
|
|
|
|
|
|
|
|
callbacks[id] = std::make_shared<sol::function>(fn);
|
|
|
|
|
|
|
|
player->guiMessageBox.id = id;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
player->guiMessageBox.id = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
player->guiMessageBox.label = label;
|
|
|
|
mbox.id = generateGuiId();
|
|
|
|
player->guiMessageBox.type = Player::GUIMessageBox::Type::MessageBox;
|
|
|
|
mbox.label = label;
|
|
|
|
|
|
|
|
mbox.type = Player::GUIMessageBox::Type::MessageBox;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guiQueue.emplace(std::move(mbox), std::move(fn));
|
|
|
|
|
|
|
|
|
|
|
|
setChanged();
|
|
|
|
setChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::customMessageBox(sol::function fn, const char *label, const char *buttons, sol::this_environment te)
|
|
|
|
void GUI::customMessageBox(sol::function fn, const char *label, const char *buttons, sol::this_environment te)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(fn.valid())
|
|
|
|
mwmp::BasePlayer::GUIMessageBox mbox;
|
|
|
|
{
|
|
|
|
mbox.id = generateGuiId();
|
|
|
|
int id = generateGuiId();
|
|
|
|
mbox.label = label;
|
|
|
|
callbacks[id] = std::make_shared<sol::function>(fn);
|
|
|
|
mbox.buttons = buttons;
|
|
|
|
player->guiMessageBox.id = id;
|
|
|
|
mbox.type = Player::GUIMessageBox::Type::CustomMessageBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
player->guiMessageBox.id = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
player->guiMessageBox.label = label;
|
|
|
|
guiQueue.emplace(std::move(mbox), std::move(fn));
|
|
|
|
player->guiMessageBox.buttons = buttons;
|
|
|
|
|
|
|
|
player->guiMessageBox.type = Player::GUIMessageBox::Type::CustomMessageBox;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setChanged();
|
|
|
|
setChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::inputDialog(sol::function fn, const char *label, sol::this_environment te)
|
|
|
|
void GUI::inputDialog(sol::function fn, const char *label, sol::this_environment te)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(fn.valid())
|
|
|
|
mwmp::BasePlayer::GUIMessageBox mbox;
|
|
|
|
{
|
|
|
|
|
|
|
|
int id = generateGuiId();
|
|
|
|
mbox.id = generateGuiId();
|
|
|
|
callbacks[id] = std::make_shared<sol::function>(fn);
|
|
|
|
mbox.label = label;
|
|
|
|
player->guiMessageBox.id = id;
|
|
|
|
mbox.type = Player::GUIMessageBox::Type::InputDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
player->guiMessageBox.id = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
player->guiMessageBox.label = label;
|
|
|
|
guiQueue.emplace(std::move(mbox), std::move(fn));
|
|
|
|
player->guiMessageBox.type = Player::GUIMessageBox::Type::InputDialog;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setChanged();
|
|
|
|
setChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::passwordDialog(sol::function fn, const char *label, const char *note, sol::this_environment te)
|
|
|
|
void GUI::passwordDialog(sol::function fn, const char *label, const char *note, sol::this_environment te)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(fn.valid())
|
|
|
|
mwmp::BasePlayer::GUIMessageBox mbox;
|
|
|
|
{
|
|
|
|
|
|
|
|
int id = generateGuiId();
|
|
|
|
|
|
|
|
callbacks[id] = std::make_shared<sol::function>(fn);
|
|
|
|
|
|
|
|
player->guiMessageBox.id = id;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
player->guiMessageBox.id = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
player->guiMessageBox.label = label;
|
|
|
|
mbox.id = generateGuiId();
|
|
|
|
player->guiMessageBox.note = note;
|
|
|
|
mbox.label = label;
|
|
|
|
player->guiMessageBox.type = Player::GUIMessageBox::Type::PasswordDialog;
|
|
|
|
mbox.note = note;
|
|
|
|
|
|
|
|
mbox.type = Player::GUIMessageBox::Type::PasswordDialog;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guiQueue.emplace(std::move(mbox), std::move(fn));
|
|
|
|
|
|
|
|
|
|
|
|
setChanged();
|
|
|
|
setChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::listBox(sol::function fn, const char *label, const char *items, sol::this_environment te)
|
|
|
|
void GUI::listBox(sol::function fn, const char *label, const char *items, sol::this_environment te)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(fn.valid())
|
|
|
|
mwmp::BasePlayer::GUIMessageBox mbox;
|
|
|
|
{
|
|
|
|
|
|
|
|
int id = generateGuiId();
|
|
|
|
mbox.id = generateGuiId();
|
|
|
|
callbacks[id] = std::make_shared<sol::function>(fn);
|
|
|
|
|
|
|
|
player->guiMessageBox.id = id;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
player->guiMessageBox.id = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
player->guiMessageBox.label = label;
|
|
|
|
mbox.label = label;
|
|
|
|
player->guiMessageBox.data = items;
|
|
|
|
mbox.data = items;
|
|
|
|
player->guiMessageBox.type = Player::GUIMessageBox::Type::ListBox;
|
|
|
|
mbox.type = Player::GUIMessageBox::Type::ListBox;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guiQueue.emplace(std::move(mbox), std::move(fn));
|
|
|
|
|
|
|
|
|
|
|
|
setChanged();
|
|
|
|
setChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::onGUIAction()
|
|
|
|
void GUI::onGUIAction()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(player->guiMessageBox.id == -1)
|
|
|
|
auto mbox = std::move(guiQueue.front().first);
|
|
|
|
return;
|
|
|
|
auto callback = std::move(guiQueue.front().second);
|
|
|
|
|
|
|
|
guiQueue.pop();
|
|
|
|
auto it = callbacks.find(player->guiMessageBox.id);
|
|
|
|
if(!guiQueue.empty())
|
|
|
|
if (it != callbacks.end() && it->second != nullptr)
|
|
|
|
setChanged();
|
|
|
|
|
|
|
|
if(player->guiMessageBox.id != mbox.id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
it->second->call(player, player->guiMessageBox.data);
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Wrong MessageBox id from %s(%d).", player->npc.mName, player->getId());
|
|
|
|
it->second = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (callback.valid())
|
|
|
|
|
|
|
|
callback.call(player, player->guiMessageBox.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::setMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state)
|
|
|
|
void GUI::setMapVisibility(unsigned short targetPID, unsigned short affectedPID, unsigned short state)
|
|
|
|