Skip to content

Commit

Permalink
[UPDATE] Adapt to base Gmod & x86 version
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMarrant committed Dec 5, 2024
1 parent 2b18970 commit 7ce2e86
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 41 deletions.
2 changes: 2 additions & 0 deletions lua/autorun/scp_1025.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ SCP_1025_CONFIG.RootFolder = "scp_1025/"
-- Actual lang server
SCP_1025_CONFIG.LangServer = GetConVar("gmod_language"):GetString()

SCP_1025_CONFIG.IsChromium = BRANCH == "x86-64"

--[[
* Load the file set in the parameters.
* @string File The name of the file to load.
Expand Down
5 changes: 5 additions & 0 deletions lua/scp_1025/config/cl_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ surface.CreateFont( "SCP01025_Book", {
size = 15
} )

surface.CreateFont( "SCP01025_Error", {
font = "CenterPrintText",
size = 20
} )

surface.CreateFont( "SCP01025_MT1", {
font = "Arial",
size = 40,
Expand Down
5 changes: 4 additions & 1 deletion lua/scp_1025/language/sh_en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ local LANG_EN = {
paranoid = "You get the impression that anyone could have been infected by SCP-1025. Everyone is a suspect ...",

-- Form
error_form = "Error Form",
error_form = "Error",
ok_form = "OK",

-- Other
chromium = "You are using the base branch version.\nI strongly recommend using the chromium branch x86-64 version\ninstead for better stability for SCP-1025.",
}

scp_1025.AddLanguage("en", LANG_EN)
5 changes: 4 additions & 1 deletion lua/scp_1025/language/sh_fr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ local LANG_FR = {
paranoid = "Vous avez l'impression que n'importe qui a pu être infecté par SCP-1025. Tout le monde est suspect...",

-- Form
error_form = "Erreur de formulaire",
error_form = "Erreur",
ok_form = "OK",

-- Other
chromium = "Je vous recommende vivement d'utiliser plutot la branche\nchromium x86-64 pour une meilleur stabilité de SCP-1025",
}

scp_1025.AddLanguage("fr", LANG_FR)
119 changes: 109 additions & 10 deletions lua/scp_1025/modules/book/cl_book_function.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <https://www.gnu.org/licenses/>.

SCP_1025_CONFIG.BasePage = [[
SCP_1025_CONFIG.BasePageChromium = [[
<head>
<title>Index Page</title>
<style>
Expand Down Expand Up @@ -112,10 +111,105 @@ SCP_1025_CONFIG.BasePage = [[
<div class="disease-column">
]]

SCP_1025_CONFIG.IndexFooterPage = [[
SCP_1025_CONFIG.BasePage = [[
<head>
<title>Index Page</title>
<style>
body {
overflow: hidden;
font-family: "Lumios Typewriter Old";
src: url("asset://garrysmod/addons/scp_1025/resource/fonts/LumiosTypewriter-Old.ttf") format("truetype");
background: url("https://i.imgur.com/eiU6Aod.png") no-repeat center center fixed;
background-size: cover;
color: #333;
}
h1 {
margin-top: 10px;
text-align: center;
font-size: %frem;
line-height: 1.2;
}
hr {
margin-top: 15px;
margin-bottom: 30px;
width: %dpx;
border: none;
border-top: 3px solid #333;
}
.disease-column button {
text-align: center;
display: block;
padding: 5px;
margin-bottom: 5px;
max-height: 1000px;
position: relative;
left: %s;
}
.footer-text {
text-align: center;
font-size: %frem;
margin-top: 50px;
}
button {
background: none;
border: none;
padding: 0;
font: inherit;
outline: inherit;
font-size: %frem;
width: inherit;
height: inherit;
}
button:hover {
cursor: pointer;
color: blue;
}
.QuitButton {
top: 10px;
right: -10px;
border-radius: 5px;
background-color: #000000;
margin-bottom: 0.5em;
transition: all 0.3s ease;
position: absolute;
width: %frem;
height: 5em;
display: grid;
margin-top: 3em;
}
.QuitButton:hover {
width: %frem;
}
.DeletePageButton {
font-size: %frem;
color: #ffffff;
}
.DeletePageButton:hover {
color: #e2e2e2;
}
</style>
</head>
<body>
<h1>The<br>Encyclopedia<br>of<br>Common<br>Diseases</h1>
<hr>
<div class="QuitButton">
<button class="DeletePageButton" onclick='DeletePage()'>Close</button>
</div>
<div class="disease-column">
]]

SCP_1025_CONFIG.IndexFooterPage = [[
<div class="footer-text">Illustrated by Coltan Press<br>1948</div>
</div>
<script>
function DeletePage() {
console.log("RUNLUA:scp_1025.CloseBook()")
Expand Down Expand Up @@ -234,7 +328,12 @@ SCP_1025_CONFIG.DescriptionFooterPage = [[
--]]
function scp_1025.IndexPage()
local ply = LocalPlayer()
local page = string.format(SCP_1025_CONFIG.BasePage, scp_1025.FontSizeResolution(3), SCP_1025_CONFIG.ScrW * 0.4, scp_1025.FontSizeResolution(2), scp_1025.FontSizeResolution(2), scp_1025.FontSizeResolution(10), scp_1025.FontSizeResolution(10.5), scp_1025.FontSizeResolution(2))
local page = ""
if (SCP_1025_CONFIG.IsChromium) then
page = string.format(SCP_1025_CONFIG.BasePageChromium, scp_1025.FontSizeResolution(3), SCP_1025_CONFIG.ScrW * 0.4, scp_1025.FontSizeResolution(2), scp_1025.FontSizeResolution(2), scp_1025.FontSizeResolution(10), scp_1025.FontSizeResolution(10.5), scp_1025.FontSizeResolution(2))
else
page = string.format(SCP_1025_CONFIG.BasePage, scp_1025.FontSizeResolution(3), SCP_1025_CONFIG.ScrW * 0.4, "40%", scp_1025.FontSizeResolution(1.8), scp_1025.FontSizeResolution(1.5), scp_1025.FontSizeResolution(10), scp_1025.FontSizeResolution(10.5), scp_1025.FontSizeResolution(2))
end
local i = 1
for k, v in pairs(SCP_1025_CONFIG.DiseaseAvailable) do
if (k == "writer_block") then
Expand All @@ -254,7 +353,6 @@ end
* @string disease The disease to display.
--]]
function scp_1025.DescriptionPage(ply, disease)
scp_1025.DeletePage()
local diseaseSelect = SCP_1025_CONFIG.DiseaseAvailable[disease]
local page = string.format(SCP_1025_CONFIG.DescriptionPage, scp_1025.FontSizeResolution(2), scp_1025.FontSizeResolution(2), scp_1025.FontSizeResolution(10.5), scp_1025.FontSizeResolution(10.5), scp_1025.FontSizeResolution(10), SCP_1025_CONFIG.ScrW * 0.35, diseaseSelect.name)
page = page .. diseaseSelect.description .. SCP_1025_CONFIG.DescriptionFooterPage
Expand Down Expand Up @@ -292,9 +390,10 @@ end
* @string content The page content.
--]]
function scp_1025.CreateDHTMLPage(ply, content, w, h, canClose)
scp_1025.DeletePage(ply)
local page = ply.scp_1025_CurrentPage
if (page) then page = page:IsValid() and page or nil end

local frame = vgui.Create("DFrame")
local frame = page and page:GetParent() or vgui.Create("DFrame")
frame:SetSize(w, h)
frame:Center()
frame:SetTitle("")
Expand All @@ -305,14 +404,14 @@ function scp_1025.CreateDHTMLPage(ply, content, w, h, canClose)
height = canClose and height - 30 or height

-- Create the DHTML panel
local dhtml = vgui.Create("DHTML", frame)
local dhtml = page or vgui.Create("DHTML", frame)
dhtml:SetSize(width, height)
dhtml:SetHTML(content)
dhtml:SetAllowLua(true)
dhtml:RequestFocus()
if (canClose) then dhtml:Dock(BOTTOM) end

ply.scp_1025_CurrentPage = frame
ply.scp_1025_CurrentPage = dhtml
end

--[[
Expand All @@ -321,7 +420,7 @@ end
function scp_1025.DeletePage()
local ply = LocalPlayer()
if (ply.scp_1025_CurrentPage) then
ply.scp_1025_CurrentPage:Remove()
ply.scp_1025_CurrentPage:GetParent():Remove()
ply.scp_1025_CurrentPage = nil
end
end
Expand Down
66 changes: 37 additions & 29 deletions lua/scp_1025/modules/menu/cl_menu_function.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ SCP_1025_CONFIG.AddDiseaseMenu = [[
<h1>SCP-1025</h1>
<h2>Add disease</h2>
<form name="formdisease" action="javascript:CreateDisease()">
<form name="formdisease" action="javascript:;" onsubmit="CreateDisease(this)">
<label for="dname">Disease name:</label><br>
<input type="text" id="dname" name="dname" placeholder="Influenza"><br><br>
<label for="ddescription">Disease description:</label><br>
<textarea type="text" id="ddescription" name="ddescription" rows="8" cols="50" placeholder='Flu, also called influenza, is an infection of the nose, throat and lungs, which are part of the respiratory system. The flu is caused by a virus. Influenza viruses are different from the "stomach flu" viruses that cause diarrhea and vomiting.'></textarea><br><br>
<textarea type="text" id="ddescription" name="ddescription" rows="3" cols="50" placeholder='Flu, also called influenza, is an infection of the nose, throat and lungs, which are part of the respiratory system. The flu is caused by a virus. Influenza viruses are different from the "stomach flu" viruses that cause diarrhea and vomiting.'></textarea><br><br>
<label for="dfunction">Disease function to call:<br>
<b>- The function must exist.<br>
- The function must have only one parameter who should receive a player.<br>
Expand All @@ -51,29 +51,28 @@ SCP_1025_CONFIG.AddDiseaseMenu = [[
<input class="submit" type="submit" value="Confirm">
</form>
<script>
// Check if every parameter are not empty
function CreateDisease(form) {
func = FormatText(form.dfunction.value)
name = FormatText(form.dname.value)
description = FormatText(form.ddescription.value)
index = FormatText(form.dindex.value)
isValid = IsFormValid(func, name, description, index);
if (isValid) {
console.log("RUNLUA:scp_1025.CreateDisease('"+func+"', '"+name+"', '"+description+"', '"+index+"')");
}
}
function IsFormValid(func, name, description, index) {
if (func == "" || name == "" || description == "" || index == "") {
console.log("RUNLUA:scp_1025.AlertChat('fillall')")
return false;
}
return true;
}
function FormatText(func, name, description, index) {
func = func.replace(/'/g, "\\'");
name = name.replace(/'/g, "\\'");
description = description.replace(/'/g, "\\'");
index = index.replace(/'/g, "\\'");
return [func, name, description, index];
}
function CreateDisease() {
let form = document.formdisease;
let [func, name, description, index] = [form.dfunction.value, form.dname.value, form.ddescription.value, form.dindex.value];
isValid = IsFormValid(func, name, description, index);
if (isValid) {
[func, name, description, index] = FormatText(func, name, description, index)
console.log("RUNLUA:scp_1025.CreateDisease('"+func+"', '"+name+"', '"+description+"', '"+index+"')");
}
function FormatText(text) {
return text.replace(/'/g, "\\'");
}
</script>
</body>
Expand Down Expand Up @@ -220,28 +219,31 @@ end

--[[
* Create a notificatino message to the screen of the player.
* @string message The message to display.
* @number|nil notiftype The type notification icon to display.
* @string message The index message translation to display.
--]]
function scp_1025.AlertChat(message)
local DFrame = vgui.Create("DFrame")
DFrame:Center()
DFrame:SetSize(300, 200)
local sizeFW, sizeFH = SCP_1025_CONFIG.ScrW * 0.3, SCP_1025_CONFIG.ScrH * 0.3
DFrame:SetPos(SCP_1025_CONFIG.ScrW * 0.5 - sizeFW / 2, SCP_1025_CONFIG.ScrH * 0.5 - sizeFH / 2)
DFrame:SetSize(sizeFW, sizeFH)
DFrame:SetTitle(scp_1025.GetTranslation("error_form"))
DFrame:MakePopup()
DFrame:SetDraggable(false)
DFrame:ShowCloseButton(false)
local w, h = DFrame:GetSize()
local wFrame, hFrame = DFrame:GetSize()

local richtext = vgui.Create("RichText", DFrame)
richtext:Dock(TOP)
richtext:InsertColorChange( 255, 0, 0, 255 )
richtext:AppendText(scp_1025.GetTranslation(message))
local background = Color(121, 121, 121, 200)
local colorText = Color(155, 0, 0)
DFrame.Paint = function(self, w, h)
draw.RoundedBox(2, 0, 0, w, h, background)
draw.DrawText(scp_1025.GetTranslation(message), "SCP01025_Error", w * 0.5, h * 0.4, colorText, TEXT_ALIGN_CENTER)
end

local DermaButton = vgui.Create("DButton", DFrame)
local sizeBW, sizeBH = 250, 30
DermaButton:SetText(scp_1025.GetTranslation("ok_form"))
DermaButton:SetPos(w * 0.1, h * 0.5)
DermaButton:SetSize(250, 30)
DermaButton:SetPos(wFrame * 0.5 - sizeBW / 2, hFrame * 0.8)
DermaButton:SetSize(sizeBW, sizeBH)
DermaButton.DoClick = function()
DFrame:Remove()
end
Expand Down Expand Up @@ -310,4 +312,10 @@ hook.Add("PopulateToolMenu", "PopulateToolMenu.SCP1025", function()
panel:AddItem(AddDisease)
panel:AddItem(RemoveDisease)
end)
end)

hook.Add("OnGamemodeLoaded", "OnGamemodeLoaded.SCP1025", function()
if (not SCP_1025_CONFIG.IsChromium) then
scp_1025.AlertChat("chromium")
end
end)

0 comments on commit 7ce2e86

Please sign in to comment.