Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/meetric1/gwater2
Browse files Browse the repository at this point in the history
  • Loading branch information
googer committed Jan 11, 2025
2 parents b9662c4 + bd03d1a commit fa8d322
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 327 deletions.
57 changes: 24 additions & 33 deletions lua/autorun/gwater2_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ AddCSLuaFile()

gwater2 = nil

local toload = (BRANCH == "x86-64" or BRANCH == "chromium") and "gwater2" or "gwater2_main" -- carrying

local load_stub = not util.IsBinaryModuleInstalled(toload) and (system.IsLinux() or system.IsOSX())
-- whether to load stub instead of actual module
-- useful for testing lua side of gw2 on native linux gmod

if SERVER then
include("gwater2_net.lua")
include("gwater2_interactions.lua")
Expand Down Expand Up @@ -61,32 +55,29 @@ local function gw2_error(text)
)
end

if not load_stub then
if !util.IsBinaryModuleInstalled(toload) then
gw2_error(string.format(
"===========================================================\n\n" ..
language.GetPhrase("gwater2.error.modulenotinstalled") .."\n\n" ..
language.GetPhrase("gwater2.error.modulefailedtoload.3") .."\n\n" ..
"===========================================================\n",
"NONE", BRANCH, jit.arch
))
return
end
local toload = (BRANCH == "x86-64" or BRANCH == "chromium") and "gwater2" or "gwater2_main" -- carrying
if !util.IsBinaryModuleInstalled(toload) then
gw2_error(string.format(
"===========================================================\n\n" ..
language.GetPhrase("gwater2.error.modulenotinstalled") .."\n\n" ..
language.GetPhrase("gwater2.error.modulefailedtoload.3") .."\n\n" ..
"===========================================================\n",
"NONE", BRANCH, jit.arch
))
return
end

local noerror, pcerr = pcall(function() require(toload) end)
if !noerror then
gw2_error(string.format(
"===========================================================\n\n" ..
language.GetPhrase("gwater2.error.modulefailedtoload.1").."\n"..
language.GetPhrase("gwater2.error.modulefailedtoload.2").."\n\n"..
language.GetPhrase("gwater2.error.modulefailedtoload.3") .."\n\n" ..
"===========================================================\n",
pcerr or "NONE", BRANCH, jit.arch
))
return
end
else
include("gwater2_stub.lua")
local noerror, pcerr = pcall(function() require(toload) end)
if !noerror then
gw2_error(string.format(
"===========================================================\n\n" ..
language.GetPhrase("gwater2.error.modulefailedtoload.1").."\n"..
language.GetPhrase("gwater2.error.modulefailedtoload.2").."\n\n"..
language.GetPhrase("gwater2.error.modulefailedtoload.3") .."\n\n" ..
"===========================================================\n",
pcerr or "NONE", BRANCH, jit.arch
))
return
end

