Prepare for v1.0.0 release (#2)
* Replace sh_stats.gnut with pulse.gnut * Add menu_stats_utility.nut * Add menu_stats_overview.nut --------- Co-authored-by: legonzaur <legonzaur@live.fr>
This commit is contained in:
@@ -0,0 +1,460 @@
|
||||
untyped
|
||||
|
||||
global function InitViewStatsOverviewMenu
|
||||
|
||||
struct
|
||||
{
|
||||
var menu
|
||||
} file
|
||||
|
||||
const MAX_DOTS_ON_GRAPH = 10
|
||||
|
||||
const IMAGE_TITAN_STRYDER = $"ui/menu/personal_stats/ps_titan_icon_stryder"
|
||||
const IMAGE_TITAN_ATLAS = $"ui/menu/personal_stats/ps_titan_icon_atlas"
|
||||
const IMAGE_TITAN_OGRE = $"ui/menu/personal_stats/ps_titan_icon_ogre"
|
||||
|
||||
void function InitViewStatsOverviewMenu()
|
||||
{
|
||||
PrecacheHUDMaterial( IMAGE_TITAN_STRYDER )
|
||||
PrecacheHUDMaterial( IMAGE_TITAN_ATLAS )
|
||||
PrecacheHUDMaterial( IMAGE_TITAN_OGRE )
|
||||
|
||||
var menu = GetMenu( "ViewStats_Overview_Menu" )
|
||||
file.menu = menu
|
||||
|
||||
AddMenuEventHandler( menu, eUIEvent.MENU_OPEN, OnStatsOverview_Open )
|
||||
|
||||
AddMenuFooterOption( menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" )
|
||||
}
|
||||
|
||||
void function OnStatsOverview_Open()
|
||||
{
|
||||
UI_SetPresentationType( ePresentationType.NO_MODELS )
|
||||
|
||||
UpdateViewStatsOverviewMenu()
|
||||
}
|
||||
|
||||
function UpdateViewStatsOverviewMenu()
|
||||
{
|
||||
entity player = GetUIPlayer()
|
||||
if ( player == null )
|
||||
return
|
||||
|
||||
//#########################
|
||||
// Games
|
||||
//#########################
|
||||
|
||||
string timePlayed = StatToTimeString( "time_stats", "hours_total" )
|
||||
int gamesPlayed = GetPlayerStat_AllCompetitiveModesAndMapsInt( player, "game_stats", "game_completed" )
|
||||
int gamesWon = GetPlayerStat_AllCompetitiveModesAndMapsInt( player, "game_stats", "game_won" )
|
||||
string winPercent = GetPercent( float( gamesWon ), float( gamesPlayed ), 0 )
|
||||
int timesMVP = GetPlayerStatInt( player, "game_stats", "mvp_total" )
|
||||
int timesTop3 = GetPlayerStat_AllCompetitiveModesAndMapsInt( player, "game_stats", "top3OnTeam" )
|
||||
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat0" ), Localize( "#STATS_HEADER_TIME_PLAYED" ), timePlayed )
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat1" ), Localize( "#STATS_GAMES_PLAYED" ), string( gamesPlayed ) )
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat2" ), Localize( "#STATS_GAMES_WON" ), string( gamesWon ) )
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat3" ), Localize( "#STATS_GAMES_WIN_PERCENT" ), Localize( "#STATS_PERCENTAGE", winPercent ) )
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat4" ), Localize( "#STATS_GAMES_MVP" ), string( timesMVP ) )
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat5" ), Localize( "#STATS_GAMES_TOP3" ), string( timesTop3 ) )
|
||||
|
||||
//#########################
|
||||
// Modes
|
||||
//#########################
|
||||
|
||||
/*local gameModePlayedVar = GetStatVar( "game_stats", "mode_played" )
|
||||
local basicModes = [ "tdm", "cp", "at", "lts", "ctf" ]
|
||||
|
||||
local timesPlayedArray = []
|
||||
local gameModeNamesArray = []
|
||||
local otherGameModesPlayed = 0
|
||||
array<string> gameModesArray = GetPersistenceEnumAsArray( "gameModes" )
|
||||
|
||||
foreach ( modeName in gameModesArray )
|
||||
{
|
||||
local gameModePlaysVar = StringReplace( expect string( gameModePlayedVar ), "%gamemode%", modeName )
|
||||
local timesPlayed = player.GetPersistentVar( gameModePlaysVar )
|
||||
|
||||
if ( basicModes.contains( modeName ) ) //Don't really like doing ArrayContains, but Chad prefers not storing a separate enum in persistence that contains the "other" gamemodes
|
||||
{
|
||||
timesPlayedArray.append( timesPlayed )
|
||||
gameModeNamesArray.append( GAMETYPE_TEXT[ modeName] )
|
||||
}
|
||||
else
|
||||
{
|
||||
otherGameModesPlayed += timesPlayed
|
||||
}
|
||||
}
|
||||
|
||||
//Add Other game modes' data to the end of the arrays
|
||||
gameModeNamesArray.append( "#GAMEMODE_OTHER" )
|
||||
timesPlayedArray.append( otherGameModesPlayed )
|
||||
|
||||
local data = {}
|
||||
data.names <- gameModeNamesArray
|
||||
data.values <- timesPlayedArray
|
||||
|
||||
SetPieChartData( menu, "ModesPieChart", "#GAME_MODES_PLAYED", data )*/
|
||||
|
||||
//#########################
|
||||
// Completion
|
||||
//#########################
|
||||
|
||||
// Challenges complete
|
||||
//local challengeData = GetChallengeCompleteData()
|
||||
//SetStatsBarValues( menu, "CompletionBar0", "#STATS_COMPLETION_CHALLENGES", 0, challengeData.total, challengeData.complete )
|
||||
|
||||
// Item unlocks
|
||||
//local itemUnlockData = GetItemUnlockCountData()
|
||||
//SetStatsBarValues( menu, "CompletionBar1", "#STATS_COMPLETION_WEAPONS", 0, itemUnlockData["weapons"].total, itemUnlockData["weapons"].unlocked )
|
||||
//SetStatsBarValues( menu, "CompletionBar2", "#STATS_COMPLETION_ATTACHMENTS", 0, itemUnlockData["attachments"].total, itemUnlockData["attachments"].unlocked )
|
||||
//SetStatsBarValues( menu, "CompletionBar3", "#STATS_COMPLETION_MODS", 0, itemUnlockData["mods"].total, itemUnlockData["mods"].unlocked )
|
||||
//SetStatsBarValues( menu, "CompletionBar4", "#STATS_COMPLETION_ABILITIES", 0, itemUnlockData["abilities"].total, itemUnlockData["abilities"].unlocked )
|
||||
//SetStatsBarValues( menu, "CompletionBar5", "#STATS_COMPLETION_GEAR", 0, itemUnlockData["gear"].total, itemUnlockData["gear"].unlocked )
|
||||
|
||||
//#########################
|
||||
// Weapons
|
||||
//#########################
|
||||
|
||||
table<string, table> weaponData = GetOverviewWeaponData()
|
||||
table mostKillsData = weaponData[ "most_kills" ]
|
||||
table mostUsedData = weaponData[ "most_used" ]
|
||||
table highestKPMData = weaponData[ "highest_kpm" ]
|
||||
|
||||
var weaponImageElem
|
||||
var weaponRui
|
||||
var weaponNameElem
|
||||
var weaponDescElem
|
||||
var noDataElem
|
||||
|
||||
// Weapon with most kills
|
||||
weaponImageElem = Hud_GetChild( file.menu, "WeaponImage0" )
|
||||
weaponRui = Hud_GetRui( weaponImageElem )
|
||||
weaponNameElem = Hud_GetChild( file.menu, "WeaponName0" )
|
||||
weaponDescElem = Hud_GetChild( file.menu, "WeaponDesc0" )
|
||||
noDataElem = Hud_GetChild( file.menu, "WeaponImageTextOverlay0" )
|
||||
if ( mostKillsData.ref != "" )
|
||||
{
|
||||
SetItemImageWidth( weaponImageElem, expect string( mostKillsData.ref ) )
|
||||
RuiSetImage( weaponRui, "buttonImage", GetItemImage( expect string( mostKillsData.ref ) ) )
|
||||
Hud_Show( weaponImageElem )
|
||||
Hud_SetText( weaponNameElem, mostKillsData.printName )
|
||||
Hud_Show( weaponNameElem )
|
||||
Hud_SetText( weaponDescElem, "#STATS_MOST_KILLS_VALUE", mostKillsData.val )
|
||||
Hud_Show( weaponDescElem )
|
||||
Hud_Hide( noDataElem )
|
||||
}
|
||||
else
|
||||
{
|
||||
Hud_Hide( weaponImageElem )
|
||||
Hud_Hide( weaponNameElem )
|
||||
Hud_Hide( weaponDescElem )
|
||||
Hud_Show( noDataElem )
|
||||
}
|
||||
|
||||
// Most Used Weapon
|
||||
weaponImageElem = Hud_GetChild( file.menu, "WeaponImage1" )
|
||||
weaponRui = Hud_GetRui( weaponImageElem )
|
||||
weaponNameElem = Hud_GetChild( file.menu, "WeaponName1" )
|
||||
weaponDescElem = Hud_GetChild( file.menu, "WeaponDesc1" )
|
||||
noDataElem = Hud_GetChild( file.menu, "WeaponImageTextOverlay1" )
|
||||
if ( mostUsedData.ref != "" )
|
||||
{
|
||||
SetItemImageWidth( weaponImageElem, expect string( mostUsedData.ref ) )
|
||||
RuiSetImage( weaponRui, "buttonImage", GetItemImage( expect string( mostUsedData.ref ) ) )
|
||||
Hud_Show( weaponImageElem )
|
||||
Hud_SetText( weaponNameElem, mostUsedData.printName )
|
||||
Hud_Show( weaponNameElem )
|
||||
SetStatsLabelValue( file.menu, "WeaponDesc1", HoursToTimeString( expect float( mostUsedData.val ) ) )
|
||||
Hud_Show( weaponDescElem )
|
||||
Hud_Hide( noDataElem )
|
||||
}
|
||||
else
|
||||
{
|
||||
Hud_Hide( weaponImageElem )
|
||||
Hud_Hide( weaponNameElem )
|
||||
Hud_Hide( weaponDescElem )
|
||||
Hud_Show( noDataElem )
|
||||
}
|
||||
|
||||
// Weapon with highest KPM
|
||||
weaponImageElem = Hud_GetChild( file.menu, "WeaponImage2" )
|
||||
weaponRui = Hud_GetRui( weaponImageElem )
|
||||
weaponNameElem = Hud_GetChild( file.menu, "WeaponName2" )
|
||||
weaponDescElem = Hud_GetChild( file.menu, "WeaponDesc2" )
|
||||
noDataElem = Hud_GetChild( file.menu, "WeaponImageTextOverlay2" )
|
||||
if ( highestKPMData.ref != "" )
|
||||
{
|
||||
SetItemImageWidth( weaponImageElem, expect string( highestKPMData.ref ) )
|
||||
RuiSetImage( weaponRui, "buttonImage", GetItemImage( expect string( highestKPMData.ref ) ) )
|
||||
Hud_Show( weaponImageElem )
|
||||
Hud_SetText( weaponNameElem, highestKPMData.printName )
|
||||
Hud_Show( weaponNameElem )
|
||||
Hud_SetText( weaponDescElem, "#STATS_MOST_EFFICIENT_VALUE", highestKPMData.val )
|
||||
Hud_Show( weaponDescElem )
|
||||
Hud_Hide( noDataElem )
|
||||
}
|
||||
else
|
||||
{
|
||||
Hud_Hide( weaponImageElem )
|
||||
Hud_Hide( weaponNameElem )
|
||||
Hud_Hide( weaponDescElem )
|
||||
Hud_Show( noDataElem )
|
||||
}
|
||||
|
||||
//#########################
|
||||
// Titan Unlocks
|
||||
//#########################
|
||||
|
||||
Assert( player == GetUIPlayer() )
|
||||
Assert( player != null )
|
||||
|
||||
int unlockedCount = 0
|
||||
|
||||
//var imageLabel = GetElem( menu, "TitanUnlockImage0" )
|
||||
//if ( !IsItemLocked( player, "titan_stryder" ) )
|
||||
//{
|
||||
// imageLabel.SetImage( IMAGE_TITAN_STRYDER )
|
||||
// unlockedCount++
|
||||
//}
|
||||
//else
|
||||
// imageLabel.SetImage( $"ui/menu/personal_stats/ps_titan_icon_locked" )
|
||||
//
|
||||
//imageLabel = GetElem( menu, "TitanUnlockImage1" )
|
||||
//if ( !IsItemLocked( player, "titan_atlas" ) )
|
||||
//{
|
||||
// imageLabel.SetImage( IMAGE_TITAN_ATLAS )
|
||||
// unlockedCount++
|
||||
//}
|
||||
//else
|
||||
// imageLabel.SetImage( $"ui/menu/personal_stats/ps_titan_icon_locked" )
|
||||
//
|
||||
//imageLabel = GetElem( menu, "TitanUnlockImage2" )
|
||||
//if ( !IsItemLocked( player, "titan_ogre" ) )
|
||||
//{
|
||||
// imageLabel.SetImage( IMAGE_TITAN_OGRE )
|
||||
// unlockedCount++
|
||||
//}
|
||||
//else
|
||||
// imageLabel.SetImage( $"ui/menu/personal_stats/ps_titan_icon_locked" )
|
||||
//
|
||||
//var unlockCountLabel = GetElem( menu, "TitanUnlocksCount" )
|
||||
//Hud_SetText( unlockCountLabel, "#STATS_CHASSIS_UNLOCK_COUNT", string( unlockedCount ) )
|
||||
|
||||
//#########################
|
||||
// K/D Ratios
|
||||
//#########################
|
||||
|
||||
// Lifetime
|
||||
local lifetimeAverage = player.GetPersistentVar( "kdratio_lifetime" ).tofloat()
|
||||
local formattedLifetimeAverage
|
||||
if ( lifetimeAverage % 1 == 0 )
|
||||
formattedLifetimeAverage = format( "%.0f", lifetimeAverage )
|
||||
else
|
||||
formattedLifetimeAverage = format( "%.1f", lifetimeAverage )
|
||||
SetStatsLabelValue( file.menu, "LifetimeAverageValue", [ "#STATS_KD_VALUE", formattedLifetimeAverage ] )
|
||||
|
||||
// Lifetime (PVP)
|
||||
local lifetimeAveragePVP = player.GetPersistentVar( "kdratio_lifetime_pvp" ).tofloat()
|
||||
local formattedLifetimeAveragePVP
|
||||
if ( lifetimeAveragePVP % 1 == 0 )
|
||||
formattedLifetimeAveragePVP = format( "%.0f", lifetimeAveragePVP )
|
||||
else
|
||||
formattedLifetimeAveragePVP = format( "%.1f", lifetimeAveragePVP )
|
||||
SetStatsLabelValue( file.menu, "LifetimePVPAverageValue", [ "#STATS_KD_VALUE", formattedLifetimeAveragePVP ] )
|
||||
|
||||
bool last10GamesStatsVisible = gamesPlayed >= NUM_GAMES_TRACK_KDRATIO ? true : false
|
||||
SetLast10GamesStatVisibility( file.menu, last10GamesStatsVisible )
|
||||
|
||||
// Last 10 Matches
|
||||
local kdratio_match = []
|
||||
local kdratiopvp_match = []
|
||||
for ( int i = NUM_GAMES_TRACK_KDRATIO - 1 ; i >= 0 ; i-- )
|
||||
{
|
||||
kdratio_match.append( player.GetPersistentVar( "kdratio_match[" + i + "]" ) )
|
||||
kdratiopvp_match.append( player.GetPersistentVar( "kdratiopvp_match[" + i + "]" ) )
|
||||
}
|
||||
|
||||
// Last 10
|
||||
local kdratio_match_sum = 0
|
||||
local count = 0
|
||||
foreach( value in kdratio_match )
|
||||
{
|
||||
if ( value == 0 )
|
||||
continue
|
||||
kdratio_match_sum += value
|
||||
count++
|
||||
}
|
||||
local kdratio_match_average = count > 0 ? kdratio_match_sum / count : kdratio_match_sum
|
||||
if ( kdratio_match_average % 1 == 0 )
|
||||
kdratio_match_average = format( "%.0f", kdratio_match_average )
|
||||
else
|
||||
kdratio_match_average = format( "%.1f", kdratio_match_average )
|
||||
SetStatsLabelValue( file.menu, "Last10GamesValue", [ "#STATS_KD_VALUE", kdratio_match_average ] )
|
||||
PlotKDPointsOnGraph( file.menu, 0, kdratio_match, lifetimeAverage )
|
||||
|
||||
// Last 10 (PVP)
|
||||
local kdratiopvp_match_sum = 0
|
||||
count = 0
|
||||
foreach( value in kdratiopvp_match )
|
||||
{
|
||||
if ( value == 0 )
|
||||
continue
|
||||
kdratiopvp_match_sum += value
|
||||
count++
|
||||
}
|
||||
local kdratiopvp_match_average = count > 0 ? kdratiopvp_match_sum / count : kdratiopvp_match_sum
|
||||
if ( kdratiopvp_match_average % 1 == 0 )
|
||||
kdratiopvp_match_average = format( "%.0f", kdratiopvp_match_average )
|
||||
else
|
||||
kdratiopvp_match_average = format( "%.1f", kdratiopvp_match_average )
|
||||
SetStatsLabelValue( file.menu, "Last10GamesPVPValue", [ "#STATS_KD_VALUE", kdratiopvp_match_average ] )
|
||||
PlotKDPointsOnGraph( file.menu, 1, kdratiopvp_match, lifetimeAveragePVP )
|
||||
|
||||
var totalPilotKills = 0
|
||||
|
||||
foreach (var key, var value in globalToneAPIKillData) {
|
||||
totalPilotKills += value
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue0" ), string( totalPilotKills ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue1" ), string( GetPlayerStatInt( player, "kills_stats", "titanKillsAsPilot" ) ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue2" ), string( GetPlayerStatInt( player, "kills_stats", "totalNPC" ) ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue3" ), string( GetPlayerStatInt( player, "kills_stats", "pilotKickMeleePilot" ) ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsPilotValue4" ), string( GetPlayerStatInt( player, "kills_stats", "pilotExecutePilot" ) ) )
|
||||
// Hud_SetText( GetElem( file.menu, "KillsAsPilotValue5" ), string( GetPlayerStatInt( player, "kills_stats", "titanFallKill" ) ) )
|
||||
|
||||
|
||||
|
||||
int totalTitanExecutions = 0
|
||||
totalTitanExecutions += GetPlayerStatInt( player, "kills_stats", "titanExocutionIon" )
|
||||
totalTitanExecutions += GetPlayerStatInt( player, "kills_stats", "titanExocutionScorch" )
|
||||
totalTitanExecutions += GetPlayerStatInt( player, "kills_stats", "titanExocutionNorthstar" )
|
||||
totalTitanExecutions += GetPlayerStatInt( player, "kills_stats", "titanExocutionRonin" )
|
||||
totalTitanExecutions += GetPlayerStatInt( player, "kills_stats", "titanExocutionTone" )
|
||||
totalTitanExecutions += GetPlayerStatInt( player, "kills_stats", "titanExocutionLegion" )
|
||||
totalTitanExecutions += GetPlayerStatInt( player, "kills_stats", "titanExocutionVanguard" )
|
||||
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsTitanValue0" ), string( GetPlayerStatInt( player, "kills_stats", "pilotKillsAsTitan" ) ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsTitanValue1" ), string( GetPlayerStatInt( player, "kills_stats", "titanKillsAsTitan" ) ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsTitanValue2" ), string( totalTitanExecutions ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsTitanValue3" ), string( GetPlayerStatInt( player, "kills_stats", "titanMeleePilot" ) ) )
|
||||
Hud_SetText( GetElem( file.menu, "KillsAsTitanValue4" ), string( GetPlayerStatInt( player, "kills_stats", "titanStepCrushPilot" ) ) )
|
||||
}
|
||||
|
||||
function PlotKDPointsOnGraph( menu, graphIndex, values, dottedAverage )
|
||||
{
|
||||
//printt( "values:" )
|
||||
//PrintTable( values )
|
||||
|
||||
var background = GetElem( menu, "KDRatioLast10Graph" + graphIndex )
|
||||
local graphHeight = Hud_GetBaseHeight( background )
|
||||
local graphOrigin = Hud_GetAbsPos( background )
|
||||
graphOrigin[1] += graphHeight
|
||||
local dotSpacing = Hud_GetBaseWidth( background ) / 9.0
|
||||
local dotPositions = []
|
||||
|
||||
// Calculate min/max for the graph
|
||||
local graphMin = 0.0
|
||||
local graphMax = max( dottedAverage, 1.0 )
|
||||
foreach( value in values )
|
||||
{
|
||||
if ( value > graphMax )
|
||||
graphMax = value
|
||||
}
|
||||
graphMax += graphMax * 0.1
|
||||
|
||||
var maxLabel = GetElem( menu, "Graph" + graphIndex + "ValueMax" )
|
||||
local maxValueString = format( "%.1f", graphMax )
|
||||
Hud_SetText( maxLabel, maxValueString )
|
||||
|
||||
// Plot the dots
|
||||
for ( int i = 0; i < MAX_DOTS_ON_GRAPH; i++ )
|
||||
{
|
||||
var dot = GetElem( menu, "Graph" + graphIndex + "Dot" + i )
|
||||
|
||||
if ( i >= values.len() )
|
||||
{
|
||||
Hud_Hide( dot )
|
||||
continue
|
||||
}
|
||||
|
||||
float dotOffset = GraphCapped( values[i], graphMin, graphMax, 0, graphHeight )
|
||||
|
||||
local posX = graphOrigin[0] - ( Hud_GetBaseWidth( dot ) * 0.5 ) + ( dotSpacing * i )
|
||||
local posY = graphOrigin[1] - ( Hud_GetBaseHeight( dot ) * 0.5 ) - dotOffset
|
||||
Hud_SetPos( dot, posX, posY )
|
||||
Hud_Show( dot )
|
||||
|
||||
dotPositions.append( [ posX + ( Hud_GetBaseWidth( dot ) * 0.5 ), posY + ( Hud_GetBaseHeight( dot ) * 0.5 ) ] )
|
||||
}
|
||||
|
||||
{
|
||||
// Place the dotted lifetime average line
|
||||
var dottedLine = GetElem( menu, "KDRatioLast10Graph" + graphIndex + "DottedLine0" )
|
||||
float dottedLineOffset = GraphCapped( dottedAverage, graphMin, graphMax, 0, graphHeight )
|
||||
local posX = graphOrigin[0]
|
||||
local posY = graphOrigin[1] - ( Hud_GetBaseHeight( dottedLine ) * 0.5 ) - dottedLineOffset
|
||||
Hud_SetPos( dottedLine, posX, posY )
|
||||
Hud_Show( dottedLine )
|
||||
}
|
||||
|
||||
{
|
||||
// Place the dotted zero line
|
||||
var dottedLine = GetElem( menu, "KDRatioLast10Graph" + graphIndex + "DottedLine1" )
|
||||
float dottedLineOffset = GraphCapped( 0.0, graphMin, graphMax, 0, graphHeight )
|
||||
local posX = graphOrigin[0]
|
||||
local posY = graphOrigin[1] - ( Hud_GetBaseHeight( dottedLine ) * 0.5 ) - dottedLineOffset
|
||||
Hud_SetPos( dottedLine, posX, posY )
|
||||
Hud_Show( dottedLine )
|
||||
}
|
||||
|
||||
// Connect the dots with lines
|
||||
for ( int i = 1; i < MAX_DOTS_ON_GRAPH; i++ )
|
||||
{
|
||||
var line = GetElem( menu, "Graph" + graphIndex + "Line" + i )
|
||||
|
||||
if ( i >= values.len() )
|
||||
{
|
||||
Hud_Hide( line )
|
||||
continue
|
||||
}
|
||||
|
||||
// Get angle from previous dot to this dot
|
||||
local startPos = dotPositions[i-1]
|
||||
local endPos = dotPositions[i]
|
||||
local offsetX = endPos[0] - startPos[0]
|
||||
local offsetY = endPos[1] - startPos[1]
|
||||
local angle = ( atan( offsetX / offsetY ) * ( 180 / PI ) )
|
||||
|
||||
// Get line length
|
||||
local length = sqrt( offsetX * offsetX + offsetY * offsetY )
|
||||
|
||||
// Calculate where the line should be positioned
|
||||
local posX = endPos[0] - ( offsetX / 2.0 ) - ( length / 2.0 )
|
||||
local posY = endPos[1] - ( offsetY / 2.0 ) - ( Hud_GetBaseHeight( line ) / 2.0 )
|
||||
|
||||
//line.SetHeight( 2.0 )
|
||||
Hud_SetWidth( line, length )
|
||||
Hud_SetRotation( line, angle + 90.0 )
|
||||
Hud_SetPos( line, posX, posY )
|
||||
Hud_Show( line )
|
||||
}
|
||||
}
|
||||
|
||||
void function SetLast10GamesStatVisibility( var menu, bool visible )
|
||||
{
|
||||
Hud_SetVisible( Hud_GetChild( menu, "Last10GamesLabel" ), visible )
|
||||
Hud_SetVisible( Hud_GetChild( menu, "Last10GamesValue" ), visible )
|
||||
Hud_SetVisible( Hud_GetChild( menu, "Last10GamesPVPLabel" ), visible )
|
||||
Hud_SetVisible( Hud_GetChild( menu, "Last10GamesPVPValue" ), visible )
|
||||
}
|
||||
|
||||
void function SetItemImageWidth( var imageElem, string ref )
|
||||
{
|
||||
vector vec = GetItemImageAspect( ref )
|
||||
float aspectRatio = vec.x / vec.y
|
||||
int imageWidth = int( Hud_GetHeight( imageElem ) * aspectRatio )
|
||||
Hud_SetWidth( imageElem, imageWidth )
|
||||
}
|
||||
@@ -0,0 +1,551 @@
|
||||
untyped
|
||||
|
||||
|
||||
global function SetPieChartData
|
||||
global function SetStatsBarValues
|
||||
global function SetStatsValueInfo
|
||||
global function SetStatsLabelValue
|
||||
global function GetPercent
|
||||
//global function GetChallengeCompleteData
|
||||
global function GetItemUnlockCountData
|
||||
global function GetOverviewWeaponData
|
||||
global function StatToTimeString
|
||||
global function HoursToTimeString
|
||||
global function StatToDistanceString
|
||||
global function ComparePieChartEntryValues
|
||||
global function SetStatBoxDisplay
|
||||
global function SetMedalStatBoxDisplay
|
||||
|
||||
void function SetPieChartData( var menu, string panelName, string titleString, PieChartData data )
|
||||
{
|
||||
Assert( data.entries.len() <= 8 )
|
||||
|
||||
// Get nested panel
|
||||
var piePanel = GetElem( menu, panelName )
|
||||
|
||||
// Create background
|
||||
var background = Hud_GetChild( piePanel, "BarBG" )
|
||||
Hud_SetBarProgress( background, 1.0 )
|
||||
Hud_SetColor( background, [190, 190, 190, 255] )
|
||||
|
||||
// Calculate total of all values combined
|
||||
foreach ( entry in data.entries )
|
||||
data.sum += entry.numValue
|
||||
|
||||
// Calculate bar fraction for each value
|
||||
foreach ( entry in data.entries )
|
||||
{
|
||||
if ( data.sum > 0 )
|
||||
entry.fracValue = entry.numValue / data.sum
|
||||
else
|
||||
entry.fracValue = 0.0
|
||||
}
|
||||
|
||||
// Set slice sizes and text data
|
||||
var titleLabel = Hud_GetChild( piePanel, "Title" )
|
||||
Hud_SetText( titleLabel, titleString )
|
||||
Hud_SetColor( titleLabel, data.labelColor )
|
||||
|
||||
var noDataLabel = Hud_GetChild( piePanel, "NoData" )
|
||||
|
||||
for ( int index = 0; index < 8; index++ )
|
||||
{
|
||||
var barColorGuide = Hud_GetChild( piePanel, "BarColorGuide" + index )
|
||||
// Hud_SetColor( barColorGuide, entry.color )
|
||||
Hud_Hide( barColorGuide )
|
||||
|
||||
var barColorGuideFrame = Hud_GetChild( piePanel, "BarColorGuideFrame" + index )
|
||||
Hud_Hide( barColorGuideFrame )
|
||||
|
||||
var barName = Hud_GetChild( piePanel, "BarName" + index )
|
||||
Hud_SetColor( barName, data.labelColor )
|
||||
Hud_SetText( barName, "" )
|
||||
|
||||
var bar = Hud_GetChild( piePanel, "Bar" + index )
|
||||
//Hud_SetBarProgress( bar, combinedFrac )
|
||||
//Hud_SetColor( bar, entry.color )
|
||||
Hud_Hide( bar )
|
||||
}
|
||||
|
||||
if ( data.entries.len() > 0 )
|
||||
{
|
||||
Hud_Hide( noDataLabel )
|
||||
|
||||
float combinedFrac = 0.0
|
||||
int largestTextWidth = 0
|
||||
|
||||
foreach ( index, entry in data.entries )
|
||||
{
|
||||
var barColorGuide = Hud_GetChild( piePanel, "BarColorGuide" + index )
|
||||
Hud_SetColor( barColorGuide, entry.color )
|
||||
Hud_Show( barColorGuide )
|
||||
|
||||
var barColorGuideFrame = Hud_GetChild( piePanel, "BarColorGuideFrame" + index )
|
||||
Hud_Show( barColorGuideFrame )
|
||||
|
||||
string percent = GetPercent( entry.fracValue, 1.0, 0, true )
|
||||
var barName = Hud_GetChild( piePanel, "BarName" + index )
|
||||
Hud_SetColor( barName, data.labelColor )
|
||||
|
||||
if ( data.timeBased )
|
||||
Hud_SetText( barName, PieChartHoursToTimeString( entry.numValue, entry.displayName, percent ) )
|
||||
else
|
||||
Hud_SetText( barName, "#STATS_TEXT_AND_PERCENTAGE", entry.displayName, percent )
|
||||
|
||||
int currentTextWidth = Hud_GetTextWidth( barName )
|
||||
if ( currentTextWidth > largestTextWidth )
|
||||
largestTextWidth = currentTextWidth
|
||||
|
||||
Hud_Show( barName )
|
||||
|
||||
combinedFrac += entry.fracValue
|
||||
var bar = Hud_GetChild( piePanel, "Bar" + index )
|
||||
Hud_SetBarProgress( bar, combinedFrac )
|
||||
Hud_SetColor( bar, entry.color )
|
||||
Hud_Show( bar )
|
||||
}
|
||||
|
||||
// Position the list
|
||||
int xOffset = int( ( largestTextWidth / -2 ) + ContentScaledX( 18 ) )
|
||||
Hud_SetX( Hud_GetChild( piePanel, "BarName0" ), xOffset )
|
||||
}
|
||||
else
|
||||
{
|
||||
Hud_Show( noDataLabel )
|
||||
for ( int index = 0; index < 8; index++ )
|
||||
{
|
||||
var barColorGuide = Hud_GetChild( piePanel, "BarColorGuide" + index )
|
||||
// Hud_SetColor( barColorGuide, entry.color )
|
||||
Hud_Hide( barColorGuide )
|
||||
|
||||
var barColorGuideFrame = Hud_GetChild( piePanel, "BarColorGuideFrame" + index )
|
||||
Hud_Hide( barColorGuideFrame )
|
||||
|
||||
var barName = Hud_GetChild( piePanel, "BarName" + index )
|
||||
Hud_SetColor( barName, data.labelColor )
|
||||
Hud_SetText( barName, "" )
|
||||
|
||||
var bar = Hud_GetChild( piePanel, "Bar" + index )
|
||||
//Hud_SetBarProgress( bar, combinedFrac )
|
||||
//Hud_SetColor( bar, entry.color )
|
||||
Hud_Hide( bar )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function SetStatsBarValues( menu, panelName, titleString, startValue, endValue, currentValue )
|
||||
{
|
||||
Assert( endValue > startValue )
|
||||
Assert( currentValue >= startValue && currentValue <= endValue )
|
||||
|
||||
// Get nested panel
|
||||
var panel = GetElem( menu, panelName )
|
||||
|
||||
// Update titel
|
||||
var title = Hud_GetChild( panel, "Title" )
|
||||
Hud_SetText( title, titleString )
|
||||
|
||||
// Update progress text
|
||||
var progressText = Hud_GetChild( panel, "ProgressText" )
|
||||
Hud_SetText( progressText, "#STATS_PROGRESS_BAR_VALUE", currentValue, endValue )
|
||||
|
||||
// Update bar progress
|
||||
float frac = GraphCapped( currentValue, startValue, endValue, 0.0, 1.0 )
|
||||
|
||||
var barFill = Hud_GetChild( panel, "BarFill" )
|
||||
Hud_SetScaleX( barFill, frac )
|
||||
|
||||
var barFillShadow = Hud_GetChild( panel, "BarFillShadow" )
|
||||
Hud_SetScaleX( barFillShadow, frac )
|
||||
}
|
||||
|
||||
void function SetStatsValueInfo( var menu, valueID, labelText, textString )
|
||||
{
|
||||
var elem = GetElem( menu, "Column0Label" + valueID )
|
||||
Assert( elem != null )
|
||||
Hud_SetText( elem, labelText )
|
||||
|
||||
elem = GetElem( menu, "Column0Value" + valueID )
|
||||
Assert( elem != null )
|
||||
SetStatsLabelValueOnLabel( elem, textString )
|
||||
}
|
||||
|
||||
void function SetStatsLabelValue( var menu, labelName, textString )
|
||||
{
|
||||
var elem = GetElem( menu, labelName )
|
||||
Assert( elem != null)
|
||||
SetStatsLabelValueOnLabel( elem, textString )
|
||||
}
|
||||
|
||||
void function SetStatsLabelValueOnLabel( elem, textString )
|
||||
{
|
||||
if ( type( textString ) == "array" )
|
||||
{
|
||||
if ( textString.len() == 6 )
|
||||
Hud_SetText( elem, string( textString[0] ), textString[1], textString[2], textString[3], textString[4], textString[5] )
|
||||
if ( textString.len() == 5 )
|
||||
Hud_SetText( elem, string( textString[0] ), textString[1], textString[2], textString[3], textString[4] )
|
||||
if ( textString.len() == 4 )
|
||||
Hud_SetText( elem, string( textString[0] ), textString[1], textString[2], textString[3] )
|
||||
if ( textString.len() == 3 )
|
||||
Hud_SetText( elem, string( textString[0] ), textString[1], textString[2] )
|
||||
if ( textString.len() == 2 )
|
||||
Hud_SetText( elem, string( textString[0] ), textString[1] )
|
||||
if ( textString.len() == 1 )
|
||||
Hud_SetText( elem, string( textString[0] ) )
|
||||
}
|
||||
else
|
||||
{
|
||||
Hud_SetText( elem, string( textString ) )
|
||||
}
|
||||
}
|
||||
|
||||
string function GetPercent( float val, float total, float defaultPercent, bool doClamp = true )
|
||||
{
|
||||
float percent = defaultPercent
|
||||
if ( total > 0 )
|
||||
{
|
||||
percent = val / total
|
||||
percent *= 100
|
||||
}
|
||||
|
||||
if ( doClamp )
|
||||
percent = clamp( percent, 0, 100 )
|
||||
|
||||
string formattedPercent
|
||||
if ( int( percent * 10 ) % 10 == 0 )
|
||||
formattedPercent = format( "%.0f", percent )
|
||||
else
|
||||
formattedPercent = format( "%.1f", percent )
|
||||
|
||||
return formattedPercent
|
||||
}
|
||||
|
||||
//function GetChallengeCompleteData()
|
||||
//{
|
||||
// local Table = {}
|
||||
// Table.total <- 0
|
||||
// Table.complete <- 0
|
||||
//
|
||||
// UI_GetAllChallengesProgress()
|
||||
// var allChallenges = GetLocalChallengeTable()
|
||||
//
|
||||
// foreach( challengeRef, val in allChallenges )
|
||||
// {
|
||||
// if ( IsDailyChallenge( challengeRef ) )
|
||||
// continue
|
||||
// local tierCount = GetChallengeTierCount( challengeRef )
|
||||
// Table.total += tierCount
|
||||
// for ( int i = 0; i < tierCount; i++ )
|
||||
// {
|
||||
// if ( IsChallengeTierComplete( challengeRef, i ) )
|
||||
// Table.complete++
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return Table
|
||||
//}
|
||||
|
||||
function GetItemUnlockCountData()
|
||||
{
|
||||
entity player = GetUIPlayer()
|
||||
if ( player == null )
|
||||
return {}
|
||||
|
||||
local Table = {}
|
||||
Table[ "weapons" ] <- {}
|
||||
Table[ "weapons" ].total <- 0
|
||||
Table[ "weapons" ].unlocked <- 0
|
||||
Table[ "attachments" ] <- {}
|
||||
Table[ "attachments" ].total <- 0
|
||||
Table[ "attachments" ].unlocked <- 0
|
||||
Table[ "mods" ] <- {}
|
||||
Table[ "mods" ].total <- 0
|
||||
Table[ "mods" ].unlocked <- 0
|
||||
Table[ "abilities" ] <- {}
|
||||
Table[ "abilities" ].total <- 0
|
||||
Table[ "abilities" ].unlocked <- 0
|
||||
Table[ "gear" ] <- {}
|
||||
Table[ "gear" ].total <- 0
|
||||
Table[ "gear" ].unlocked <- 0
|
||||
/*
|
||||
local tableMapping = {}
|
||||
|
||||
tableMapping[ eItemTypes.PILOT_PRIMARY ] <- "weapons"
|
||||
tableMapping[ eItemTypes.PILOT_SECONDARY ] <- "weapons"
|
||||
tableMapping[ eItemTypes.PILOT_ORDNANCE ] <- "weapons"
|
||||
tableMapping[ eItemTypes.TITAN_PRIMARY ] <- "weapons"
|
||||
tableMapping[ eItemTypes.TITAN_ORDNANCE ] <- "weapons"
|
||||
tableMapping[ eItemTypes.PILOT_PRIMARY_ATTACHMENT ] <- "attachments"
|
||||
tableMapping[ eItemTypes.PILOT_PRIMARY_MOD ] <- "mods"
|
||||
tableMapping[ eItemTypes.PILOT_SECONDARY_MOD ] <- "mods"
|
||||
tableMapping[ eItemTypes.TITAN_PRIMARY_MOD ] <- "mods"
|
||||
tableMapping[ eItemTypes.PILOT_SPECIAL_MOD ] <- "mods"
|
||||
tableMapping[ eItemTypes.TITAN_SPECIAL_MOD ] <- "mods"
|
||||
tableMapping[ eItemTypes.PILOT_SPECIAL ] <- "abilities"
|
||||
tableMapping[ eItemTypes.TITAN_SPECIAL ] <- "abilities"
|
||||
|
||||
local itemRefs = GetAllItemRefs()
|
||||
foreach ( data in itemRefs )
|
||||
{
|
||||
if ( !( data.Type in tableMapping ) )
|
||||
continue
|
||||
Table[ tableMapping[ data.Type ] ].total++
|
||||
|
||||
if ( !IsItemLocked( player, expect string( data.childRef ), expect string( data.ref ) ) )
|
||||
Table[ tableMapping[ data.Type ] ].unlocked++
|
||||
}
|
||||
*/
|
||||
return Table
|
||||
}
|
||||
|
||||
table<string, table> function GetOverviewWeaponData()
|
||||
{
|
||||
table<string, table> Table = {}
|
||||
Table[ "most_kills" ] <- {}
|
||||
Table[ "most_kills" ].ref <- ""
|
||||
Table[ "most_kills" ].printName <- ""
|
||||
Table[ "most_kills" ].val <- 0
|
||||
Table[ "most_used" ] <- {}
|
||||
Table[ "most_used" ].ref <- ""
|
||||
Table[ "most_used" ].printName <- ""
|
||||
Table[ "most_used" ].val <- 0
|
||||
Table[ "highest_kpm" ] <- {}
|
||||
Table[ "highest_kpm" ].ref <- ""
|
||||
Table[ "highest_kpm" ].printName <- ""
|
||||
Table[ "highest_kpm" ].val <- 0
|
||||
|
||||
entity player = GetUIPlayer()
|
||||
if ( player == null )
|
||||
return Table
|
||||
|
||||
array<ItemDisplayData> allWeapons = []
|
||||
|
||||
allWeapons.extend( GetVisibleItemsOfType( eItemTypes.PILOT_PRIMARY ) )
|
||||
allWeapons.extend( GetVisibleItemsOfType( eItemTypes.PILOT_SECONDARY ) )
|
||||
//allWeapons.extend( GetVisibleItemsOfType( eItemTypes.PILOT_ORDNANCE ) ) // art looks bad
|
||||
allWeapons.extend( GetVisibleItemsOfType( eItemTypes.TITAN_PRIMARY ) )
|
||||
allWeapons.extend( GetVisibleItemsOfType( eItemTypes.TITAN_ORDNANCE ) )
|
||||
allWeapons.extend( GetVisibleItemsOfType( eItemTypes.TITAN_ANTIRODEO ) )
|
||||
allWeapons.extend( GetVisibleItemsOfType( eItemTypes.TITAN_SPECIAL ) )
|
||||
//allWeapons.extend( GetVisibleItemsOfType( eItemTypes.BURN_METER_REWARD ) ) // script errors
|
||||
|
||||
foreach ( weapon in allWeapons )
|
||||
{
|
||||
string weaponName = weapon.ref
|
||||
string weaponDisplayName = expect string( GetWeaponInfoFileKeyField_Global( weaponName, "printname" ) )
|
||||
|
||||
if ( !PersistenceEnumValueIsValid( "loadoutWeaponsAndAbilities", weaponName ) )
|
||||
continue
|
||||
|
||||
int val = getWeaponKillsFromToneApi(weaponName)
|
||||
if ( val > Table[ "most_kills" ].val )
|
||||
{
|
||||
Table[ "most_kills" ].ref = weaponName
|
||||
Table[ "most_kills" ].printName = weaponDisplayName
|
||||
Table[ "most_kills" ].val = val
|
||||
}
|
||||
|
||||
float fVal = GetPlayerStatFloat( player, "weapon_stats", "hoursUsed", weaponName )
|
||||
if ( fVal > Table[ "most_used" ].val )
|
||||
{
|
||||
Table[ "most_used" ].ref = weaponName
|
||||
Table[ "most_used" ].printName = weaponDisplayName
|
||||
Table[ "most_used" ].val = fVal
|
||||
}
|
||||
|
||||
local killsPerMinute = 0
|
||||
local hoursEquipped = GetPlayerStatFloat( player, "weapon_stats", "hoursEquipped", weaponName )
|
||||
local killCount = GetPlayerStatInt( player, "weapon_kill_stats", "total", weaponName )
|
||||
if ( hoursEquipped > 0 )
|
||||
killsPerMinute = format( "%.2f", ( killCount / ( hoursEquipped * 60.0 ) ).tofloat() )
|
||||
if ( killsPerMinute.tofloat() > Table[ "highest_kpm" ].val.tofloat() )
|
||||
{
|
||||
Table[ "highest_kpm" ].ref = weaponName
|
||||
Table[ "highest_kpm" ].printName = weaponDisplayName
|
||||
Table[ "highest_kpm" ].val = killsPerMinute
|
||||
}
|
||||
}
|
||||
|
||||
return Table
|
||||
}
|
||||
|
||||
string function StatToTimeString( string category, string alias, string weapon = "" )
|
||||
{
|
||||
entity player = GetUIPlayer()
|
||||
if ( player == null )
|
||||
return "0"
|
||||
|
||||
string statString = GetStatVar( category, alias, weapon )
|
||||
float savedHours = expect float( player.GetPersistentVar( statString ) )
|
||||
|
||||
return HoursToTimeString( savedHours )
|
||||
}
|
||||
|
||||
string function HoursToTimeString( float savedHours )
|
||||
{
|
||||
string timeString
|
||||
local minutes = floor( savedHours * 60.0 )
|
||||
|
||||
if ( minutes < 0 )
|
||||
minutes = 0
|
||||
|
||||
int days = 0
|
||||
int hours = 0
|
||||
|
||||
while ( minutes >= 1440 )
|
||||
{
|
||||
minutes -= 1440
|
||||
days++
|
||||
}
|
||||
|
||||
while ( minutes >= 60 )
|
||||
{
|
||||
minutes -= 60
|
||||
hours++
|
||||
}
|
||||
|
||||
if ( days > 0 && hours > 0 && minutes > 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_D_H_M", days, hours, minutes )
|
||||
}
|
||||
else if ( days > 0 && hours == 0 && minutes == 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_D", days )
|
||||
}
|
||||
else if ( days == 0 && hours > 0 && minutes == 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_H", hours )
|
||||
}
|
||||
else if ( days == 0 && hours == 0 && minutes >= 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_M", minutes )
|
||||
}
|
||||
else if ( days > 0 && hours > 0 && minutes == 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_D_H", days, hours )
|
||||
}
|
||||
else if ( days == 0 && hours > 0 && minutes > 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_H_M", hours, minutes )
|
||||
}
|
||||
else if ( days > 0 && hours == 0 && minutes > 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_D_M", days, minutes )
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert( 0, "Unhandled time string creation case" )
|
||||
}
|
||||
|
||||
return timeString
|
||||
}
|
||||
|
||||
string function PieChartHoursToTimeString( float savedHours, string pieChartHeader, string pieChartPercent )
|
||||
{
|
||||
string timeString
|
||||
local minutes = floor( savedHours * 60.0 )
|
||||
|
||||
if ( minutes < 0 )
|
||||
minutes = 0
|
||||
|
||||
int days = 0
|
||||
int hours = 0
|
||||
|
||||
while ( minutes >= 1440 )
|
||||
{
|
||||
minutes -= 1440
|
||||
days++
|
||||
}
|
||||
|
||||
while ( minutes >= 60 )
|
||||
{
|
||||
minutes -= 60
|
||||
hours++
|
||||
}
|
||||
|
||||
if ( days > 0 && hours > 0 && minutes > 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_D_H_M_PIECHART", days, hours, minutes, Localize( pieChartHeader ), pieChartPercent )
|
||||
}
|
||||
else if ( days > 0 && hours == 0 && minutes == 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_D_PIECHART", days, Localize( pieChartHeader ), pieChartPercent )
|
||||
}
|
||||
else if ( days == 0 && hours > 0 && minutes == 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_H_PIECHART", hours, Localize( pieChartHeader ), pieChartPercent )
|
||||
}
|
||||
else if ( days == 0 && hours == 0 && minutes >= 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_M_PIECHART", minutes, Localize( pieChartHeader ), pieChartPercent )
|
||||
}
|
||||
else if ( days > 0 && hours > 0 && minutes == 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_D_H_PIECHART", days, hours, Localize( pieChartHeader ), pieChartPercent )
|
||||
}
|
||||
else if ( days == 0 && hours > 0 && minutes > 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_H_M_PIECHART", hours, minutes, Localize( pieChartHeader ), pieChartPercent )
|
||||
}
|
||||
else if ( days > 0 && hours == 0 && minutes > 0 )
|
||||
{
|
||||
timeString = Localize( "#STATS_TIME_STRING_D_M_PIECHART", days, minutes, Localize( pieChartHeader ), pieChartPercent )
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert( 0, "Unhandled time string creation case" )
|
||||
}
|
||||
|
||||
return timeString
|
||||
}
|
||||
|
||||
string function StatToDistanceString( string category, string alias, string weapon = "" )
|
||||
{
|
||||
entity player = GetUIPlayer()
|
||||
if ( player == null )
|
||||
return ""
|
||||
|
||||
string statString = GetStatVar( category, alias, weapon )
|
||||
float kilometers = expect float( player.GetPersistentVar( statString ) )
|
||||
|
||||
string formattedNum
|
||||
if ( kilometers % 1 == 0 )
|
||||
formattedNum = format( "%.0f", kilometers )
|
||||
else
|
||||
formattedNum = format( "%.2f", kilometers )
|
||||
|
||||
string distString = Localize( "#STATS_KILOMETERS_ABBREVIATION", formattedNum )
|
||||
|
||||
return distString
|
||||
}
|
||||
|
||||
int function ComparePieChartEntryValues( PieChartEntry a, PieChartEntry b )
|
||||
{
|
||||
float aVal = a.numValue
|
||||
float bVal = b.numValue
|
||||
|
||||
if ( aVal < bVal )
|
||||
return 1
|
||||
else if ( aVal > bVal )
|
||||
return -1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
void function SetStatBoxDisplay( var vguiElem, string text, string value )
|
||||
{
|
||||
var rui = Hud_GetRui( vguiElem )
|
||||
|
||||
RuiSetString( rui, "statText", text )
|
||||
RuiSetString( rui, "statValue", value )
|
||||
}
|
||||
|
||||
void function SetMedalStatBoxDisplay( var vguiElem, string text, asset image, int value )
|
||||
{
|
||||
var rui = Hud_GetRui( vguiElem )
|
||||
|
||||
RuiSetString( rui, "statText", text )
|
||||
RuiSetString( rui, "statValue", string( value ) )
|
||||
RuiSetImage( rui, "statImage", image )
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
//TODO: Kills Per Minute stat
|
||||
|
||||
global function InitViewStatsWeaponsMenu
|
||||
|
||||
struct
|
||||
{
|
||||
var menu
|
||||
GridMenuData gridData
|
||||
bool isGridInitialized = false
|
||||
array<ItemDisplayData> allPilotWeapons
|
||||
} file
|
||||
|
||||
void function InitViewStatsWeaponsMenu()
|
||||
{
|
||||
var menu = GetMenu( "ViewStats_Weapons_Menu" )
|
||||
file.menu = menu
|
||||
|
||||
Hud_SetText( Hud_GetChild( file.menu, "MenuTitle" ), "#STATS_PILOT_WEAPONS" )
|
||||
|
||||
file.gridData.rows = 5
|
||||
file.gridData.columns = 1
|
||||
//file.gridData.numElements // Set in OnViewStatsWeapons_Open after itemdata exists
|
||||
file.gridData.pageType = eGridPageType.VERTICAL
|
||||
file.gridData.tileWidth = 224
|
||||
file.gridData.tileHeight = 112
|
||||
file.gridData.paddingVert = 6
|
||||
file.gridData.paddingHorz = 6
|
||||
|
||||
Grid_AutoAspectSettings( menu, file.gridData )
|
||||
|
||||
file.gridData.initCallback = WeaponButton_Init
|
||||
file.gridData.getFocusCallback = WeaponButton_GetFocus
|
||||
//file.gridData.clickCallback = WeaponButton_Activate
|
||||
|
||||
AddMenuEventHandler( file.menu, eUIEvent.MENU_OPEN, OnViewStatsWeapons_Open )
|
||||
|
||||
AddMenuFooterOption( file.menu, BUTTON_B, "#B_BUTTON_BACK", "#BACK" )
|
||||
}
|
||||
|
||||
void function OnViewStatsWeapons_Open()
|
||||
{
|
||||
//UI_SetPresentationType( ePresentationType.NO_MODELS )
|
||||
UI_SetPresentationType( ePresentationType.STORE_WEAPON_SKINS )
|
||||
|
||||
// Get Pilot weapon list
|
||||
file.allPilotWeapons = GetVisibleItemsOfType( eItemTypes.PILOT_PRIMARY )
|
||||
file.allPilotWeapons.extend( GetVisibleItemsOfType( eItemTypes.PILOT_SECONDARY ) )
|
||||
file.allPilotWeapons.sort( SortItemsAlphabetically )
|
||||
//file.allPilotWeapons.extend( GetVisibleItemsOfType( eItemTypes.PILOT_ORDNANCE ) )
|
||||
//file.allPilotWeapons.extend( GetVisibleItemsOfType( eItemTypes.PILOT_SPECIAL ) )
|
||||
|
||||
file.gridData.numElements = file.allPilotWeapons.len()
|
||||
|
||||
if ( !file.isGridInitialized )
|
||||
{
|
||||
GridMenuInit( file.menu, file.gridData )
|
||||
file.isGridInitialized = true
|
||||
}
|
||||
|
||||
file.gridData.currentPage = 0
|
||||
|
||||
Grid_InitPage( file.menu, file.gridData )
|
||||
Hud_SetFocused( Grid_GetButtonForElementNumber( file.menu, 0 ) )
|
||||
UpdateStatsForWeapon( file.allPilotWeapons[ 0 ].ref )
|
||||
}
|
||||
|
||||
bool function WeaponButton_Init( var button, int elemNum )
|
||||
{
|
||||
string ref = file.allPilotWeapons[ elemNum ].ref
|
||||
int itemType = GetItemType( ref )
|
||||
|
||||
var rui = Hud_GetRui( button )
|
||||
asset image = GetImage( itemType, ref )
|
||||
RuiSetImage( rui, "buttonImage", image )
|
||||
|
||||
Hud_SetEnabled( button, true )
|
||||
Hud_SetVisible( button, true )
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
void function WeaponButton_GetFocus( var button, int elemNum )
|
||||
{
|
||||
//if ( IsControllerModeActive() )
|
||||
UpdateStatsForWeapon( file.allPilotWeapons[ elemNum ].ref )
|
||||
}
|
||||
|
||||
//void function WeaponButton_Activate( var button, int elemNum )
|
||||
//{
|
||||
// if ( !IsControllerModeActive() )
|
||||
// UpdateStatsForWeapon( file.allPilotWeapons[ elemNum ].ref )
|
||||
//}
|
||||
|
||||
void function UpdateStatsForWeapon( string weaponRef )
|
||||
{
|
||||
//Sliced names are to be removed afterwards
|
||||
string slicedName = ""
|
||||
if(weaponRef.find("mp_weapon")){
|
||||
slicedName = weaponRef.slice(10)
|
||||
}
|
||||
entity player = GetUIPlayer()
|
||||
if ( player == null )
|
||||
return
|
||||
|
||||
RunMenuClientFunction( "UpdateStoreWeaponModelSkin", weaponRef, 0 )
|
||||
|
||||
// Name
|
||||
Hud_SetText( Hud_GetChild( file.menu, "WeaponName" ), GetItemName( weaponRef ) )
|
||||
|
||||
// Locked info
|
||||
var lockLabel = GetElementsByClassname( file.menu, "LblWeaponLocked" )[0]
|
||||
|
||||
if ( IsItemLocked( player, weaponRef ) )
|
||||
{
|
||||
Hud_SetText( lockLabel, "#LOUADOUT_UNLOCK_REQUIREMENT_LEVEL", GetUnlockLevelReq( weaponRef ) )
|
||||
Hud_Show( lockLabel )
|
||||
}
|
||||
else
|
||||
{
|
||||
Hud_Hide( lockLabel )
|
||||
}
|
||||
|
||||
// Get required data needed for some calculations
|
||||
//float hoursUsed = GetPlayerStatFloat( player, "weapon_stats", "hoursUsed", weaponRef )
|
||||
string timeUsed = StatToTimeString( "weapon_stats", "hoursUsed", weaponRef )
|
||||
int shotsHit = GetPlayerStatInt( player, "weapon_stats", "shotsHit", weaponRef )
|
||||
int headshots = GetPlayerStatInt( player, "weapon_stats", "headshots", weaponRef )
|
||||
int crits = GetPlayerStatInt( player, "weapon_stats", "critHits", weaponRef )
|
||||
|
||||
string headShotsValue = Localize( "#STATS_NOT_APPLICABLE" )
|
||||
bool headshotWeapon = GetWeaponInfoFileKeyField_Global( weaponRef, "allow_headshots" ) == true
|
||||
if ( headshotWeapon )
|
||||
headShotsValue = string( headshots )
|
||||
|
||||
string critHitsValue = Localize( "#STATS_NOT_APPLICABLE" )
|
||||
bool critHitWeapon = GetWeaponInfoFileKeyField_Global( weaponRef, "critical_hit" ) == true
|
||||
if ( critHitWeapon )
|
||||
critHitsValue = string( crits )
|
||||
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat0" ), Localize( "#STATS_HEADER_TIME_USED" ), timeUsed )
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat1" ), Localize( "#STATS_HEADER_SHOTS_HIT" ), string( shotsHit ) )
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat2" ), Localize( "#STATS_HEADER_HEADSHOTS" ), headShotsValue )
|
||||
SetStatBoxDisplay( Hud_GetChild( file.menu, "Stat3" ), Localize( "#STATS_HEADER_CRITICAL_HITS" ), critHitsValue )
|
||||
|
||||
string nextUnlockRef = GetNextUnlockForWeaponLevel( player, weaponRef, WeaponGetRawLevel( player, weaponRef ) + 1 )
|
||||
if ( nextUnlockRef != "" )
|
||||
{
|
||||
var rui = Hud_GetRui( Hud_GetChild( file.menu, "NextUnlock" ) )
|
||||
|
||||
if ( nextUnlockRef == "random" )
|
||||
{
|
||||
RuiSetString( rui, "unlockName", "" )
|
||||
RuiSetImage( rui, "unlockImage", $"rui/menu/common/unlock_random" )
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemDisplayData displayData
|
||||
if ( IsSubItemType( GetItemType( nextUnlockRef ) ) )
|
||||
displayData = GetItemDisplayData( nextUnlockRef, weaponRef )
|
||||
else
|
||||
displayData = GetItemDisplayData( nextUnlockRef )
|
||||
|
||||
RuiSetString( rui, "unlockName", displayData.name )
|
||||
RuiSetImage( rui, "unlockImage", displayData.image )
|
||||
|
||||
vector aspect = GetItemImageAspect( nextUnlockRef )
|
||||
|
||||
float mult = 1.0
|
||||
if ( aspect.x > aspect.y )
|
||||
mult = 120.0 / aspect.x
|
||||
else
|
||||
mult = 120.0 / aspect.y
|
||||
|
||||
aspect.x *= mult
|
||||
aspect.y *= mult
|
||||
|
||||
RuiSetFloat2( rui, "unlockImageSize", aspect )
|
||||
}
|
||||
//printt( displayData.image )
|
||||
}
|
||||
|
||||
// Total Kills Stats
|
||||
SetStatsLabelValue( file.menu, "KillsValue0", getWeaponKillsFromToneApi(weaponRef) )
|
||||
SetStatsLabelValue( file.menu, "KillsValue1", getWeaponKillsFromToneApi(weaponRef) )
|
||||
SetStatsLabelValue( file.menu, "KillsValue2", GetPlayerStatInt( player, "weapon_kill_stats", "titansTotal", weaponRef ) )
|
||||
SetStatsLabelValue( file.menu, "KillsValue3", GetPlayerStatInt( player, "weapon_kill_stats", "ai", weaponRef ) )
|
||||
}
|
||||
Reference in New Issue
Block a user