mirror of
https://github.com/metrostroi-repo/MetrostroiAddon.git
synced 2026-05-02 00:42:29 +00:00
Добавлена проверка на ULX Добавлена возможность двойного клика для телепорта Закрытие окна после телепорта
85 lines
2.9 KiB
Lua
85 lines
2.9 KiB
Lua
local function OpenGUI()
|
|
-- Main frame
|
|
local Frame = vgui.Create("DFrame")
|
|
Frame:SetSize(600,300)
|
|
Frame:Center()
|
|
Frame:SetTitle(Metrostroi.GetPhrase("StationList.Title"))
|
|
Frame:SetDeleteOnClose(true)
|
|
Frame:MakePopup()
|
|
|
|
-- Check ULX
|
|
if not ulx.tps then
|
|
local ErrorLabel = vgui.Create("DLabel",Frame)
|
|
ErrorLabel:SetTextColor(Color(255,50,50))
|
|
ErrorLabel:SetFont("CloseCaption_Bold")
|
|
ErrorLabel:SetText(Metrostroi.GetPhrase("StationList.NoULX"))
|
|
ErrorLabel:SizeToContents()
|
|
ErrorLabel:Center()
|
|
return
|
|
end
|
|
|
|
-- Check stations table
|
|
if not Metrostroi.StationConfigurations then
|
|
local ErrorLabel = vgui.Create("DLabel",Frame)
|
|
ErrorLabel:SetTextColor(Color(255,50,50))
|
|
ErrorLabel:SetFont("CloseCaption_Bold")
|
|
ErrorLabel:SetText(Metrostroi.GetPhrase("StationList.NoConfig"))
|
|
ErrorLabel:SizeToContents()
|
|
ErrorLabel:Center()
|
|
return
|
|
end
|
|
|
|
-- Create list
|
|
local StList = vgui.Create("DListView",Frame)
|
|
StList:Dock(FILL)
|
|
StList:SetMultiSelect(false)
|
|
StList:AddColumn("ID"):SetWidth(10)
|
|
StList:AddColumn(Metrostroi.GetPhrase("StationList.Name")):SetWidth(405)
|
|
StList:AddColumn(Metrostroi.GetPhrase("StationList.NamePos")):SetWidth(5)
|
|
|
|
local SelectedID,SelectedPosID = 1,1
|
|
-- Adding stations
|
|
for k,v in pairs(Metrostroi.StationConfigurations) do
|
|
local tblPos = v.positions
|
|
if not tblPos then continue end
|
|
|
|
local stLine = StList:AddLine(k,table.concat(v.names,", "))
|
|
stLine.StID = k
|
|
|
|
if table.Count(tblPos) == 1 then continue end
|
|
local PosSelector = vgui.Create("DComboBox",stLine)
|
|
PosSelector:Dock(RIGHT)
|
|
for idPos,tbl in pairs(tblPos) do
|
|
PosSelector:AddChoice(idPos)
|
|
end
|
|
PosSelector:ChooseOptionID(1)
|
|
function PosSelector:OnSelect(index,val)
|
|
StList:ClearSelection()
|
|
StList:SelectItem(stLine)
|
|
SelectedID = k
|
|
SelectedPosID = val
|
|
end
|
|
end
|
|
StList:SortByColumn(1)
|
|
function StList:DoDoubleClick(lineID, line)
|
|
RunConsoleCommand("ulx","station",tostring(SelectedID)..":"..tostring(SelectedPosID))
|
|
Frame:Close()
|
|
end
|
|
|
|
-- Create teleport button
|
|
local TpBtn = vgui.Create("DButton",Frame)
|
|
TpBtn:Dock(BOTTOM)
|
|
TpBtn:SetText(Metrostroi.GetPhrase("StationList.Select"))
|
|
TpBtn:SetEnabled(false)
|
|
function StList:OnRowSelected(rowIndex,row)
|
|
TpBtn:SetEnabled(true)
|
|
TpBtn:SetText(Metrostroi.GetPhrase("StationList.Teleport"))
|
|
SelectedID = row.StID
|
|
end
|
|
function TpBtn:DoClick()
|
|
RunConsoleCommand("ulx","station",tostring(SelectedID)..":"..tostring(SelectedPosID))
|
|
Frame:Close()
|
|
end
|
|
end
|
|
concommand.Add("metrostroi_stations",OpenGUI,nil,"GUI for station list")
|
|
net.Receive("metrostroi_stations_gui",OpenGUI) |