2013-11-27 16:30:54 +09:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 yvt
|
|
|
|
Portion of the code is based on Serverbrowser.cpp.
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
This file is part of OpenSpades.
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
OpenSpades is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
OpenSpades is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-12-03 18:23:47 +09:00
|
|
|
*/
|
2013-11-27 16:30:54 +09:00
|
|
|
|
|
|
|
#include "ClientUI.h"
|
|
|
|
#include "ClientUIHelper.h"
|
2016-12-03 18:23:47 +09:00
|
|
|
#include "NetClient.h"
|
2013-11-27 16:30:54 +09:00
|
|
|
#include <Client/Client.h>
|
2016-12-03 18:23:47 +09:00
|
|
|
#include <Client/FontData.h>
|
2016-12-16 05:05:23 +09:00
|
|
|
#include <Client/Fonts.h>
|
2016-12-03 18:23:47 +09:00
|
|
|
#include <Core/Exception.h>
|
2013-11-27 16:30:54 +09:00
|
|
|
#include <Core/Settings.h>
|
2015-01-24 12:44:57 +09:00
|
|
|
#include <ScriptBindings/Config.h>
|
2016-12-03 18:23:47 +09:00
|
|
|
#include <ScriptBindings/ScriptFunction.h>
|
2013-11-27 16:30:54 +09:00
|
|
|
|
|
|
|
namespace spades {
|
|
|
|
namespace client {
|
2016-12-16 05:05:23 +09:00
|
|
|
ClientUI::ClientUI(IRenderer *r, IAudioDevice *a, FontManager *fontManager, Client *client)
|
|
|
|
: renderer(r), audioDevice(a), fontManager(fontManager), client(client) {
|
2013-11-27 16:30:54 +09:00
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (r == NULL)
|
2013-11-27 16:30:54 +09:00
|
|
|
SPInvalidArgument("r");
|
2016-12-03 18:23:47 +09:00
|
|
|
if (a == NULL)
|
2013-11-27 16:30:54 +09:00
|
|
|
SPInvalidArgument("a");
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
helper.Set(new ClientUIHelper(this), false);
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2016-12-03 18:23:47 +09:00
|
|
|
static ScriptFunction uiFactory(
|
2016-12-16 05:05:23 +09:00
|
|
|
"ClientUI@ CreateClientUI(Renderer@, AudioDevice@, FontManager@, ClientUIHelper@)");
|
2013-11-27 16:30:54 +09:00
|
|
|
{
|
|
|
|
ScriptContextHandle ctx = uiFactory.Prepare();
|
|
|
|
ctx->SetArgObject(0, renderer);
|
|
|
|
ctx->SetArgObject(1, audioDevice);
|
2016-12-16 05:05:23 +09:00
|
|
|
ctx->SetArgObject(2, fontManager);
|
2013-11-27 16:30:54 +09:00
|
|
|
ctx->SetArgObject(3, &*helper);
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
ctx.ExecuteChecked();
|
|
|
|
ui = reinterpret_cast<asIScriptObject *>(ctx->GetReturnObject());
|
|
|
|
}
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
|
|
|
ClientUI::~ClientUI() {
|
2013-11-27 16:30:54 +09:00
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
helper->ClientUIDestroyed();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
|
|
|
void ClientUI::SendChat(const std::string &msg, bool isGlobal) {
|
|
|
|
if (!client)
|
|
|
|
return;
|
2013-12-02 19:42:38 +09:00
|
|
|
client->net->SendChat(msg, isGlobal);
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2014-04-01 02:18:28 +09:00
|
|
|
void ClientUI::AlertNotice(const std::string &msg) {
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!client)
|
|
|
|
return;
|
2014-04-01 02:18:28 +09:00
|
|
|
client->ShowAlert(msg, Client::AlertType::Notice);
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2014-04-01 02:18:28 +09:00
|
|
|
void ClientUI::AlertWarning(const std::string &msg) {
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!client)
|
|
|
|
return;
|
2014-04-01 02:18:28 +09:00
|
|
|
client->ShowAlert(msg, Client::AlertType::Warning);
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2014-04-01 02:18:28 +09:00
|
|
|
void ClientUI::AlertError(const std::string &msg) {
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!client)
|
|
|
|
return;
|
2014-04-01 02:18:28 +09:00
|
|
|
client->ShowAlert(msg, Client::AlertType::Error);
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
|
|
|
void ClientUI::ClientDestroyed() { client = NULL; }
|
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
void ClientUI::MouseEvent(float x, float y) {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-11-27 16:30:54 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-11-27 16:30:54 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void MouseEvent(float, float)");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c->SetArgFloat(0, x);
|
|
|
|
c->SetArgFloat(1, y);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-12-09 17:36:05 +09:00
|
|
|
void ClientUI::WheelEvent(float x, float y) {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-12-09 17:36:05 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-09 17:36:05 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void WheelEvent(float, float)");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c->SetArgFloat(0, x);
|
|
|
|
c->SetArgFloat(1, y);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
|
|
|
void ClientUI::KeyEvent(const std::string &key, bool down) {
|
2013-11-27 16:30:54 +09:00
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-11-27 16:30:54 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-11-27 16:30:54 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void KeyEvent(string, bool)");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
std::string k = key;
|
|
|
|
c->SetObject(&*ui);
|
2016-12-03 18:23:47 +09:00
|
|
|
c->SetArgObject(0, reinterpret_cast<void *>(&k));
|
2013-11-27 16:30:54 +09:00
|
|
|
c->SetArgByte(1, down ? 1 : 0);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-12-09 17:36:05 +09:00
|
|
|
void ClientUI::TextInputEvent(const std::string &ch) {
|
2013-11-27 16:30:54 +09:00
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-11-27 16:30:54 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-09 17:36:05 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void TextInputEvent(string)");
|
2013-11-27 16:30:54 +09:00
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
std::string k = ch;
|
|
|
|
c->SetObject(&*ui);
|
2016-12-03 18:23:47 +09:00
|
|
|
c->SetArgObject(0, reinterpret_cast<void *>(&k));
|
2013-11-27 16:30:54 +09:00
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
|
|
|
void ClientUI::TextEditingEvent(const std::string &ch, int start, int len) {
|
2013-12-09 17:36:05 +09:00
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-12-09 17:36:05 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-09 17:36:05 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void TextEditingEvent(string,int,int)");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
std::string k = ch;
|
|
|
|
c->SetObject(&*ui);
|
2016-12-03 18:23:47 +09:00
|
|
|
c->SetArgObject(0, reinterpret_cast<void *>(&k));
|
2013-12-09 17:36:05 +09:00
|
|
|
c->SetArgDWord(1, static_cast<asDWORD>(start));
|
|
|
|
c->SetArgDWord(2, static_cast<asDWORD>(len));
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-12-09 17:36:05 +09:00
|
|
|
bool ClientUI::AcceptsTextInput() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-12-09 17:36:05 +09:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-09 17:36:05 +09:00
|
|
|
static ScriptFunction func("ClientUI", "bool AcceptsTextInput()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
return c->GetReturnByte() != 0;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-12-09 17:36:05 +09:00
|
|
|
AABB2 ClientUI::GetTextInputRect() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-12-09 17:36:05 +09:00
|
|
|
return AABB2();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-09 17:36:05 +09:00
|
|
|
static ScriptFunction func("ClientUI", "AABB2 GetTextInputRect()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
2016-12-03 18:23:47 +09:00
|
|
|
return *reinterpret_cast<AABB2 *>(c->GetReturnObject());
|
2013-12-09 17:36:05 +09:00
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
bool ClientUI::WantsClientToBeClosed() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-11-27 16:30:54 +09:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-11-27 16:30:54 +09:00
|
|
|
static ScriptFunction func("ClientUI", "bool WantsClientToBeClosed()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
return c->GetReturnByte() != 0;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
bool ClientUI::NeedsInput() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-11-27 16:30:54 +09:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-11-27 16:30:54 +09:00
|
|
|
static ScriptFunction func("ClientUI", "bool NeedsInput()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
return c->GetReturnByte() != 0;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
void ClientUI::RunFrame(float dt) {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-11-27 16:30:54 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void RunFrame(float)");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c->SetArgFloat(0, dt);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
void ClientUI::Closing() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-11-27 16:30:54 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-11-27 16:30:54 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void Closing()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
|
|
|
void ClientUI::RecordChatLog(const std::string &msg, Vector4 color) {
|
2013-12-31 16:29:10 +09:00
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-12-31 16:29:10 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-31 16:29:10 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void RecordChatLog(string, Vector4)");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
std::string k = msg;
|
|
|
|
c->SetObject(&*ui);
|
2016-12-03 18:23:47 +09:00
|
|
|
c->SetArgObject(0, reinterpret_cast<void *>(&k));
|
|
|
|
c->SetArgObject(1, reinterpret_cast<void *>(&color));
|
2013-12-31 16:29:10 +09:00
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
void ClientUI::EnterClientMenu() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-11-27 16:30:54 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-11-27 16:30:54 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void EnterClientMenu()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2013-12-02 19:42:38 +09:00
|
|
|
void ClientUI::EnterGlobalChatWindow() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-12-02 19:42:38 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-02 19:42:38 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void EnterGlobalChatWindow()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
|
|
|
void ClientUI::EnterTeamChatWindow() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-12-02 19:42:38 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-02 19:42:38 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void EnterTeamChatWindow()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
|
|
|
void ClientUI::EnterCommandWindow() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-12-02 19:42:38 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-02 19:42:38 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void EnterCommandWindow()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
|
|
|
void ClientUI::CloseUI() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
2016-12-03 18:23:47 +09:00
|
|
|
if (!ui) {
|
2013-12-02 19:42:38 +09:00
|
|
|
return;
|
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-12-02 19:42:38 +09:00
|
|
|
static ScriptFunction func("ClientUI", "void CloseUI()");
|
|
|
|
ScriptContextHandle c = func.Prepare();
|
|
|
|
c->SetObject(&*ui);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
2014-03-09 14:32:45 +01:00
|
|
|
|
2016-12-03 18:23:47 +09:00
|
|
|
bool ClientUI::isIgnored(const std::string &key) {
|
|
|
|
return !ignoreInput.empty() && EqualsIgnoringCase(ignoreInput, key);
|
2014-03-09 14:32:45 +01:00
|
|
|
}
|
2016-12-03 18:23:47 +09:00
|
|
|
void ClientUI::setIgnored(const std::string &key) { ignoreInput = key; }
|
2013-11-27 16:30:54 +09:00
|
|
|
}
|
|
|
|
}
|