|
| 1 | +-- TODO: long term - implement new UI resembling original game design |
| 2 | +-- more code cleanup? |
| 3 | +local SCREEN_WIDTH, SCREEN_HEIGHT = guiGetScreenSize() |
| 4 | + |
| 5 | +-- |
| 6 | +-- client HUD definitions |
| 7 | +-- |
| 8 | +_hud = {} |
| 9 | +-- loading screen |
| 10 | +_hud.loadingScreen = {} |
| 11 | +_hud.loadingScreen.deathmatchText = dxText:create("Deathmatch", 0, 0, false, "bankgothic", 2) |
| 12 | +_hud.loadingScreen.deathmatchText:color(230, 200, 110) |
| 13 | +_hud.loadingScreen.deathmatchText:boundingBox(0, 0, 1, 0.2, true) |
| 14 | +_hud.loadingScreen.deathmatchText:align("bottom", "center") |
| 15 | +_hud.loadingScreen.deathmatchText:type("stroke", 1) |
| 16 | +_hud.loadingScreen.mapInfoText = dxText:create("", 0, 0, false, "pricedown", 2) |
| 17 | +_hud.loadingScreen.mapInfoText:color(125, 85, 13) |
| 18 | +_hud.loadingScreen.mapInfoText:boundingBox(0, 0.65, 0.95, 1, true) |
| 19 | +_hud.loadingScreen.mapInfoText:align("right", "top") |
| 20 | +_hud.loadingScreen.mapInfoText:type("stroke", 1) |
| 21 | +_hud.loadingScreen.setVisible = function(_, visible) |
| 22 | + _hud.loadingScreen.deathmatchText:visible(visible) |
| 23 | + _hud.loadingScreen.mapInfoText:visible(visible) |
| 24 | +end |
| 25 | +_hud.loadingScreen.update = function() |
| 26 | + _hud.loadingScreen.mapInfoText:text(_mapTitle..(_mapAuthor and ("\n by ".._mapAuthor) or "")) |
| 27 | +end |
| 28 | +-- score display |
| 29 | +_hud.scoreDisplay = {} |
| 30 | +_hud.scoreDisplay.roundInfoText = dxText:create("", 0, 0, false, "bankgothic", 1) |
| 31 | +_hud.scoreDisplay.roundInfoText:color(175, 200, 240) |
| 32 | +_hud.scoreDisplay.roundInfoText:boundingBox(0, 0, 0.95, 0.95, true) |
| 33 | +_hud.scoreDisplay.roundInfoText:align("right", "bottom") |
| 34 | +_hud.scoreDisplay.roundInfoText:type("stroke", 1) |
| 35 | +_hud.scoreDisplay.setVisible = function(_, visible) |
| 36 | + _hud.scoreDisplay.roundInfoText:visible(visible) |
| 37 | +end |
| 38 | +_hud.scoreDisplay.update = function() |
| 39 | + -- don't do anything if a round isn't in progress |
| 40 | + if getElementData(resourceRoot, "gameState") ~= GAME_IN_PROGRESS then |
| 41 | + return |
| 42 | + end |
| 43 | + -- update score and rank text |
| 44 | + local score = getElementData(localPlayer, "Score") |
| 45 | + local rank = getElementData(localPlayer, "Rank") |
| 46 | + _hud.scoreDisplay.roundInfoText:text( |
| 47 | + "Score: "..score..(_fragLimit > 0 and "/".._fragLimit or "") |
| 48 | + .."\nRank: "..getElementData(localPlayer, "Rank").."/"..#getElementsByType("player") |
| 49 | + ) |
| 50 | +end |
| 51 | +-- respawn screen |
| 52 | +_hud.respawnScreen = {} |
| 53 | +-- respawn counter (You will respawn in x seconds) |
| 54 | +_hud.respawnScreen.respawnCounter = dxText:create("", 0.5, 0.5, true, "beckett", 4) |
| 55 | +_hud.respawnScreen.respawnCounter:type("stroke", 6) |
| 56 | +_hud.respawnScreen.respawnCounter:color(255, 225, 225) |
| 57 | +_hud.respawnScreen.respawnCounter:visible(false) |
| 58 | +_hud.respawnScreen.setVisible = function(_, visible) |
| 59 | + _hud.respawnScreen.respawnCounter:visible(visible) |
| 60 | +end |
| 61 | +_hud.respawnScreen.startCountdown = function() |
| 62 | + if _respawnTime > 0 then |
| 63 | + startCountdown(_respawnTime) |
| 64 | + else |
| 65 | + _hud.respawnScreen.respawnCounter:text("Wasted") |
| 66 | + end |
| 67 | +end |
| 68 | +-- end screen |
| 69 | +_hud.endScreen = {} |
| 70 | +-- announcement text (x has won the round!) |
| 71 | +_hud.endScreen.announcementText = dxText:create("", 0, 0, false, "pricedown", 2) |
| 72 | +_hud.endScreen.announcementText:color(225, 225, 225, 225) |
| 73 | +_hud.endScreen.announcementText:boundingBox(0, 0, 1, 0.2, true) |
| 74 | +_hud.endScreen.announcementText:align("bottom", "center") |
| 75 | +_hud.endScreen.announcementText:type("border", 1) |
| 76 | +_hud.endScreen.setVisible = function(_, visible) |
| 77 | + _hud.endScreen.announcementText:visible(visible) |
| 78 | +end |
| 79 | +_hud.endScreen.update = function(_, winner, draw, aborted) |
| 80 | + if winner then |
| 81 | + _hud.endScreen.announcementText:text(getPlayerName(winner).." has won the round!") |
| 82 | + _hud.endScreen.announcementText:color(getPlayerNametagColor(winner)) |
| 83 | + else |
| 84 | + if draw then |
| 85 | + _hud.endScreen.announcementText:text("The round was a draw!") |
| 86 | + else |
| 87 | + _hud.endScreen.announcementText:text("Round ended.") |
| 88 | + end |
| 89 | + _hud.endScreen.announcementText:color(225, 225, 225, 225) |
| 90 | + end |
| 91 | + if not aborted then |
| 92 | + playSound("client/audio/mission_accomplished.mp3") |
| 93 | + end |
| 94 | +end |
| 95 | +-- hide all HUD elements by default |
| 96 | +_hud.loadingScreen:setVisible(false) |
| 97 | +_hud.scoreDisplay:setVisible(false) |
| 98 | +_hud.respawnScreen:setVisible(false) |
| 99 | +_hud.endScreen:setVisible(false) |
| 100 | + |
| 101 | +-- TODO: clean this junk up |
| 102 | +local function dxSetAlpha ( dx, a ) |
| 103 | + local r,g,b = dx:color() |
| 104 | + dx:color(r,g,b,a) |
| 105 | +end |
| 106 | + |
| 107 | +local countdownCR |
| 108 | +local function countdown(time) |
| 109 | + for i=time,0,-1 do |
| 110 | + _hud.respawnScreen.respawnCounter:text("Wasted\n"..i) |
| 111 | + setTimer ( countdownCR, 1000, 1 ) |
| 112 | + coroutine.yield() |
| 113 | + end |
| 114 | +end |
| 115 | + |
| 116 | +local function hideCountdown() |
| 117 | + setTimer ( |
| 118 | + function() |
| 119 | + _hud.respawnScreen:setVisible(false) |
| 120 | + end, |
| 121 | + 600, 1 |
| 122 | + ) |
| 123 | + Animation.createAndPlay( |
| 124 | + _hud.respawnScreen.respawnCounter, |
| 125 | + {{ from = 225, to = 0, time = 400, fn = dxSetAlpha }} |
| 126 | + ) |
| 127 | + removeEventHandler ( "onClientPlayerSpawn", localPlayer, hideCountdown ) |
| 128 | +end |
| 129 | + |
| 130 | +function startCountdown(time) |
| 131 | + Animation.createAndPlay( |
| 132 | + _hud.respawnScreen.respawnCounter, |
| 133 | + {{ from = 0, to = 225, time = 600, fn = dxSetAlpha }} |
| 134 | + ) |
| 135 | + addEventHandler ( "onClientPlayerSpawn", localPlayer, hideCountdown ) |
| 136 | + _hud.respawnScreen:setVisible(true) |
| 137 | + time = math.floor(time/1000) |
| 138 | + countdownCR = coroutine.wrap(countdown) |
| 139 | + countdownCR(time) |
| 140 | +end |
0 commit comments