Skip to content

Commit

Permalink
Update v2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Musiker15 committed Oct 26, 2024
1 parent 1827f65 commit 7f0f7e2
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 29 deletions.
20 changes: 12 additions & 8 deletions client/functions/progressbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ MSK.Progress.Start = function(data, text, color)
if type(data) == 'table' then
duration = data.duration
text = data.text
color = data.color or Config.progressColor
color = data.color or Config.ProgressColor or Config.progressColor
forceOverride = data.forceOverride or forceOverride
end

Expand All @@ -111,20 +111,20 @@ MSK.Progress.Start = function(data, text, color)
action = 'progressBarStart',
time = duration,
text = text or '',
color = color or Config.progressColor,
color = color or Config.ProgressColor or Config.progressColor,
})

if type(data) == 'table' then
return setProgressData(data)
end
end
MSK.Progressbar = MSK.Progress.Start -- Support for old Scripts
MSK.Progressbar = MSK.Progress.Start -- Backwards compatibility
exports('Progressbar', MSK.Progress.Start)
RegisterNetEvent("msk_core:progressbar", MSK.Progress.Start)

setmetatable(MSK.Progress, {
__call = function(self, data, text, color)
self.Start(data, text, color)
__call = function(self, ...)
self.Start(...)
end
})

Expand All @@ -138,8 +138,7 @@ MSK.Progress.Stop = function()
isProgressActive = false
progressData = nil
end
MSK.ProgressStop = MSK.Progress.Stop -- Support for old Scripts
exports('ProgressStop', MSK.Progress.Stop) -- Support for old Scripts
MSK.ProgressStop = MSK.Progress.Stop -- Backwards compatibility
RegisterNetEvent("msk_core:progressbarStop", MSK.Progress.Stop)

MSK.Progress.Active = function()
Expand All @@ -158,4 +157,9 @@ RegisterCommand('stopProgress', function()
end
end)
RegisterKeyMapping('stopProgress', 'Cancel Progressbar', 'keyboard', 'X')
TriggerEvent('chat:removeSuggestion', '/stopProgress')
TriggerEvent('chat:removeSuggestion', '/stopProgress')

AddEventHandler('onResourceStop', function(resource)
if GetCurrentResourceName() ~= resource then return end
MSK.Progress.Stop()
end)
68 changes: 68 additions & 0 deletions client/functions/textui.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
MSK.TextUI = {}

local isTextUIOpen = false
local thread = false

MSK.TextUI.Show = function(key, text, color)
if isTextUIOpen then return end
isTextUIOpen = true

SendNUIMessage({
action = 'textUI',
show = true,
key = key or 'E',
text = text or '',
color = color or Config.TextUIColor,
})
end
exports('ShowTextUI', MSK.TextUI.Show)
RegisterNetEvent("msk_core:textUiShow", MSK.TextUI.Show)

setmetatable(MSK.TextUI, {
__call = function(self, ...)
self.Show(...)
end
})

MSK.TextUI.ShowThread = function(key, text, color)
MSK.TextUI.Show(key, text, color)

if thread then return end
thread = true

local timer = GetGameTimer()
CreateThread(function()
while timer + 100 >= GetGameTimer() do Wait(100) end
thread = false
Wait(0)

if not thread then
MSK.TextUI.Hide()
end
end)
end
exports('ShowTextUIThread', MSK.TextUI.ShowThread)
RegisterNetEvent("msk_core:textUiShowThread", MSK.TextUI.ShowThread)

MSK.TextUI.Hide = function()
if not isTextUIOpen then return end
isTextUIOpen = false
thread = false

SendNUIMessage({
action = 'textUI',
show = false
})
end
exports('HideTextUI', MSK.TextUI.Hide)
RegisterNetEvent("msk_core:textUiHide", MSK.TextUI.Hide)

MSK.TextUI.Active = function()
return isTextUIOpen
end
exports('TextUIActive', MSK.TextUI.Active)

