Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new look is now customizable and minor behaviour fixes #26

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
31 changes: 25 additions & 6 deletions lua/entities/entity_fishing_rod/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ language.Add("entity_fishing_rod", "Fishing Rod")

include("shared.lua")


fishingmod.ColorTable = fishingmod.LoadUIColors()

local uiText = fishingmod.DefaultUIColors().uiText
Earu marked this conversation as resolved.
Show resolved Hide resolved
local uiTextCaught = fishingmod.DefaultUIColors().uiTextCaught
local uiBackground = fishingmod.DefaultUIColors().uiBackground
local xpBarForeGr = fishingmod.DefaultUIColors().xpBarForeGr
local xpBarBackGr = fishingmod.DefaultUIColors().xpBarBackGr
local xpBarText = fishingmod.DefaultUIColors().xpBarText

local rope_material = Material("cable/rope")

function ENT:Draw()
Expand Down Expand Up @@ -34,6 +44,15 @@ function ENT:RenderScene()
end

function ENT:HUDPaint()
if fishingmod.ColorTable then
uiText = fishingmod.ColorTable.uiText or uiText
uiTextCaught = fishingmod.ColorTable.uiTextCaught or uiTextCaught
uiBackground = fishingmod.ColorTable.uiBackground or uiBackground
xpBarForeGr = fishingmod.ColorTable.xpBarForeGr or xpBarForeGr
xpBarBackGr = fishingmod.ColorTable.xpBarBackGr or xpBarBackGr
xpBarText = fishingmod.ColorTable.xpBarText or xpBarText
end

local ply = self:GetPlayer()

if not IsValid(ply) or (ply and not ply.fishingmod) then return end
Expand Down Expand Up @@ -74,7 +93,7 @@ function ENT:HUDPaint()
end

surface.SetFont("fixed_Height_Font")
local textBelow = "Total Catch: " .. ply.fishingmod.catches .. "\nMoney: " .. (math.Round(ply.fishingmod.money,2) or "0") .. "\nLevel: " .. ply.fishingmod.level .. "\nLength: " .. tostring(math.Round((self:GetLength() * 2.54) / 100 * 10) / 10) .. depth .. catch
local textBelow = "Total Catch: " .. ply.fishingmod.catches .. "\nMoney: " .. (math.Round(ply.fishingmod.money) or "0") .. "\nLevel: " .. ply.fishingmod.level .. "\nLength: " .. tostring(math.Round((self:GetLength() * 2.54) / 100 * 10) / 10) .. depth .. catch
Earu marked this conversation as resolved.
Show resolved Hide resolved
local boxBelow_W, boxBelow_H = surface.GetTextSize(textBelow)

surface.SetFont("fixed_NameFont")
Expand All @@ -86,7 +105,7 @@ function ENT:HUDPaint()
local bg_y, bg_height = xy.y - 120 - height_offset, 70 + boxBelow_H
local ecbg_x, ecbg_width = xy.x - math.max(minwid, stripped_name_width / 2, ( boxBelow_W / 2)) - 10, (math.max(minwid, stripped_name_width / 2, boxBelow_W / 2) + 10) * 2

surface.SetDrawColor(0, 0, 0, 144)
surface.SetDrawColor(uiBackground.r, uiBackground.g, uiBackground.b, uiBackground.a)

