Guest User

Untitled

a guest
Apr 27th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.72 KB | None | 0 0
  1. --[[
  2.     © 2015 CloudSixteen.com do not share, re-distribute or modify
  3.     without permission of its author (kurozael@gmail.com).
  4.  
  5.     Clockwork was created by Conna Wiles (also known as kurozael.)
  6.     http://cloudsixteen.com/license/clockwork.html
  7. --]]
  8.  
  9. local Clockwork = Clockwork;
  10. local IsValid = IsValid;
  11. local pairs = pairs;
  12. local ScrH = ScrH;
  13. local ScrW = ScrW;
  14. local table = table;
  15. local vgui = vgui;
  16. local math = math;
  17.  
  18. local PANEL = {};
  19.  
  20. -- Called when the panel is initialized.
  21. function PANEL:Init()
  22.     self:SetSize(Clockwork.menu:GetWidth(), Clockwork.menu:GetHeight());
  23.    
  24.     self.panelList = vgui.Create("cwPanelList", self);
  25.     self.panelList:SetPadding(8);
  26.     self.panelList:SetSpacing(8);
  27.     self.panelList:StretchToParent(4, 4, 4, 4);
  28.     self.panelList:HideBackground();
  29.    
  30.     Clockwork.scoreboard = self;
  31.     Clockwork.scoreboard:Rebuild();
  32. end;
  33.  
  34. -- A function to rebuild the panel.
  35. function PANEL:Rebuild()
  36.     self.panelList:Clear();
  37.    
  38.     local availableClasses = {};
  39.     local classes = {};
  40.    
  41.     for k, v in pairs(cwPlayer.GetAll()) do
  42.         if (v:HasInitialized()) then
  43.             local class = Clockwork.plugin:Call("GetPlayerScoreboardClass", v);
  44.            
  45.             if (class) then
  46.                 if (!availableClasses[class]) then
  47.                     availableClasses[class] = {};
  48.                 end;
  49.                
  50.                 if (Clockwork.plugin:Call("PlayerShouldShowOnScoreboard", v)) then
  51.                     availableClasses[class][#availableClasses[class] + 1] = v;
  52.                 end;
  53.             end;
  54.         end;
  55.     end;
  56.    
  57.     for k, v in pairs(availableClasses) do
  58.         table.sort(v, function(a, b)
  59.             return Clockwork.plugin:Call("ScoreboardSortClassPlayers", k, a, b);
  60.         end);
  61.        
  62.         if (#v > 0) then
  63.             classes[#classes + 1] = {name = k, players = v};
  64.         end;
  65.     end;
  66.    
  67.     table.sort(classes, function(a, b)
  68.         return a.name < b.name;
  69.     end);
  70.    
  71.     if (table.Count(classes) > 0) then
  72.         local label = vgui.Create("cwInfoText", self);
  73.             label:SetText("Click on a player's model icon to bring up available commands.");
  74.             label:SetInfoColor("blue");
  75.         self.panelList:AddItem(label);
  76.        
  77.         for k, v in pairs(classes) do
  78.             local classData = Clockwork.class:FindByID(v.name);
  79.             local classColor = nil;
  80.            
  81.             if (classData) then
  82.                 --classColor = classData.color;
  83.             end;
  84.            
  85.             local characterForm = vgui.Create("cwBasicForm", self);
  86.             characterForm:SetPadding(8);
  87.             characterForm:SetSpacing(8);
  88.             characterForm:SetAutoSize(true);
  89.             characterForm:SetText((v.name.." ("..cwTeam.NumPlayers(player:Team())..")", Clockwork.option:GetFont("scoreboard_class"), classColor);
  90.            
  91.             local panelList = vgui.Create("DPanelList", self);
  92.            
  93.             panelList:SetAutoSize(true);
  94.             panelList:SetPadding(4);
  95.             panelList:SetSpacing(4);
  96.            
  97.             for k2, v2 in pairs(v.players) do
  98.                 self.playerData = {
  99.                     avatarImage = true,
  100.                     steamName = v2:SteamName(),
  101.                     faction = v2:GetFaction(),
  102.                     player = v2,
  103.                     class = cwTeam.GetName(v2:Team()),
  104.                     model = v2:GetModel(),
  105.                     skin = v2:GetSkin(),
  106.                     name = v2:Name()
  107.                 };
  108.                
  109.                 panelList:AddItem(vgui.Create("cwScoreboardItem", self));
  110.             end;
  111.            
  112.             characterForm:AddItem(panelList);
  113.            
  114.             self.panelList:AddItem(characterForm);
  115.            
  116.             panelList:InvalidateLayout(true);
  117.         end;
  118.     else
  119.         local label = vgui.Create("cwInfoText", self);
  120.             label:SetText("There are no players to display.");
  121.             label:SetInfoColor("orange");
  122.         self.panelList:AddItem(label);
  123.     end;
  124.    
  125.     self.panelList:InvalidateLayout(true);
  126. end;
  127.  
  128. -- Called when the menu is opened.
  129. function PANEL:OnMenuOpened()
  130.     if (Clockwork.menu:IsPanelActive(self)) then
  131.         self:Rebuild();
  132.     end;
  133. end;
  134.  
  135. -- Called when the panel is selected.
  136. function PANEL:OnSelected() self:Rebuild(); end;
  137.  
  138. -- Called when the layout should be performed.
  139. function PANEL:PerformLayout(w, h) end;
  140.  
  141. -- Called when the panel is painted.
  142. function PANEL:Paint(w, h)
  143.     DERMA_SLICED_BG:Draw(0, 0, w, h, 8, COLOR_WHITE);
  144.    
  145.     return true;
  146. end;
  147.  
  148. vgui.Register("cwScoreboard", PANEL, "EditablePanel");
  149.  
  150. local PANEL = {};
  151.  
  152. -- Called when the panel is initialized.
  153. function PANEL:Init()
  154.     SCOREBOARD_PANEL = true;
  155.    
  156.     self:SetSize(self:GetParent():GetWide(), 48);
  157.    
  158. --  local nameFont = Clockwork.fonts:GetSize(Clockwork.option:GetFont("scoreboard_name"), 20);
  159. --  local descFont = Clockwork.fonts:GetSize(Clockwork.option:GetFont("scoreboard_desc"), 16);
  160.     local nameFont = Clockwork.option:GetFont("scoreboard_name");
  161.     local descFont = Clockwork.option:GetFont("scoreboard_desc");
  162.     local playerData = self:GetParent().playerData;
  163.     local info = {
  164.         doesRecognise = Clockwork.player:DoesRecognise(playerData.player),
  165.         avatarImage = playerData.avatarImage,
  166.         steamName = playerData.steamName,
  167.         faction = playerData.faction,
  168.         player = playerData.player,
  169.         class = playerData.class,
  170.         model = playerData.model,
  171.         skin = playerData.skin,
  172.         name = playerData.name
  173.     };
  174.    
  175.     info.text = Clockwork.plugin:Call("GetPlayerScoreboardText", info.player);
  176.    
  177.     Clockwork.plugin:Call("ScoreboardAdjustPlayerInfo", info);
  178.    
  179.     self.toolTip = info.toolTip;
  180.     self.player = info.player;
  181.    
  182.     self.nameLabel = vgui.Create("DLabel", self);
  183.     self.nameLabel:SetText(info.name);
  184.     self.nameLabel:SetFont(nameFont);
  185.     self.nameLabel:SetTextColor(Clockwork.option:GetColor("scoreboard_name"));
  186.     self.nameLabel:SizeToContents();
  187.    
  188.     self.factionLabel = vgui.Create("DLabel", self);
  189.     self.factionLabel:SetText(info.faction);
  190.     self.factionLabel:SetFont(descFont);
  191.     self.factionLabel:SetTextColor(Clockwork.option:GetColor("scoreboard_desc"));
  192.     self.factionLabel:SizeToContents();
  193.    
  194.     if (type(info.text) == "string") then
  195.         self.factionLabel:SetText(info.text);
  196.         self.factionLabel:SizeToContents();
  197.     end;
  198.    
  199.     if (info.doesRecognise) then
  200.         self.spawnIcon = vgui.Create("cwSpawnIcon", self);
  201.         self.spawnIcon:SetModel(info.model, info.skin);
  202.         self.spawnIcon:SetSize(40, 40);
  203.     else
  204.         self.spawnIcon = vgui.Create("DImageButton", self);
  205.         self.spawnIcon:SetImage("clockwork/unknown.png");
  206.         self.spawnIcon:SetSize(40, 40);
  207.     end;
  208.    
  209.     -- Called when the spawn icon is clicked.
  210.     function self.spawnIcon.DoClick(spawnIcon)
  211.         local options = {};
  212.        
  213.         Clockwork.plugin:Call("GetPlayerScoreboardOptions", info.player, options);
  214.         Clockwork.kernel:AddMenuFromData(nil, options);
  215.     end;
  216.    
  217.     self.avatarImage = vgui.Create("AvatarImage", self);
  218.     self.avatarImage:SetSize(40, 40);
  219.    
  220.     self.avatarButton = vgui.Create("DButton", self.avatarImage);
  221.     self.avatarButton:Dock(FILL);
  222.     self.avatarButton:SetText("");
  223.     self.avatarButton:SetDrawBorder(false);
  224.     self.avatarButton:SetDrawBackground(false);
  225.  
  226.     if (info.avatarImage) then
  227.         self.avatarButton:SetToolTip("This player's name is "..info.steamName..".\nThis player's Steam ID is "..info.player:SteamID()..".");
  228.         self.avatarButton.DoClick = function(button)
  229.             if (IsValid(info.player)) then
  230.                 info.player:ShowProfile();
  231.             end;
  232.         end;
  233.  
  234.         self.avatarImage:SetPlayer(info.player);
  235.     end;
  236.    
  237.     SCOREBOARD_PANEL = nil;
  238. end;
  239.  
  240. function PANEL:Paint(width, height)
  241.     INFOTEXT_SLICED:Draw(0, 0, width, height, 8, Clockwork.option:GetColor("scoreboard_item_background"));
  242.    
  243.     return true;
  244. end;
  245.  
  246. -- Called each frame.
  247. function PANEL:Think()
  248.     if (IsValid(self.player)) then
  249.         if (self.toolTip) then
  250.             self.spawnIcon:SetToolTip(self.toolTip);
  251.         else
  252.             self.spawnIcon:SetToolTip("This player's ping is "..self.player:Ping()..".");
  253.         end;
  254.     end;
  255.    
  256.     self.spawnIcon:SetPos(4, 4);
  257.     self.spawnIcon:SetSize(40, 40);
  258. end;
  259.  
  260. -- Called when the layout should be performed.
  261. function PANEL:PerformLayout(w, h)
  262.     self.factionLabel:SizeToContents();
  263.    
  264.     self.spawnIcon:SetPos(4, 4);
  265.     self.spawnIcon:SetSize(40, 40);
  266.     self.avatarImage:SetPos(44, 4);
  267.     self.avatarImage:SetSize(40, 40);
  268.    
  269.     self.nameLabel:SetPos(92, 4);
  270.     self.factionLabel:SetPos(92, self.nameLabel.y + self.nameLabel:GetTall() + 2);
  271. end;
  272.  
  273. vgui.Register("cwScoreboardItem", PANEL, "DPanel");
Add Comment
Please, Sign In to add comment