Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Convert to spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRazor1337 committed Sep 22, 2019
1 parent 3f00fb0 commit 4433f9b
Showing 1 changed file with 112 additions and 112 deletions.
224 changes: 112 additions & 112 deletions chat2_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ local chatInstanceLoading
local chatInstanceLoaded

local state = {
show = false,
activeInputKeyButton = nil,
activeScrollKeyButton = nil
show = false,
activeInputKeyButton = nil,
activeScrollKeyButton = nil
}

-- Define your local/global/team/etc input types here
Expand All @@ -18,13 +18,13 @@ local state = {
-- Do not forget to execute exports.chat2:useDefaultOutput(false)
-- and then handle this messageTypes in "onPlayerChat" event handlers
local inputKeyButtons = {
["t"] = {"say", 0},
["y"] = {"teamsay", 2}
["t"] = {"say", 0},
["y"] = {"teamsay", 2}
}

local scrollKeyButtons = {
["pgup"] = "scrollup",
["pgdn"] = "scrolldown"
["pgup"] = "scrollup",
["pgdn"] = "scrolldown"
}

addEvent("onChat2Loaded")
Expand All @@ -34,184 +34,184 @@ addEvent("onChat2Clear", true)
addEvent("onChat2Show", true)

function create()
chatInstance = guiGetBrowser(guiCreateBrowser(0.01, 0.01, 0.25, 0.4, true, true, true))
chatInstanceLoading = true
addEventHandler("onClientBrowserCreated", chatInstance, load)
chatInstance = guiGetBrowser(guiCreateBrowser(0.01, 0.01, 0.25, 0.4, true, true, true))
chatInstanceLoading = true
addEventHandler("onClientBrowserCreated", chatInstance, load)
end

function load()
loadBrowserURL(chatInstance, "http://mta/local/index.html")
loadBrowserURL(chatInstance, "http://mta/local/index.html")
end

function output(message)
if not chatInstanceLoaded then
return setTimer(output, 250, 1, message)
end
if not chatInstanceLoaded then
return setTimer(output, 250, 1, message)
end

if not state.show then
return
end
if not state.show then
return
end

execute(string.format("addMessage(%s)", toJSON(message)))
execute(string.format("addMessage(%s)", toJSON(message)))
end

function clear()
execute("clear()")
execute("clear()")
end

function isChatVisible()
return state.show
return state.show
end

function show(bool)
if chatInstanceLoaded ~= true then
if chatInstanceLoading ~= true then
create()
return setTimer(show, 300, 1, bool)
else
return setTimer(show, 300, 1, bool)
end
end
if chatInstanceLoaded ~= true then
if chatInstanceLoading ~= true then
create()
return setTimer(show, 300, 1, bool)
else
return setTimer(show, 300, 1, bool)
end
end

execute(string.format("show(%s)", tostring(bool)))
state.show = bool
execute(string.format("show(%s)", tostring(bool)))
state.show = bool
end

function registerKeyButtons()
for keyButton, definition in pairs(inputKeyButtons) do
bindKey(keyButton, "down", onChatInputButton, keyButton, definition)
end
for keyButton, definition in pairs(inputKeyButtons) do
bindKey(keyButton, "down", onChatInputButton, keyButton, definition)
end

for keyButton, definition in pairs(scrollKeyButtons) do
bindKey(keyButton, "down", onChatScrollStartButton, keyButton, definition)
end
for keyButton, definition in pairs(scrollKeyButtons) do
bindKey(keyButton, "down", onChatScrollStartButton, keyButton, definition)
end

for keyButton, definition in pairs(scrollKeyButtons) do
bindKey(keyButton, "up", onChatScrollStopButton, keyButton, definition)
end
for keyButton, definition in pairs(scrollKeyButtons) do
bindKey(keyButton, "up", onChatScrollStopButton, keyButton, definition)
end
end

function execute(eval)
executeBrowserJavascript(chatInstance, eval)
executeBrowserJavascript(chatInstance, eval)
end

function onChatLoaded()
chatInstanceLoaded = true
focusBrowser(chatInstance)
adoptFont()
chatInstanceLoaded = true
focusBrowser(chatInstance)
adoptFont()
end

function onChatInputButton(_, _, keyButton, definition)
if not state.show then
return
end
if not state.show then
return
end

if state.activeInputKeyButton then
return
end
if state.activeInputKeyButton then
return
end

execute(string.format("showInput(%s)", toJSON(definition[1])))
focusBrowser(chatInstance)
guiSetInputEnabled(true)
state.activeInputKeyButton = keyButton
execute(string.format("showInput(%s)", toJSON(definition[1])))
focusBrowser(chatInstance)
guiSetInputEnabled(true)
state.activeInputKeyButton = keyButton
end

function onChatEnterButton(message)
if not state.show then
return
end
if not state.show then
return
end

if not state.activeInputKeyButton then
return
end
if not state.activeInputKeyButton then
return
end

execute("hideInput()")
guiSetInputEnabled(false)
triggerServerEvent("onChat2Message", resourceRoot, message, inputKeyButtons[state.activeInputKeyButton][2])
state.activeInputKeyButton = nil
execute("hideInput()")
guiSetInputEnabled(false)
triggerServerEvent("onChat2Message", resourceRoot, message, inputKeyButtons[state.activeInputKeyButton][2])
state.activeInputKeyButton = nil
end

function onChatScrollStartButton(_, _, keyButton, definition)
if state.activeScrollKeyButton then
return
end
if state.activeScrollKeyButton then
return
end

execute(string.format("startScroll(%s)", toJSON(definition)))
state.activeScrollKeyButton = keyButton
execute(string.format("startScroll(%s)", toJSON(definition)))
state.activeScrollKeyButton = keyButton
end

function onChatScrollStopButton(_, _, _, definition)
if not state.activeScrollKeyButton then
return
end
if not state.activeScrollKeyButton then
return
end

execute("stopScroll()")
state.activeScrollKeyButton = nil
execute("stopScroll()")
state.activeScrollKeyButton = nil
end

function listenForOutputChatBox(_, _, _, _, _, message, r, g, b)
local hexColor = ""
local hexColor = ""

if (r and g and b) then
hexColor = RGBToHex(r, g, b)
end
if (r and g and b) then
hexColor = RGBToHex(r, g, b)
end

output(string.format("%s%s", hexColor, message))
return "skip"
output(string.format("%s%s", hexColor, message))
return "skip"
end

function listenForShowChat(_, _, _, _, _, bool)
show(bool)
return "skip"
show(bool)
return "skip"
end

function listenForClearChatBox()
clear()
return "skip"
clear()
return "skip"
end

function onClientResourceStart()
showChat(false)
addDebugHook("preFunction", listenForShowChat, {"showChat"})
addDebugHook("preFunction", listenForOutputChatBox, {"outputChatBox"})
addDebugHook("preFunction", listenForClearChatBox, {"clearChatBox"})
showChat(true)
showChat(false)
addDebugHook("preFunction", listenForShowChat, {"showChat"})
addDebugHook("preFunction", listenForOutputChatBox, {"outputChatBox"})
addDebugHook("preFunction", listenForClearChatBox, {"clearChatBox"})
showChat(true)

registerKeyButtons()
registerKeyButtons()
end

function onClientResourceStop()
showChat(false)
showChat(false)

if state.activeInputKeyButton then
guiSetInputEnabled(false)
end
if state.activeInputKeyButton then
guiSetInputEnabled(false)
end

removeDebugHook("preFunction", listenForShowChat)
removeDebugHook("preFunction", listenForOutputChatBox)
removeDebugHook("preFunction", listenForClearChatBox)
showChat(true)
removeDebugHook("preFunction", listenForShowChat)
removeDebugHook("preFunction", listenForOutputChatBox)
removeDebugHook("preFunction", listenForClearChatBox)
showChat(true)
end

function getAspectRatio()
local dxResolution
local dw, dh = guiGetScreenSize()
local aspectRatio = math.round( dw / dh, 2 )
local dxAspectRatio = "16:9"
if aspectRatio == 1.33 then dxAspectRatio = "4:3"
elseif aspectRatio == 1.25 then dxAspectRatio = "5:4"
elseif aspectRatio == 1.77 then dxAspectRatio = "16:9"
end
return dxAspectRatio
local dxResolution
local dw, dh = guiGetScreenSize()
local aspectRatio = math.round( dw / dh, 2 )
local dxAspectRatio = "16:9"
if aspectRatio == 1.33 then dxAspectRatio = "4:3"
elseif aspectRatio == 1.25 then dxAspectRatio = "5:4"
elseif aspectRatio == 1.77 then dxAspectRatio = "16:9"
end
return dxAspectRatio
end

function adoptFont()
if getAspectRatio() ~= "16:9" then
executeBrowserJavascript(chatInstance,
"let stylesElement = document.createElement('style');" ..
'stylesElement.innerHTML = ".chat__message {font-size: 4vh} .chat__input {font-size: 4vh}";' ..
'document.body.appendChild(stylesElement);')
end
if getAspectRatio() ~= "16:9" then
executeBrowserJavascript(chatInstance,
"let stylesElement = document.createElement('style');" ..
'stylesElement.innerHTML = ".chat__message {font-size: 4vh} .chat__input {font-size: 4vh}";' ..
'document.body.appendChild(stylesElement);')
end
end

addEventHandler("onChat2Loaded", resourceRoot, onChatLoaded)
Expand Down

0 comments on commit 4433f9b

Please sign in to comment.