add sborka
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
|
||||
netstream.Hook("ixViewPaper", function(itemID, text, bEditable)
|
||||
bEditable = tobool(bEditable)
|
||||
|
||||
local panel = vgui.Create("ixPaper")
|
||||
panel:SetText(text)
|
||||
panel:SetEditable(bEditable)
|
||||
panel:SetItemID(itemID)
|
||||
end)
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
local PANEL = {}
|
||||
|
||||
AccessorFunc(PANEL, "bEditable", "Editable", FORCE_BOOL)
|
||||
AccessorFunc(PANEL, "itemID", "ItemID", FORCE_NUMBER)
|
||||
|
||||
function PANEL:Init()
|
||||
if (IsValid(PLUGIN.panel)) then
|
||||
PLUGIN.panel:Remove()
|
||||
end
|
||||
|
||||
self:SetSize(256, 318)
|
||||
self:Center()
|
||||
self:SetBackgroundBlur(true)
|
||||
self:SetDeleteOnClose(true)
|
||||
self:SetTitle(L("paper"))
|
||||
|
||||
self.close = self:Add("DButton")
|
||||
self.close:Dock(BOTTOM)
|
||||
self.close:DockMargin(0, 4, 0, 0)
|
||||
self.close:SetText(L("close"))
|
||||
self.close.DoClick = function()
|
||||
if (self.bEditable) then
|
||||
netstream.Start("ixWritingEdit", self.itemID, self.text:GetValue():sub(1, PLUGIN.maxLength))
|
||||
end
|
||||
|
||||
self:Close()
|
||||
end
|
||||
|
||||
self.text = self:Add("DTextEntry")
|
||||
self.text:SetMultiline(true)
|
||||
self.text:SetEditable(false)
|
||||
self.text:SetDisabled(true)
|
||||
self.text:Dock(FILL)
|
||||
|
||||
self:MakePopup()
|
||||
|
||||
self.bEditable = false
|
||||
PLUGIN.panel = self
|
||||
end
|
||||
|
||||
function PANEL:Think()
|
||||
local text = self.text:GetValue()
|
||||
|
||||
if (text:len() > PLUGIN.maxLength) then
|
||||
local newText = text:sub(1, PLUGIN.maxLength)
|
||||
|
||||
self.text:SetValue(newText)
|
||||
self.text:SetCaretPos(newText:len())
|
||||
|
||||
surface.PlaySound("common/talk.wav")
|
||||
end
|
||||
end
|
||||
|
||||
function PANEL:SetEditable(bValue)
|
||||
bValue = tobool(bValue)
|
||||
|
||||
if (bValue == self.bEditable) then
|
||||
return
|
||||
end
|
||||
|
||||
if (bValue) then
|
||||
self.close:SetText(L("save"))
|
||||
self.text:SetEditable(true)
|
||||
self.text:SetDisabled(false)
|
||||
else
|
||||
self.close:SetText(L("close"))
|
||||
self.text:SetEditable(false)
|
||||
self.text:SetDisabled(true)
|
||||
end
|
||||
|
||||
self.bEditable = bValue
|
||||
end
|
||||
|
||||
function PANEL:SetText(text)
|
||||
self.text:SetValue(text)
|
||||
end
|
||||
|
||||
function PANEL:OnRemove()
|
||||
PLUGIN.panel = nil
|
||||
end
|
||||
|
||||
vgui.Register("ixPaper", PANEL, "DFrame")
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
ITEM.name = "Writing Base"
|
||||
ITEM.model = Model("models/props_c17/paper01.mdl")
|
||||
ITEM.description = "Something that can be written on."
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
ITEM.name = "Бумага"
|
||||
ITEM.description = "Кусочек бумаги, %s."
|
||||
ITEM.price = 2
|
||||
ITEM.model = Model("models/props_c17/paper01.mdl")
|
||||
ITEM.width = 1
|
||||
ITEM.height = 1
|
||||
ITEM.classes = {CLASS_EOW}
|
||||
ITEM.business = true
|
||||
ITEM.bAllowMultiCharacterInteraction = true
|
||||
|
||||
function ITEM:GetDescription()
|
||||
return self:GetData("owner", 0) == 0
|
||||
and string.format(self.description, "он потрепанный и грязный.")
|
||||
or string.format(self.description, "на нем написано.")
|
||||
end
|
||||
|
||||
function ITEM:SetText(text, character)
|
||||
text = tostring(text):sub(1, PLUGIN.maxLength)
|
||||
|
||||
self:SetData("text", text, false, false, true)
|
||||
self:SetData("owner", character and character:GetID() or 0)
|
||||
end
|
||||
|
||||
ITEM.functions.View = {
|
||||
OnRun = function(item)
|
||||
netstream.Start(item.player, "ixViewPaper", item:GetID(), item:GetData("text", ""), 0)
|
||||
return false
|
||||
end,
|
||||
|
||||
OnCanRun = function(item)
|
||||
local owner = item:GetData("owner", 0)
|
||||
|
||||
return owner != 0
|
||||
end
|
||||
}
|
||||
|
||||
ITEM.functions.Edit = {
|
||||
OnRun = function(item)
|
||||
netstream.Start(item.player, "ixViewPaper", item:GetID(), item:GetData("text", ""), 1)
|
||||
return false
|
||||
end,
|
||||
|
||||
OnCanRun = function(item)
|
||||
local owner = item:GetData("owner", 0)
|
||||
|
||||
return owner == 0 or owner == item.player:GetCharacter():GetID() and item:GetData("text", "") == ""
|
||||
end
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
LANGUAGE = {
|
||||
paper = "Бумага"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
PLUGIN.name = "Writing"
|
||||
PLUGIN.description = "Adds purchasable items which players can write/edit."
|
||||
PLUGIN.author = "`impulse"
|
||||
PLUGIN.maxLength = 512
|
||||
|
||||
ix.util.Include("sv_hooks.lua")
|
||||
ix.util.Include("cl_hooks.lua")
|
||||
18
garrysmod/gamemodes/militaryrp/plugins/writing/sv_hooks.lua
Normal file
18
garrysmod/gamemodes/militaryrp/plugins/writing/sv_hooks.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
netstream.Hook("ixWritingEdit", function(client, itemID, text)
|
||||
text = tostring(text):sub(1, PLUGIN.maxLength)
|
||||
|
||||
local character = client:GetCharacter()
|
||||
local item = ix.item.instances[itemID]
|
||||
|
||||
-- we don't check for entity since data can be changed in the player's inventory
|
||||
if (character and item and item.base == "base_writing") then
|
||||
local owner = item:GetData("owner", 0)
|
||||
|
||||
if ((owner == 0 or owner == character:GetID()) and text:len() > 0) then
|
||||
item:SetText(text, character)
|
||||
end
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user