-
-
Notifications
You must be signed in to change notification settings - Fork 453
/
Copy pathCLuaClientDefs.cpp
101 lines (85 loc) · 3.72 KB
/
CLuaClientDefs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*****************************************************************************
*
* PROJECT: Multi Theft Auto
* LICENSE: See LICENSE in the top level directory
* FILE: mods/deathmatch/logic/luadefs/CLuaClientDefs.cpp
* PURPOSE: Lua client definitions class
*
* Multi Theft Auto is available from https://multitheftauto.com/
*
*****************************************************************************/
#include "StdInc.h"
#include "CLuaClientDefs.h"
#include "lua/CLuaFunctionParser.h"
void CLuaClientDefs::LoadFunctions()
{
constexpr static const std::pair<const char*, lua_CFunction> functions[]{{"setTransferBoxVisible", ArgumentParser<SetTransferBoxVisible>},
{"isTransferBoxVisible", ArgumentParser<IsTransferBoxVisible>},
{"isTransferBoxAlwaysVisible", ArgumentParser<IsTransferBoxAlwaysVisible>},
{"showChat", ArgumentParserWarn<false, ShowChat>},
{"isChatVisible", ArgumentParserWarn<false, IsChatVisible>},
{"isChatInputBlocked", ArgumentParser<IsChatInputBlocked>},
{"clearDebugBox", ArgumentParser<ClearDebug>},
{"isMTAWindowFocused", ArgumentParser<IsMTAWindowFocused>},
{"isCapsLockEnabled", ArgumentParser<IsCapsLockEnabled>},
{"setCursorColor", ArgumentParser<SetCursorColor>},
{"getCursorColor", ArgumentParser<GetCursorColor>}};
for (const auto& [name, func] : functions)
CLuaCFunctions::AddFunction(name, func);
}
bool CLuaClientDefs::SetTransferBoxVisible(bool visible)
{
return g_pClientGame->GetTransferBox()->SetClientVisibility(visible);
}
bool CLuaClientDefs::IsTransferBoxVisible()
{
return g_pClientGame->GetTransferBox()->IsVisible();
}
bool CLuaClientDefs::IsTransferBoxAlwaysVisible()
{
return g_pClientGame->GetTransferBox()->IsAlwaysVisible();
}
bool CLuaClientDefs::ShowChat(bool bVisible, std::optional<bool> optInputBlocked)
{
// Keep old behaviour: input is blocked when chat is hidden
bool bInputBlocked = !bVisible;
if (optInputBlocked.has_value())
bInputBlocked = optInputBlocked.value();
g_pCore->SetChatVisible(bVisible, bInputBlocked);
return true;
}
bool CLuaClientDefs::IsChatVisible()
{
return g_pCore->IsChatVisible();
}
bool CLuaClientDefs::IsChatInputBlocked()
{
return g_pCore->IsChatInputBlocked();
}
bool CLuaClientDefs::ClearDebug()
{
g_pCore->DebugClear();
return true;
}
bool CLuaClientDefs::IsMTAWindowFocused()
{
return m_pClientGame->IsWindowFocused();
}
bool CLuaClientDefs::IsCapsLockEnabled()
{
return ((::GetKeyState(VK_CAPITAL) & 0x0001) != 0);
}
bool CLuaClientDefs::SetCursorColor(float r, float g, float b, float alpha) noexcept
{
if (!g_pCore->IsMenuVisible())
g_pCore->GetGUI()->SetCursorColor(r, g, b, alpha);
else
g_pCore->GetGUI()->ResetCursorColor(r, g, b, alpha); // Force values to be updated
return true;
}
CLuaMultiReturn<float, float, float, float> CLuaClientDefs::GetCursorColor() noexcept
{
float r, g, b, alpha;
g_pCore->GetGUI()->GetCursorColor(r, g, b, alpha);
return {r, g, b, alpha};
}