Author Topic: DListView  (Read 4415 times)

0 Members and 1 Guest are viewing this topic.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
DListView
« on: May 06, 2014, 09:31:46 PM »
Alright, I'm very frustrated, and annoyed at this. About once a month, I come back to lua, and try for about two days, then I get frustrated because the wikis really suck, and then I just get annoyed, and quit again. I'm done quitting, and I need assistance on this.

Alright, I'm trying to make it so that I can select a name from DListView, and then when I press a button, it takes the name( or unique ID, i don't care) of that selected person, and sends it through a console command... that's all I want, but I just can't find out how to do this for the love of my life. I'm quit annoyed right now, so please excuse my terrible punctuation.

This is what I have so far.

Code: [Select]
GetGiveMoneyPlayers = vgui.Create("DListView", TabThree )
GetGiveMoneyPlayers:SetPos(273, 75)
GetGiveMoneyPlayers:SetSize(300, 175)
GetGiveMoneyPlayers:SetMultiSelect(false)
GetGiveMoneyPlayers:AddColumn("Name")
GetGiveMoneyPlayers:AddColumn("Points")
for k,v in pairs(player.GetAll()) do
    GetGiveMoneyPlayers:AddLine(v:Nick(),v:GetPData('MyXPPoints'))
end

GiveMoneyBox = vgui.Create( "DTextEntry", TabThree)
GiveMoneyBox:SetPos( 348,50 )
GiveMoneyBox:SetTall( 25 )
GiveMoneyBox:SetWide( 75 )
GiveMoneyBox:SetEnterAllowed( true )
GiveMoneyBox:SetValue(100)

MoneyButton = vgui.Create( "DButton", TabThree )
MoneyButton:SetSize( 72, 25 )
MoneyButton:SetPos( 88, 70 )
MoneyButton:SetPos( 273, 50 )
MoneyButton:SetText( "Give Money" )
MoneyButton.DoClick = function()
-- MsgN(GetGiveMoneyPlayers:GetSelectedLine())
PrintTable(GetGiveMoneyPlayers:GetSelected(GetGiveMoneyPlayers:GetSelectedLine()))

--    RunConsoleCommand( "TDMGiveMoney", GetGiveMoneyPlayers:GetSelected(), GiveMoneyBox:GetValue() )
--PrintTable(GetGiveMoneyPlayers:GetSelected():GetValue(1))
--MsgN(GetGiveMoneyPlayers:GetSelected():GetValue(1))
end
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: DListView
« Reply #1 on: May 07, 2014, 06:15:59 AM »
You're very close.

You need to call the function GetLine( line index) and GetValue(index) where index is the index of the column you want the information from. If you want to return their name use this:

GetGiveMoneyPlayers:GetLine(GetGiveMoneyPlayers:GetSelectedLine()):GetValue(1)

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: DListView
« Reply #2 on: May 07, 2014, 04:18:36 PM »


Though, I have another issue, seeing as XGUI is made up all of client, maybe you guys could further help me. This might be asking for too much though, but never hurts to try, or find out another way of doing it.


So, I wanted to make it so that whenever any button is pressed, it updates all the "DListView", or when a player joins, it updates the DListView so that it will show more accurate results.

This is my entire code at the moment, I even tried to make it togglible menu, but I never got it to work. I think I asked you guys about the togglible menu before, in the past, but it never worked.
Code: [Select]
// CLIENT SIDE

function tdm_menu(data)
PlayerName = data:ReadString()
/*
local TestPanel = 0
if TestingPanel != nil then
if TestingPanel:IsVisible( ) then
MsgN('IsVisible')
else
MsgN('IsNotVisible')
end

else
*/
local GAMEMODE_VERSION = "1.0b"

// Start of Main Frame
local MainMenuFrame = vgui.Create( "DFrame" )
MainMenuFrame:SetSize( 600, 250 )
MainMenuFrame:SetTitle("Team Deathmatch Menu: Version "..GAMEMODE_VERSION )
MainMenuFrame:Center()
MainMenuFrame:ShowCloseButton(false)
MainMenuFrame:SetVisible( true )
MainMenuFrame:SetDraggable( false )
MainMenuFrame:MakePopup()
function MainMenuFrame:Paint( w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color(team.GetColor(LocalPlayer():Team()).r,team.GetColor(LocalPlayer():Team()).g,team.GetColor(LocalPlayer():Team()).b,50))
surface.SetDrawColor(0,0,0)
surface.DrawOutlinedRect(1,1,w-1,h-1)
end

