summaryrefslogtreecommitdiff
path: root/gamemode/structuresystem
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/structuresystem')
-rw-r--r--gamemode/structuresystem/common.lua58
-rw-r--r--gamemode/structuresystem/structures/stonefurnace.lua5
2 files changed, 53 insertions, 10 deletions
diff --git a/gamemode/structuresystem/common.lua b/gamemode/structuresystem/common.lua
index d7da6d6..4996223 100644
--- a/gamemode/structuresystem/common.lua
+++ b/gamemode/structuresystem/common.lua
@@ -19,6 +19,7 @@ local function makeCraftingWindow(name)
DermaPanel.info = vgui.Create("DPanel",DermaPanel)
DermaPanel.info:SetPos(10,(buts * 2) + 30)
DermaPanel.info:SetSize(pw - 20, buts * 0.75)
+ DermaPanel.info:Dock(BOTTOM)
DermaPanel.infotext = vgui.Create("DLabel",DermaPanel.info)
DermaPanel.infotext:SetText("")
DermaPanel.infotext:SetPos(10,10)
@@ -29,7 +30,18 @@ local function makeCraftingWindow(name)
DermaPanel.reqtext:SetPos(10,30)
DermaPanel.reqtext:SetDark(true)
DermaPanel.reqtext:Dock(FILL)
-
+ DermaPanel.makebutton = vgui.Create("DButton",DermaPanel)
+ DermaPanel.makebutton:SetPos(10,(buts * 2) + (buts * 0.75) + 30)
+ DermaPanel.makebutton:SetSize(ScrW() / 1.3 - 20, (buts / 4))
+ DermaPanel.makebutton:SetText("Craft")
+ DermaPanel.makebutton.DoClick = function()
+ net.Start("makerecipe")
+ net.WriteString(DermaPanel.structname)
+ if tbl.uniquedata then net.WriteUInt(self:EntIndex(), GMS.NETINT_BITCOUNT) end
+ net.WriteUInt(DermaPanel.recipeNum, GMS.NETINT_BITCOUNT)
+ net.WriteUInt(DermaPanel.recipeMult, GMS.NETINT_BITCOUNT)
+ net.SendToServer()
+ end
return DermaPanel
end
@@ -60,6 +72,16 @@ function genericMakeCrafting(tbl)
thisrecipe.Name = v.Name .. " x" .. j
thisrecipe.Description = v.Description
thisrecipe.genericNum = k
+ thisrecipe.Image = v.Image
+ thisrecipe.haslevelsfor = v.CanCraft(ply)
+ thisrecipe.hasmatsfor = true
+ PrintTable(thisrecipe.Req)
+ for l,m in pairs(thisrecipe.Req) do
+ if(Resources[l] < m) then
+ thisrecipe.hasmatsfor = false
+ break
+ end
+ end
thisrecipe.mult = j
table.insert(tbl.Recipes,0,thisrecipe)
end
@@ -67,9 +89,24 @@ function genericMakeCrafting(tbl)
local DermaPanel = makeCraftingWindow(tbl.Name)
for k,v in pairs(tbl.Recipes) do
- local testbut = vgui.Create("DButton")
+ local testbut = vgui.Create("DImageButton")
testbut:SetText(v.Name)
+ testbut:SetImage(v.Image)
testbut:SetSize(buts,buts)
+ testbut.Paint = function(self,w,h)
+ draw.RoundedBox( 8, 5, 5, w-10, h-10, Color( 0, 0, 0 ) )
+ local fillcolor = Color(0,0,200)
+ if v.haslevelsfor then
+ if v.hasmatsfor then
+ fillcolor = Color(200,200,200)
+ else
+ fillcolor = Color(200,0,0)
+ end
+ else
+ fillcolor = Color(200,200,0)
+ end
+ draw.RoundedBox(8,10,10,w-20,h-20,fillcolor)
+ end
testbut.DoClick = function(button)
DermaPanel.structname = tbl.Name
DermaPanel.recipeNum = v.genericNum
@@ -80,17 +117,12 @@ function genericMakeCrafting(tbl)
end
DermaPanel.infotext:SetText(v.Name)
DermaPanel.reqtext:SetText(text)
- local cancraft = true
- for i,j in pairs(v.Req) do
- if Resources[i] < j then
- cancraft = false
- end
- end
- DermaPanel.makebutton:SetEnabled(cancraft)
+ DermaPanel.makebutton:SetEnabled(v.haslevelsfor and v.hasmatsfor)
end
DermaPanel.Grid:AddItem(testbut)
DermaPanel:MakePopup()
end
+ /*
DermaPanel.makebutton = vgui.Create("DButton",DermaPanel)
DermaPanel.makebutton:SetPos(10,(buts * 2) + (buts * 0.75) + 30)
DermaPanel.makebutton:SetSize(ScrW() / 1.3 - 20, (buts / 4))
@@ -103,7 +135,7 @@ function genericMakeCrafting(tbl)
net.WriteUInt(DermaPanel.recipeMult, GMS.NETINT_BITCOUNT)
net.SendToServer()
end
-
+ */
end
tbl.onUse = overrideuse
end
@@ -127,6 +159,12 @@ net.Receive( "makerecipe", function(ln,ply)
end
end
+ --Check that we're allowed to craft this
+ if not recipe.CanCraft(ply) then
+ ply:SendMessage("You can't craft that!", 3, Color(255, 255, 255, 255))
+ return
+ end
+
--We have enough resources! make it!
startProcessGeneric(ply,"Crafting " .. recipe.Name, recipe.Time(ply,mult), function(player)
for k,v in pairs(recipe.Results) do
diff --git a/gamemode/structuresystem/structures/stonefurnace.lua b/gamemode/structuresystem/structures/stonefurnace.lua
index 029b242..03ae99e 100644
--- a/gamemode/structuresystem/structures/stonefurnace.lua
+++ b/gamemode/structuresystem/structures/stonefurnace.lua
@@ -24,6 +24,9 @@ local timefunc = function(ply, num)
print("Time was: " .. time)
return time
end
+local checkfunc = function(ply)
+ return true
+end
local genericRecipe = {
["Name"] = "Copper",
@@ -31,6 +34,8 @@ local genericRecipe = {
["Requirements"] = {["Copper Ore"] = 1},
["Results"] = {["Copper"] = 1},
["Ratio"] = {1,1},
+ ["Image"] = "test.png",
+ ["CanCraft"] = checkfunc,
["Time"] = timefunc,
["Mults"] = {1,5,10,20,50}
}