Skip to content

Commit

Permalink
Merge pull request #327 from Alf21/Adaptive_Default_Fontcolor
Browse files Browse the repository at this point in the history
Adaptive Default Fontcolor
  • Loading branch information
Alf21 authored May 8, 2019
2 parents 48138ac + 67570ae commit d287eb4
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ DEFINE_BASECLASS(base)
HUDELEMENT.Base = base

if CLIENT then
local shadowColor = Color(0, 0, 0, 200)
local shadowColorDark = Color(0, 0, 0, 200)
local shadowColorWhite = Color(200, 200, 200, 200)

function HUDELEMENT:DrawBg(x, y, w, h, c)
DrawHUDElementBg(x, y, w, h, c)
Expand Down Expand Up @@ -34,12 +35,21 @@ if CLIENT then

-- draw text
if t then
self:AdvancedText(t, "PureSkinBar", x + 14, y + 1, COLOR_WHITE, TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, true, s)
self:AdvancedText(t, "PureSkinBar", x + 14, y + 1, self:GetDefaultFontColor(c), TEXT_ALIGN_LEFT, TEXT_ALIGN_LEFT, true, s)
end
end

function HUDELEMENT:ShadowedText(text, font, x, y, color, xalign, yalign)
local tmpCol = Color(shadowColor.r, shadowColor.g, shadowColor.b, color.a)
function HUDELEMENT:GetDefaultFontColor(bgcolor)
local color = 0
if bgcolor.r + bgcolor.g + bgcolor.b < 500 then
return COLOR_WHITE
else
return COLOR_BLACK
end
end

function HUDELEMENT:ShadowedText(text, font, x, y, color, xalign, yalign, dark)
local tmpCol = color.r + color.g + color.b > 200 and Color(shadowColorDark.r, shadowColorDark.g, shadowColorDark.b, color.a) or Color(shadowColorWhite.r, shadowColorWhite.g, shadowColorWhite.b, color.a)

draw.SimpleText(text, font, x + 2, y + 2, tmpCol, xalign, yalign)
draw.SimpleText(text, font, x + 1, y + 1, tmpCol, xalign, yalign)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ if CLIENT then

role_scale_multiplier = math.Clamp(role_scale_multiplier, 0.55, 0.85) * self.scale

self:AdvancedText(string.upper(text), "PureSkinRole", nx, ry, COLOR_WHITE, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, true, Vector(role_scale_multiplier * 0.9, role_scale_multiplier, role_scale_multiplier))
self:AdvancedText(string.upper(text), "PureSkinRole", nx, ry, self:GetDefaultFontColor(self.basecolor), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, true, Vector(role_scale_multiplier * 0.9, role_scale_multiplier, role_scale_multiplier))
end

-- player informations
Expand All @@ -187,7 +187,7 @@ if CLIENT then
surface.SetDrawColor(clr(secInfoTbl.color))
surface.DrawRect(nx2, ny, sri_width, nh)

self:AdvancedText(sri_text_caps, "PureSkinBar", nx2 + sri_width * 0.5, ry, COLOR_WHITE, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, true, self.scale)
self:AdvancedText(sri_text_caps, "PureSkinBar", nx2 + sri_width * 0.5, ry, self:GetDefaultFontColor(secInfoTbl.color), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, true, self.scale)

-- draw lines around the element
self:DrawLines(nx2, ny, sri_width, nh, secInfoTbl.color.a)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ if CLIENT then

self:DrawBg(bx, by, bw, infoH, self.basecolor)

self:AdvancedText(info, "ItemInfoFont", tx + 2, ty + 2, COLOR_BLACK, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, false, self.scale)
self:AdvancedText(info, "ItemInfoFont", tx, ty, COLOR_WHITE, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, false, self.scale)
self:AdvancedText(info, "ItemInfoFont", tx, ty, self:GetDefaultFontColor(self.basecolor), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, false, self.scale)

self:DrawLines(bx, by, bw, infoH, self.basecolor.a)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ if CLIENT then

