This commit is contained in:
lifestorm
2024-08-04 22:55:00 +03:00
parent 8064ba84d8
commit 73479cff9e
7338 changed files with 1718883 additions and 14 deletions

View File

@@ -0,0 +1,308 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
local PANEL = {}
AccessorFunc(PANEL, "bReadOnly", "ReadOnly", FORCE_BOOL)
function PANEL:Init()
self:SetSize(ScrW() * 0.45, ScrH() * 0.65)
self:SetTitle("")
self:MakePopup()
self:Center()
self.playerCurrency = ""
end
function PANEL:Populate(playerCredits)
local header = self:Add("DPanel")
header:SetTall(34)
header:Dock(TOP)
self.vendorName = header:Add("DLabel")
self.vendorName:Dock(LEFT)
self.vendorName:SetWide(self:GetWide() * 0.5 - 7)
self.vendorName:SetText("John Doe")
self.vendorName:SetTextInset(4, 0)
self.vendorName:SetTextColor(color_white)
self.vendorName:SetFont("ixMediumFont")
if (!playerCredits) then
self.playerCurrency = ix.currency.Get(LocalPlayer():GetCharacter():GetMoney())
else
self.playerCurrency = L("vendorNCredits", playerCredits)
end
self.useCredits = playerCredits and true or false
self.ourName = header:Add("DLabel")
self.ourName:Dock(RIGHT)
self.ourName:SetWide(self:GetWide() * 0.5 - 7)
self.ourName:SetTextInset(0, 0)
self.ourName:SetTextColor(color_white)
self.ourName:SetFont("ixMediumFont")
local footer = self:Add("DPanel")
footer:SetTall(34)
footer:Dock(BOTTOM)
footer:SetPaintBackground(false)
self.vendorSell = footer:Add("DButton")
self.vendorSell:SetFont("ixMediumFont")
self.vendorSell:SetWide(self.vendorName:GetWide())
self.vendorSell:Dock(LEFT)
self.vendorSell:SetContentAlignment(5)
-- The text says purchase but the vendor is selling it to us.
self.vendorSell:SetText(L"purchase")
self.vendorSell:SetTextColor(color_white)
self.vendorSell.DoClick = function(this)
if (IsValid(self.activeSell)) then
net.Start("ixVendorTrade")
net.WriteString(self.activeSell.item)
net.WriteBool(false)
net.SendToServer()
end
end
self.vendorBuy = footer:Add("DButton")
self.vendorBuy:SetFont("ixMediumFont")
self.vendorBuy:SetWide(self.ourName:GetWide())
self.vendorBuy:Dock(RIGHT)
self.vendorBuy:SetContentAlignment(5)
self.vendorBuy:SetText(L"sell")
self.vendorBuy:SetTextColor(color_white)
self.vendorBuy.DoClick = function(this)
if (IsValid(self.activeBuy)) then
net.Start("ixVendorTrade")
net.WriteString(self.activeBuy.item)
net.WriteBool(true)
net.SendToServer()
end
end
self.selling = self:Add("DScrollPanel")
self.selling:SetWide(self:GetWide() * 0.5 - 7)
self.selling:Dock(LEFT)
self.selling:DockMargin(0, 4, 0, 4)
self.selling:SetPaintBackground(true)
self.sellingItems = self.selling:Add("DListLayout")
self.sellingItems:SetSize(self.selling:GetSize())
self.sellingItems:DockPadding(0, 0, 0, 4)
self.sellingItems:SetTall(ScrH())
self.buying = self:Add("DScrollPanel")
self.buying:SetWide(self:GetWide() * 0.5 - 7)
self.buying:Dock(RIGHT)
self.buying:DockMargin(0, 4, 0, 4)
self.buying:SetPaintBackground(true)
self.buyingItems = self.buying:Add("DListLayout")
self.buyingItems:SetSize(self.buying:GetSize())
self.buyingItems:DockPadding(0, 0, 0, 4)
self.sellingList = {}
self.buyingList = {}
end
function PANEL:addItem(uniqueID, listID)
local entity = self.entity
local items = entity.items
local data = items[uniqueID]
if ((!listID or listID == "selling") and !IsValid(self.sellingList[uniqueID])
and ix.item.list[uniqueID]) then
if (data and data[VENDOR_MODE] and data[VENDOR_MODE] != VENDOR_BUYONLY) then
local item = self.sellingItems:Add("ixVendorItem")
item:Setup(uniqueID)
self.sellingList[uniqueID] = item
self.sellingItems:InvalidateLayout()
end
end
if ((!listID or listID == "buying") and !IsValid(self.buyingList[uniqueID])
and LocalPlayer():GetCharacter():GetInventory():HasItem(uniqueID)) then
if (data and data[VENDOR_MODE] and data[VENDOR_MODE] != VENDOR_SELLONLY) then
local item = self.buyingItems:Add("ixVendorItem")
item:Setup(uniqueID)
item.isLocal = true
self.buyingList[uniqueID] = item
self.buyingItems:InvalidateLayout()
end
end
end
function PANEL:removeItem(uniqueID, listID)
if (!listID or listID == "selling") then
if (IsValid(self.sellingList[uniqueID])) then
self.sellingList[uniqueID]:Remove()
self.sellingItems:InvalidateLayout()
end
end
if (!listID or listID == "buying") then
if (IsValid(self.buyingList[uniqueID])) then
self.buyingList[uniqueID]:Remove()
self.buyingItems:InvalidateLayout()
end
end
end
function PANEL:Setup(entity)
self.entity = entity
self:SetTitle(entity:GetDisplayName())
self.vendorBuy:SetEnabled(!self:GetReadOnly())
self.vendorSell:SetEnabled(!self:GetReadOnly())
for k, _ in SortedPairs(entity.items) do
self:addItem(k, "selling")
end
for _, v in SortedPairs(LocalPlayer():GetCharacter():GetInventory():GetItems()) do
self:addItem(v.uniqueID, "buying")
end
end
function PANEL:OnRemove()
net.Start("ixVendorClose")
net.SendToServer()
if (IsValid(ix.gui.vendorEditor)) then
ix.gui.vendorEditor:Remove()
end
end
function PANEL:Think()
local entity = self.entity
if (!IsValid(entity)) then
self:Remove()
return
end
if ((self.nextUpdate or 0) < CurTime()) then
local moneyAmount = self.useCredits and L("vendorNCredits", entity.money) or ix.currency.Get(entity.money)
self:SetTitle(entity:GetDisplayName())
self.vendorName:SetText(entity:GetDisplayName() .. (entity.money and " (" .. moneyAmount .. ")" or ""))
self.ourName:SetText(L"you" .. " (" .. self.playerCurrency .. ")")
self.nextUpdate = CurTime() + 0.25
end
end
function PANEL:OnItemSelected(panel)
local price = self.entity:GetPrice(panel.item, panel.isLocal)
local priceString = !self.useCredits and ix.currency.Get(price) or L("vendorNCredits", price)
if (panel.isLocal) then
self.vendorBuy:SetText("Vendre", priceString)
else
self.vendorSell:SetText("Acheter", priceString)
end
end
vgui.Register("ixVendor", PANEL, "DFrame")
PANEL = {}
function PANEL:Init()
self:SetTall(36)
self:DockMargin(4, 4, 4, 0)
self.icon = self:Add("SpawnIcon")
self.icon:SetPos(2, 2)
self.icon:SetSize(32, 32)
self.icon:SetModel("models/error.mdl")
self.name = self:Add("DLabel")
self.name:Dock(FILL)
self.name:DockMargin(42, 0, 0, 0)
self.name:SetFont("ixChatFont")
self.name:SetTextColor(color_white)
self.name:SetExpensiveShadow(1, Color(0, 0, 0, 200))
self.click = self:Add("DButton")
self.click:Dock(FILL)
self.click:SetText("")
self.click.Paint = function() end
self.click.DoClick = function(this)
if (self.isLocal) then
ix.gui.vendor.activeBuy = self
else
ix.gui.vendor.activeSell = self
end
ix.gui.vendor:OnItemSelected(self)
end
end
function PANEL:SetCallback(callback)
self.click.DoClick = function(this)
callback()
self.selected = true
end
end
function PANEL:Setup(uniqueID)
local item = ix.item.list[uniqueID]
if (item) then
self.item = uniqueID
self.icon:SetModel(item:GetModel(), item:GetSkin())
self.name:SetText(item:GetName())
self.itemName = item:GetName()
self.click:SetHelixTooltip(function(tooltip)
ix.hud.PopulateItemTooltip(tooltip, item)
local entity = ix.gui.vendor.entity
if (entity and entity.items[self.item] and entity.items[self.item][VENDOR_MAXSTOCK]) then
local info = entity.items[self.item]
local stock = tooltip:AddRowAfter("name", "stock")
stock:SetText(string.format("Stock: %d/%d", info[VENDOR_STOCK], info[VENDOR_MAXSTOCK]))
stock:SetBackgroundColor(derma.GetColor("Info", self))
stock:SizeToContents()
end
end)
end
end
function PANEL:Think()
if ((self.nextUpdate or 0) < CurTime()) then
local entity = ix.gui.vendor.entity
if (entity and self.isLocal) then
local count = LocalPlayer():GetCharacter():GetInventory():GetItemCount(self.item)
if (count == 0) then
self:Remove()
end
end
self.nextUpdate = CurTime() + 0.1
end
end
function PANEL:Paint(w, h)
if (ix.gui.vendor.activeBuy == self or ix.gui.vendor.activeSell == self) then
surface.SetDrawColor(ix.config.Get("color"))
else
surface.SetDrawColor(0, 0, 0, 100)
end
surface.DrawRect(0, 0, w, h)
end
vgui.Register("ixVendorItem", PANEL, "DPanel")

