aboutsummaryrefslogtreecommitdiff
path: root/gamemode/client
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/client')
-rw-r--r--gamemode/client/cl_inventory.lua21
-rw-r--r--gamemode/client/cl_state.lua9
-rw-r--r--gamemode/client/hud/cl_healthbar.lua197
-rw-r--r--gamemode/client/qtabs/cl_qinventory.lua51
4 files changed, 178 insertions, 100 deletions
diff --git a/gamemode/client/cl_inventory.lua b/gamemode/client/cl_inventory.lua
index 0e14d50..b1f5728 100644
--- a/gamemode/client/cl_inventory.lua
+++ b/gamemode/client/cl_inventory.lua
@@ -9,6 +9,7 @@
4 - Quests
]]
local qinv = nrequire("cl_qinventory.lua")
+local state = nrequire("cl_state.lua") --Holds weather or not player is in inventory
--local qpray = nrequire("cl_qprayers.lua")
print("Hello from cl_inventory.lua")
@@ -25,9 +26,6 @@ end)
local lastpanel = lastpanel or 1
---Wether the player is in the inventory or not
-local plyisininventory = false
-
local qframe = nil --The master frame
local qtabs = {} --The tabs
@@ -53,7 +51,12 @@ local function BuildInventory()
qframe:SetDraggable(true)
qframe:MakePopup()
qframe.OnClose = function(self)
- plyisininventory = false
+ state.invopen = false
+ self:Hide()
+ return
+ end
+ qframe.Remove = function(self)
+ state.invopen = false
self:Hide()
return
end
@@ -75,14 +78,14 @@ local function ShowInventory()
print("qframe is ", qframe)
if not qframe then BuildInventory()
else qframe:Show() end
- plyisininventory = true
+ state.invopen = true
end
hook.Add("OnSpawnMenuOpen","ArteryOpenInventory",ShowInventory)
hook.Add("OnSpawnMenuClose","ArteryCloseInventory",function()
- plyisininventory = false
+ state.invopen = false
qframe:Hide()
if (not sheet) or (not sheet:GetActiveTab()) or (not sheet:GetActiveTab():GetPanel()) then return end
lastpanel = sheet:GetActiveTab():GetPanel().sheetnum
@@ -106,7 +109,7 @@ hook.Add("CalcView","ArteryInventoryView",function(ply,pos,ang,fov,nearz,farz)
local view = {}
--view.origin = LocalPlayer():GetBonePosition(bone) + LocalPlayer():GetUp() * 2
view.origin = pos
- if plyisininventory then
+ if state.invopen then
local trot = math.rad(CurTime() * rotatespeed)
local xoff = viewdistance * math.sin(trot)
local yoff = viewdistance * math.cos(trot)
@@ -116,12 +119,12 @@ hook.Add("CalcView","ArteryInventoryView",function(ply,pos,ang,fov,nearz,farz)
end
view.angles = ang
view.fov = fov
- if not plyisininventory then
+ if not state.invopen then
LocalPlayer():ManipulateBoneScale(bone,Vector(0,0,0))
else
LocalPlayer():ManipulateBoneScale(bone,previousheadscale)
end
- view.drawviewer = plyisininventory
+ view.drawviewer = state.invopen
return view
end)
diff --git a/gamemode/client/cl_state.lua b/gamemode/client/cl_state.lua
new file mode 100644
index 0000000..f5677e9
--- /dev/null
+++ b/gamemode/client/cl_state.lua
@@ -0,0 +1,9 @@
+--[[
+ Holds some information about client state, this is in a seperate file so I don't have circular dependancies.
+]]
+
+local state = {}
+
+state.invopen = false
+
+return state
diff --git a/gamemode/client/hud/cl_healthbar.lua b/gamemode/client/hud/cl_healthbar.lua
index 67a3090..5655b1c 100644
--- a/gamemode/client/hud/cl_healthbar.lua
+++ b/gamemode/client/hud/cl_healthbar.lua
@@ -1,50 +1,63 @@
-
-hook.Add( "HUDShouldDraw", "HideHUD", function( name )
+hook.Add("HUDShouldDraw", "HideHUD", function(name)
if name == "CHudHealth" then return false end
-end )
+end)
+--[[
--A function that rotates a point around another point
-local function rotatepoint(x,y,cx,cy,rot)
+local function rotatepoint(x, y, cx, cy, rot)
rot = math.rad(rot)
- local cs,sn = math.cos(rot),math.sin(rot)
- local px = x * cs - y * sn;
- local py = x * sn + y * cs;
- return px,py
+ local cs, sn = math.cos(rot), math.sin(rot)
+ local px = x * cs - y * sn
+ local py = x * sn + y * cs
+
+ return px, py
end
+]]
--Add a function to the draw library to draw elipses for blood
local segments = 20
local fade = 0.5
-function draw.DrawElipse(x,y,radius,elong,rotation)
+
+function draw.DrawElipse(x, y, radius, elong, rotation)
rotation = math.rad(rotation)
local cir = {}
- table.insert( cir, { x = x, y = y, u = fade, v = fade } )
+
+ table.insert(cir, {
+ x = x,
+ y = y,
+ u = fade,
+ v = fade
+ })
+
for i = 0, segments do
- local a = math.rad( ( i / segments ) * -360 )
- local xu,yu = math.sin(a),math.cos(a)
+ local a = math.rad((i / segments) * -360)
+ local xu, yu = math.sin(a), math.cos(a)
local xpos = xu * radius * elong
local ypos = yu * radius
- local cs,sn = math.cos(rotation),math.sin(rotation)
- xpos,ypos = xpos * cs - ypos * sn, xpos * sn + ypos * cs
- table.insert( cir, {
+ local cs, sn = math.cos(rotation), math.sin(rotation)
+ xpos, ypos = xpos * cs - ypos * sn, xpos * sn + ypos * cs
+
+ table.insert(cir, {
x = x + xpos,
y = y + ypos,
u = 1,
- v = 1 } )
+ v = 1
+ })
end
- surface.DrawPoly( cir )
+
+ surface.DrawPoly(cir)
end
-local width,height = ScrW(),ScrH()
+local width, height = ScrW(), ScrH()
local padding = height / 32
local barheight = height / 16
local bubbles = {}
local blobs = {}
-local lastpos = 0
-local bubbleradius = height/64
+local bubbleradius = height / 64
local delpoint = height
-hook.Add( "Tick", "Hudpaintbloodtick",function()
- for k,v in pairs(blobs) do
+
+hook.Add("Tick", "Hudpaintbloodtick", function()
+ for k, v in pairs(blobs) do
if v.y > delpoint then
blobs[k] = nil
else
@@ -52,102 +65,114 @@ hook.Add( "Tick", "Hudpaintbloodtick",function()
["x"] = v.x + v.xv,
["y"] = v.y + v.yv,
["xv"] = v.xv,
- ["yv"] = v.yv + 1,
+ ["yv"] = v.yv + 1
}
end
end
- for k,v in pairs(bubbles) do
- if v.y < height - padding - barheight -bubbleradius then
- bubbles[k] = nil
- else
- local subheight = v.y - (1.5 + math.sin((v.y/4) + (v.x*10)))/5
- bubbles[k].y = subheight
- end
- end
+
+ for k, v in pairs(bubbles) do
+ if v.y < height - padding - barheight - bubbleradius then
+ bubbles[k] = nil
+ else
+ local subheight = v.y - (1.5 + math.sin((v.y / 4) + (v.x * 10))) / 5
+ bubbles[k].y = subheight
+ end
+ end
end)
local lasthealth
local obarlength = width / 4
local barlength = obarlength
-local xs,ys = padding,height - padding - barheight
-local bubblespawnrate,bubblespawnchance = 1,0.7
-
-timer.Create("Healthbar_bubble_timer",bubblespawnrate,0,function()
- if math.random() < bubblespawnchance then
- local newbubble = {
- ["x"] = math.random(xs + bubbleradius,barlength-bubbleradius),
- ["y"] = height - padding + bubbleradius
- }
- table.insert(bubbles,newbubble)
- end
-end)
+local xs, ys = padding, height - padding - barheight
+local bubblespawnrate, bubblespawnchance = 1, 0.7
+
+timer.Create("Healthbar_bubble_timer", bubblespawnrate, 0, function()
+ if math.random() < bubblespawnchance then
+ local newbubble = {
+ ["x"] = math.random(xs + bubbleradius, barlength - bubbleradius),
+ ["y"] = height - padding + bubbleradius
+ }
-hook.Add( "HUDPaint", "HUD_DrawHealth", function()
+ table.insert(bubbles, newbubble)
+ end
+end)
+hook.Add("HUDPaint", "HUD_DrawHealth", function()
--Spawn a bunch of blobs if our health has changed
local health = LocalPlayer():Health()
+
if lasthealth == nil then
lasthealth = health
end
+
if health ~= lasthealth then
local difference = lasthealth - health
- barlength = obarlength * (health/100)
- for i=0,difference*3 do
+ barlength = obarlength * (health / 100)
+
+ for i = 0, difference * 3 do
local rtime = math.random()
- timer.Simple(rtime,function()
+
+ timer.Simple(rtime, function()
local yvel = -20 + math.random(10)
- local xvel = (math.random()*5)
+ local xvel = math.random() * 5
local xpos = padding + xs + barlength - difference - 5
local ypos = ys + (math.random() * barheight)
- table.insert(blobs,{
+
+ table.insert(blobs, {
x = xpos,
y = ypos,
xv = xvel,
- yv = yvel,
+ yv = yvel
})
end)
end
+
lasthealth = health
end
+
--Draw the current health thing
- --Background
- surface.SetDrawColor(100,100,100,100)
- surface.DrawRect( xs, ys, obarlength, barheight)
- --Foreground
- surface.SetDrawColor( 150, 0, 0, 255 )
- surface.DrawRect( xs, ys, barlength, barheight )
-
- --Heighlighting/shadows
- local heighlightheight = barheight/3
- for k = 1, heighlightheight do
- local perc = Lerp(k/heighlightheight,100,0)
- surface.SetDrawColor( 150+perc, perc, perc, 255)
- surface.DrawRect( xs, ys+k, barlength, 1)
- end
- for k = 1, heighlightheight do
- local perc = Lerp(k/heighlightheight,0,100)
- surface.SetDrawColor( 150 - perc, 0, 0, 255)
- surface.DrawRect(xs, ys+k+(2*heighlightheight), barlength, 1)
- end
-
- --Draw bubbles
- render.SetScissorRect( xs, ys, xs + barlength, ys + barheight, true ) -- Enable the rect
- surface.SetDrawColor(250,150,150,10)
- for k,v in pairs(bubbles) do
- surface.DrawCircle(v.x,v.y,bubbleradius,250,150,150,30)
- draw.DrawElipse(v.x,v.y,bubbleradius,1,0)
- end
- render.SetScissorRect( 0, 0, 0, 0, false ) -- Disable after you are done
+ --Background
+ surface.SetDrawColor(100, 100, 100, 100)
+ surface.DrawRect(xs, ys, obarlength, barheight)
+ --Foreground
+ surface.SetDrawColor(150, 0, 0, 255)
+ surface.DrawRect(xs, ys, barlength, barheight)
+ --Heighlighting/shadows
+ local heighlightheight = barheight / 3
+
+ for k = 1, heighlightheight do
+ local perc = Lerp(k / heighlightheight, 100, 0)
+ surface.SetDrawColor(150 + perc, perc, perc, 255)
+ surface.DrawRect(xs, ys + k, barlength, 1)
+ end
+
+ for k = 1, heighlightheight do
+ local perc = Lerp(k / heighlightheight, 0, 100)
+ surface.SetDrawColor(150 - perc, 0, 0, 255)
+ surface.DrawRect(xs, ys + k + (2 * heighlightheight), barlength, 1)
+ end
+
+ --Draw bubbles
+ render.SetScissorRect(xs, ys, xs + barlength, ys + barheight, true) -- Enable the rect
+ surface.SetDrawColor(250, 150, 150, 10)
+ for k, v in pairs(bubbles) do
+ if k > 50 then break end
+ surface.DrawCircle(v.x, v.y, bubbleradius, 250, 150, 150, 30)
+ draw.DrawElipse(v.x, v.y, bubbleradius, 1, 0)
+ end
+
+ render.SetScissorRect(0, 0, 0, 0, false) -- Disable after you are done
--Draw the animation for blobs
- surface.SetDrawColor(150,0,0,255)
- for k,v in pairs(blobs) do
+ surface.SetDrawColor(150, 0, 0, 255)
+
+ for k, v in pairs(blobs) do
--Elongation is based on velocity
- local elong = (v.yv^2 + v.xv^2)^0.5
- elong = elong/5
- elong = math.Clamp(elong,1,3)
+ local elong = (v.yv ^ 2 + v.xv ^ 2) ^ 0.5
+ elong = elong / 5
+ elong = math.Clamp(elong, 1, 3)
--Rotation is also based on velcotiy
- local rot = math.deg(math.atan(v.yv/v.xv))
- draw.DrawElipse(v.x,v.y,10/elong,elong, rot)
+ local rot = math.deg(math.atan(v.yv / v.xv))
+ draw.DrawElipse(v.x, v.y, 10 / elong, elong, rot)
end
-end )
+end)
diff --git a/gamemode/client/qtabs/cl_qinventory.lua b/gamemode/client/qtabs/cl_qinventory.lua
index e60424f..e4dfaa8 100644
--- a/gamemode/client/qtabs/cl_qinventory.lua
+++ b/gamemode/client/qtabs/cl_qinventory.lua
@@ -3,13 +3,44 @@
]]
local inv = nrequire("inventory/inventory.lua")
local itm = nrequire("item.lua")
+--local state = nrequire("cl_state.lua")
local q = {}
local known_inventories = {}
local inventory_frames = {}
local invsheet
+
+local drawfloatinginventory = function(id, inventory)
+ print("Drawing a floating inventory!")
+ local frame = vgui.Create("DFrame")
+ frame:SetPos( 100, 100 )
+ frame:SetSize( 300, 200 )
+ frame:SetTitle( "My new Derma frame" )
+ frame:SetDraggable( true )
+ local panel = vgui.Create("DPanel",frame)
+ panel:Dock(FILL)
+ if inventory.DrawOnDPanel then
+ local prox = inventory:DrawOnDPanel(panel)
+ frame.id = known_inventories[id]:AddObserver(prox)
+ else
+ error("Inventory needs a DrawOnDPanel method!")
+ end
+ frame:MakePopup()
+ frame.OnClose = function(self)
+ print("Closeing chest id", id)
+ print("entity is", known_inventories[id].Owner)
+ known_inventories[id]:RemoveObserver(self.id)
+ net.Start("closechestinv")
+ net.WriteEntity(known_inventories[id].Owner)
+ net.SendToServer()
+ known_inventories[id] = nil
+ self:Remove()
+ end
+end
+
local drawsheeton = function(id,inventory)
+ print("Drawing an inventory on a sheet!")
if invsheet == nil then return end
local tpanel = vgui.Create( "DPanel", invsheet )
--tpanel.Paint = function( self, w, h )
@@ -34,15 +65,20 @@ net.Receive("art_ObserveInventory",function()
local datalen = net.ReadUInt(32)
local inital_data = net.ReadData(datalen)
local ownent = net.ReadEntity()
+ print("Owning ent of this inventory is", ownent)
+ assert(known_inventories[id] == nil, "Trying to observe the same inventory twice!",id)
local tinv = inv.CreateInventoryFromData(inv_type,inital_data)
- tinv.owner = ownent
+ tinv.Owner = ownent
tinv.id = id
print("Created new inventory:")
PrintTable(tinv)
known_inventories[id] = tinv
- drawsheeton(id,tinv)
- print("known inventories is now:")
- PrintTable(known_inventories)
+ if id > 10 then
+ drawfloatinginventory(id,tinv)
+ hook.Call("OnSpawnMenuOpen")
+ else
+ drawsheeton(id,tinv)
+ end
end)
net.Receive("art_UpdateInventory",function()
@@ -81,7 +117,12 @@ q.CreateInventorySheet = function(dpanel_parent)
invsheet:Dock( FILL )
for k,v in pairs(known_inventories) do
- drawsheeton(k,v)
+ print("This inventory id in known_inventories is", k)
+ if k <= 10 then
+ drawsheeton(k,v)
+ else
+ drawfloatinginventory(k,v)
+ end
--[[
local tpanel = vgui.Create( "DPanel", invsheet )
tpanel.Paint = function( self, w, h )