if EasyChat then
surface.DrawRect(ecbg_x, bg_y, ecbg_width, bg_height)
Expand All @@ -97,10 +116,10 @@ function ENT:HUDPaint()
surface.DrawRect(bg_x + innerBoxXY, bg_y + innerBoxXY, bg_width - (2 * innerBoxXY), bg_height - (2 * innerBoxXY) )
draw.DrawText(tempNick, "fixed_NameFont", xy.x, xy.y - 112 - height_offset, team_col, 1)
end
draw.RoundedBox(1, xy.x - 50, xy.y - 88 - height_offset, 100, 23, Color(255, 255, 255, 55))
draw.RoundedBox(1, xy.x - 50, xy.y - 88 - height_offset, math.min(ply.fishingmod.percent, 100), 23, Color(0, 255, 0, 150))
draw.DrawText(tostring(math.Round(ply.fishingmod.expleft)), "fixed_Height_Font" , xy.x, xy.y - 84 - height_offset, color_black, 1)
draw.DrawText(textBelow, "fixed_Height_Font", xy.x, xy.y - 60 - height_offset, hooked_entity and Color(0, 255, 0, 255) or color_white,1)
draw.RoundedBox(1, xy.x - 50, xy.y - 88 - height_offset, 100, 23, xpBarBackGr)
draw.RoundedBox(1, xy.x - 50, xy.y - 88 - height_offset, math.min(ply.fishingmod.percent, 100), 23, xpBarForeGr)
draw.DrawText(tostring(math.Round(ply.fishingmod.expleft)), "fixed_Height_Font" , xy.x, xy.y - 84 - height_offset, xpBarText, 1)
draw.DrawText(textBelow, "fixed_Height_Font", xy.x, xy.y - 60 - height_offset, hooked_entity and uiTextCaught or uiText, 1)
end

function ENT:Initialize()
Expand Down
11 changes: 9 additions & 2 deletions lua/entities/entity_fishing_rod/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ function ENT:SetLength(length)
if not IsValid(self.physical_rope) then return end
self.physical_rope:Fire("SetSpringLength", length/2+10)
local hookent = self:GetHook()
if IsValid(hookent) then
if IsValid(hookent) and IsValid(hookent.physical_rope) then
hookent.physical_rope:Fire("SetSpringLength", length/2+10)
end
self.dt.length = length
end

function ENT:CanTool() return false end
function ENT:CanProperty() return false end

function ENT:AssignPlayer(ply)
self:SetOwner(ply)

Expand All @@ -87,6 +90,8 @@ function ENT:AssignPlayer(ply)
fish_hook:SetOwner(ply)
fish_hook:SetPos(position)
fish_hook:Spawn()
function fish_hook:CanTool() return false end
function fish_hook:CanProperty() return false end
hook.Run("PlayerSpawnedSENT", ply, fish_hook)
if fish_hook.CPPISetOwner then fish_hook:CPPISetOwner(ply) end

Expand Down Expand Up @@ -119,5 +124,7 @@ function ENT:OnRemove()
SafeRemoveEntity(self.dt.attach)
SafeRemoveEntity(self.physical_rope)
SafeRemoveEntity(self.avatar)
SafeRemoveEntity(self.dt.attach.dt.hook)
if self.dt.attach.dt then
SafeRemoveEntity(self.dt.attach.dt.hook)
end
end
3 changes: 2 additions & 1 deletion lua/entities/fishing_mod_seagull/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ function ENT:OnTakeDamage(data)
local inflictor = data:GetInflictor()
local attacker = data:GetAttacker()

if data:IsBulletDamage() and attacker:IsPlayer() then
if not self.spawnedRagdoll and data:IsBulletDamage() and attacker:IsPlayer() then
self.spawnedRagdoll = true
local ragdoll = ents.Create("prop_ragdoll")
ragdoll:SetModel(self:GetModel())
ragdoll:SetPos(self:GetPos())
Expand Down
3 changes: 3 additions & 0 deletions lua/entities/fishing_rod_bobber/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function ENT:Initialize()
end
end

function ENT:CanTool() return false end
function ENT:CanProperty() return false end

function ENT:Yank( force )
force = force or math.random( 50, 100 )
self:GetPhysicsObject():AddVelocity( Vector( 0, 0, -force ) )
Expand Down
20 changes: 15 additions & 5 deletions lua/entities/fishing_rod_hook/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@ function ENT:StartTouch(entity)
if fishingmod.IsBait(entity) then
self:HookBait(entity)
end
fishingmod.HookBait(self.bobber.rod:GetPlayer(), entity)
if self.bobber.rod then
fishingmod.HookBait(self.bobber.rod:GetPlayer(), entity)
end
end

