1
0
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:
Ivan Gordeev
2021-07-26 09:22:22 +03:00
committed by GitHub
parent b453809877
commit 523c4fd873
4 changed files with 166 additions and 73 deletions

View 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)

View File

@@ -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

View File

@@ -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контактного рельса

View File

@@ -1,4 +1,5 @@
local CATEGORY_NAME = "Metrostroi"
if SERVER then util.AddNetworkString("metrostroi_stations_gui") end
------------------------------ Wagons ------------------------------
local waittime = 10
@@ -413,22 +414,29 @@ traunfuck:addParam{ type=ULib.cmds.PlayersArg }
traunfuck:defaultAccess( ULib.ACCESS_ADMIN )
traunfuck:help( "Trainfucks a player." )
function ulx.tps( calling_ply,station )
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))
-- 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
--Проверка на наличие таблицы
if not Metrostroi.StationConfigurations then ULib.tsayError( calling_ply, "This map is not configured", true ) return end
--Создание массива найденых станций по индкесу станции или куска имени
-- Search input pattern
local st = {}
for k,v in pairs(Metrostroi.StationConfigurations) do
if not v.positions then continue end
@@ -445,6 +453,7 @@ function ulx.tps( calling_ply,station )
end
end
-- Output same stations
if #st == 0 then
ULib.tsayError( calling_ply, Format("Station not found %s",station), true )
return
@@ -453,7 +462,7 @@ function ulx.tps( calling_ply,station )
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 )
ULib.tsayError( calling_ply, Format("\t%s = %s",v,tbl.names[1]), true )
else
ULib.tsayError( calling_ply, Format("\t%s",k), true )
end
@@ -461,39 +470,38 @@ function ulx.tps( calling_ply,station )
ULib.tsayError( calling_ply, "Enter a more specific name or station ID", true )
return
end
local key = st[1]
st = Metrostroi.StationConfigurations[key]
-- Set target position
local ID = st[1]
st = Metrostroi.StationConfigurations[ID]
local ptbl
if add > 0 then
local pos = st.positions
ptbl = pos[math.min(#pos,add+1)]
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
if IsValid(calling_ply) then
-- Teleport
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_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 key)
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 "..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))
end
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." )