2013-11-27 16:30:54 +09:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 yvt
|
|
|
|
Portion of the code is based on Serverbrowser.cpp.
|
|
|
|
|
|
|
|
This file is part of OpenSpades.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "ClientUI.h"
|
|
|
|
#include <Core/Exception.h>
|
|
|
|
#include <Client/Quake3Font.h>
|
|
|
|
#include <Client/FontData.h>
|
|
|
|
#include <ScriptBindings/ScriptFunction.h>
|
|
|
|
#include "ClientUIHelper.h"
|
|
|
|
#include <Client/Client.h>
|
|
|
|
#include <Core/Settings.h>
|
2013-12-02 19:42:38 +09:00
|
|
|
#include "NetClient.h"
|
2015-01-24 12:44:57 +09:00
|
|
|
#include <ScriptBindings/Config.h>
|
2013-11-27 16:30:54 +09:00
|
|
|
|
|
|
|
namespace spades {
|
|
|
|
namespace client {
|
|
|
|
ClientUI::ClientUI(client::IRenderer *r, client::IAudioDevice *a, IFont *font, Client *client) :
|
|
|
|
renderer(r),
|
|
|
|
audioDevice(a),
|
|
|
|
font(font),client(client){
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(r == NULL)
|
|
|
|
SPInvalidArgument("r");
|
|
|
|
if(a == NULL)
|
|
|
|
SPInvalidArgument("a");
|
|
|
|
|
|
|
|
helper.Set(new ClientUIHelper(this), false);
|
|
|
|
|
2015-01-24 12:44:57 +09:00
|
|
|
ScopedPrivilegeEscalation privilege;
|
2013-11-27 16:30:54 +09:00
|
|
|
static ScriptFunction uiFactory("ClientUI@ CreateClientUI(Renderer@, AudioDevice@, Font@, ClientUIHelper@)");
|
|
|
|
{
|
|
|
|
ScriptContextHandle ctx = uiFactory.Prepare();
|
|
|
|
ctx->SetArgObject(0, renderer);
|
|
|
|
ctx->SetArgObject(1, audioDevice);
|
|
|
|
ctx->SetArgObject(2, font);
|
|
|
|
ctx->SetArgObject(3, &*helper);
|
|
|
|
|
|
|
|
ctx.ExecuteChecked();
|
|
|
|
ui = reinterpret_cast<asIScriptObject *>(ctx->GetReturnObject());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientUI::~ClientUI(){
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
helper->ClientUIDestroyed();
|
|
|
|
}
|
|
|
|
|
2013-12-02 19:42:38 +09:00
|
|
|
void ClientUI::SendChat(const std::string &msg,
|
|
|
|
bool isGlobal) {
|
|
|
|
if(!client) return;
|
|
|
|
client->net->SendChat(msg, isGlobal);
|
|
|
|
}
|
|
|
|
|
2014-04-01 02:18:28 +09:00
|
|
|
void ClientUI::AlertNotice(const std::string &msg) {
|
|
|
|
if(!client) return;
|
|
|
|
client->ShowAlert(msg, Client::AlertType::Notice);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientUI::AlertWarning(const std::string &msg) {
|
|
|
|
if(!client) return;
|
|
|
|
client->ShowAlert(msg, Client::AlertType::Warning);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientUI::AlertError(const std::string &msg) {
|
|
|
|
if(!client) return;
|
|
|
|
client->ShowAlert(msg, Client::AlertType::Error);
|
|
|
|
}
|
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
void ClientUI::ClientDestroyed() {
|
|
|
|
client = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientUI::MouseEvent(float x, float y) {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:36:05 +09:00
|
|
|
void ClientUI::WheelEvent(float x, float y) {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
void ClientUI::KeyEvent(const std::string & key, bool down) {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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);
|
|
|
|
c->SetArgObject(0, reinterpret_cast<void*>(&k));
|
|
|
|
c->SetArgByte(1, down ? 1 : 0);
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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);
|
|
|
|
c->SetArgObject(0, reinterpret_cast<void*>(&k));
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:36:05 +09:00
|
|
|
void ClientUI::TextEditingEvent(const std::string &ch,
|
|
|
|
int start, int len) {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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);
|
|
|
|
c->SetArgObject(0, reinterpret_cast<void*>(&k));
|
|
|
|
c->SetArgDWord(1, static_cast<asDWORD>(start));
|
|
|
|
c->SetArgDWord(2, static_cast<asDWORD>(len));
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientUI::AcceptsTextInput() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return false;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
AABB2 ClientUI::GetTextInputRect() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return AABB2();
|
|
|
|
}
|
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();
|
|
|
|
return *reinterpret_cast<AABB2*>(c->GetReturnObject());
|
|
|
|
}
|
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
bool ClientUI::WantsClientToBeClosed() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return false;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientUI::NeedsInput() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return false;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientUI::RunFrame(float dt) {
|
|
|
|
SPADES_MARK_FUNCTION();
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientUI::Closing() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2013-12-31 16:29:10 +09:00
|
|
|
void ClientUI::RecordChatLog(const std::string &msg,
|
|
|
|
Vector4 color) {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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);
|
|
|
|
c->SetArgObject(0, reinterpret_cast<void*>(&k));
|
|
|
|
c->SetArgObject(1, reinterpret_cast<void*>(&color));
|
|
|
|
c.ExecuteChecked();
|
|
|
|
}
|
|
|
|
|
2013-11-27 16:30:54 +09:00
|
|
|
void ClientUI::EnterClientMenu() {
|
|
|
|
SPADES_MARK_FUNCTION();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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();
|
|
|
|
if(!ui){
|
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
bool ClientUI::isIgnored(const std::string& key)
|
|
|
|
{
|
2014-05-08 14:44:35 +03:00
|
|
|
return !ignoreInput.empty() && EqualsIgnoringCase(ignoreInput, key );
|
2014-03-09 14:32:45 +01:00
|
|
|
}
|
|
|
|
void ClientUI::setIgnored(const std::string& key)
|
|
|
|
{
|
|
|
|
ignoreInput = key;
|
|
|
|
}
|
2013-11-27 16:30:54 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|