View File

@@ -0,0 +1,307 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
local PANEL = {}
function PANEL:Init()
local entity = ix.gui.vendor.entity
self:SetSize(320, 480)
self:MoveLeftOf(ix.gui.vendor, 8)
self:MakePopup()
self:CenterVertical()
self:SetTitle(L"vendorEditor")
self.lblTitle:SetTextColor(color_white)
self.name = self:Add("DTextEntry")
self.name:Dock(TOP)
self.name:SetText(entity:GetDisplayName())
self.name:SetPlaceholderText(L"name")
self.name.OnEnter = function(this)
if (entity:GetDisplayName() != this:GetText()) then
self:updateVendor("name", this:GetText())
end
end
self.description = self:Add("DTextEntry")
self.description:Dock(TOP)
self.description:DockMargin(0, 4, 0, 0)
self.description:SetText(entity:GetDescription())
self.description:SetPlaceholderText(L"description")
self.description.OnEnter = function(this)
if (entity:GetDescription() != this:GetText()) then
self:updateVendor("description", this:GetText())
end
end
self.model = self:Add("DTextEntry")
self.model:Dock(TOP)
self.model:DockMargin(0, 4, 0, 0)
self.model:SetText(entity:GetModel())
self.model:SetPlaceholderText(L"model")
self.model.OnEnter = function(this)
if (entity:GetModel():lower() != this:GetText():lower()) then
self:updateVendor("model", this:GetText():lower())
end
end
local useMoney = tonumber(entity.money) != nil
self.money = self:Add("DTextEntry")
self.money:Dock(TOP)
self.money:DockMargin(0, 4, 0, 0)
self.money:SetText(!useMoney and "" or entity.money)
self.money:SetPlaceholderText(L"money")
self.money:SetDisabled(!useMoney)
self.money:SetEnabled(useMoney)
self.money:SetNumeric(true)
self.money.OnEnter = function(this)
local value = tonumber(this:GetText()) or entity.money
if (value == entity.money) then
return
end
self:updateVendor("money", value)
end
self.bubble = self:Add("DCheckBoxLabel")
self.bubble:SetText(L"vendorNoBubble")
self.bubble:Dock(TOP)
self.bubble:DockMargin(0, 4, 0, 0)
self.bubble:SetValue(entity:GetNoBubble() and 1 or 0)
self.bubble.OnChange = function(this, value)
if (this.noSend) then
this.noSend = nil
else
self:updateVendor("bubble", value)
end
end
self.useMoney = self:Add("DCheckBoxLabel")
self.useMoney:SetText(L"vendorUseMoney")
self.useMoney:Dock(TOP)
self.useMoney:DockMargin(0, 4, 0, 0)
self.useMoney:SetChecked(useMoney)
self.useMoney.OnChange = function(this, value)
self:updateVendor("useMoney")
end
local useCredits = entity:GetUseCredits()
self.useCredits = self:Add("DCheckBoxLabel")
self.useCredits:SetText(L"vendorUseCredits")
self.useCredits:Dock(TOP)
self.useCredits:DockMargin(0, 4, 0, 0)
self.useCredits:SetChecked(useCredits)
self.useCredits.OnChange = function(this, value)
self:updateVendor("useCredits", value)
end
self.sellScale = self:Add("DNumSlider")
self.sellScale:Dock(TOP)
self.sellScale:DockMargin(0, 4, 0, 0)
self.sellScale:SetText(L"vendorSellScale")
self.sellScale.Label:SetTextColor(color_white)
self.sellScale.TextArea:SetTextColor(color_white)
self.sellScale:SetDecimals(1)
self.sellScale.noSend = true
self.sellScale:SetValue(entity.scale)
self.sellScale.OnValueChanged = function(this, value)
if (this.noSend) then
this.noSend = nil
else
timer.Create("ixVendorScale", 1, 1, function()
if (IsValid(self) and IsValid(self.sellScale)) then
value = self.sellScale:GetValue()
if (value != entity.scale) then
self:updateVendor("scale", value)
end
end
end)
end
end
self.faction = self:Add("DButton")
self.faction:SetText(L"vendorFaction")
self.faction:Dock(TOP)
self.faction:SetTextColor(color_white)
self.faction:DockMargin(0, 4, 0, 0)
self.faction.DoClick = function(this)
if (IsValid(ix.gui.editorFaction)) then
ix.gui.editorFaction:Remove()
end
ix.gui.editorFaction = vgui.Create("ixVendorFactionEditor")
ix.gui.editorFaction.updateVendor = self.updateVendor
ix.gui.editorFaction.entity = entity
ix.gui.editorFaction:Setup()
end
self.searchBar = self:Add("DTextEntry")
self.searchBar:Dock(TOP)
self.searchBar:DockMargin(0, 4, 0, 0)
self.searchBar:SetUpdateOnType(true)
self.searchBar:SetPlaceholderText("Search...")
self.searchBar.OnValueChange = function(this, value)
self:ReloadItemList(value)
end
local menu
self.items = self:Add("DListView")
self.items:Dock(FILL)
self.items:DockMargin(0, 4, 0, 0)
self.items:AddColumn(L"name").Header:SetTextColor(color_black)
self.items:AddColumn(L"category").Header:SetTextColor(color_black)
self.items:AddColumn(L"mode").Header:SetTextColor(color_black)
self.items:AddColumn(L"price").Header:SetTextColor(color_black)
self.items:AddColumn(L"stock").Header:SetTextColor(color_black)
self.items:SetMultiSelect(false)
self.items.OnRowRightClick = function(this, index, line)
if (IsValid(menu)) then
menu:Remove()
end
local uniqueID = line.item
menu = DermaMenu()
-- Modes of the item.
local mode, panel = menu:AddSubMenu(L"mode")
panel:SetImage("icon16/key.png")
-- Disable buying/selling of the item.
mode:AddOption(L"none", function()
self:updateVendor("mode", {uniqueID, nil})
end):SetImage("icon16/cog_error.png")
-- Allow the vendor to sell and buy this item.
mode:AddOption(L"vendorBoth", function()
self:updateVendor("mode", {uniqueID, VENDOR_SELLANDBUY})
end):SetImage("icon16/cog.png")
-- Only allow the vendor to buy this item from players.
mode:AddOption(L"vendorBuy", function()
self:updateVendor("mode", {uniqueID, VENDOR_BUYONLY})
end):SetImage("icon16/cog_delete.png")
-- Only allow the vendor to sell this item to players.
mode:AddOption(L"vendorSell", function()
self:updateVendor("mode", {uniqueID, VENDOR_SELLONLY})
end):SetImage("icon16/cog_add.png")
local itemTable = ix.item.list[uniqueID]
-- Set the price of the item.
menu:AddOption(L"price", function()
Derma_StringRequest(
itemTable.GetName and itemTable:GetName() or L(itemTable.name),
L"vendorPriceReq",
entity:GetPrice(uniqueID),
function(text)
text = tonumber(text)
if (text == itemTable.price) then
text = nil
end
self:updateVendor("price", {uniqueID, text})
end
)
end):SetImage("icon16/coins.png")
-- Set the stock of the item or disable it.
local stock, menuPanel = menu:AddSubMenu(L"stock")
menuPanel:SetImage("icon16/table.png")
-- Disable the use of stocks for this item.
stock:AddOption(L"disable", function()
self:updateVendor("stockDisable", uniqueID)
end):SetImage("icon16/table_delete.png")
-- Edit the maximum stock for this item.
stock:AddOption(L"edit", function()
local _, max = entity:GetStock(uniqueID)
Derma_StringRequest(
itemTable.GetName and itemTable:GetName() or L(itemTable.name),
L"vendorStockReq",
max or 1,
function(text)
self:updateVendor("stockMax", {uniqueID, text})
end
)
end):SetImage("icon16/table_edit.png")
-- Edit the current stock of this item.
stock:AddOption(L"vendorEditCurStock", function()
Derma_StringRequest(
itemTable.GetName and itemTable:GetName() or L(itemTable.name),
L"vendorStockCurReq",
entity:GetStock(uniqueID) or 0,
function(text)
self:updateVendor("stock", {uniqueID, text})
end
)
end):SetImage("icon16/table_edit.png")
menu:Open()
end
self:ReloadItemList()
end
function PANEL:ReloadItemList(filter)
local entity = ix.gui.vendor.entity
self.lines = {}
self.items:Clear()
for k, v in SortedPairs(ix.item.list) do
local itemName = v.GetName and v:GetName() or L(v.name)
if (filter and !itemName:lower():find(filter:lower(), 1, false)) then
continue
end
local mode = entity.items[k] and entity.items[k][VENDOR_MODE]
local current, max = entity:GetStock(k)
local panel = self.items:AddLine(
itemName,
v.category or L"none",
mode and L(VENDOR_TEXT[mode]) or L"none",
entity:GetPrice(k),
max and current.."/"..max or "-"
)
panel.item = k
self.lines[k] = panel
end
end
function PANEL:OnRemove()
if (IsValid(ix.gui.vendor)) then
ix.gui.vendor:Remove()
end
if (IsValid(ix.gui.editorFaction)) then
ix.gui.editorFaction:Remove()
end
end
function PANEL:updateVendor(key, value)
net.Start("ixVendorEdit")
net.WriteString(key)
net.WriteType(value)
net.SendToServer()
end
vgui.Register("ixVendorEditor", PANEL, "DFrame")