/*
if LocalPlayer():GetPData("TDMMenuOpen") == 1 || LocalPlayer():GetPData("TDMMenuOpen") == "1" then
LocalPlayer():SetPData("TDMMenuOpen", 0)
MainMenuFrame:Close()
MsgN('Should be closing')
return
end
LocalPlayer():SetPData("TDMMenuOpen", 1)
*/

local CloseButton = vgui.Create( "DButton", MainMenuFrame )
CloseButton:SetSize( 30, 18 )
CloseButton:SetPos( 565, 4 )
CloseButton:SetText( "Close" )
CloseButton.DoClick = function( btn )
LocalPlayer():SetPData("TDMMenuOpen", 0)
MainMenuFrame:Close()
end

/*
local TestingPanel = vgui.Create( "DPanel", MainMenuFrame )
TestingPanel:SetPos( 25, 50 )
TestingPanel:SetSize( 250, 250 )
TestingPanel.Paint = function() -- Paint function
    --Set our rect color below us; we do this so you can see items added to this panel
    surface.SetDrawColor( 50, 50, 50, 255 )
    surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() ) -- Draw the rect
end
*/

// Start of TabsList
local MainMenuSheet = vgui.Create( "DPropertySheet", MainMenuFrame )
MainMenuSheet:SetPos( 5, 27 )
MainMenuSheet:SetSize( 590, 217 )
 
local TabOne = vgui.Create( "DPanelList" )
TabOne:SetPos( 0, 0 )
TabOne:SetSize( MainMenuSheet:GetWide(), MainMenuSheet:GetTall() )
TabOne:SetSpacing( 5 )
TabOne:EnableHorizontal( false )
TabOne:EnableVerticalScrollbar( true )

local TabThree = vgui.Create( "DPanelList" )
TabThree:SetPos( 0, 0 )
TabThree:SetSize( MainMenuSheet:GetWide(), MainMenuSheet:GetTall() )
TabThree:SetSpacing( 5 )
TabThree:EnableHorizontal( false )
TabThree:EnableVerticalScrollbar( true )

local TabTwo = vgui.Create( "DPanelList" )
TabTwo:SetPos( 0, 0 )
TabTwo:SetSize( MainMenuSheet:GetWide(), MainMenuSheet:GetTall() )
TabTwo:SetSpacing( 5 )
TabTwo:EnableHorizontal( false )
TabTwo:EnableVerticalScrollbar( true )
// End of TabList


// Start of Team Tab
local ChooseATeam = vgui.Create("DLabel", TabOne)
ChooseATeam:SetPos(10,5)
ChooseATeam:SetColor( Color( 0, 0, 0, 255 ) )
ChooseATeam:SetFont("default")
ChooseATeam:SetText("Choose a Team:")
ChooseATeam:SizeToContents()

local PlayerTeamList = vgui.Create("DListView", TabOne)
PlayerTeamList:SetPos(273, 0)
PlayerTeamList:SetSize(300, 180)
PlayerTeamList:SetMultiSelect(false)
PlayerTeamList:AddColumn("Player")
PlayerTeamList:AddColumn("Team")
PlayerTeamList:AddColumn("Kills")
PlayerTeamList:AddColumn("Deaths")
for k,v in pairs(player.GetAll()) do
    PlayerTeamList:AddLine(v:Nick(),team.GetName(v:Team()),v:Frags(),v:Deaths())
end

local MenuButton = vgui.Create("DButton", TabOne)
MenuButton:SetText( "Team Chooser:" )
MenuButton:SetPos(7, 20)
MenuButton:SetSize( 150, 25 )
MenuButton.DoClick = function ( btn )
    local MenuButtonOptions = DermaMenu()
for k,v in pairs(team.GetAllTeams()) do
if k != 0 and k < 1000 then
MenuButtonOptions:AddOption(team.GetName(k), function() 
RunConsoleCommand( "SwitchTDMTeamIndex", tonumber(k) )
MainMenuFrame:Close()
end )
MenuButtonOptions:Open()
end
end

end
// End of Team Tab