local msgfont = "PureSkinMSTACKMsg"
local imagedmsgfont = "PureSkinMSTACKImageMsg"
local text_color = COLOR_WHITE

local const_defaults = {
basepos = {x = 0, y = 0},
Expand Down Expand Up @@ -113,7 +112,7 @@ if CLIENT then
item.bg = item.bg and table.Copy(item.bg) or table.Copy(bg_color)
item.bg.a_max = item.bg.a

item.col = item.col and table.Copy(item.col) or table.Copy(text_color)
item.col = item.col and table.Copy(item.col) or table.Copy(self:GetDefaultFontColor(item.bg))
item.col.a_max = item.col.a

if item.image then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if CLIENT then
self:DrawBar(x + self.pad, y + self.pad, w - self.pad * 2, h - self.pad * 2, draw_col, punch, self.scale, L.punch_title)
self:DrawLines(x, y, w, h, self.basecolor.a)

self:AdvancedText(L.punch_help, "TabLarge", x + w * 0.5, y, COLOR_WHITE, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, true, self.scale)
self:AdvancedText(L.punch_help, "TabLarge", x + w * 0.5, y, self:GetDefaultFontColor(self.basecolor), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, true, self.scale)

local bonus = client:GetNWInt("bonuspunches", 0)
if bonus ~= 0 then
Expand All @@ -70,7 +70,7 @@ if CLIENT then
text = interp(L.punch_malus, {num = bonus})
end

self:AdvancedText(text, "TabLarge", x + w * 0.5, y + self.margin * 2 + 20, COLOR_WHITE, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, true, self.scale)
self:AdvancedText(text, "TabLarge", x + w * 0.5, y + self.margin * 2 + 20, self:GetDefaultFontColor(self.basecolor), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, true, self.scale)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ if CLIENT then
local is_traitor = not client:IsActive() or client:HasTeam(TEAM_TRAITOR)
local endtime = GetGlobalFloat("ttt_round_end", 0) - CurTime()
local font = "TimeLeft"
local color = COLOR_WHITE
local color = self:GetDefaultFontColor(self.basecolor)

local tmpx = self.pos.x + self.size.w * 0.5
local tmpy = self.pos.y + self.size.h * 0.5
Expand Down Expand Up @@ -113,7 +113,7 @@ if CLIENT then
self:AdvancedText(text, font, rx, ry, color, TEXT_ALIGN_CENTER, vert_align_clock, true, self.scale)

if is_haste then
self:AdvancedText(L.hastemode, "PureSkinMSTACKMsg", tmpx, self.pos.y + self.pad, COLOR_WHITE, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, true, self.scale)
self:AdvancedText(L.hastemode, "PureSkinMSTACKMsg", tmpx, self.pos.y + self.pad, self:GetDefaultFontColor(self.basecolor), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP, true, self.scale)
end

-- draw lines around the element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if CLIENT then -- CLIENT
local w, h = size.w, size.h

self:DrawBg(x, y, w, h, self.basecolor)
self:AdvancedText(name, "PureSkinBar", x + self.iconSize + self.pad, y + h * 0.5, COLOR_WHITE, TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, true, self.scale)
self:AdvancedText(name, "PureSkinBar", x + self.iconSize + self.pad, y + h * 0.5, self:GetDefaultFontColor(self.basecolor), TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, true, self.scale)
self:DrawLines(x, y, w, h, self.basecolor.a)

local nSize = self.iconSize - 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,10 @@ DEFINE_BASECLASS(base)
HUDELEMENT.Base = base

if CLIENT then
-- color defines
local col_active = {
text_empty = Color(200, 20, 20, 255),
text = Color(255, 255, 255, 255),
shadow = 255
}

local col_dark = {
text_empty = Color(200, 20, 20, 100),
text = Color(255, 255, 255, 100),
shadow = 100
}
-- color defines
local color_empty = Color(200, 20, 20, 255)
local color_empty_dark = Color(200, 20, 20, 100)

local element_height = 28
local margin = 5
Expand Down Expand Up @@ -70,14 +62,14 @@ if CLIENT then
BaseClass.PerformLayout(self)
end

function HUDELEMENT:DrawBarBg(x, y, w, h, col)
function HUDELEMENT:DrawBarBg(x, y, w, h, active)
local ply = LocalPlayer()
local c = (col == col_active and ply:GetRoleColor() or ply:GetRoleDkColor()) or Color(100, 100, 100)
local c = (active and ply:GetRoleColor() or ply:GetRoleDkColor()) or Color(100, 100, 100)

-- draw bg and shadow
self.drawer:DrawBg(x, y, w, h, self.basecolor)

if col == col_active then
if active then
surface.SetDrawColor(0, 0, 0, 90)
surface.DrawRect(x, y, w, h)
end
Expand All @@ -88,13 +80,24 @@ if CLIENT then

-- draw lines around the element
self.drawer:DrawLines(x, y, w, h, self.basecolor.a)

return c
end

function HUDELEMENT:DrawWeapon(x, y, c, wep)
function HUDELEMENT:DrawWeapon(x, y, active, wep, tip_color)
if not IsValid(wep) or not IsValid(wep.Owner) or not isfunction(wep.Owner.GetAmmoCount) then
return false
end

--define colors
local text_color = self.drawer:GetDefaultFontColor(self.basecolor)
text_color = active and text_color or Color(text_color.r, text_color.g, text_color.b, text_color.r > 128 and 100 or 180)

local number_color = self.drawer:GetDefaultFontColor(tip_color)
number_color = active and number_color or Color(number_color.r, number_color.g, number_color.b, number_color.r > 128 and 100 or 180)

local empty_color = active and color_empty or color_empty_dark

local name = TryTranslation(wep:GetPrintName() or wep.PrintName or "...")
local cl1, am1 = wep:Clip1(), (wep.Ammo1 and wep:Ammo1() or false)
local ammo = false
Expand All @@ -106,13 +109,13 @@ if CLIENT then
end

-- Slot
self.drawer:AdvancedText(MakeKindValid(wep.Kind), "PureSkinWepNum", x + self.lpw * 0.5, y + self.element_height * 0.5, c.text, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, true, self.scale)
self.drawer:AdvancedText(MakeKindValid(wep.Kind), "PureSkinWepNum", x + self.lpw * 0.5, y + self.element_height * 0.5, number_color, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, true, self.scale)

-- Name
self.drawer:AdvancedText(string.upper(name), "PureSkinWep", x + 10 + self.element_height, y + self.element_height * 0.5, c.text, nil, TEXT_ALIGN_CENTER, true, self.scale)
self.drawer:AdvancedText(string.upper(name), "PureSkinWep", x + 10 + self.element_height, y + self.element_height * 0.5, text_color, nil, TEXT_ALIGN_CENTER, true, self.scale)

if ammo then
local col = (wep:Clip1() == 0 and wep:Ammo1() == 0) and c.text_empty or c.text
local col = (wep:Clip1() == 0 and wep:Ammo1() == 0) and empty_color or text_color

-- Ammo
self.drawer:AdvancedText(tostring(ammo), "PureSkinWep", x + self.size.w - self.margin * 3, y + self.element_height * 0.5, col, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER, false, self.scale)
Expand Down Expand Up @@ -141,18 +144,14 @@ if CLIENT then
end

function HUDELEMENT:DrawElement(i, x, y, w, h)
local col = col_dark

if WSWITCH.Selected == i then
col = col_active
end
local active = WSWITCH.Selected == i

self:DrawBarBg(x, y, w, h, col)
local tipCol = self:DrawBarBg(x, y, w, h, active)

if not self:DrawWeapon(x, y, col, WSWITCH.WeaponCache[i]) then
if not self:DrawWeapon(x, y, active, WSWITCH.WeaponCache[i], tipCol) then
WSWITCH:UpdateWeaponCache()

return
end
end
end
end

0 comments on commit d287eb4

Please sign in to comment.