Merge branch 'newui' of https://github.com/nullworks/cathook into newui

This commit is contained in:
LightCat 2018-09-15 16:52:17 +02:00
commit 78f20b26b9
2 changed files with 118 additions and 11 deletions

View File

@ -1,4 +1,4 @@
<Window width="content" height="content" x="200" y="200" name="Test2">
<Window width="content" height="content" x="200" y="200" name="Playerlist (Incomplete. Use cat_pl_set_state instead!)">
<Table id="special-player-list">
<Column width="25"/>
<Column width="70" />
@ -19,4 +19,4 @@
<TData height="15"><Text height="fill" padding="0 0 0 4">Kick</Text></TData>
</TRow>
</Table>
</Window>
</Window>

View File

@ -11,6 +11,7 @@
#include <stdint.h>
#include <dirent.h>
#include <sys/stat.h>
#include <boost/algorithm/string.hpp>
namespace playerlist
{
@ -175,21 +176,121 @@ CatCommand pl_load("pl_load", "Load playerlist", Load);
CatCommand pl_set_state(
"pl_set_state",
"pl_set_state uniqueid state\nfor example pl_set_state 306902159 0",
"cat_pl_set_state [playername] [state] (Tab to autocomplete)",
[](const CCommand &args) {
if (args.ArgC() < 3)
if (args.ArgC() != 3)
{
logging::Info("Invalid call");
return;
}
unsigned steamid = strtoul(args.Arg(1), nullptr, 10);
k_EState state =
static_cast<k_EState>(strtol(args.Arg(2), nullptr, 10));
if (state < k_EState::DEFAULT || state > k_EState::STATE_LAST)
state = k_EState::DEFAULT;
AccessData(steamid).state = state;
logging::Info("Set %d to %d", steamid, state);
auto name = args.Arg(1);
int id = -1;
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
{
player_info_s info;
if (!g_IEngine->GetPlayerInfo(i, &info))
continue;
std::string currname(info.name);
std::replace(currname.begin(), currname.end(), ' ', '-');
if (currname.find(name) != 0)
continue;
id = i;
break;
}
if (id == -1)
{
logging::Info("Unknown Player Name. (Use tab for autocomplete)");
return;
}
std::string state = args.Arg(2);
boost::to_upper(state);
player_info_s info;
g_IEngine->GetPlayerInfo(id, &info);
if (k_Names[0] == state)
AccessData(info.friendsID).state = k_EState::DEFAULT;
else if (k_Names[1] == state)
AccessData(info.friendsID).state = k_EState::FRIEND;
else if (k_Names[2] == state)
AccessData(info.friendsID).state = k_EState::RAGE;
else if (k_Names[3] == state)
AccessData(info.friendsID).state = k_EState::IPC;
else if (k_Names[4] == state)
AccessData(info.friendsID).state = k_EState::DEVELOPER;
else
logging::Info("Unknown State. (Use tab for autocomplete)");
});
static int cat_pl_set_state_completionCallback(
const char *c_partial,
char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH])
{
std::string partial = c_partial;
std::string parts[2]{};
auto j = 0u;
auto f = false;
int count = 0;
for (auto i = 0u; i < partial.size() && j < 3; ++i)
{
auto space = (bool) isspace(partial[i]);
if (!space)
{
if (j)
parts[j - 1].push_back(partial[i]);
f = true;
}
if (i == partial.size() - 1 || (f && space))
{
if (space)
++j;
f = false;
}
}
std::vector<std::string> names;
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
{
player_info_s info;
if (!g_IEngine->GetPlayerInfo(i, &info))
continue;
std::string name(info.name);
std::replace(name.begin(), name.end(), ' ', '-');
names.push_back(name);
}
std::sort(names.begin(), names.end());
if (parts[0].empty() ||
parts[1].empty() && (!parts[0].empty() && partial.back() != ' '))
{
boost::to_lower(parts[0]);
for (const auto &s : names)
{
// if (s.find(parts[0]) == 0)
if (boost::to_lower_copy(s).find(parts[0]) == 0)
{
snprintf(commands[count++], COMMAND_COMPLETION_ITEM_LENGTH - 1,
"cat_pl_set_state %s", s.c_str());
}
}
return count;
}
boost::to_lower(parts[1]);
for (const auto &s : k_Names)
{
if (boost::to_lower_copy(s).find(parts[1]) == 0)
{
snprintf(commands[count++], COMMAND_COMPLETION_ITEM_LENGTH - 1,
"cat_pl_set_state %s %s", parts[0].c_str(), s.c_str());
if (count == COMMAND_COMPLETION_MAXITEMS)
break;
}
}
return count;
}
#if ENABLE_VISUALS
CatCommand pl_set_color("pl_set_color", "pl_set_color uniqueid r g b",
[](const CCommand &args) {
@ -222,4 +323,10 @@ CatCommand pl_info("pl_info", "pl_info uniqueid", [](const CCommand &args) {
ConColorMsg(*reinterpret_cast<::Color*>(&clr), "[CUSTOM COLOR]\n");
}*/
});
static InitRoutine init([]() {
pl_set_state.cmd->m_bHasCompletionCallback = true;
pl_set_state.cmd->m_fnCompletionCallback =
cat_pl_set_state_completionCallback;
});
} // namespace playerlist