function ENT:HookBait(bait)
if not IsValid(self.dt.bait) then
if not IsValid(self.dt.bait) and not bait.JustSeparated and not self:GetHookedEntity() then
bait.JustSeparated = true
timer.Simple(1, function() if IsValid(bait) then bait.JustSeparated = false end end)
local phys = bait:GetPhysicsObject()
if IsValid(phys) then
phys:EnableMotion(true)
phys:Wake()
end
bait:SetPos(self:GetPos())

self:SetPos(bait:GetPos())
constraint.NoCollide( self, self.dt.bait, 0, 0)
self.dt.bait = bait
constraint.Weld(self, self.dt.bait, 0, 0, 0, false, false)
end
Expand Down Expand Up @@ -71,12 +77,12 @@ function ENT:Hook( entity, data )
if data.size then
entity:SetNWFloat("fishingmod size", data.size)
end
self:SetPos(self:GetPos()+Vector(0,0,64))
entity.is_catch = true
entity.data = data
entity.data.caught = os.time()
entity.data.owner = ply
entity.data.ownerid = ply:UniqueID()

entity:SetPos(self:GetPos())
entity:SetOwner(self)
entity.is_catch = true
Expand All @@ -87,6 +93,7 @@ function ENT:Hook( entity, data )
else
constraint.Weld(entity, self, 0, 0, ply.fishingmod.force * 700 + 1000 )
end

fishingmod.SetCatchInfo(entity)
self.dt.hooked = entity
if entity.PostHook then entity:PostHook(ply, true) end
Expand Down Expand Up @@ -192,13 +199,16 @@ function ENT:UnHook()
end
end

function ENT:CanTool() return false end
function ENT:CanProperty() return false end

function ENT:OnRemove()
if IsValid(self.dt.hooked) then
self.dt.hooked:SetParent()
end

-- This is a needed fix as physical_rope can be a bool
if type(self.physical_rope) == "Entity" then
if type(self.physical_rope) == "Entity" and IsValid(self.physical_rope) then
self.physical_rope:Remove()
end
end
Expand Down
2 changes: 1 addition & 1 deletion lua/fishing_mod/catch/money.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fishingmod.AddCatch{
remove_on_release = false,
bait = {
"models/props_c17/cashregister01a.mdl",
"models/props_misc/cash_register.mdl",
--"models/props_misc/cash_register.mdl", -- broken bait model
}
}

Expand Down
45 changes: 30 additions & 15 deletions lua/fishing_mod/catch/stove.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

