mirror of
https://github.com/metrostroi-repo/MetrostroiAddon.git
synced 2026-05-02 00:42:29 +00:00
Global change. (#286)
Добавлен GUI список станции. Добавлена возможность установки имён позиций на станции
This commit is contained in:
69
lua/metrostroi/cl_stations.lua
Normal file
69
lua/metrostroi/cl_stations.lua
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
local function OpenGUI()
|
||||||
|
-- Main frame
|
||||||
|
local Frame = vgui.Create("DFrame")
|
||||||
|
Frame:SetSize(600,300)
|
||||||
|
Frame:Center()
|
||||||
|
Frame:SetTitle(Metrostroi.GetPhrase("StationList.Title"))
|
||||||
|
Frame:MakePopup()
|
||||||
|
Frame.OnClose = Frame.Remove
|
||||||
|
|
||||||
|
-- Check stations table
|
||||||
|
if not Metrostroi.StationConfigurations then
|
||||||
|
local ErrorLabel = vgui.Create("DLabel",Frame)
|
||||||
|
ErrorLabel:Dock(FILL)
|
||||||
|
ErrorLabel:SetTextColor(Color(255,50,50))
|
||||||
|
ErrorLabel:DockMargin(7,0,0,7)
|
||||||
|
ErrorLabel:SetFont("CloseCaption_Bold")
|
||||||
|
ErrorLabel:SetText(Metrostroi.GetPhrase("StationList.NoConfig"))
|
||||||
|
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)
|
||||||
|
|
||||||
|
-- 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))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
concommand.Add("metrostroi_stations",OpenGUI,nil,"GUI for station list")
|
||||||
|
net.Receive("metrostroi_stations_gui",OpenGUI)
|
||||||
@@ -21,6 +21,14 @@ Workshop.ErrorEnhancers = This addon contains a graphic enhancers that may i
|
|||||||
Workshop.Error1 = This addon contain an old script code of the Metrostroi that conflicts with current. May be "Scripts errors" and unstable work of the addon.
|
Workshop.Error1 = This addon contain an old script code of the Metrostroi that conflicts with current. May be "Scripts errors" and unstable work of the addon.
|
||||||
Workshop.ErrorOld = Old models detected (81-702 and 81-717 old models). Check and remove old metrostroi content files, remove "cache", "download" and "downloads" folders from "garrysmod" folder.
|
Workshop.ErrorOld = Old models detected (81-702 and 81-717 old models). Check and remove old metrostroi content files, remove "cache", "download" and "downloads" folders from "garrysmod" folder.
|
||||||
|
|
||||||
|
#Station list GUI
|
||||||
|
StationList.Title = Station list
|
||||||
|
StationList.Name = Name
|
||||||
|
StationList.NamePos = Position
|
||||||
|
StationList.Select = Select station
|
||||||
|
StationList.Teleport = Teleport
|
||||||
|
StationList.NoConfig = This map is not configured
|
||||||
|
|
||||||
#Client settings
|
#Client settings
|
||||||
Panel.Admin = Admin
|
Panel.Admin = Admin
|
||||||
Panel.RequireThirdRail = Require third rail
|
Panel.RequireThirdRail = Require third rail
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ Workshop.ErrorEnhancers = Этот аддон содержит улучше
|
|||||||
Workshop.Error1 = Данный аддон содержит в себе старый код мода Metrostroi, который конфликтует с текущим. Возможны "Script errors"(ошибки скриптов) и неопределённое поведение аддона.
|
Workshop.Error1 = Данный аддон содержит в себе старый код мода Metrostroi, который конфликтует с текущим. Возможны "Script errors"(ошибки скриптов) и неопределённое поведение аддона.
|
||||||
Workshop.ErrorOld = Обнаружены старые модели(вагон типа Д и старая модель 81-717). Проверьте и удалите старый контент метростроя, или почистите папки cache, download и downloads в папке с игрой (garrysmod).
|
Workshop.ErrorOld = Обнаружены старые модели(вагон типа Д и старая модель 81-717). Проверьте и удалите старый контент метростроя, или почистите папки cache, download и downloads в папке с игрой (garrysmod).
|
||||||
|
|
||||||
|
#Station list GUI
|
||||||
|
StationList.Title = Список станций
|
||||||
|
StationList.Name = Название
|
||||||
|
StationList.NamePos = Позиция
|
||||||
|
StationList.Select = Выберите станцию
|
||||||
|
StationList.Teleport = Телепортироваться!
|
||||||
|
StationList.NoConfig = Эта карта не сконфигурирована
|
||||||
|
|
||||||
#Client settings
|
#Client settings
|
||||||
Panel.Admin = Админ
|
Panel.Admin = Админ
|
||||||
Panel.RequireThirdRail = Вкл. необходимость наличия\nконтактного рельса
|
Panel.RequireThirdRail = Вкл. необходимость наличия\nконтактного рельса
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
local CATEGORY_NAME = "Metrostroi"
|
local CATEGORY_NAME = "Metrostroi"
|
||||||
|
if SERVER then util.AddNetworkString("metrostroi_stations_gui") end
|
||||||
|
|
||||||
------------------------------ Wagons ------------------------------
|
------------------------------ Wagons ------------------------------
|
||||||
local waittime = 10
|
local waittime = 10
|
||||||
@@ -413,22 +414,29 @@ traunfuck:addParam{ type=ULib.cmds.PlayersArg }
|
|||||||
traunfuck:defaultAccess( ULib.ACCESS_ADMIN )
|
traunfuck:defaultAccess( ULib.ACCESS_ADMIN )
|
||||||
traunfuck:help( "Trainfucks a player." )
|
traunfuck:help( "Trainfucks a player." )
|
||||||
|
|
||||||
|
|
||||||
function ulx.tps(calling_ply,station)
|
function ulx.tps(calling_ply,station)
|
||||||
station = string.PatternSafe(station:lower())
|
station = string.PatternSafe(station:lower())
|
||||||
|
|
||||||
--Обработка сообщений вида станция:номер для станций, которые имеют несоклько позиций
|
-- Check stations table
|
||||||
local add = 0
|
if not Metrostroi.StationConfigurations then ULib.tsayError(calling_ply,"This map is not configured",true) return end
|
||||||
if station:find("[^:]+:%d+$") then
|
if not IsValid(calling_ply) then return end
|
||||||
local st,en = station:find(":%d+$")
|
|
||||||
add = tonumber(station:sub(st+1,en))
|
-- Open GUI with station list
|
||||||
|
if station == "" then
|
||||||
|
net.Start("metrostroi_stations_gui")
|
||||||
|
net.Send(calling_ply)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- For input station like [Station name]:[Position]
|
||||||
|
local posID
|
||||||
|
if station:find("[^:]+:%w+$")then
|
||||||
|
local st,en = station:find(":%w+$")
|
||||||
|
posID = tostring(station:sub(st+1,en))
|
||||||
station = station:sub(1,st-1)
|
station = station:sub(1,st-1)
|
||||||
end
|
end
|
||||||
|
|
||||||
--Проверка на наличие таблицы
|
-- Search input pattern
|
||||||
if not Metrostroi.StationConfigurations then ULib.tsayError( calling_ply, "This map is not configured", true ) return end
|
|
||||||
|
|
||||||
--Создание массива найденых станций по индкесу станции или куска имени
|
|
||||||
local st = {}
|
local st = {}
|
||||||
for k,v in pairs(Metrostroi.StationConfigurations) do
|
for k,v in pairs(Metrostroi.StationConfigurations) do
|
||||||
if not v.positions then continue end
|
if not v.positions then continue end
|
||||||
@@ -445,6 +453,7 @@ function ulx.tps( calling_ply,station )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Output same stations
|
||||||
if #st == 0 then
|
if #st == 0 then
|
||||||
ULib.tsayError( calling_ply, Format("Station not found %s",station), true )
|
ULib.tsayError( calling_ply, Format("Station not found %s",station), true )
|
||||||
return
|
return
|
||||||
@@ -461,39 +470,38 @@ function ulx.tps( calling_ply,station )
|
|||||||
ULib.tsayError( calling_ply, "Enter a more specific name or station ID", true )
|
ULib.tsayError( calling_ply, "Enter a more specific name or station ID", true )
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local key = st[1]
|
|
||||||
st = Metrostroi.StationConfigurations[key]
|
-- Set target position
|
||||||
|
local ID = st[1]
|
||||||
|
st = Metrostroi.StationConfigurations[ID]
|
||||||
local ptbl
|
local ptbl
|
||||||
if add > 0 then
|
if posID then
|
||||||
local pos = st.positions
|
for k,v in pairs(st.positions) do
|
||||||
ptbl = pos[math.min(#pos,add+1)]
|
if tostring(k):find(posID) then
|
||||||
|
ptbl = v
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
ptbl = st.positions and st.positions[1]
|
ptbl = st.positions and st.positions[1]
|
||||||
end
|
end
|
||||||
if IsValid(calling_ply) then
|
|
||||||
|
-- Teleport
|
||||||
if ptbl and ptbl[1] then
|
if ptbl and ptbl[1] then
|
||||||
if calling_ply:InVehicle() then calling_ply:ExitVehicle() end
|
if calling_ply:InVehicle() then calling_ply:ExitVehicle() end
|
||||||
calling_ply.ulx_prevpos = calling_ply:GetPos()--ulx return
|
calling_ply.ulx_prevpos = calling_ply:GetPos()
|
||||||
calling_ply.ulx_prevang = calling_ply:EyeAngles()
|
calling_ply.ulx_prevang = calling_ply:EyeAngles()
|
||||||
calling_ply:SetPos(ptbl[1])
|
calling_ply:SetPos(ptbl[1])
|
||||||
calling_ply:SetAngles(ptbl[2])
|
calling_ply:SetAngles(ptbl[2])
|
||||||
calling_ply:SetEyeAngles(ptbl[2])
|
calling_ply:SetEyeAngles(ptbl[2])
|
||||||
ulx.fancyLogAdmin( calling_ply, "#A teleported to #s", st.names and st.names[1] or key)
|
ulx.fancyLogAdmin( calling_ply, "#A teleported to #s", st.names and st.names[1] or ID)
|
||||||
else
|
else
|
||||||
ULib.tsayError( calling_ply, "Configuration error for station "..key, true )
|
ULib.tsayError( calling_ply, "Configuration error for station "..ID, true )
|
||||||
ulx.fancyLogAdmin( calling_ply, "Configuration error for station #s", key)
|
ulx.fancyLogAdmin( calling_ply, "Configuration error for station #s", ID)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
local tps = ulx.command( "Metrostroi", "ulx station", ulx.tps, {"!station","!stations"} )
|
||||||
if ptbl and ptbl[1] then
|
tps:addParam{ type=ULib.cmds.StringArg, hint="Station or station number", ULib.cmds.optional }
|
||||||
print(Format("DEBUG1:Teleported to %s(%s) pos:%s ang:%s",st.names and st.names[1] or key,key,ptbl[1],ptbl[2]))
|
|
||||||
else
|
|
||||||
ulx.fancyLogAdmin( calling_ply, "Configuration error for station #s", station:gsub("^%l", string.upper))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local tps = ulx.command( "Metrostroi", "ulx station", ulx.tps, "!station" )
|
|
||||||
tps:addParam{ type=ULib.cmds.StringArg, hint="Station or station number", ULib.cmds.takeRestOfLine }
|
|
||||||
tps:defaultAccess( ULib.ACCESS_ALL )
|
tps:defaultAccess( ULib.ACCESS_ALL )
|
||||||
tps:help( "Teleport between stations." )
|
tps:help( "Teleport between stations." )
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user