View File

@@ -0,0 +1,70 @@
--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
local PANEL = {}
function PANEL:Init()
self:SetSize(256, 280)
self:Center()
self:MakePopup()
self:SetTitle(L"vendorFaction")
self.scroll = self:Add("DScrollPanel")
self.scroll:Dock(FILL)
self.scroll:DockPadding(0, 0, 0, 4)
self.factions = {}
self.classes = {}
for k, v in ipairs(ix.faction.indices) do
local panel = self.scroll:Add("DPanel")
panel:Dock(TOP)
panel:DockPadding(4, 4, 4, 4)
panel:DockMargin(0, 0, 0, 4)
local faction = panel:Add("DCheckBoxLabel")
faction:Dock(TOP)
faction:SetText(L(v.name))
faction:DockMargin(0, 0, 0, 4)
faction.OnChange = function(this, state)
self:updateVendor("faction", v.uniqueID)
end
self.factions[v.uniqueID] = faction
for _, v2 in ipairs(ix.class.list) do
if (v2.faction == k) then
local class = panel:Add("DCheckBoxLabel")
class:Dock(TOP)
class:DockMargin(16, 0, 0, 4)
class:SetText(L(v2.name))
class.OnChange = function(this, state)
self:updateVendor("class", v2.uniqueID)
end
self.classes[v2.uniqueID] = class
panel:SetTall(panel:GetTall() + class:GetTall() + 4)
end
end
end
end
function PANEL:Setup()
for k, _ in pairs(self.entity.factions or {}) do
self.factions[k]:SetChecked(true)
end
for k, _ in pairs(self.entity.classes or {}) do
self.classes[k]:SetChecked(true)
end
end
vgui.Register("ixVendorFactionEditor", PANEL, "DFrame")