mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-17 05:43:46 +03:00
Upload
This commit is contained in:
270
gamemodes/helix/plugins/area/cl_hooks.lua
Normal file
270
gamemodes/helix/plugins/area/cl_hooks.lua
Normal file
@@ -0,0 +1,270 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
local function DrawTextBackground(x, y, text, font, backgroundColor, padding)
|
||||
font = font or "ixSubTitleFont"
|
||||
padding = padding or 8
|
||||
backgroundColor = backgroundColor or Color(88, 88, 88, 255)
|
||||
|
||||
surface.SetFont(font)
|
||||
local textWidth, textHeight = surface.GetTextSize(text)
|
||||
local width, height = textWidth + padding * 2, textHeight + padding * 2
|
||||
|
||||
ix.util.DrawBlurAt(x, y, width, height)
|
||||
surface.SetDrawColor(0, 0, 0, 40)
|
||||
surface.DrawRect(x, y, width, height)
|
||||
|
||||
derma.SkinFunc("DrawImportantBackground", x, y, width, height, backgroundColor)
|
||||
|
||||
surface.SetTextColor(color_white)
|
||||
surface.SetTextPos(x + padding, y + padding)
|
||||
surface.DrawText(text)
|
||||
|
||||
return height
|
||||
end
|
||||
|
||||
function PLUGIN:InitPostEntity()
|
||||
hook.Run("SetupAreaProperties")
|
||||
end
|
||||
|
||||
function PLUGIN:ChatboxCreated()
|
||||
if (IsValid(self.panel)) then
|
||||
self.panel:Remove()
|
||||
end
|
||||
|
||||
self.panel = vgui.Create("ixArea")
|
||||
end
|
||||
|
||||
function PLUGIN:ChatboxPositionChanged(x, y, width, height)
|
||||
if (!IsValid(self.panel)) then
|
||||
return
|
||||
end
|
||||
|
||||
self.panel:SetSize(width, y)
|
||||
self.panel:SetPos(32, 0)
|
||||
end
|
||||
|
||||
function PLUGIN:ShouldDrawCrosshair()
|
||||
if (ix.area.bEditing) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerBindPress(client, bind, bPressed)
|
||||
if (!ix.area.bEditing) then
|
||||
return
|
||||
end
|
||||
|
||||
if ((bind:find("invnext") or bind:find("invprev")) and bPressed) then
|
||||
return true
|
||||
elseif (bind:find("attack2") and bPressed) then
|
||||
self:EditRightClick()
|
||||
return true
|
||||
elseif (bind:find("attack") and bPressed) then
|
||||
self:EditClick()
|
||||
return true
|
||||
elseif (bind:find("reload") and bPressed) then
|
||||
self:EditReload()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:HUDPaint()
|
||||
if (!ix.area.bEditing) then
|
||||
return
|
||||
end
|
||||
|
||||
local id = LocalPlayer():GetArea()
|
||||
local area = ix.area.stored[id]
|
||||
local height = ScrH()
|
||||
|
||||
local y = 64
|
||||
y = y + DrawTextBackground(64, y, L("areaEditMode"), nil, ix.config.Get("color"))
|
||||
|
||||
if (!self.editStart) then
|
||||
y = y + DrawTextBackground(64, y, L("areaEditTip"), "ixSmallTitleFont")
|
||||
DrawTextBackground(64, y, L("areaRemoveTip"), "ixSmallTitleFont")
|
||||
else
|
||||
DrawTextBackground(64, y, L("areaFinishTip"), "ixSmallTitleFont")
|
||||
end
|
||||
|
||||
if (area) then
|
||||
DrawTextBackground(64, height - 64 - ScreenScale(12), id, "ixSmallTitleFont", area.properties.color)
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:PostDrawTranslucentRenderables(bDepth, bSkybox)
|
||||
if (bSkybox or !ix.area.bEditing) then
|
||||
return
|
||||
end
|
||||
|
||||
-- draw all areas
|
||||
for k, v in pairs(ix.area.stored) do
|
||||
local center, min, max = self:GetLocalAreaPosition(v.startPosition, v.endPosition)
|
||||
local color = ColorAlpha(v.properties.color or ix.config.Get("color"), 255)
|
||||
|
||||
render.DrawWireframeBox(center, angle_zero, min, max, color)
|
||||
|
||||
cam.Start2D()
|
||||
local centerScreen = center:ToScreen()
|
||||
local _, textHeight = draw.SimpleText(
|
||||
k, "BudgetLabel", centerScreen.x, centerScreen.y, color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
|
||||
if (v.type != "area") then
|
||||
draw.SimpleText(
|
||||
"(" .. L(v.type) .. ")", "BudgetLabel",
|
||||
centerScreen.x, centerScreen.y + textHeight, color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER
|
||||
)
|
||||
end
|
||||
cam.End2D()
|
||||
end
|
||||
|
||||
-- draw currently edited area
|
||||
if (self.editStart) then
|
||||
local center, min, max = self:GetLocalAreaPosition(self.editStart, self:GetPlayerAreaTrace().HitPos)
|
||||
local color = Color(255, 255, 255, 25 + (1 + math.sin(SysTime() * 6)) * 115)
|
||||
|
||||
render.DrawWireframeBox(center, angle_zero, min, max, color)
|
||||
|
||||
cam.Start2D()
|
||||
local centerScreen = center:ToScreen()
|
||||
|
||||
draw.SimpleText(L("areaNew"), "BudgetLabel",
|
||||
centerScreen.x, centerScreen.y, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
cam.End2D()
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:EditRightClick()
|
||||
if (self.editStart) then
|
||||
self.editStart = nil
|
||||
else
|
||||
self:StopEditing()
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:EditClick()
|
||||
if (!self.editStart) then
|
||||
self.editStart = LocalPlayer():GetEyeTraceNoCursor().HitPos
|
||||
elseif (self.editStart and !self.editProperties) then
|
||||
self.editProperties = true
|
||||
|
||||
local panel = vgui.Create("ixAreaEdit")
|
||||
panel:MakePopup()
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:EditReload()
|
||||
if (self.editStart) then
|
||||
return
|
||||
end
|
||||
|
||||
local id = LocalPlayer():GetArea()
|
||||
local area = ix.area.stored[id]
|
||||
|
||||
if (!area) then
|
||||
return
|
||||
end
|
||||
|
||||
Derma_Query(L("areaDeleteConfirm", id), L("areaDelete"),
|
||||
L("no"), nil,
|
||||
L("yes"), function()
|
||||
net.Start("ixAreaRemove")
|
||||
net.WriteString(id)
|
||||
net.SendToServer()
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
function PLUGIN:ShouldDisplayArea(id)
|
||||
if (ix.area.bEditing) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:OnAreaChanged(oldID, newID)
|
||||
local client = LocalPlayer()
|
||||
client.ixArea = newID
|
||||
|
||||
local area = ix.area.stored[newID]
|
||||
|
||||
if (!area) then
|
||||
client.ixInArea = false
|
||||
return
|
||||
end
|
||||
|
||||
client.ixInArea = true
|
||||
|
||||
if (hook.Run("ShouldDisplayArea", newID) == false or !area.properties.display) then
|
||||
return
|
||||
end
|
||||
|
||||
local format = newID .. (ix.option.Get("24hourTime", false) and ", %H:%M." or ", %I:%M %p.")
|
||||
format = ix.date.GetFormatted(format)
|
||||
|
||||
if (ix.option.Get("showAreaNotices", true)) then
|
||||
self.panel:AddEntry(format, area.properties.color)
|
||||
end
|
||||
end
|
||||
|
||||
net.Receive("ixAreaEditStart", function()
|
||||
PLUGIN:StartEditing()
|
||||
end)
|
||||
|
||||
net.Receive("ixAreaEditEnd", function()
|
||||
PLUGIN:StopEditing()
|
||||
end)
|
||||
|
||||
net.Receive("ixAreaAdd", function()
|
||||
local name = net.ReadString()
|
||||
local type = net.ReadString()
|
||||
local startPosition, endPosition = net.ReadVector(), net.ReadVector()
|
||||
local properties = net.ReadTable()
|
||||
|
||||
if (name != "") then
|
||||
ix.area.stored[name] = {
|
||||
type = type,
|
||||
startPosition = startPosition,
|
||||
endPosition = endPosition,
|
||||
properties = properties
|
||||
}
|
||||
end
|
||||
end)
|
||||
|
||||
net.Receive("ixAreaRemove", function()
|
||||
local name = net.ReadString()
|
||||
|
||||
if (ix.area.stored[name]) then
|
||||
ix.area.stored[name] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
net.Receive("ixAreaSync", function()
|
||||
local length = net.ReadUInt(32)
|
||||
local data = net.ReadData(length)
|
||||
local uncompressed = util.Decompress(data)
|
||||
|
||||
if (!uncompressed) then
|
||||
ErrorNoHalt("[Helix] Unable to decompress area data!\n")
|
||||
return
|
||||
end
|
||||
|
||||
-- Set the list of texts to the ones provided by the server.
|
||||
ix.area.stored = util.JSONToTable(uncompressed)
|
||||
end)
|
||||
|
||||
net.Receive("ixAreaChanged", function()
|
||||
local oldID, newID = net.ReadString(), net.ReadString()
|
||||
|
||||
hook.Run("OnAreaChanged", oldID, newID)
|
||||
end)
|
||||
36
gamemodes/helix/plugins/area/cl_plugin.lua
Normal file
36
gamemodes/helix/plugins/area/cl_plugin.lua
Normal file
@@ -0,0 +1,36 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
function PLUGIN:GetPlayerAreaTrace()
|
||||
local client = LocalPlayer()
|
||||
|
||||
return util.TraceLine({
|
||||
start = client:GetShootPos(),
|
||||
endpos = client:GetShootPos() + client:GetForward() * 96,
|
||||
filter = client
|
||||
})
|
||||
end
|
||||
|
||||
function PLUGIN:StartEditing()
|
||||
ix.area.bEditing = true
|
||||
self.editStart = nil
|
||||
self.editProperties = nil
|
||||
end
|
||||
|
||||
function PLUGIN:StopEditing()
|
||||
ix.area.bEditing = false
|
||||
|
||||
if (IsValid(ix.gui.areaEdit)) then
|
||||
ix.gui.areaEdit:Remove()
|
||||
end
|
||||
end
|
||||
192
gamemodes/helix/plugins/area/derma/cl_area.lua
Normal file
192
gamemodes/helix/plugins/area/derma/cl_area.lua
Normal file
@@ -0,0 +1,192 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
-- area entry
|
||||
DEFINE_BASECLASS("Panel")
|
||||
local PANEL = {}
|
||||
|
||||
AccessorFunc(PANEL, "text", "Text", FORCE_STRING)
|
||||
AccessorFunc(PANEL, "backgroundColor", "BackgroundColor")
|
||||
AccessorFunc(PANEL, "tickSound", "TickSound", FORCE_STRING)
|
||||
AccessorFunc(PANEL, "tickSoundRange", "TickSoundRange")
|
||||
AccessorFunc(PANEL, "backgroundAlpha", "BackgroundAlpha", FORCE_NUMBER)
|
||||
AccessorFunc(PANEL, "expireTime", "ExpireTime", FORCE_NUMBER)
|
||||
AccessorFunc(PANEL, "animationTime", "AnimationTime", FORCE_NUMBER)
|
||||
|
||||
function PANEL:Init()
|
||||
self:DockPadding(4, 4, 4, 4)
|
||||
self:SetSize(self:GetParent():GetWide(), 0)
|
||||
|
||||
self.label = self:Add("DLabel")
|
||||
self.label:Dock(FILL)
|
||||
self.label:SetFont("ixMediumLightFont")
|
||||
self.label:SetTextColor(color_white)
|
||||
self.label:SetExpensiveShadow(1, color_black)
|
||||
self.label:SetText("Area")
|
||||
|
||||
self.text = ""
|
||||
self.tickSound = "ui/buttonrollover.wav"
|
||||
self.tickSoundRange = {190, 200}
|
||||
self.backgroundAlpha = 255
|
||||
self.expireTime = 8
|
||||
self.animationTime = 2
|
||||
|
||||
self.character = 1
|
||||
self.createTime = RealTime()
|
||||
self.currentAlpha = 255
|
||||
self.currentHeight = 0
|
||||
self.nextThink = RealTime()
|
||||
end
|
||||
|
||||
function PANEL:Show()
|
||||
self:CreateAnimation(0.5, {
|
||||
index = -1,
|
||||
target = {currentHeight = self.label:GetTall() + 8},
|
||||
easing = "outQuint",
|
||||
|
||||
Think = function(animation, panel)
|
||||
panel:SetTall(panel.currentHeight)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
function PANEL:SetFont(font)
|
||||
self.label:SetFont(font)
|
||||
end
|
||||
|
||||
function PANEL:SetText(text)
|
||||
if (text:sub(1, 1) == "@") then
|
||||
text = L(text:sub(2))
|
||||
end
|
||||
|
||||
self.label:SetText(text)
|
||||
self.text = text
|
||||
self.character = 1
|
||||
end
|
||||
|
||||
function PANEL:Think()
|
||||
local time = RealTime()
|
||||
|
||||
if (time >= self.nextThink) then
|
||||
if (self.character < self.text:utf8len()) then
|
||||
self.character = self.character + 1
|
||||
self.label:SetText(string.utf8sub(self.text, 1, self.character))
|
||||
|
||||
LocalPlayer():EmitSound(self.tickSound, 100, math.random(self.tickSoundRange[1], self.tickSoundRange[2]))
|
||||
end
|
||||
|
||||
if (time >= self.createTime + self.expireTime and !self.bRemoving) then
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
self.nextThink = time + 0.05
|
||||
end
|
||||
end
|
||||
|
||||
function PANEL:SizeToContents()
|
||||
self:SetWide(self:GetParent():GetWide())
|
||||
|
||||
self.label:SetWide(self:GetWide())
|
||||
self.label:SizeToContentsY()
|
||||
end
|
||||
|
||||
function PANEL:Paint(width, height)
|
||||
self.backgroundAlpha = math.max(self.backgroundAlpha - 200 * FrameTime(), 0)
|
||||
|
||||
derma.SkinFunc("PaintAreaEntry", self, width, height)
|
||||
end
|
||||
|
||||
function PANEL:Remove()
|
||||
if (self.bRemoving) then
|
||||
return
|
||||
end
|
||||
|
||||
self:CreateAnimation(self.animationTime, {
|
||||
target = {currentAlpha = 0},
|
||||
|
||||
Think = function(animation, panel)
|
||||
panel:SetAlpha(panel.currentAlpha)
|
||||
end,
|
||||
|
||||
OnComplete = function(animation, panel)
|
||||
panel:CreateAnimation(0.5, {
|
||||
index = -1,
|
||||
target = {currentHeight = 0},
|
||||
easing = "outQuint",
|
||||
|
||||
Think = function(_, sizePanel)
|
||||
sizePanel:SetTall(sizePanel.currentHeight)
|
||||
end,
|
||||
|
||||
OnComplete = function(_, sizePanel)
|
||||
sizePanel:OnRemove()
|
||||
BaseClass.Remove(sizePanel)
|
||||
end
|
||||
})
|
||||
end
|
||||
})
|
||||
|
||||
self.bRemoving = true
|
||||
end
|
||||
|
||||
function PANEL:OnRemove()
|
||||
end
|
||||
|
||||
vgui.Register("ixAreaEntry", PANEL, "Panel")
|
||||
|
||||
-- main panel
|
||||
PANEL = {}
|
||||
|
||||
function PANEL:Init()
|
||||
local chatWidth, _ = chat.GetChatBoxSize()
|
||||
local _, chatY = chat.GetChatBoxPos()
|
||||
|
||||
self:SetSize(chatWidth, chatY)
|
||||
self:SetPos(32, 0)
|
||||
self:ParentToHUD()
|
||||
|
||||
self.entries = {}
|
||||
ix.gui.area = self
|
||||
end
|
||||
|
||||
function PANEL:AddEntry(entry, color)
|
||||
color = color or ix.config.Get("color")
|
||||
|
||||
local id = #self.entries + 1
|
||||
local panel = entry
|
||||
|
||||
if (isstring(entry)) then
|
||||
panel = self:Add("ixAreaEntry")
|
||||
panel:SetText(entry)
|
||||
end
|
||||
|
||||
panel:SetBackgroundColor(color)
|
||||
panel:SizeToContents()
|
||||
panel:Dock(BOTTOM)
|
||||
panel:Show()
|
||||
panel.OnRemove = function()
|
||||
for k, v in pairs(self.entries) do
|
||||
if (v == panel) then
|
||||
table.remove(self.entries, k)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.entries[id] = panel
|
||||
return id
|
||||
end
|
||||
|
||||
function PANEL:GetEntries()
|
||||
return self.entries
|
||||
end
|
||||
|
||||
vgui.Register("ixArea", PANEL, "Panel")
|
||||
203
gamemodes/helix/plugins/area/derma/cl_areaedit.lua
Normal file
203
gamemodes/helix/plugins/area/derma/cl_areaedit.lua
Normal file
@@ -0,0 +1,203 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
local PANEL = {}
|
||||
|
||||
function PANEL:Init()
|
||||
if (IsValid(ix.gui.areaEdit)) then
|
||||
ix.gui.areaEdit:Remove()
|
||||
end
|
||||
|
||||
ix.gui.areaEdit = self
|
||||
self.list = {}
|
||||
self.properties = {}
|
||||
|
||||
self:SetDeleteOnClose(true)
|
||||
self:SetSizable(true)
|
||||
self:SetTitle(L("areaNew"))
|
||||
|
||||
-- scroll panel
|
||||
self.canvas = self:Add("DScrollPanel")
|
||||
self.canvas:Dock(FILL)
|
||||
|
||||
-- name entry
|
||||
self.nameEntry = vgui.Create("ixTextEntry")
|
||||
self.nameEntry:SetFont("ixMenuButtonFont")
|
||||
self.nameEntry:SetText(L("areaNew"))
|
||||
|
||||
local listRow = self.canvas:Add("ixListRow")
|
||||
listRow:SetList(self.list)
|
||||
listRow:SetLabelText(L("name"))
|
||||
listRow:SetRightPanel(self.nameEntry)
|
||||
listRow:Dock(TOP)
|
||||
listRow:SizeToContents()
|
||||
|
||||
-- type entry
|
||||
self.typeEntry = self.canvas:Add("DComboBox")
|
||||
self.typeEntry:Dock(RIGHT)
|
||||
self.typeEntry:SetFont("ixMenuButtonFont")
|
||||
self.typeEntry:SetTextColor(color_white)
|
||||
self.typeEntry.OnSelect = function(panel)
|
||||
panel:SizeToContents()
|
||||
panel:SetWide(panel:GetWide() + 12) -- padding for arrow (nice)
|
||||
end
|
||||
|
||||
for id, name in pairs(ix.area.types) do
|
||||
self.typeEntry:AddChoice(L(name), id, id == "area")
|
||||
end
|
||||
|
||||
listRow = self.canvas:Add("ixListRow")
|
||||
listRow:SetList(self.list)
|
||||
listRow:SetLabelText(L("type"))
|
||||
listRow:SetRightPanel(self.typeEntry)
|
||||
listRow:Dock(TOP)
|
||||
listRow:SizeToContents()
|
||||
|
||||
-- properties
|
||||
for k, v in pairs(ix.area.properties) do
|
||||
local panel
|
||||
|
||||
if (v.type == ix.type.string or v.type == ix.type.number) then
|
||||
panel = vgui.Create("ixTextEntry")
|
||||
panel:SetFont("ixMenuButtonFont")
|
||||
panel:SetText(tostring(v.default))
|
||||
|
||||
if (v.type == ix.type.number) then
|
||||
panel.realGetValue = panel.GetValue
|
||||
panel.GetValue = function()
|
||||
return tonumber(panel:realGetValue()) or v.default
|
||||
end
|
||||
end
|
||||
elseif (v.type == ix.type.bool) then
|
||||
panel = vgui.Create("ixCheckBox")
|
||||
panel:SetChecked(v.default, true)
|
||||
elseif (v.type == ix.type.color) then
|
||||
panel = vgui.Create("DButton")
|
||||
panel.value = v.default
|
||||
panel:SetText("")
|
||||
panel:SetSize(64, 64)
|
||||
|
||||
panel.picker = vgui.Create("DColorCombo")
|
||||
panel.picker:SetColor(panel.value)
|
||||
panel.picker:SetVisible(false)
|
||||
panel.picker.OnValueChanged = function(_, newColor)
|
||||
panel.value = newColor
|
||||
end
|
||||
|
||||
panel.Paint = function(_, width, height)
|
||||
surface.SetDrawColor(0, 0, 0, 255)
|
||||
surface.DrawOutlinedRect(0, 0, width, height)
|
||||
|
||||
surface.SetDrawColor(panel.value)
|
||||
surface.DrawRect(4, 4, width - 8, height - 8)
|
||||
end
|
||||
|
||||
panel.DoClick = function()
|
||||
if (!panel.picker:IsVisible()) then
|
||||
local x, y = panel:LocalToScreen(0, 0)
|
||||
|
||||
panel.picker:SetPos(x, y + 32)
|
||||
panel.picker:SetColor(panel.value)
|
||||
panel.picker:SetVisible(true)
|
||||
panel.picker:MakePopup()
|
||||
else
|
||||
panel.picker:SetVisible(false)
|
||||
end
|
||||
end
|
||||
|
||||
panel.OnRemove = function()
|
||||
panel.picker:Remove()
|
||||
end
|
||||
|
||||
panel.GetValue = function()
|
||||
return panel.picker:GetColor()
|
||||
end
|
||||
end
|
||||
|
||||
if (IsValid(panel)) then
|
||||
local row = self.canvas:Add("ixListRow")
|
||||
row:SetList(self.list)
|
||||
row:SetLabelText(L(k))
|
||||
row:SetRightPanel(panel)
|
||||
row:Dock(TOP)
|
||||
row:SizeToContents()
|
||||
end
|
||||
|
||||
self.properties[k] = function()
|
||||
return panel:GetValue()
|
||||
end
|
||||
end
|
||||
|
||||
-- save button
|
||||
self.saveButton = self:Add("DButton")
|
||||
self.saveButton:SetText(L("save"))
|
||||
self.saveButton:SizeToContents()
|
||||
self.saveButton:Dock(BOTTOM)
|
||||
self.saveButton.DoClick = function()
|
||||
self:Submit()
|
||||
end
|
||||
|
||||
self:SizeToContents()
|
||||
self:SetPos(64, 0)
|
||||
self:CenterVertical()
|
||||
end
|
||||
|
||||
function PANEL:SizeToContents()
|
||||
local width = 64
|
||||
local height = 37
|
||||
|
||||
for _, v in ipairs(self.canvas:GetCanvas():GetChildren()) do
|
||||
width = math.max(width, v:GetLabelWidth())
|
||||
height = height + v:GetTall()
|
||||
end
|
||||
|
||||
self:SetWide(width + 200)
|
||||
self:SetTall(height + self.saveButton:GetTall())
|
||||
end
|
||||
|
||||
function PANEL:Submit()
|
||||
local name = self.nameEntry:GetValue()
|
||||
|
||||
if (ix.area.stored[name]) then
|
||||
ix.util.NotifyLocalized("areaAlreadyExists")
|
||||
return
|
||||
end
|
||||
|
||||
local properties = {}
|
||||
|
||||
for k, v in pairs(self.properties) do
|
||||
properties[k] = v()
|
||||
end
|
||||
|
||||
local _, type = self.typeEntry:GetSelected()
|
||||
|
||||
net.Start("ixAreaAdd")
|
||||
net.WriteString(name)
|
||||
net.WriteString(type)
|
||||
net.WriteVector(PLUGIN.editStart)
|
||||
net.WriteVector(PLUGIN:GetPlayerAreaTrace().HitPos)
|
||||
net.WriteTable(properties)
|
||||
net.SendToServer()
|
||||
|
||||
PLUGIN.editStart = nil
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
function PANEL:OnRemove()
|
||||
PLUGIN.editProperties = nil
|
||||
end
|
||||
|
||||
vgui.Register("ixAreaEdit", PANEL, "DFrame")
|
||||
|
||||
if (IsValid(ix.gui.areaEdit)) then
|
||||
ix.gui.areaEdit:Remove()
|
||||
end
|
||||
29
gamemodes/helix/plugins/area/languages/sh_english.lua
Normal file
29
gamemodes/helix/plugins/area/languages/sh_english.lua
Normal file
@@ -0,0 +1,29 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
LANGUAGE = {
|
||||
area = "Area",
|
||||
areas = "Areas",
|
||||
areaEditMode = "Area Edit Mode",
|
||||
areaNew = "New Area",
|
||||
areaAlreadyExists = "An area with this name already exists!",
|
||||
areaDoesntExist = "An area with that name doesn't exist!",
|
||||
areaInvalidType = "You have specified an invalid area type!",
|
||||
areaEditTip = "Click to start creating an area. Right click to exit.",
|
||||
areaFinishTip = "Click again to finish drawing the area. Right click to go back.",
|
||||
areaRemoveTip = "Press reload to remove the area you're currently in.",
|
||||
areaDeleteConfirm = "Are you sure you want to delete the area \"%s\"?",
|
||||
areaDelete = "Delete Area",
|
||||
|
||||
cmdAreaEdit = "Enters area edit mode.",
|
||||
|
||||
optShowAreaNotices = "Show Area Notices",
|
||||
optdShowAreaNotices = "Whether a notification should appear on the screen when you enter a new area."
|
||||
}
|
||||
26
gamemodes/helix/plugins/area/languages/sh_russian.lua
Normal file
26
gamemodes/helix/plugins/area/languages/sh_russian.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
LANGUAGE = {
|
||||
area = "Зона",
|
||||
areas = "Зоны",
|
||||
areaEditMode = "Редактирование зоны",
|
||||
areaNew = "Новая зона",
|
||||
areaAlreadyExists = "Зона с таким названием уже существует!",
|
||||
areaDoesntExist = "Зона с таким названием не существует!",
|
||||
areaInvalidType = "Вы указали неверный тип зоны!",
|
||||
areaEditTip = "Нажмите, чтобы начать создание зоны. Щелкните правой кнопкой мыши, чтобы выйти.",
|
||||
areaFinishTip = "Нажмите еще раз, чтобы закончить создание зоны. Щелкните правой кнопкой мыши, чтобы вернуться.",
|
||||
areaRemoveTip = "Нажмите перезарядку, чтобы удалить зону, в которой вы находитесь.",
|
||||
areaDeleteConfirm = "Вы уверены, что хотите удалить зону \"%s\"?",
|
||||
areaDelete = "Удалить зону",
|
||||
|
||||
cmdAreaEdit = "Вход в режим редактирования зоны."
|
||||
}
|
||||
104
gamemodes/helix/plugins/area/sh_plugin.lua
Normal file
104
gamemodes/helix/plugins/area/sh_plugin.lua
Normal file
@@ -0,0 +1,104 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
PLUGIN.name = "Areas"
|
||||
PLUGIN.author = "`impulse"
|
||||
PLUGIN.description = "Provides customizable area definitions."
|
||||
|
||||
ix.area = ix.area or {}
|
||||
ix.area.types = ix.area.types or {}
|
||||
ix.area.properties = ix.area.properties or {}
|
||||
ix.area.stored = ix.area.stored or {}
|
||||
|
||||
ix.config.Add("areaTickTime", 1, "How many seconds between each time a character's current area is calculated.",
|
||||
function(oldValue, newValue)
|
||||
if (SERVER) then
|
||||
timer.Remove("ixAreaThink")
|
||||
timer.Create("ixAreaThink", newValue, 0, function()
|
||||
PLUGIN:AreaThink()
|
||||
end)
|
||||
end
|
||||
end,
|
||||
{
|
||||
data = {min = 0.1, max = 4},
|
||||
category = "areas"
|
||||
}
|
||||
)
|
||||
|
||||
ix.option.Add("showAreaNotices", ix.type.bool, true, {
|
||||
category = "appearance",
|
||||
})
|
||||
|
||||
function ix.area.AddProperty(name, type, default, data)
|
||||
ix.area.properties[name] = {
|
||||
type = type,
|
||||
default = default
|
||||
}
|
||||
end
|
||||
|
||||
function ix.area.AddType(type, name)
|
||||
name = name or type
|
||||
|
||||
-- only store localized strings on the client
|
||||
ix.area.types[type] = CLIENT and name or true
|
||||
end
|
||||
|
||||
function PLUGIN:SetupAreaProperties()
|
||||
ix.area.AddType("area")
|
||||
|
||||
ix.area.AddProperty("color", ix.type.color, ix.config.Get("color"))
|
||||
ix.area.AddProperty("display", ix.type.bool, true)
|
||||
end
|
||||
|
||||
ix.util.Include("sv_plugin.lua")
|
||||
ix.util.Include("cl_plugin.lua")
|
||||
ix.util.Include("sv_hooks.lua")
|
||||
ix.util.Include("cl_hooks.lua")
|
||||
|
||||
-- return world center, local min, and local max from world start/end positions
|
||||
function PLUGIN:GetLocalAreaPosition(startPosition, endPosition)
|
||||
local center = LerpVector(0.5, startPosition, endPosition)
|
||||
local min = WorldToLocal(startPosition, angle_zero, center, angle_zero)
|
||||
local max = WorldToLocal(endPosition, angle_zero, center, angle_zero)
|
||||
|
||||
return center, min, max
|
||||
end
|
||||
|
||||
do
|
||||
local COMMAND = {}
|
||||
COMMAND.description = "@cmdAreaEdit"
|
||||
COMMAND.adminOnly = true
|
||||
|
||||
function COMMAND:OnRun(client)
|
||||
client:SetWepRaised(false)
|
||||
|
||||
net.Start("ixAreaEditStart")
|
||||
net.Send(client)
|
||||
end
|
||||
|
||||
ix.command.Add("AreaEdit", COMMAND)
|
||||
end
|
||||
|
||||
do
|
||||
local PLAYER = FindMetaTable("Player")
|
||||
|
||||
-- returns the current area the player is in, or the last valid one if the player is not in an area
|
||||
function PLAYER:GetArea()
|
||||
return self.ixArea
|
||||
end
|
||||
|
||||
-- returns true if the player is in any area, this does not use the last valid area like GetArea does
|
||||
function PLAYER:IsInArea()
|
||||
return self.ixInArea
|
||||
end
|
||||
end
|
||||
136
gamemodes/helix/plugins/area/sv_hooks.lua
Normal file
136
gamemodes/helix/plugins/area/sv_hooks.lua
Normal file
@@ -0,0 +1,136 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
function PLUGIN:LoadData()
|
||||
hook.Run("SetupAreaProperties")
|
||||
ix.area.stored = self:GetData() or {}
|
||||
|
||||
timer.Create("ixAreaThink", ix.config.Get("areaTickTime"), 0, function()
|
||||
self:AreaThink()
|
||||
end)
|
||||
end
|
||||
|
||||
function PLUGIN:SaveData()
|
||||
self:SetData(ix.area.stored)
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerInitialSpawn(client)
|
||||
timer.Simple(1, function()
|
||||
if (IsValid(client)) then
|
||||
local json = util.TableToJSON(ix.area.stored)
|
||||
local compressed = util.Compress(json)
|
||||
local length = compressed:len()
|
||||
|
||||
net.Start("ixAreaSync")
|
||||
net.WriteUInt(length, 32)
|
||||
net.WriteData(compressed, length)
|
||||
net.Send(client)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerLoadedCharacter(client)
|
||||
client.ixArea = ""
|
||||
client.ixInArea = nil
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerSpawn(client)
|
||||
client.ixArea = ""
|
||||
client.ixInArea = nil
|
||||
end
|
||||
|
||||
function PLUGIN:AreaThink()
|
||||
for _, client in ipairs(player.GetAll()) do
|
||||
local character = client:GetCharacter()
|
||||
|
||||
if (!client:Alive() or !character) then
|
||||
continue
|
||||
end
|
||||
|
||||
local overlappingBoxes = {}
|
||||
local position = client:GetPos() + client:OBBCenter()
|
||||
|
||||
for id, info in pairs(ix.area.stored) do
|
||||
if (position:WithinAABox(info.startPosition, info.endPosition)) then
|
||||
overlappingBoxes[#overlappingBoxes + 1] = id
|
||||
end
|
||||
end
|
||||
|
||||
if (#overlappingBoxes > 0) then
|
||||
local oldID = client:GetArea()
|
||||
local id = overlappingBoxes[1]
|
||||
|
||||
if (oldID != id) then
|
||||
hook.Run("OnPlayerAreaChanged", client, client.ixArea, id)
|
||||
client.ixArea = id
|
||||
end
|
||||
|
||||
client.ixInArea = true
|
||||
else
|
||||
client.ixInArea = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PLUGIN:OnPlayerAreaChanged(client, oldID, newID)
|
||||
net.Start("ixAreaChanged")
|
||||
net.WriteString(oldID)
|
||||
net.WriteString(newID)
|
||||
net.Send(client)
|
||||
end
|
||||
|
||||
net.Receive("ixAreaAdd", function(length, client)
|
||||
if (!client:Alive() or !CAMI.PlayerHasAccess(client, "Helix - AreaEdit", nil)) then
|
||||
return
|
||||
end
|
||||
|
||||
local id = net.ReadString()
|
||||
local type = net.ReadString()
|
||||
local startPosition, endPosition = net.ReadVector(), net.ReadVector()
|
||||
local properties = net.ReadTable()
|
||||
|
||||
if (!ix.area.types[type]) then
|
||||
client:NotifyLocalized("areaInvalidType")
|
||||
return
|
||||
end
|
||||
|
||||
if (ix.area.stored[id]) then
|
||||
client:NotifyLocalized("areaAlreadyExists")
|
||||
return
|
||||
end
|
||||
|
||||
for k, v in pairs(properties) do
|
||||
if (!isstring(k) or !ix.area.properties[k]) then
|
||||
continue
|
||||
end
|
||||
|
||||
properties[k] = ix.util.SanitizeType(ix.area.properties[k].type, v)
|
||||
end
|
||||
|
||||
ix.area.Create(id, type, startPosition, endPosition, nil, properties)
|
||||
ix.log.Add(client, "areaAdd", id)
|
||||
end)
|
||||
|
||||
net.Receive("ixAreaRemove", function(length, client)
|
||||
if (!client:Alive() or !CAMI.PlayerHasAccess(client, "Helix - AreaEdit", nil)) then
|
||||
return
|
||||
end
|
||||
|
||||
local id = net.ReadString()
|
||||
|
||||
if (!ix.area.stored[id]) then
|
||||
client:NotifyLocalized("areaDoesntExist")
|
||||
return
|
||||
end
|
||||
|
||||
ix.area.Remove(id)
|
||||
ix.log.Add(client, "areaRemove", id)
|
||||
end)
|
||||
65
gamemodes/helix/plugins/area/sv_plugin.lua
Normal file
65
gamemodes/helix/plugins/area/sv_plugin.lua
Normal file
@@ -0,0 +1,65 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
|
||||
util.AddNetworkString("ixAreaSync")
|
||||
util.AddNetworkString("ixAreaAdd")
|
||||
util.AddNetworkString("ixAreaRemove")
|
||||
util.AddNetworkString("ixAreaChanged")
|
||||
|
||||
util.AddNetworkString("ixAreaEditStart")
|
||||
util.AddNetworkString("ixAreaEditEnd")
|
||||
|
||||
ix.log.AddType("areaAdd", function(client, name)
|
||||
return string.format("%s has added area \"%s\".", client:Name(), tostring(name))
|
||||
end)
|
||||
|
||||
ix.log.AddType("areaRemove", function(client, name)
|
||||
return string.format("%s has removed area \"%s\".", client:Name(), tostring(name))
|
||||
end)
|
||||
|
||||
local function SortVector(first, second)
|
||||
return Vector(math.min(first.x, second.x), math.min(first.y, second.y), math.min(first.z, second.z)),
|
||||
Vector(math.max(first.x, second.x), math.max(first.y, second.y), math.max(first.z, second.z))
|
||||
end
|
||||
|
||||
function ix.area.Create(name, type, startPosition, endPosition, bNoReplicate, properties)
|
||||
local min, max = SortVector(startPosition, endPosition)
|
||||
|
||||
ix.area.stored[name] = {
|
||||
type = type or "area",
|
||||
startPosition = min,
|
||||
endPosition = max,
|
||||
bNoReplicate = bNoReplicate,
|
||||
properties = properties
|
||||
}
|
||||
|
||||
-- network to clients if needed
|
||||
if (!bNoReplicate) then
|
||||
net.Start("ixAreaAdd")
|
||||
net.WriteString(name)
|
||||
net.WriteString(type)
|
||||
net.WriteVector(startPosition)
|
||||
net.WriteVector(endPosition)
|
||||
net.WriteTable(properties)
|
||||
net.Broadcast()
|
||||
end
|
||||
end
|
||||
|
||||
function ix.area.Remove(name, bNoReplicate)
|
||||
ix.area.stored[name] = nil
|
||||
|
||||
-- network to clients if needed
|
||||
if (!bNoReplicate) then
|
||||
net.Start("ixAreaRemove")
|
||||
net.WriteString(name)
|
||||
net.Broadcast()
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user