|
| 1 | +"use strict"; |
| 2 | +/// <reference path="csgo.d.ts" /> |
| 3 | +/// <reference path="rating_emblem.ts" /> |
| 4 | +var SeasonProgress; |
| 5 | +(function (SeasonProgress) { |
| 6 | + function _Init() { |
| 7 | + SetRating(); |
| 8 | + } |
| 9 | + function SetRating() { |
| 10 | + let elRatingEmblem = $.GetContextPanel().FindChildInLayoutFile('js-highest-rating'); |
| 11 | + let rating = MyPersonaAPI.GetPipRankHighest("Premier"); |
| 12 | + let options; |
| 13 | + options = { |
| 14 | + root_panel: elRatingEmblem, |
| 15 | + rating_type: 'Premier', |
| 16 | + leaderboard_details: { score: rating }, |
| 17 | + do_fx: true, |
| 18 | + full_details: false, |
| 19 | + local_player: true |
| 20 | + }; |
| 21 | + RatingEmblem.SetXuid(options); |
| 22 | + _SetProgressBar(rating); |
| 23 | + } |
| 24 | + SeasonProgress.SetRating = SetRating; |
| 25 | + function _SetProgressBar(rating) { |
| 26 | + let nWins = MyPersonaAPI.GetPipRankWins("Premier"); |
| 27 | + let clampedRating = RatingEmblem.GetClampedRating(rating); |
| 28 | + let color = clampedRating; |
| 29 | + let nBars = nWins > 24 && nWins < 50 ? 1 : |
| 30 | + nWins > 49 && nWins < 75 ? 2 : |
| 31 | + nWins > 74 && nWins < 100 ? 3 : |
| 32 | + nWins > 99 && nWins < 125 ? 4 : |
| 33 | + nWins > 124 ? 5 : |
| 34 | + 0; |
| 35 | + nBars = nBars < 5 ? nBars + 1 : 5; |
| 36 | + let elPips = $.GetContextPanel().FindChildInLayoutFile('id-premier-season-pips'); |
| 37 | + elPips.SwitchClass('scale', (nBars === 4) ? 'four-medals' : (nBars === 5) ? 'five-medals' : (nBars === 2) ? 'two-medals' : ''); |
| 38 | + let nTotalBars = nBars * 25; |
| 39 | + let nTotalPips = nTotalBars < 126 ? nTotalBars + 1 : nTotalBars; |
| 40 | + let nSinglePipWidth = (nTotalPips < 27) ? 17 : |
| 41 | + (nTotalPips > 27 && nTotalPips < 52) ? 7 : |
| 42 | + (nTotalPips > 52 && nTotalPips < 77) ? 4 : |
| 43 | + (nTotalPips > 77 && nTotalPips < 102) ? 3 : |
| 44 | + (nTotalPips > 102 && nTotalPips < 127) ? 2 : |
| 45 | + 4; |
| 46 | + for (let i = 1; i < nTotalPips; i++) { |
| 47 | + let elPip = elPips.FindChild('pip-' + i); |
| 48 | + if (!elPip) { |
| 49 | + elPip = $.CreatePanel('Panel', elPips, 'pip-' + i, { clampfractionalpixelpositions: "false", class: 'premier-season-progress-pip' }); |
| 50 | + let isMedalPip = (i % 25 === 0 && i !== 0); |
| 51 | + elPip.SetHasClass('premier-season-progress-pip-medal', isMedalPip); |
| 52 | + if (!isMedalPip) |
| 53 | + elPip.style.width = nSinglePipWidth + 'px;'; |
| 54 | + } |
| 55 | + if (i <= nWins) { |
| 56 | + elPip.SwitchClass('tier', 'tier-' + color); |
| 57 | + } |
| 58 | + else { |
| 59 | + elPip.SwitchClass('tier', 'tier-none'); |
| 60 | + } |
| 61 | + } |
| 62 | + clampedRating = clampedRating < 1 ? 1 : clampedRating + 1; |
| 63 | + let itemDef = InventoryAPI.GetItemDefinitionIndexFromDefinitionName('premier season coin s=2 c=' + clampedRating + ' b=' + nBars); |
| 64 | + let itemId = InventoryAPI.GetFauxItemIDFromDefAndPaintIndex(itemDef, 0); |
| 65 | + $.GetContextPanel().FindChildInLayoutFile('id-medal-end').itemid = itemId; |
| 66 | + $.GetContextPanel().SetDialogVariableInt('wins', nWins); |
| 67 | + $.GetContextPanel().SetDialogVariableInt('threshold', nBars * 25); |
| 68 | + } |
| 69 | + function ReadyForDisplay() { |
| 70 | + SetRating(); |
| 71 | + } |
| 72 | + SeasonProgress.ReadyForDisplay = ReadyForDisplay; |
| 73 | + function UnReadyForDisplay() { |
| 74 | + } |
| 75 | + SeasonProgress.UnReadyForDisplay = UnReadyForDisplay; |
| 76 | + function PipRankUpdate() { |
| 77 | + SetRating(); |
| 78 | + } |
| 79 | + SeasonProgress.PipRankUpdate = PipRankUpdate; |
| 80 | + { |
| 81 | + $.RegisterEventHandler('ReadyForDisplay', $.GetContextPanel(), SeasonProgress.ReadyForDisplay); |
| 82 | + $.RegisterEventHandler('UnreadyForDisplay', $.GetContextPanel(), SeasonProgress.UnReadyForDisplay); |
| 83 | + $.RegisterForUnhandledEvent('PanoramaComponent_MyPersona_PipRankUpdate', PipRankUpdate); |
| 84 | + _Init(); |
| 85 | + } |
| 86 | +})(SeasonProgress || (SeasonProgress = {})); |
0 commit comments