print("[GWater2]: Loaded successfully with language: " .. lang)
Expand Down Expand Up @@ -280,8 +271,8 @@ hook.Add("HUDPaint", "gwater2_status", function()
end
if gwater2.solver:GetActiveParticles() <= 0 and frac >= 1 then return end
local text = format_int(gwater2.solver:GetActiveParticles()) .. " / " .. format_int(gwater2.solver:GetMaxParticles())
draw.DrawText(text, "GWater2Text", ScrW()/2+2, 18-18*(1-frac), Color(0, 0, 0, 255*frac), TEXT_ALIGN_CENTER)
draw.DrawText(text, "GWater2Text", ScrW()/2, 16-18*(1-frac), ColorAlpha(color_white, 255*frac), TEXT_ALIGN_CENTER)
draw.DrawText(text, "CloseCaption_Normal", ScrW()/2+2, 18-18*(1-frac), Color(0, 0, 0, 255*frac), TEXT_ALIGN_CENTER)
draw.DrawText(text, "CloseCaption_Normal", ScrW()/2, 16-18*(1-frac), ColorAlpha(color_white, 255*frac), TEXT_ALIGN_CENTER)

last = math.Approach(last, gwater2.solver:GetActiveParticles(), FrameTime()*100000)
local part_frac = last / gwater2.solver:GetMaxParticles()
Expand Down
115 changes: 11 additions & 104 deletions lua/gwater2_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ local function create_menu(init)
help_text:SetWrap(true)
help_text:SetColor(Color(255, 255, 255))
help_text:SetContentAlignment(7)
help_text:SetFont("GWater2Text")
help_text:SetFont("GWater2Param")
function tabs:Paint(w, h) styling.draw_main_background(0, 23, w, h-23) end

function frame:OnKeyCodePressed(key)
Expand All @@ -320,7 +320,7 @@ local function create_menu(init)

styling.define_scrollbar(tab:GetVBar())

local _ = tab:Add("DLabel") _:SetText(" ") _:SetFont("GWater2Title") _:Dock(TOP) _:SizeToContents() _:SetTall(_:GetTall() + 5)
local _ = tab:Add("DLabel") _:SetText(" ") _:SetFont("GWater2Title") _:Dock(TOP) _:SizeToContents()
function _:Paint(w, h)
draw.DrawText(_util.get_localised("About Tab.titletext", gwater2.VERSION), "GWater2Title", 6, 6, Color(0, 0, 0), TEXT_ALIGN_LEFT)
draw.DrawText(_util.get_localised("About Tab.titletext", gwater2.VERSION), "GWater2Title", 5, 5, Color(187, 245, 255), TEXT_ALIGN_LEFT)
Expand All @@ -334,7 +334,7 @@ local function create_menu(init)
label:SetTextInset(5, 5)
label:SetWrap(true)
label:SetContentAlignment(7)
label:SetFont("GWater2Text")
label:SetFont("GWater2Param")

label:SetPos(0, 0)
label:SetTall(800)
Expand All @@ -356,7 +356,7 @@ local function create_menu(init)

styling.define_scrollbar(tab:GetVBar())

local _ = tab:Add("DLabel") _:SetText(" ") _:SetFont("GWater2Title") _:Dock(TOP) _:SizeToContents() _:SetTall(_:GetTall() + 5)
local _ = tab:Add("DLabel") _:SetText(" ") _:SetFont("GWater2Title") _:Dock(TOP) _:SizeToContents()
function _:Paint(w, h)
draw.DrawText(_util.get_localised("Credits.titletext"), "GWater2Title", 6, 6, Color(0, 0, 0), TEXT_ALIGN_LEFT)
draw.DrawText(_util.get_localised("Credits.titletext"), "GWater2Title", 5, 5, Color(187, 245, 255), TEXT_ALIGN_LEFT)
Expand All @@ -370,7 +370,7 @@ local function create_menu(init)
label:SetTextInset(5, 5)
label:SetWrap(true)
label:SetContentAlignment(7)
label:SetFont("GWater2TextMono")
label:SetFont("GWater2Param")

local patrons_table = {"<Failed to load patron data!>"}

Expand All @@ -391,7 +391,7 @@ local function create_menu(init)

local top = math.max(math.floor((tab:GetVBar():GetScroll() - 440) / 20), 1) -- only draw what we see
for i = top, math.min(top + 30, #patrons_table) do
draw.DrawText(patrons_table[i], "GWater2Text", 6, height + i * 20, supporter_color, TEXT_ALIGN_LEFT)
draw.DrawText(patrons_table[i], "GWater2Param", 6, height + i * 20, supporter_color, TEXT_ALIGN_LEFT)
end
end

Expand All @@ -409,7 +409,7 @@ local function create_menu(init)

styling.define_scrollbar(tab:GetVBar())

local _ = tab:Add("DLabel") _:SetText(" ") _:SetFont("GWater2Title") _:Dock(TOP) _:SizeToContents() _:SetTall(_:GetTall() + 5)
local _ = tab:Add("DLabel") _:SetText(" ") _:SetFont("GWater2Title") _:Dock(TOP) _:SizeToContents()
function _:Paint(w, h)
draw.DrawText(_util.get_localised("Menu.titletext"), "GWater2Title", 6, 6, Color(0, 0, 0), TEXT_ALIGN_LEFT)
draw.DrawText(_util.get_localised("Menu.titletext"), "GWater2Title", 5, 5, Color(187, 245, 255), TEXT_ALIGN_LEFT)
Expand Down Expand Up @@ -494,39 +494,6 @@ local function create_menu(init)
end
})
end

