• I need help with TTT scoreboard!
    4 replies, posted
I want some icons on the scoreboard next to staff members name, I've done so successfully but I want when you hovering your mouse over it, it says what rank it is, but i cant get tooltip to work. How to do this? Here's my modified code from sb_row.lua. I have commented out where I have put my custom code. ---- Scoreboard player score row, based on sandbox version include("sb_info.lua") local GetTranslation = LANG.GetTranslation local GetPTranslation = LANG.GetParamTranslation SB_ROW_HEIGHT = 24--16local PANEL = {} function PANEL:Init()-- cannot create info card until player state is known self.info = nil self.open = false self.cols = {} self:AddColumn( GetTranslation("sb_ping"), function(ply)return ply:Ping() end ) self:AddColumn( GetTranslation("sb_deaths"), function(ply)return ply:Deaths() end ) self:AddColumn( GetTranslation("sb_score"), function(ply)return ply:Frags() end ) if KARMA.IsEnabled() then self:AddColumn( GetTranslation("sb_karma"), function(ply)returnmath.Round(ply:GetBaseKarma()) end ) end-- Let hooks add their custom columns hook.Call("TTTScoreboardColumns", nil, self) for _, c inipairs(self.cols) do c:SetMouseInputEnabled(false) end self.tag = vgui.Create("DLabel", self) self.tag:SetText("") self.tag:SetMouseInputEnabled(false) self.sresult = vgui.Create("DImage", self) self.sresult:SetSize(16,16) self.sresult:SetMouseInputEnabled(false) --// CUSTOM CODE self.rank = vgui.Create("DImage", self) self.rank:SetSize(16,16) self.rank:SetMouseInputEnabled(false) --// END self.avatar = vgui.Create( "AvatarImage", self ) self.avatar:SetSize(SB_ROW_HEIGHT, SB_ROW_HEIGHT) self.avatar:SetMouseInputEnabled(false) self.nick = vgui.Create("DLabel", self) self.nick:SetMouseInputEnabled(false) self.voice = vgui.Create("DImageButton", self) self.voice:SetSize(16,16) self:SetCursor( "hand" ) endfunction PANEL:AddColumn( label, func, width, _, _ )local lbl = vgui.Create( "DLabel", self ) lbl.GetPlayerText = func lbl.IsHeading = false lbl.Width = width or50-- Retain compatibility with existing codetable.insert( self.cols, lbl ) return lbl end-- Mirror sb_main, of which it and this file both call using the-- TTTScoreboardColumns hook, but it is useless in this file-- Exists only so the hook wont return an error if it tries to-- use the AddFakeColumn function of `sb_main`, which would-- cause this file to raise a `function not found` error or othersfunction PANEL:AddFakeColumn()endlocal namecolor = { default = COLOR_WHITE, admin = Color(220, 180, 0, 255), dev = Color(100, 240, 105, 255) } local rolecolor = { default = Color(0, 0, 0, 0), traitor = Color(255, 0, 0, 30), detective = Color(0, 0, 255, 30) } function GM:TTTScoreboardColorForPlayer(ply)ifnot IsValid(ply) thenreturn namecolor.default endif ply:SteamID() == "STEAM_0:0:1963640"thenreturn namecolor.dev --// CUSTOM CODEelseif ply:IsUserGroup("superadmin") or ply:IsUserGroup("admin") or ply:IsUserGroup("moderator") and GetGlobalBool("ttt_highlight_admins", true) then--// ENDreturn namecolor.admin endreturn namecolor.default endfunction GM:TTTScoreboardRowColorForPlayer(ply)ifnot IsValid(ply) thenreturn rolecolor.default endif ply:IsTraitor() thenreturn rolecolor.traitor elseif ply:IsDetective() thenreturn rolecolor.detective endreturn rolecolor.default endlocalfunction ColorForPlayer(ply)if IsValid(ply) thenlocal c = hook.Call("TTTScoreboardColorForPlayer", GAMEMODE, ply) -- verify that we got a proper colorif c andtype(c) == "table"and c.r and c.b and c.g and c.a thenreturn c else ErrorNoHalt("TTTScoreboardColorForPlayer hook returned something that isn't a color!\n") endendreturn namecolor.default endfunction PANEL:Paint(width, height)ifnot IsValid(self.Player) thenreturnend-- if ( self.Player:GetFriendStatus() == "friend" ) then-- color = Color( 236, 181, 113, 255 )-- endlocal ply = self.Player local c = hook.Call("TTTScoreboardRowColorForPlayer", GAMEMODE, ply) surface.SetDrawColor(c) surface.DrawRect(0, 0, width, SB_ROW_HEIGHT) if ply == LocalPlayer() then surface.SetDrawColor( 200, 200, 200, math.Clamp(math.sin(RealTime() * 2) * 50, 0, 100)) surface.DrawRect(0, 0, width, SB_ROW_HEIGHT ) endreturntrueendfunction PANEL:SetPlayer(ply) self.Player = ply self.avatar:SetPlayer(ply) ifnot self.info thenlocal g = ScoreGroup(ply) if g == GROUP_TERROR and ply != LocalPlayer() then self.info = vgui.Create("TTTScorePlayerInfoTags", self) self.info:SetPlayer(ply) self:InvalidateLayout() elseif g == GROUP_FOUND or g == GROUP_NOTFOUND then self.info = vgui.Create("TTTScorePlayerInfoSearch", self) self.info:SetPlayer(ply) self:InvalidateLayout() endelse self.info:SetPlayer(ply) self:InvalidateLayout() end self.voice.DoClick = function()if IsValid(ply) and ply != LocalPlayer() then ply:SetMuted(not ply:IsMuted()) endend self:UpdatePlayerData() endfunction PANEL:GetPlayer()return self.Player endfunction PANEL:UpdatePlayerData()ifnot IsValid(self.Player) thenreturnendlocal ply = self.Player for i=1,#self.cols do-- Set text from function, passing the label along so stuff like text-- color can be changed self.cols[i]:SetText( self.cols[i].GetPlayerText(ply, self.cols[i]) ) end self.nick:SetText(ply:Nick()) self.nick:SizeToContents() self.nick:SetTextColor(ColorForPlayer(ply)) local ptag = ply.sb_tag if ScoreGroup(ply) != GROUP_TERROR then ptag = nilend self.tag:SetText(ptag and GetTranslation(ptag.txt) or"") self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE) self.sresult:SetVisible(ply.search_result != nil) -- more blue if a detective searched themif ply.search_result and (LocalPlayer():IsDetective() or (not ply.search_result.show)) then self.sresult:SetImageColor(Color(200, 200, 255)) end-- cols are likely to need re-centering self:LayoutColumns() if self.info then self.info:UpdatePlayerData() endif self.Player != LocalPlayer() thenlocal muted = self.Player:IsMuted() self.voice:SetImage(muted and"icon16/sound_mute.png"or"icon16/sound.png") else self.voice:Hide() end--// CUSTOM CODEif ply:IsUserGroup("superadmin") then self.rank:SetImage("icon16/star.png") self.rank:SetImageColor(Color(230, 230, 230, 230)) endif ply:IsUserGroup("admin") then self.rank:SetImage("icon16/shield_add.png") self.rank:SetImageColor(Color(230, 230, 230, 230)) endif ply:IsUserGroup("moderator") then self.rank:SetImage("icon16/shield.png") self.rank:SetImageColor(Color(230, 230, 230, 230)) end--// ENDendfunction PANEL:ApplySchemeSettings()for k,v inpairs(self.cols) do v:SetFont("treb_small") v:SetTextColor(COLOR_WHITE) end self.nick:SetFont("treb_small") self.nick:SetTextColor(ColorForPlayer(self.Player)) local ptag = self.Player and self.Player.sb_tag self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE) self.tag:SetFont("treb_small") self.sresult:SetImage("icon16/magnifier.png") self.sresult:SetImageColor(Color(170, 170, 170, 150)) endfunction PANEL:LayoutColumns()local cx = self:GetWide() for k,v inipairs(self.cols) do v:SizeToContents() cx = cx - v.Width v:SetPos(cx - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2) end self.tag:SizeToContents() cx = cx - 90 self.tag:SetPos(cx - self.tag:GetWide()/2, (SB_ROW_HEIGHT - self.tag:GetTall()) / 2) self.sresult:SetPos(cx - 8, (SB_ROW_HEIGHT - 16) / 2) endfunction PANEL:PerformLayout() self.avatar:SetPos(0,0) self.avatar:SetSize(SB_ROW_HEIGHT,SB_ROW_HEIGHT) local fw = sboard_panel.ply_frame:GetWide() self:SetWide( sboard_panel.ply_frame.scroll.Enabled and fw-16or fw ) ifnot self.openthen self:SetSize(self:GetWide(), SB_ROW_HEIGHT) if self.info then self.info:SetVisible(false) endelseif self.info then self:SetSize(self:GetWide(), 100 + SB_ROW_HEIGHT) self.info:SetVisible(true) self.info:SetPos(5, SB_ROW_HEIGHT + 5) self.info:SetSize(self:GetWide(), 100) self.info:PerformLayout() self:SetSize(self:GetWide(), SB_ROW_HEIGHT + self.info:GetTall()) end self.nick:SizeToContents() self.nick:SetPos(SB_ROW_HEIGHT + 10, (SB_ROW_HEIGHT - self.nick:GetTall()) / 2) --// CUSTOM CODE self.rank:SizeToContents() self.rank:SetPos(SB_ROW_HEIGHT + self.nick:GetWide() + 16, (SB_ROW_HEIGHT - self.nick:GetTall()) / 2 - 1) --// END self:LayoutColumns() self.voice:SetVisible(not self.open) self.voice:SetSize(16, 16) self.voice:DockMargin(4, 4, 4, 4) self.voice:Dock(RIGHT) endfunction PANEL:DoClick(x, y) self:SetOpen(not self.open) endfunction PANEL:SetOpen(o)if self.openthen surface.PlaySound("ui/buttonclickrelease.wav") else surface.PlaySound("ui/buttonclick.wav") end self.open = o self:PerformLayout() self:GetParent():PerformLayout() sboard_panel:PerformLayout() endfunction PANEL:DoRightClick()local menu = DermaMenu() menu.Player = self:GetPlayer() localclose = hook.Call( "TTTScoreboardMenu", nil, menu ) ifclosethen menu:Remove() returnend menu:Open() end vgui.Register( "TTTScorePlayerRow", PANEL, "DButton" )
Panel/SetTooltip ?
I've already tried the that, i can't get tooltip to work on dimage.
Because you set SetMouseInputEnabled(false)
That worked. I appreciate it.
Sorry, you need to Log In to post a reply to this thread.