7#include <networksystem/networkvar.h>
8#include <tier0/utlstring.h>
25static void SetStr(CUtlString& out, std::string_view text)
27 out.SetDirect(text.data(),
static_cast<int>(text.size()));
30int ScreenEntity::PlayerStateCount()
const
33 const Schema::CCSCustomHudLayout layout{_entities.
Get(_entity).
Raw()};
34 return layout ? layout.PlayerLayoutStates() : -1;
39 Entity entity = _entities.Get(_entity);
42 return std::unexpected(
Error::NotFound(
"the custom_hud_layout entity no longer exists"));
45 const Schema::CCSCustomHudLayout layout{entity.Raw()};
46 for (
const auto& [name, table] :
47 {std::pair{
"element id", layout.PanelIds()}, std::pair{
"class name", layout.ClassNames()},
48 std::pair{
"text variable", layout.DialogVariableNames()}})
50 const int count = table ?
static_cast<const StringTable*
>(table)->Count() : -1;
53 return std::unexpected(
61Status ScreenEntity::SendText(std::string_view variable, std::string_view value)
63 auto entity = ResolveWritable();
66 return std::unexpected(entity.error());
69 const auto& set = _entities.Bindings().CustomHudSetDialogVariable;
75 CUtlString root, name, text;
76 SetStr(root, _layout.Name());
79 set(*entity, &root, &name, &text);
83Status ScreenEntity::SendClass(std::string_view elementId, std::string_view className,
bool on)
85 auto entity = ResolveWritable();
88 return std::unexpected(entity.error());
91 const auto& set = _entities.Bindings().CustomHudSetHasClass;
94 return std::unexpected(
Error::Unsupported(
"the custom HUD class setter did not bind"));
97 CUtlString element, name;
98 SetStr(element, elementId);
104Status ScreenEntity::SendCursor(
bool shown)
106 auto entity = ResolveWritable();
109 return std::unexpected(entity.error());
113 if (
const int states = PlayerStateCount(); states <= _owner)
115 return std::unexpected(
116 Error::Failed(std::format(
"slot {} has no per-player layout state (the entity holds {})", _owner, states)));
119 const auto& set = _entities.Bindings().CustomHudSetInputCapture;
122 return std::unexpected(
Error::Unsupported(
"the custom HUD input capture setter did not bind"));
124 set(*entity, _owner, shown);
Entity Get(EntityRef ref)
CEntityInstance * Raw() const noexcept
static constexpr int32_t ClassAbsent
CNetworkUtlVectorBase< CUtlString > StringTable
std::expected< void, Error > Status
static constexpr int32_t ClassPresent
std::expected< T, Error > Result
static constexpr int StringTableCap
static void SetStr(CUtlString &out, std::string_view text)
static constexpr int StringTableHeadroom
static Error Failed(std::string detail)
static Error Unsupported(std::string detail)
static Error NotFound(std::string detail)