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

[scoreboard] Added countryflags to TAB #89

Merged
merged 4 commits into from Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 21 additions & 6 deletions [gameplay]/scoreboard/dxscoreboard_client.lua
Expand Up @@ -715,6 +715,19 @@ function doDrawScoreboard( rtPass, onlyAnim, sX, sY )
dxDrawText( partOfName, xPos, y, topX+x+s(column.width), y+dxGetFontHeight( fontscale(contentFont, scoreboardScale), contentFont ), tocolor( r or 255, g or 255, b or 255, a or 255 ), fontscale(contentFont, s(1)), contentFont, "left", "top", true, false, drawOverGUI )
xPos = xPos + textLength
end
elseif column.isImage then
if type(content)=="table" then
if fileExists (content[1]) then
dxDrawImage( topX+theX, y+s(1), (column.imageW or 17)*scoreboardScale, (column.imageH or 11)*scoreboardScale, content[1], 0, 0, 0, cWhite, drawOverGUI )
dxDrawText( content[2], topX+theX+s(1)+((column.imageW or 17)*scoreboardScale)+2, y+s(1), topX+x+s(1+column.width), y+s(11)+dxGetFontHeight( fontscale(contentFont, scoreboardScale), contentFont ), tocolor( 0, 0, 0, a or 255 ), fontscale(contentFont, s(1)), contentFont, "left", "top", true, false, drawOverGUI )
dxDrawText( content[2], topX+theX+((column.imageW or 17)*scoreboardScale)+2, y, topX+x+s(column.width), y+dxGetFontHeight( fontscale(contentFont, scoreboardScale), contentFont ), tocolor( r or 255, g or 255, b or 255, a or 255 ), fontscale(contentFont, s(1)), contentFont, "left", "top", true, false, drawOverGUI )

end
else
if fileExists (content) then
dxDrawImage( topX+theX, y+s(1), column.imageW or 17, column.imageH or 15, content[1], 0, 0, 0, cWhite, drawOverGUI )
end
end
elseif type( content ) == "table" and column.name ~= "name" then
if content.type == "image" and content.src then
local itemHeight = dxGetFontHeight( fontscale(contentFont, scoreboardScale), contentFont )
Expand All @@ -728,6 +741,7 @@ function doDrawScoreboard( rtPass, onlyAnim, sX, sY )
content.rotOffY = content.rotOffY or 0

dxDrawImage ( topX+theX, y, itemWidth, itemHeight, content.src, content.rot, content.rotOffX, content.rotOffY, content.color, drawOverGUI )

end
else
dxDrawText( content, topX+theX+s(1), y+s(1), topX+x+s(1+column.width), y+s(11)+dxGetFontHeight( fontscale(contentFont, scoreboardScale), contentFont ), tocolor( 0, 0, 0, a or 255 ), fontscale(contentFont, s(1)), contentFont, "left", "top", true, false, drawOverGUI )
Expand All @@ -748,23 +762,23 @@ end

-- FUNCTIONS
-- addColumn
function scoreboardAddColumn( name, width, friendlyName, priority, textFunction, fromResource )
function scoreboardAddColumn( name, width, friendlyName, priority, textFunction, fromResource, isImage, imageW, imageH )
if type( name ) == "string" then
width = width or 70
friendlyName = friendlyName or name
priority = tonumber( priority ) or getNextFreePrioritySlot( scoreboardGetColumnPriority( "name" ) )
fixPrioritySlot( priority )
textFunction = textFunction or nil
fromResource = sourceResource or fromResource or nil

if not (priority > MAX_PRIRORITY_SLOT or priority < 1) then
for key, value in ipairs( scoreboardColumns ) do
if name == value.name then
return false
end
end
table.insert( scoreboardColumns, { ["name"] = name, ["width"] = width, ["friendlyName"] = friendlyName, ["priority"] = priority, ["textFunction"] = textFunction } )
table.insert( scoreboardColumns, { ["name"] = name, ["width"] = width, ["friendlyName"] = friendlyName, ["priority"] = priority, ["textFunction"] = textFunction, ["isImage"] = isImage, ["imageW"] = imageW, ["imageH"] = imageH } )
table.sort( scoreboardColumns, function ( a, b ) return a.priority < b.priority end )