local soundpacks = {
[1] = "default", ["default"] = 1
}

for _, pack in ipairs(select(-1, file.Find("sound/gwater2/menu/packs/*", "GAME"))) do
if pack == "default" then continue end
soundpacks[#soundpacks+1] = pack
soundpacks[pack] = #soundpacks
end
local _soundpack_label
_util.make_parameter_scratch(tab, "Menu.soundpack", "Sound Pack", {
nosync=true,
func=function(val)
gwater2.options.write_config({["menusp"]=soundpacks[val] or "default"})
_soundpack_label:SetText(soundpacks[val] or "default")
return true
end,
setup=function(slider)
slider:GetParent().button:Remove()
local label = slider:GetParent():Add("DLabel")
slider:GetParent().dlabel = label
_soundpack_label = label
label:Dock(BOTTOM)
label:SetText(gwater2.options.read_config().menusp or "default")
label:SetFont("GWater2Text")
slider:GetParent():SetTall(slider:GetParent():GetTall() * 2)
slider:SetValue(soundpacks[gwater2.options.read_config().menusp])
return true
end,
min=1,
max=#soundpacks
})
end

tabs.help_text = help_text
Expand All @@ -549,7 +516,6 @@ local function create_menu(init)
for _,tab in pairs(tabs:GetItems()) do
local rt = tab
tab = tab.Tab
tab:SetFont("GWater2TextSmall")
function tab:Paint(w, h)
styling.draw_main_background(0, 0, w - 4, self:IsActive() and h - 4 or h)
if tab.lastpush ~= nil then
Expand Down Expand Up @@ -609,69 +575,11 @@ local function create_menu(init)
cfg.sounds = sounds
end

function tabs.tabScroller.btnLeft:Paint(w, h)
styling.draw_main_background(0, 0, w, h) styling.draw_main_background(0, 0, w, h)
surface.SetDrawColor(255, 255, 255, 255)

surface.DrawLine(w/2-w/6, h/2, w/2+w/6, 4)
surface.DrawLine(w/2-w/6, h/2, w/2+w/6, h-4)
end

function tabs.tabScroller.btnRight:Paint(w, h)
styling.draw_main_background(0, 0, w, h) styling.draw_main_background(0, 0, w, h)
surface.SetDrawColor(255, 255, 255, 255)

surface.DrawLine(w/2-w/6, 4, w/2+w/6, h/2)
surface.DrawLine(w/2-w/6, h-4, w/2+w/6, h/2)
end

return frame
end

surface.CreateFont("GWater2TextSmall", {
font = (system.IsWindows() and "Roboto" or "RobotoVariable.ttf"),
--font = (system.IsWindows() and "Space Mono" or "SpaceMonoRegular.ttf"),
--font = (system.IsWindows() and "Titillium Web" or "TitilliumWeb-Regular.ttf"),
extended = false,
size = 16,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
})

surface.CreateFont("GWater2Text", {
font = (system.IsWindows() and "Roboto" or "RobotoVariable.ttf"),
--font = (system.IsWindows() and "Space Mono" or "SpaceMonoRegular.ttf"),
--font = (system.IsWindows() and "Titillium Web" or "TitilliumWeb-Regular.ttf"),
extended = false,
size = 20,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
})

surface.CreateFont("GWater2TextMono", {
font = (system.IsWindows() and "Roboto Mono" or "RobotoMonoVariable.ttf"),
--font = (system.IsWindows() and "Space Mono" or "SpaceMonoRegular.ttf"),
--font = (system.IsWindows() and "Titillium Web" or "TitilliumWeb-Regular.ttf"),
surface.CreateFont("GWater2Param", {
font = "Space Mono",
extended = false,
size = 20,
weight = 500,
Expand All @@ -689,8 +597,7 @@ surface.CreateFont("GWater2TextMono", {
})

surface.CreateFont("GWater2Title", {
font = (system.IsWindows() and "Roboto" or "RobotoVariable.ttf"),
--font = (system.IsWindows() and "coolvetica" or "coolvetica.ttf"),
font = "coolvetica",
extended = false,
size = 24,
weight = 500,
Expand Down Expand Up @@ -745,7 +652,7 @@ hook.Add("GUIMousePressed", "gwater2_menuclose", function(mouse_code, aim_vector
end)

hook.Add("PopulateToolMenu", "gwater2_menu", function()
spawnmenu.AddToolMenuOption("Utilities", "gwater2", "gwater2_menu", "Menu Options", "", "", function(panel)
spawnmenu.AddToolMenuOption("Utilities", "GWater2", "gwater2_menu", "Menu Options", "", "", function(panel)
panel:ClearControls()
panel:Button("Open Menu", "gwater2_menu")
panel:KeyBinder("Menu Key", "gwater2_menukey")
Expand Down
28 changes: 4 additions & 24 deletions lua/menu/gwater2_params.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,18 @@ local performance = {

slider:SetValue(gwater2.solver:GetMaxParticles())
local panel = slider:GetParent()
local button = panel:Add("DImageButton")
local button = panel:Add("DButton")
button:Dock(RIGHT)
button:SetText("")
button:SetImage("icon16/accept.png")
button:SizeToContents()
button:SetKeepAspect(true)
button:SetStretchToFit(false)
button:SetWide(button:GetTall())
button.Paint = nil
panel.button_apply = button
function button:DoClick()
local frame = styling.create_blocking_frame()
frame:SetSize(600, 300)
frame:Center()
frame:SetScreenLock(false)
frame:ShowCloseButton(false)

local label = frame:Add("DLabel")
label:Dock(TOP)
Expand All @@ -255,9 +253,7 @@ local performance = {
local confirm = vgui.Create("DImageButton", buttons)
confirm:SetPos(600 * (3/4) - 10, 0)
confirm:SetSize(20, 20)
confirm:SetText("5")
confirm:SetFont("GWater2TextMono")
confirm:SetKeepAspect(true)
confirm:SetImage("icon16/accept.png")
confirm.Paint = nil
function confirm:DoClick()
gwater2.solver:Destroy()
Expand All @@ -270,25 +266,9 @@ local performance = {
_util.emit_sound("select_ok")
end

confirm:SetEnabled(false)
confirm:SetColor(Color(255, 255, 255))
for i=1, 4 do
timer.Simple(i, function()
if not IsValid(confirm) then return end
confirm:SetText(tostring(5-i))
end)
end
timer.Simple(5, function()
if not IsValid(confirm) then return end
confirm:SetImage("icon16/accept.png")
confirm:SetText("")
confirm:SetEnabled(true)
end)

local deny = vgui.Create("DImageButton", buttons)
deny:SetPos(600 * (1/4) - 10, 0)
deny:SetSize(20, 20)
deny:SetKeepAspect(true)
deny:SetImage("icon16/cross.png")
deny.Paint = nil
function deny:DoClick()
Expand Down
2 changes: 1 addition & 1 deletion lua/menu/gwater2_paramstabs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ local function init_tab(tabs, tab_name, image, recursive)

styling.define_scrollbar(tab:GetVBar())

local _ = tab:Add("DLabel") _:SetText(" ") _:SetFont("GWater2Title") _:Dock(TOP) _:SizeToContents() _:SetTall(_:GetTall() + 5)
local _ = tab:Add("DLabel") _:SetText(" ") _:SetFont("GWater2Title") _:Dock(TOP) _:SizeToContents()
function _:Paint(w, h)
draw.DrawText(util.get_localised(tab_name .. ".titletext"), "GWater2Title", 6, 6, Color(0, 0, 0), TEXT_ALIGN_LEFT)
draw.DrawText(util.get_localised(tab_name .. ".titletext"), "GWater2Title", 5, 5, Color(187, 245, 255), TEXT_ALIGN_LEFT)
Expand Down
Loading

0 comments on commit fa8d322

Please sign in to comment.