// Start of Config Tab
local FriendlyFire = vgui.Create("DLabel", TabTwo)
FriendlyFire:SetPos(10,5)
FriendlyFire:SetColor( Color( 0, 0, 0, 255 ) )
FriendlyFire:SetFont("default")
FriendlyFire:SetText("Friendly Fire")
FriendlyFire:SizeToContents()

local FriendlyFireButton = vgui.Create( "DButton", TabTwo )
FriendlyFireButton:SetSize( 150, 25 )
FriendlyFireButton:SetPos( 7, 20 )
FriendlyFireButton:SetText( "Friendly Fire" )
FriendlyFireButton.DoClick = function( btn )
    local MenuButtonOptions = DermaMenu()
MenuButtonOptions:AddOption("Friendly Fire On", function() 
RunConsoleCommand( "TDMFriendlyFireButton", 1 )
end )
MenuButtonOptions:AddOption("Friendly Fire Off", function() 
RunConsoleCommand( "TDMFriendlyFireButton", 0 )
end )
MenuButtonOptions:Open()
end

local TDM_CONSOLE_HELP = vgui.Create("DLabel", TabTwo)
TDM_CONSOLE_HELP:SetPos(225,5)
TDM_CONSOLE_HELP:SetColor( Color( 0, 0, 0, 255 ) )
TDM_CONSOLE_HELP:SetFont("default")
TDM_CONSOLE_HELP:SetText("TDM HELP")
TDM_CONSOLE_HELP:SizeToContents()

local TDM_CONSOLE_HELP_BUTTON = vgui.Create( "DButton", TabTwo )
TDM_CONSOLE_HELP_BUTTON:SetSize( 150, 25 )
TDM_CONSOLE_HELP_BUTTON:SetPos( 175, 20 )
TDM_CONSOLE_HELP_BUTTON:SetText( "TDM HELP" )
TDM_CONSOLE_HELP_BUTTON.DoClick = function( btn )
    RunConsoleCommand( "tdm_help" )
    RunConsoleCommand( "tdm_help_message" )
end

local CustomGoalText = vgui.Create("DLabel", TabTwo)
CustomGoalText:SetPos(10,55)
CustomGoalText:SetColor( Color( 0, 0, 0, 255 ) )
CustomGoalText:SetFont("default")
CustomGoalText:SetText("Goal Score Limit (Number)")
CustomGoalText:SizeToContents()

local GoalDermaBox = vgui.Create( "DTextEntry", TabTwo)
GoalDermaBox:SetPos( 7,70 )
GoalDermaBox:SetTall( 25 )
GoalDermaBox:SetWide( 75 )
GoalDermaBox:SetEnterAllowed( true )
GoalDermaBox:SetValue(10)
GoalDermaBox.OnEnter = function()
    RunConsoleCommand( "TDMCustomGoalLimiter", GoalDermaBox:GetValue() )
end

local GoalButton = vgui.Create( "DButton", TabTwo )
GoalButton:SetSize( 72, 25 )
GoalButton:SetPos( 85, 70 )
GoalButton:SetText( "Set Goal" )
GoalButton.DoClick = function( btn )
    RunConsoleCommand( "TDMCustomGoalLimiter", GoalDermaBox:GetValue() )
end


local Armor = vgui.Create("DLabel", TabTwo)
Armor:SetPos(10,105)
Armor:SetColor( Color( 0, 0, 0, 255 ) )
Armor:SetFont("default")
Armor:SetText("Armor")
Armor:SizeToContents()

local ArmorButton = vgui.Create( "DButton", TabTwo )
ArmorButton:SetSize( 150, 25 )
ArmorButton:SetPos( 7, 120 )
ArmorButton:SetText( "Armor" )
ArmorButton.DoClick = function( btn )
    local MenuButtonOptions = DermaMenu()
MenuButtonOptions:AddOption("Armor On", function() 
RunConsoleCommand( "TDMArmorButton", 1 )
end )
MenuButtonOptions:AddOption("Armor Off", function() 
RunConsoleCommand( "TDMArmorButton", 0 )
end )
MenuButtonOptions:Open()
end
// End of Config Tab


// Start of Weapon Shop
local DisplayHeader = vgui.Create("DLabel", TabThree)
DisplayHeader:SetPos(10,5)
DisplayHeader:SetColor( Color( 0, 0, 0, 255 ) )
DisplayHeader:SetFont("default")
DisplayHeader:SetText("Greetings, ")
DisplayHeader:SizeToContents()