AddEventHandler('onResourceStop', function(resource)
if GetCurrentResourceName() ~= resource then return end
MSK.TextUI.Hide()
end)
3 changes: 2 additions & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Config.customNotification = function(title, message, typ, duration)
-- Add your own clientside Notification here
end
----------------------------------------------------------------
Config.progressColor = "#5eb131" -- Default Color for ProgressBar
Config.ProgressColor = "#5eb131" -- Default Color for ProgressBar
Config.TextUIColor = "#5eb131" -- Default Color for TextUI
----------------------------------------------------------------
Config.LoggingTypes = {
['debug'] = '[^3DEBUG^0]',
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ games { 'gta5' }
author 'Musiker15 - MSK Scripts'
name 'msk_core'
description 'Functions for MSK Scripts'
version '2.6.8'
version '2.7.0'

lua54 'yes'

Expand Down
3 changes: 2 additions & 1 deletion html/css/import.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
@import url("notify.css");
@import url("numpad.css");
@import url("progressbar.css");
@import url("input.css");
@import url("input.css");
@import url("textui.css");
61 changes: 61 additions & 0 deletions html/css/textui.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
.textui {
position: absolute;
bottom:6vh;
left:50%;
transform:translateX(-50%);
}

.textui-key {
position: relative;
width: 4vh;
height:4vh;
line-height:4vh;
left:50%;
font-size:2vh;
font-weight:bold;
color:white;
text-align:center;
transform:translateX(-50%);
transition: 200ms;
background: repeating-linear-gradient(
-55deg,
rgb(24, 198, 0),
rgb(24, 198, 0) 0.6vh,
rgb(18, 158, 0) 0.6vh,
rgb(18, 158, 0) 1.6vh
);
border-radius:0.4vh;
outline:0.2vh solid rgb(30, 255, 0);
box-shadow:0 1.2vh 2vh rgb(30, 255, 0);
animation:moveLines 2s infinite;
margin-bottom:2vh;
}

@keyframes moveLines {
0% {
/* opacity:1.0; */
background-position-x: 6vh;
margin-bottom:1.6vh;
}
50% {
/* opacity:0.4; */
margin-bottom:3.0vh;
}
100% {
/* opacity:1.0; */
background-position-x: 2vh;
margin-bottom:1.6vh;
}
}

.textui-text {
position: relative;
max-width:30vh;
font-size:2vh;
/* color:rgb(204, 204, 204); */
color:rgb(255, 255, 255);
font-weight:600;
text-align: center;

text-shadow:0vh 0vh 0.5vh black;
}
6 changes: 6 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,11 @@
<button class="numpad-pin-button numpad-submit-button" id='numpad-submit' onclick="submitNumpad()"><span class="white-mask"><i class="fa-solid fa-check"></i></span></button>
</div>
</div>

<!-- MSK Textui -->
<div class="textui" style="display:none">
<div class="textui-key">E</div>
<div class="textui-text">Drücke E um zu interagieren</div>
</div>
</body>
</html>
67 changes: 67 additions & 0 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ $(document).ready(function() {
closeNumpad();
} else if (data.action == 'copyCoords') {
copyCoords(data.value);
} else if (data.action == "textUI") {
toggleTextui(data)
}
})
})
Expand Down Expand Up @@ -92,6 +94,7 @@ const colors = {
"~r~": "red",
"~b~": "#378cbf",
"~g~": "green",
"~lg~": "#5eb131",
"~y~": "yellow",
"~p~": "purple",
"~c~": "grey",
Expand Down Expand Up @@ -293,4 +296,68 @@ submitNumpad = () => {
$('#numpad-display').text(numpadWrongCode)
numpadInput = ''
}
}

/* ----------------
MSK Textui
---------------- */

convertHexToRgbA = (hexVal, alpha) => {
let ret;

if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hexVal)) {
ret = hexVal.slice(1);
ret = ret.split('');

if (ret.length == 3) {
let ar = [];
ar.push(ret[0]);
ar.push(ret[0]);
ar.push(ret[1]);
ar.push(ret[1]);
ar.push(ret[2]);
ar.push(ret[2]);
ret = ar;
}

ret = '0x' + ret.join('');

let r = (ret >> 16) & 255;
let g = (ret >> 8) & 255;
let b = ret & 255;

return 'rgba(' + [r, g, b, alpha || 1].join(',') + ')';
}
}

toggleTextui = (data) => {
if (data.show) {
const primaryColor = convertHexToRgbA(data.color, 0.8)
const secondaryColor = convertHexToRgbA(data.color, 0.68)
let text = data.text

for (color in colors) {
if (text.includes(color)) {
let obj = {};

obj[color] = `<span style='color: ${colors[color]}'>`;
obj['~s~'] = '</span>';

text = replaceColors(text, obj);
}
}

$(".textui-key").text(data.key)
$(".textui-text").html(text)

$(".textui-key").css({
background:`repeating-linear-gradient(-55deg, ${primaryColor}, ${primaryColor} 0.8vh, ${secondaryColor} 0.8vh, ${secondaryColor} 1.6vh )`,
outlineColor:data.color,
boxShadow:`0 1.2vh 2vh ${data.color}`,
})

$(".textui").fadeIn("fast")
} else {
$(".textui").fadeOut("fast")
}
}
21 changes: 18 additions & 3 deletions import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,31 @@ setmetatable(MSK.Progress, {
end
})

-- MSK.Timeout(ms, cb, data)
setmetatable(MSK.Timeout, {
__call = function(self, ...)
return self.Set(...)
end
})

-- MSK.TextUI(key, text, color)
setmetatable(MSK.TextUI, {
__call = function(self, ...)
self.Show(...)
end
})

if context == 'client' then
-- MSK.Request(request, hasLoaded, assetType, asset, timeout, ...)
setmetatable(MSK.Request, {
__call = function(_, request, hasLoaded, assetType, asset, timeout, ...)
return MSK.Request.Streaming(request, hasLoaded, assetType, asset, timeout, ...)
__call = function(self, ...)
return self.Streaming(...)
end
})
end

if context == 'server' then
-- MSK.Check(repo)
-- MSK.Check({auhtor = 'MSK-Scripts', name = 'msk_core', download? = 'url'})
setmetatable(MSK.Check, {
__call = function(self, ...)
self.Version(...)
Expand Down
Loading

0 comments on commit 7f0f7e2

Please sign in to comment.