if fromResource then
if not resourceColumns[fromResource] then resourceColumns[fromResource] = {} end
table.insert ( resourceColumns[fromResource], name )
Expand All @@ -775,10 +789,11 @@ function scoreboardAddColumn( name, width, friendlyName, priority, textFunction,
return false
end


addEvent( "doScoreboardAddColumn", true )
addEventHandler( "doScoreboardAddColumn", getResourceRootElement(),
function ( name, width, friendlyName, priority, fromResource )
scoreboardAddColumn( name, width, friendlyName, priority, nil, fromResource )
function ( name, width, friendlyName, priority, fromResource, isImage, imageW, imageH )
scoreboardAddColumn( name, width, friendlyName, priority, nil, fromResource, isImage, imageW, imageH )
end
)

Expand Down Expand Up @@ -1231,4 +1246,4 @@ addEventHandler( "onClientResourceStop", getRootElement(), removeResourceScorebo
function scoreboardForceUpdate ()
bForceUpdate = true
return true
end
end
27 changes: 27 additions & 0 deletions [gameplay]/scoreboard/dxscoreboard_countries.lua
@@ -0,0 +1,27 @@
function toboolean( bool )
bool = tostring( bool )
if bool == "true" then
return true
elseif bool == "false" then
return false
else
return nil
end
end

showCountries = toboolean( get( "showCountries" ) ) or false

if showCountries then
local countryData = "Country"
local defaultCountryIndicator = "US" --If something somehow fails and setting is enabled in meta.xml
for i,players in ipairs(getElementsByType("player")) do
local cCode = exports.admin:getPlayerCountry(players)
setElementData(players,countryData,{":admin/client/images/flags/"..string.lower(cCode or defaultCountryIndicator)..".png",cCode or defaultCountryIndicator})
end

function setScoreboardData ()
local cCode = exports.admin:getPlayerCountry(source)
setElementData(source, countryData,{":admin/client/images/flags/"..string.lower(cCode or defaultCountryIndicator)..".png",cCode or defaultCountryIndicator})
end
addEventHandler("onPlayerJoin", getRootElement(), setScoreboardData)
end
20 changes: 14 additions & 6 deletions [gameplay]/scoreboard/dxscoreboard_exports.lua
Expand Up @@ -2,8 +2,9 @@ MAX_PRIRORITY_SLOT = 500

scoreboardColumns = {
{ ["name"] = "name", ["width"] = 200, ["friendlyName"] = "Name", ["priority"] = 1 },
{ ["name"] = "ping", ["width"] = 40, ["friendlyName"] = "Ping", ["priority"] = MAX_PRIRORITY_SLOT }
{ ["name"] = "ping", ["width"] = 40, ["friendlyName"] = "Ping", ["priority"] = MAX_PRIRORITY_SLOT },
}

resourceColumns = {}

function toboolean( bool )
Expand All @@ -20,16 +21,22 @@ end
forceShowTeams = toboolean( get( "forceShowTeams" ) ) or false
forceHideTeams = toboolean( get( "forceHideTeams" ) ) or false
allowColorcodedNames = toboolean( get( "allowColorcodedNames" ) ) or false
showCountries = toboolean( get( "showCountries" ) ) or false
scrollStep = tonumber( get( "scrollStep" ) ) or 1

if showCountries then
table.insert (scoreboardColumns, { ["name"] = "Country", ["width"] = 50, ["friendlyName"] = "Country", ["priority"] = MAX_PRIRORITY_SLOT-1, ["isImage"] = true, ["imageW"] = 18, ["imageH"] = 12 })
end

local function iif( cond, arg1, arg2 )
if cond then
return arg1
end
return arg2
end

function scoreboardAddColumn( name, forElement, width, friendlyName, priority )
--scoreboardAddColumn (dataName,source,width,friendlyName,priority,isImage,imageW,imageH)
function scoreboardAddColumn( name, forElement, width, friendlyName, priority, isImage, imageW, imageH )
if type( name ) == "string" then
width = tonumber( width ) or 70
friendlyName = friendlyName or name
Expand All @@ -44,16 +51,16 @@ function scoreboardAddColumn( name, forElement, width, friendlyName, priority )
return false
end
end
table.insert( scoreboardColumns, { ["name"] = name, ["width"] = width, ["friendlyName"] = friendlyName, ["priority"] = priority } )
table.insert( scoreboardColumns, { ["name"] = name, ["width"] = width, ["friendlyName"] = friendlyName, ["priority"] = priority, ["isImage"] = isImage, ["imageW"] = imageW, ["imageH"] = imageH } )
table.sort( scoreboardColumns, function ( a, b ) return a.priority < b.priority end )
if sourceResource then
if not resourceColumns[sourceResource] then resourceColumns[sourceResource] = {} end
table.insert ( resourceColumns[sourceResource], name )
end
return triggerClientEvent( getRootElement(), "doScoreboardAddColumn", getRootElement(), name, width, friendlyName, priority, sourceResource )
return triggerClientEvent( getRootElement(), "doScoreboardAddColumn", getRootElement(), name, width, friendlyName, priority, sourceResource, isImage, imageW, imageH )
end
else
return triggerClientEvent( forElement, "doScoreboardAddColumn", getRootElement(), name, width, friendlyName, priority, sourceResource )
return triggerClientEvent( forElement, "doScoreboardAddColumn", getRootElement(), name, width, friendlyName, priority, sourceResource, isImage, imageW, imageH )
end
end
return false
Expand Down Expand Up @@ -106,6 +113,7 @@ function scoreboardResetColumns( forElement )
if result then
scoreboardAddColumn( "name", 200, "Name" )
scoreboardAddColumn( "ping", 40, "Ping" )
scoreboardAddColumn( "Country", 50, "Country", 20, true, 12, 8 )
end
return result
else
Expand Down Expand Up @@ -195,7 +203,7 @@ end

function onClientDXScoreboardResourceStart()
for key, column in ipairs( scoreboardColumns ) do
triggerClientEvent( client, "doScoreboardAddColumn", getRootElement(), column.name, column.width, column.friendlyName, column.priority )
triggerClientEvent( client, "doScoreboardAddColumn", getRootElement(), column.name, column.width, column.friendlyName, column.priority, nil, column.isImage, column.imageW, column.imageH )
end
end
addEvent( "onClientDXScoreboardResourceStart", true )
Expand Down
12 changes: 9 additions & 3 deletions [gameplay]/scoreboard/meta.xml
@@ -1,12 +1,13 @@
<meta>
<info author="Awwu" type="script" name="Scoreboard" description="DirectX scoreboard resource" showInResourceBrowser="true" version="2.7.1"/>
<info author="Awwu" type="script" name="Scoreboard" description="DirectX scoreboard resource" showInResourceBrowser="true" version="2.7.2"/>

<script src="dxscoreboard_shared.lua" type="server" />
<script src="dxscoreboard_exports.lua" type="server" />
<script src="dxscoreboard_http.lua" type="server" />
<script src="dxscoreboard_client.lua" type="client" />
<script src="dxscoreboard_clientsettings.lua" type="client" />
<script src="dxscoreboard_shared.lua" type="server" />
<script src="dxscoreboard_shared.lua" type="client" />
<script src="dxscoreboard_countries.lua" type="server" />

<script src="colorpicker/colorpicker.lua" type="client" />
<file src="colorpicker/palette.png" />
Expand Down Expand Up @@ -70,6 +71,11 @@
group="General"
accept="false,true"
desc="Should the teams be always visible on the scoreboard, no matter what user has in the settings?" />
<setting name="*showCountries" value="true"
friendlyname="Show countries"
group="General"
accept="false,true"
desc="Should country flags be displayed in TAB?" />
<setting name="*forceHideTeams" value="false"
friendlyname="Force teams to be hidden"
group="General"
Expand All @@ -86,4 +92,4 @@
accept="1-10"
desc="How many lines to scroll each time the mouse wheel is moved or the up/down buttons pressed" />
</settings>
</meta>
</meta>