local DisplayName = vgui.Create("DLabel", TabThree)
DisplayName:SetPos(65,5)
DisplayName:SetColor( Color( 0, 0, 0, 255 ) )
DisplayName:SetFont("default")
DisplayName:SetText(PlayerName)
DisplayName:SizeToContents()

local DisplayerWarning = vgui.Create("DLabel", TabThree)
DisplayerWarning:SetPos(10,15)
DisplayerWarning:SetColor( Color( 255, 0, 0, 255 ) )
DisplayerWarning:SetFont("default")
DisplayerWarning:SetText("This Gunshop menu is a beta of this gamemode. So you may experience errors while using this.")
DisplayerWarning:SizeToContents()

local MenuButton = vgui.Create("DButton", TabThree)
MenuButton:SetText( "Weapons:" )
MenuButton:SetPos(10, 30)
MenuButton:SetSize( 150, 25 )
MenuButton.DoClick = function ( btn )
local MenuButtonOptions = DermaMenu()
for k,v in pairs(Weapons) do
local ov = string.Explode(":", v)
local nv = string.upper(v)
local nv = string.gsub(nv,"WEAPON","")
local nv = string.gsub(nv,"CS","")
local nv = string.gsub(nv,"_","")
local nv = string.Explode(":", nv)
MenuButtonOptions:AddOption(nv[1]..' - Cost: $'..nv[2], function() 
RunConsoleCommand( "BuyWeaponIndex", ov[1], ov[2], nv[1] )
MainMenuFrame:Close()
end )
MenuButtonOptions:Open()
end
end

-- Please don't touch below, also line breakers

GetGiveMoneyPlayers = vgui.Create("DListView", TabThree )
GetGiveMoneyPlayers:SetPos(273, 75)
GetGiveMoneyPlayers:SetSize(300, 175)
GetGiveMoneyPlayers:SetMultiSelect(false)
GetGiveMoneyPlayers:AddColumn("Name")
GetGiveMoneyPlayers:AddColumn("Points")
for k,v in pairs(player.GetAll()) do
    GetGiveMoneyPlayers:AddLine(v:Nick(),v:GetPData('MyXPPoints'))
end

GiveMoneyBox = vgui.Create( "DTextEntry", TabThree)
GiveMoneyBox:SetPos( 348,50 )
GiveMoneyBox:SetTall( 25 )
GiveMoneyBox:SetWide( 75 )
GiveMoneyBox:SetEnterAllowed( true )
GiveMoneyBox:SetValue(100)

MoneyButton = vgui.Create( "DButton", TabThree )
MoneyButton:SetSize( 72, 25 )
MoneyButton:SetPos( 88, 70 )
MoneyButton:SetPos( 273, 50 )
MoneyButton:SetText( "Give Money" )
MoneyButton.DoClick = function()
MsgN(GetGiveMoneyPlayers:GetLine(GetGiveMoneyPlayers:GetSelectedLine()):GetValue(1))
RunConsoleCommand( "TDMGiveMoney", GetGiveMoneyPlayers:GetLine(GetGiveMoneyPlayers:GetSelectedLine()):GetValue(1), GiveMoneyBox:GetValue() )
end

// End of Weapon Shop


// Start of TabListName
MainMenuSheet:AddSheet( "Team", TabOne, "icon16/group.png", false, false, "Select a team to be on." )
MainMenuSheet:AddSheet( "Weapon Shop", TabThree, "icon16/wand.png", false, false, "Weapon Shop - Beta" )
--MainMenuSheet:AddSheet( "Leaderboards", TabFour, "icon16/vcard.png", false, false, "Server Leaderboards" )
MainMenuSheet:AddSheet( "Config", TabTwo, "icon16/key.png", false, false, "Administrative Configurations" )
// End of TabListName
end
--end

concommand.Add( "tdm_menu", tdm_menu )
usermessage.Hook( "MyMenu", tdm_menu )
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: DListView
« Reply #3 on: May 08, 2014, 12:13:14 AM »
Put the code that draws your DListView inside of a function (make sure it's not local).

When a new player joins (using the appropriate hooks clientside) or inside of your button press functions just run that function.

At the top of the function make sure you clear the existing content of the list before adding new stuff to it.

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given