fishingmod.AddCatch{
friendly = "Stove",
type = "fishing_mod_catch_stove",
Expand Down Expand Up @@ -33,9 +34,7 @@ function ENT:SetupDataTables()
end

if CLIENT then

local sprite = Material( "sprites/splodesprite" )

function ENT:Initialize()
self.emitter = ParticleEmitter(self:GetPos())
self.sound = CreateSound(self, "ambient/fire/fire_small_loop2.wav")
Expand Down Expand Up @@ -136,32 +135,48 @@ if CLIENT then
render.DrawSprite( self:GetPos() + ( self:GetUp() * v.position.z ) + ( self:GetRight() * v.position.x ) + ( self:GetForward() * v.position.y ), 1, 1, Color( 255, 255, 255, 255 ) )
end
end

function ENT:ShowHeatAdjuster()
local backGround = fishingmod.DefaultUIColors().uiBackground
local buttonNotSelected = fishingmod.DefaultUIColors().uiButtonDeSelected
local uiButtonSelected = fishingmod.DefaultUIColors().uiButtonSelected
local uiButtonHovered = fishingmod.DefaultUIColors().uiButtonHovered
local uiText = fishingmod.DefaultUIColors().uiText
if fishingmod.ColorTable then
backGround = fishingmod.ColorTable.uiBackground or backGround
buttonNotSelected = fishingmod.ColorTable.uiButtonDeSelected or buttonNotSelected
uiButtonSelected = fishingmod.ColorTable.uiButtonSelected or uiButtonSelected
uiButtonHovered = fishingmod.ColorTable.uiButtonHovered or uiButtonHovered
uiText = fishingmod.ColorTable.uiText or uiText
else
fishingmod.ColorTable = fishingmod.DefaultUIColors()
end
local frame = vgui.Create("DFrame")
frame.Paint = function(s, x, y)
surface.SetDrawColor(0, 0, 0, 144)

surface.SetDrawColor(backGround.r, backGround.g, backGround.b, backGround.a)
surface.DrawRect(0, 0, x, y)
surface.DrawRect(3, 24, x-6, y-24-3)
surface.DrawRect(3, 24, x - 6, y - 24 - 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if your -3 is a constant please make it a variable such as CONSTANT = 3, if not then just put the actual number instead of doing unnecessary operations

end
frame:ShowCloseButton(false)
local closebutton = vgui.Create("DButton", frame)
local x, y = frame:GetSize()
closebutton.ButtonW = 60
closebutton:SetSize(closebutton.ButtonW, 18)
closebutton:SetText("Close")
closebutton:SetTextColor(color_white)
closebutton:SetTextColor(uiText)
closebutton:SetPos(x - closebutton.ButtonW - 3, 3)
closebutton.DoClick = function()
frame:Close()
end
closebutton.Paint = function(self, w, h)

if(closebutton:IsDown() ) then
surface.SetDrawColor(0, 0, 0, 72)
surface.SetDrawColor(buttonNotSelected.r, buttonNotSelected.g, buttonNotSelected.b, buttonNotSelected.a)
elseif(closebutton:IsHovered()) then
surface.SetDrawColor(155, 155, 155, 144)
surface.SetDrawColor(uiButtonHovered.r, uiButtonHovered.g, uiButtonHovered.b, uiButtonHovered.a)
else
surface.SetDrawColor(0, 0, 0, 144)
surface.SetDrawColor(backGround.r, backGround.g, backGround.b, backGround.a)
end
surface.DrawRect(0, 0, w, h)
end
Expand All @@ -170,7 +185,7 @@ if CLIENT then
closebutton:SetSize(math.min(closebutton.ButtonW, x - 6) , 18 )
end
frame:SetSize(300, 80)
frame:GetTable().lblTitle:SetTextColor(color_white)
frame.lblTitle:SetTextColor(uiText)
frame:Center()
local p = LocalPlayer()

Expand All @@ -184,8 +199,8 @@ if CLIENT then
slider:SetMax(100)
slider:SetText("Heat")
slider:SetConVar("fishingmod_stove_heat")
slider:GetTable().Label:SetTextColor(color_white)
slider:GetTable().Wang.m_Skin.colTextEntryText = color_white
slider.Label:SetTextColor(uiText)
slider.Wang.m_Skin.colTextEntryText = uiText
end


Expand Down Expand Up @@ -234,7 +249,7 @@ else

self.smoothheat = self.smoothheat + ((heat - self.smoothheat) / 1000)

self.dt.heat = self.smoothheat * -1 +100
self.dt.heat = self.smoothheat * -1 + 100

for key, data in pairs(self.storage) do

Expand All @@ -251,7 +266,7 @@ else
if catch:IsOnFire() then catch.data.fried = 1000 end

catch.data.fried = catch.data.fried or 0
catch.data.fried = math.Clamp(catch.data.fried + (catch.data.fried*self.dt.heat/700), 1, 1000)
catch.data.fried = math.Clamp(catch.data.fried + (catch.data.fried * self.dt.heat / 700), 1, 1000)

--[[ if (lastprint or 0) < CurTime() then
print(catch.data.fried, self.smoothheat)
Expand All @@ -274,7 +289,7 @@ else

if (self.next_search or 0) < CurTime() then

for key, entity in pairs( ents.FindInBox( self:GetPos() + self:OBBMins(), self:GetPos() + self:OBBMaxs() ) ) do
for key, entity in pairs( ents.FindInBox( self:GetPos() + self:OBBMins(), self:GetPos() + self:OBBMaxs() * Vector(1, 1, 1.2) ) ) do
if entity.data and entity ~= self and not entity.shelf_stored and entity:GetClass() ~= "fishing_mod_catch_stove" and not entity.is_bait then
self:AddItem( entity )
end
Expand Down
Loading