Skip to content
Permalink
Browse files

Improved typing display with lookup for codes + reinstated icon size fix

  • Loading branch information
kurozael committed Aug 28, 2017
1 parent 85163cd commit 383551566bdc7d1520a5ffc419b6d2d0bed292ff
@@ -167,7 +167,7 @@ if (CLIENT) then

Clockwork.option:SetKey("top_bar_width_scale", 0.3);

Clockwork.option:SetKey("info_text_icon_size", 20);
Clockwork.option:SetKey("info_text_icon_size", 16);
Clockwork.option:SetKey("info_text_red_icon", "icon16/exclamation.png");
Clockwork.option:SetKey("info_text_green_icon", "icon16/tick.png");
Clockwork.option:SetKey("info_text_orange_icon", "icon16/error.png");
@@ -147,39 +147,32 @@ function cwDisplayTyping:ChatBoxClosed(textTyped)
end;
end;

-- A function to get whether a string starts with a command.
function cwDisplayTyping:DoesStartWithCommand(text, command)
if (string.utf8sub(newText, 1, string.utf8len(command)) == command) then

This comment has been minimized.

Copy link
@Meow

Meow Aug 28, 2017

Contributor

Just use string.StartWith

This comment has been minimized.

Copy link
@kurozael

kurozael Aug 28, 2017

Author Member

string.StartWith does not use the utf8 library IIRC.

This comment has been minimized.

Copy link
@Meow

Meow Aug 28, 2017

Contributor

neither does the way you're using this function

This comment has been minimized.

Copy link
@kurozael

kurozael Aug 28, 2017

Author Member

Yeah, it does? Look, DoesStartWithCommand uses string.utf8sub 👍

This comment has been minimized.

Copy link
@Meow

Meow Aug 28, 2017

Contributor

no i mean the way you're using DoesStartWithCommand, you're using it to detect commands. And even with w/e translations there are, commands are 99.99% of the time in english

This comment has been minimized.

Copy link
@Meow

Meow Aug 28, 2017

Contributor

plus string.StartWith detects the command even if the string is partially in UTF-8 characters: http://c2n.me/3NhXDRp.png

return true;
else
return false;
end;
end;

-- Called when the chat box text has changed.
function cwDisplayTyping:ChatBoxTextChanged(previousText, newText)
local prefix = cwConfig:Get("command_prefix"):Get();

if (string.utf8sub(newText, 1, string.utf8len(prefix) + 6) == prefix.."radio") then
if (string.utf8sub(previousText, 1, string.utf8len(prefix) + 6) != prefix.."radio") then
RunConsoleCommand("cwTypingStart", "r");
end;
elseif (string.utf8sub(newText, 1, string.utf8len(prefix) + 3) == prefix.."me") then
if (string.utf8sub(previousText, 1, string.utf8len(prefix) + 3) != prefix.."me") then
RunConsoleCommand("cwTypingStart", "p");
end;
elseif (string.utf8sub(newText, 1, string.utf8len(prefix) + 3) == prefix.."pm") then
if (string.utf8sub(previousText, 1, string.utf8len(prefix) + 3) != prefix.."pm") then
RunConsoleCommand("cwTypingStart", "o");
end;
elseif (string.utf8sub(newText, 1, string.utf8len(prefix) + 2) == prefix.."w") then
if (string.utf8sub(previousText, 1, string.utf8len(prefix) + 2) != prefix.."w") then
RunConsoleCommand("cwTypingStart", "w");
end;
elseif (string.utf8sub(newText, 1, string.utf8len(prefix) + 2) == prefix.."y") then
if (string.utf8sub(previousText, 1, string.utf8len(prefix) + 2) != prefix.."y") then
RunConsoleCommand("cwTypingStart", "y");
end;
elseif (string.utf8sub(newText, 1, 2) == "//") then
if (string.utf8sub(previousText, 1, 2) != prefix.."//") then
RunConsoleCommand("cwTypingStart", "o");
for k, v in pairs(self.typingCodes) do
if (self:DoesStartWithCommand(newText, prefix..k)) then
if (!self:DoesStartWithCommand(previousText, prefix..k)) then
RunConsoleCommand("cwTypingStart", v);
end;

return;
end;
elseif (string.utf8sub(newText, 1, 3) == ".//") then
if (string.utf8sub(previousText, 1, 3) != prefix..".//") then
RunConsoleCommand("cwTypingStart", "o");
end;

if (newText != "" and previousText != "") then
if (string.utf8len(newText) >= 4 and string.utf8len(previousText) < 4) then
RunConsoleCommand("cwTypingStart", "n");
end;
elseif (newText != "" and string.utf8len(newText) >= 4 and previousText != "" and string.utf8len(previousText) < 4) then
RunConsoleCommand("cwTypingStart", "n");
end;
end;
@@ -18,6 +18,21 @@ Clockwork.kernel:IncludePrefixed("sv_plugin.lua");
Clockwork.kernel:IncludePrefixed("sv_hooks.lua");
Clockwork.kernel:IncludePrefixed("sh_enum.lua");

--[[
A dictionary of commands and typing codes.
The command a player is typing corresponds
to a specific phrase code.
--]]
cwTypingDisplay.typingCodes = {
["radio"] = "r",
["me"] = "p",
["pm"] = "o",
["w"] = "w",
["y"] = "y",
["//"] = "o",
[".//"] = "o"
};

-- Called when the Clockwork shared variables are added.
function cwDisplayTyping:ClockworkAddSharedVars(globalVars, playerVars)
playerVars:Number("Typing");

0 comments on commit 3835515

Please sign in to comment.
You can’t perform that action at this time.