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.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
|
||||
Panel.Admin = Admin
|
||||
Panel.RequireThirdRail = Require third rail
|
||||
|
||||
@@ -21,6 +21,14 @@ Workshop.ErrorEnhancers = Этот аддон содержит улучше
|
||||
Workshop.Error1 = Данный аддон содержит в себе старый код мода Metrostroi, который конфликтует с текущим. Возможны "Script errors"(ошибки скриптов) и неопределённое поведение аддона.
|
||||
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
|
||||
Panel.Admin = Админ
|
||||
Panel.RequireThirdRail = Вкл. необходимость наличия\nконтактного рельса
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local CATEGORY_NAME = "Metrostroi"
|
||||
if SERVER then util.AddNetworkString("metrostroi_stations_gui") end
|
||||
|
||||
------------------------------ Wagons ------------------------------
|
||||
local waittime = 10
|
||||
@@ -413,87 +414,94 @@ traunfuck:addParam{ type=ULib.cmds.PlayersArg }
|
||||
traunfuck:defaultAccess( ULib.ACCESS_ADMIN )
|
||||
traunfuck:help( "Trainfucks a player." )
|
||||
|
||||
|
||||
function ulx.tps( calling_ply,station )
|
||||
station = string.PatternSafe(station:lower())
|
||||
|
||||
--Обработка сообщений вида станция:номер для станций, которые имеют несоклько позиций
|
||||
local add = 0
|
||||
if station:find("[^:]+:%d+$") then
|
||||
local st,en = station:find(":%d+$")
|
||||
add = tonumber(station:sub(st+1,en))
|
||||
station = station:sub(1,st-1)
|
||||
end
|
||||
|
||||
--Проверка на наличие таблицы
|
||||
if not Metrostroi.StationConfigurations then ULib.tsayError( calling_ply, "This map is not configured", true ) return end
|
||||
|
||||
--Создание массива найденых станций по индкесу станции или куска имени
|
||||
local st = {}
|
||||
for k,v in pairs(Metrostroi.StationConfigurations) do
|
||||
if not v.positions then continue end
|
||||
if v.names then
|
||||
for _,stat in pairs(v.names) do
|
||||
if stat:lower():find(station) then
|
||||
table.insert(st,k)
|
||||
break
|
||||
end
|
||||
function ulx.tps(calling_ply,station)
|
||||
station = string.PatternSafe(station:lower())
|
||||
|
||||
-- Check stations table
|
||||
if not Metrostroi.StationConfigurations then ULib.tsayError(calling_ply,"This map is not configured",true) return end
|
||||
if not IsValid(calling_ply) then return end
|
||||
|
||||
-- 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)
|
||||
end
|
||||
|
||||
-- Search input pattern
|
||||
local st = {}
|
||||
for k,v in pairs(Metrostroi.StationConfigurations) do
|
||||
if not v.positions then continue end
|
||||
if v.names then
|
||||
for _,stat in pairs(v.names) do
|
||||
if stat:lower():find(station) then
|
||||
table.insert(st,k)
|
||||
break
|
||||
end
|
||||
end
|
||||
if tostring(k):find(station) then
|
||||
table.insert(st,k)
|
||||
end
|
||||
end
|
||||
|
||||
if #st == 0 then
|
||||
ULib.tsayError( calling_ply, Format("Station not found %s",station), true )
|
||||
return
|
||||
elseif #st > 1 then
|
||||
ULib.tsayError( calling_ply, Format("More than 1 station for name %s:",station), true )
|
||||
for k,v in pairs(st) do
|
||||
local tbl = Metrostroi.StationConfigurations[v]
|
||||
if tbl.names and tbl.names[1] then
|
||||
ULib.tsayError( calling_ply, Format("\t%s=%s",v,tbl.names[1]), true )
|
||||
else
|
||||
ULib.tsayError( calling_ply, Format("\t%s",k), true )
|
||||
end
|
||||
end
|
||||
ULib.tsayError( calling_ply, "Enter a more specific name or station ID", true )
|
||||
return
|
||||
if tostring(k):find(station) then
|
||||
table.insert(st,k)
|
||||
end
|
||||
local key = st[1]
|
||||
st = Metrostroi.StationConfigurations[key]
|
||||
local ptbl
|
||||
if add > 0 then
|
||||
local pos = st.positions
|
||||
ptbl = pos[math.min(#pos,add+1)]
|
||||
else
|
||||
ptbl = st.positions and st.positions[1]
|
||||
end
|
||||
if IsValid(calling_ply) then
|
||||
if ptbl and ptbl[1] then
|
||||
if calling_ply:InVehicle() then calling_ply:ExitVehicle() end
|
||||
calling_ply.ulx_prevpos = calling_ply:GetPos()--ulx return
|
||||
calling_ply.ulx_prevang = calling_ply:EyeAngles()
|
||||
calling_ply:SetPos(ptbl[1])
|
||||
calling_ply:SetAngles(ptbl[2])
|
||||
calling_ply:SetEyeAngles(ptbl[2])
|
||||
ulx.fancyLogAdmin( calling_ply, "#A teleported to #s", st.names and st.names[1] or key)
|
||||
end
|
||||
|
||||
-- Output same stations
|
||||
if #st == 0 then
|
||||
ULib.tsayError( calling_ply, Format("Station not found %s",station), true )
|
||||
return
|
||||
elseif #st > 1 then
|
||||
ULib.tsayError( calling_ply, Format("More than 1 station for name %s:",station), true )
|
||||
for k,v in pairs(st) do
|
||||
local tbl = Metrostroi.StationConfigurations[v]
|
||||
if tbl.names and tbl.names[1] then
|
||||
ULib.tsayError( calling_ply, Format("\t%s = %s",v,tbl.names[1]), true )
|
||||
else
|
||||
ULib.tsayError( calling_ply, "Configuration error for station "..key, true )
|
||||
ulx.fancyLogAdmin( calling_ply, "Configuration error for station #s", key)
|
||||
end
|
||||
|
||||
else
|
||||
if ptbl and ptbl[1] then
|
||||
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))
|
||||
ULib.tsayError( calling_ply, Format("\t%s",k), true )
|
||||
end
|
||||
end
|
||||
ULib.tsayError( calling_ply, "Enter a more specific name or station ID", true )
|
||||
return
|
||||
end
|
||||
|
||||
-- Set target position
|
||||
local ID = st[1]
|
||||
st = Metrostroi.StationConfigurations[ID]
|
||||
local ptbl
|
||||
if posID then
|
||||
for k,v in pairs(st.positions) do
|
||||
if tostring(k):find(posID) then
|
||||
ptbl = v
|
||||
end
|
||||
end
|
||||
else
|
||||
ptbl = st.positions and st.positions[1]
|
||||
end
|
||||
|
||||
-- Teleport
|
||||
if ptbl and ptbl[1] then
|
||||
if calling_ply:InVehicle() then calling_ply:ExitVehicle() end
|
||||
calling_ply.ulx_prevpos = calling_ply:GetPos()
|
||||
calling_ply.ulx_prevang = calling_ply:EyeAngles()
|
||||
calling_ply:SetPos(ptbl[1])
|
||||
calling_ply:SetAngles(ptbl[2])
|
||||
calling_ply:SetEyeAngles(ptbl[2])
|
||||
ulx.fancyLogAdmin( calling_ply, "#A teleported to #s", st.names and st.names[1] or ID)
|
||||
else
|
||||
ULib.tsayError( calling_ply, "Configuration error for station "..ID, true )
|
||||
ulx.fancyLogAdmin( calling_ply, "Configuration error for station #s", ID)
|
||||
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 }
|
||||
|
||||
local tps = ulx.command( "Metrostroi", "ulx station", ulx.tps, {"!station","!stations"} )
|
||||
tps:addParam{ type=ULib.cmds.StringArg, hint="Station or station number", ULib.cmds.optional }
|
||||
tps:defaultAccess( ULib.ACCESS_ALL )
|
||||
tps:help( "Teleport between stations." )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user