| 1 |
--[[ Copyright (c) 2010 Edvin "Lego3" Linge |
| 2 |
|
| 3 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 |
this software and associated documentation files (the "Software"), to deal in |
| 5 |
the Software without restriction, including without limitation the rights to |
| 6 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 7 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 8 |
so, subject to the following conditions: |
| 9 |
|
| 10 |
The above copyright notice and this permission notice shall be included in all |
| 11 |
copies or substantial portions of the Software. |
| 12 |
|
| 13 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 |
SOFTWARE. --]] |
| 20 |
|
| 21 |
--! Annual Report fullscreen window shown at the start of each year. |
| 22 |
class "UIAnnualReport" (UIFullscreen) |
| 23 |
|
| 24 |
---@type UIAnnualReport |
| 25 |
local UIAnnualReport = _G["UIAnnualReport"] |
| 26 |
|
| 27 |
--! Helper function that enables and makes visible button or table of buttons/panels. |
| 28 |
--!param button The button or table of buttons that should be activated/deactivated. If |
| 29 |
-- a table is given it needs to have the is_table flag set to true. |
| 30 |
--!param active Defines if the new state is active (true) or inactive (false). |
| 31 |
local function setActive(button, active) |
| 32 |
if button.is_table then |
| 33 |
for _, btn in ipairs(button) do |
| 34 |
btn.enabled = active |
| 35 |
btn.visible = active |
| 36 |
end |
| 37 |
else |
| 38 |
button.enabled = active |
| 39 |
button.visible = active |
| 40 |
end |
| 41 |
end |
| 42 |
|
| 43 |
function UIAnnualReport:UIAnnualReport(ui, world) |
| 44 |
|
| 45 |
self:UIFullscreen(ui) |
| 46 |
|
| 47 |
self.ui = ui |
| 48 |
local gfx = ui.app.gfx |
| 49 |
self.won_amount = 0 |
| 50 |
self.award_won_amount = 0 |
| 51 |
self.rep_amount = 0 |
| 52 |
|
| 53 |
if not pcall(function() |
| 54 |
local palette = gfx:getPalette("Award02V.pal") |
| 55 |
|
| 56 |
-- Right now the statistics are first |
| 57 |
--self.background = gfx:loadRaw("Fame01V", 640, 480) |
| 58 |
self.award_background = gfx:loadRaw("Award01V", 640, 480) |
| 59 |
self.stat_background = gfx:loadRaw("Award02V", 640, 480, "QData", "QData", "Award02V.pal", true) |
| 60 |
self.background = self.stat_background |
| 61 |
|
| 62 |
local stone_text_color = { red = 80, green = 60, blue = 35 } |
| 63 |
self.stat_font = gfx:loadFontAndSpriteTable("QData", "Font45V", false, palette, { apply_ui_scale = true }) |
| 64 |
self.write_font = gfx:loadFontAndSpriteTable("QData", "Font47V", false, palette, { apply_ui_scale = true }) |
| 65 |
self.stone_font = gfx:loadFontAndSpriteTable("QData", "Font46V", false, palette, {ttf_color = stone_text_color, apply_ui_scale = true }) |
| 66 |
|
| 67 |
self.panel_sprites = gfx:loadSpriteTable("QData", "Award03V", true, palette) |
| 68 |
end) then |
| 69 |
ui:addWindow(UIInformation(ui, {_S.errors.dialog_missing_graphics})) |
| 70 |
self:close() |
| 71 |
return |
| 72 |
end |
| 73 |
------------------------ The current state the dialog is in. --------------------------- |
| 74 |
-- Possible values are 1, 2 and 3 = fame, statistics and awards pages respectively |
| 75 |
-- TODO: The dialog has some preparations for the fame screen, but as long as there are no |
| 76 |
-- competitor scores and the player's own score isn't increased anywhere there's no use in |
| 77 |
-- showing it. Only hall of fame is there right now too, and maybe it should be a |
| 78 |
-- stand alone dialog since it has (2) sprites in another sprite file? |
| 79 |
self.state = 2 |
| 80 |
self.default_button_sound = "selectx.wav" |
| 81 |
|
| 82 |
-- Close button, in the future different behaviours for different screens though |
| 83 |
--self.first_close = self:addPanel(0, 609, 449):makeButton(0, 0, 26, 26, 1, self.changePage) |
| 84 |
self.second_close = self:addPanel(0, 608, 449):makeButton(0, 0, 26, 26, 1, self.close) |
| 85 |
setActive(self.second_close, true) |
| 86 |
|
| 87 |
-- Change page buttons for the second and third pages |
| 88 |
local --[[persistable:annual_report_change_page]] function change() self:changePage(3) end |
| 89 |
self.second_change = self:addPanel(0, 274, 435):makeButton(0, 0, 91, 42, 3, change) |
| 90 |
setActive(self.second_change, true) |
| 91 |
|
| 92 |
self.third_change = self:addPanel(0, 272, 367):makeButton(0, 0, 91, 42, 3, self.changePage) |
| 93 |
setActive(self.third_change, false) |
| 94 |
|
| 95 |
-- The plaque showed after the player has clicked on a trophy |
| 96 |
local plaque = {} |
| 97 |
plaque[1] = self:addPanel(19, 206, 87) |
| 98 |
plaque[2] = self:addPanel(20, 206, 161) |
| 99 |
plaque[3] = self:addPanel(21, 206, 233) |
| 100 |
plaque[4] = self:addPanel(22, 206, 321) |
| 101 |
plaque.is_table = true |
| 102 |
self.plaque = plaque |
| 103 |
setActive(self.plaque, false) |
| 104 |
|
| 105 |
-- Close button for the trophy motivations |
| 106 |
self.third_close = self:addPanel(0, 389, 378):makeButton(0, 0, 26, 26, 2, self.showTrophyMotivation) |
| 107 |
setActive(self.third_close, false) |
| 108 |
|
| 109 |
-- The scroll showed after the player has clicked on an award |
| 110 |
local scroll = {} |
| 111 |
scroll[1] = self:addPanel(16, 206, 87) |
| 112 |
scroll[2] = self:addPanel(17, 206, 200) |
| 113 |
scroll[3] = self:addPanel(18, 206, 304) |
| 114 |
scroll[4] = self:addPanel(15, 300, 341) |
| 115 |
scroll.is_table = true |
| 116 |
self.scroll = scroll |
| 117 |
setActive(self.scroll, false) |
| 118 |
|
| 119 |
-- Close button for the award motivations |
| 120 |
self.fourth_close = self:addPanel(0, 369, 358):makeButton(0, 0, 26, 26, 2, self.showAwardMotivation) |
| 121 |
setActive(self.fourth_close, false) |
| 122 |
|
| 123 |
-- How many awards the player got this year. Will increase after the checkup. |
| 124 |
self.no_awards = 0 |
| 125 |
self.awards = {} |
| 126 |
|
| 127 |
-- Trophies. Currently the soda and the reputation award have been implemented |
| 128 |
self.no_trophies = 0 |
| 129 |
self.trophies = {} |
| 130 |
|
| 131 |
-- Check which awards and trophies the player should get. |
| 132 |
self:checkTrophiesAndAwards(world) |
| 133 |
|
| 134 |
-- Get and sort values used on the statistics screen. |
| 135 |
-- The six categories. The extra tables are used to be able to sort the values. |
| 136 |
self.money_sort = {} |
| 137 |
self.visitors_sort = {} |
| 138 |
self.salary_sort = {} |
| 139 |
self.deaths_sort = {} |
| 140 |
self.cures_sort = {} |
| 141 |
self.value_sort = {} |
| 142 |
|
| 143 |
-- TODO: Right now there are no real competitors, they all have initial values. |
| 144 |
for i, hospital in ipairs(world.hospitals) do |
| 145 |
self.money_sort[i] = {value = math.floor(hospital.balance - hospital.loan), hosp_index = i} |
| 146 |
self.visitors_sort[i] = {value = hospital.num_visitors, hosp_index = i} |
| 147 |
self.deaths_sort[i] = {value = hospital.num_deaths, hosp_index = i} |
| 148 |
self.cures_sort[i] = {value = hospital.num_cured, hosp_index = i} |
| 149 |
self.value_sort[i] = {value = math.floor(hospital.value), hosp_index = i} |
| 150 |
self.salary_sort[i] = {value = math.floor(hospital.player_salary), hosp_index = i} |
| 151 |
end |
| 152 |
|
| 153 |
-- sort putting local player hospital first when values the same |
| 154 |
local desc_order = function(a,b) return a.value > b.value or (a.value == b.value and a.hosp_index < b.hosp_index) end |
| 155 |
local asc_order = function(a,b) return a.value < b.value or (a.value == b.value and a.hosp_index < b.hosp_index) end |
| 156 |
table.sort(self.money_sort, desc_order) |
| 157 |
table.sort(self.visitors_sort, desc_order) |
| 158 |
table.sort(self.deaths_sort, asc_order) |
| 159 |
table.sort(self.cures_sort, desc_order) |
| 160 |
table.sort(self.value_sort, desc_order) |
| 161 |
table.sort(self.salary_sort, desc_order) |
| 162 |
|
| 163 |
TheApp.video:setBlueFilterActive(false) |
| 164 |
end |
| 165 |
|
| 166 |
-- Make sure this window pauses the game, we want to let the player browse their awards |
| 167 |
function UIAnnualReport:mustPause() |
| 168 |
return true |
| 169 |
end |
| 170 |
|
| 171 |
--! Finds out which awards and/or trophies the player has been awarded this year. |
| 172 |
function UIAnnualReport:checkTrophiesAndAwards(world) |
| 173 |
|
| 174 |
local hosp = self.ui.hospital |
| 175 |
local level_config = world.map.level_config |
| 176 |
local prices = level_config and level_config.awards_trophies or nil |
| 177 |
|
| 178 |
local anybody_cured = hosp.num_cured_ty > 1 |
| 179 |
|
| 180 |
-- Check CuresAward so that we know the new config settings are available |
| 181 |
if prices and prices.TrophyMayorBonus then |
| 182 |
self.won_amount = 0 |
| 183 |
self.rep_amount = 0 |
| 184 |
self.award_won_amount = 0 |
| 185 |
|
| 186 |
|
| 187 |
-- The trophies and certificated awards/penalties available at this time -- |
| 188 |
|
| 189 |
|
| 190 |
-------------------------------- Trophies --------------------------------- |
| 191 |
|
| 192 |
|
| 193 |
-- Coke sales |
| 194 |
if hosp.sodas_sold > prices.CansofCoke then |
| 195 |
-- Bonus |
| 196 |
self:addTrophy(_S.trophy_room.sold_drinks.trophies[math.random(1, 3)], "money", prices.CansofCokeBonus) |
| 197 |
self.won_amount = self.won_amount + prices.CansofCokeBonus |
| 198 |
end |
| 199 |
-- Impressive VIP visits |
| 200 |
if anybody_cured and hosp.num_vips_ty > 0 and hosp.pleased_vips_ty == hosp.num_vips_ty then |
| 201 |
-- Bonus |
| 202 |
local win_value = (prices.TrophyMayorBonus * hosp.pleased_vips_ty) + math.random(1, 5) |
| 203 |
self:addTrophy(_S.trophy_room.happy_vips.trophies[math.random(1, 3)], "reputation", win_value) |
| 204 |
self.rep_amount = self.rep_amount + win_value |
| 205 |
end |
| 206 |
-- Impressive Reputation in the year (above a threshold throughout the year) |
| 207 |
if anybody_cured and hosp.has_impressive_reputation then |
| 208 |
-- Bonus |
| 209 |
self:addTrophy(_S.trophy_room.consistant_rep.trophies[math.random(1, 2)], "money", prices.TrophyReputationBonus) |
| 210 |
self.won_amount = self.won_amount + prices.TrophyReputationBonus |
| 211 |
end |
| 212 |
-- Everyone treated successfully, no deaths, or around a 100% Cure rate in the year |
| 213 |
if anybody_cured and hosp.num_deaths_this_year == 0 and hosp.not_cured_ty == 0 then |
| 214 |
-- Bonus |
| 215 |
self:addTrophy(_S.trophy_room.all_cured.trophies[math.random(1, 2)], "money", prices.TrophyAllCuredBonus) |
| 216 |
self.won_amount = self.won_amount + prices.TrophyAllCuredBonus |
| 217 |
elseif anybody_cured and hosp.num_deaths_this_year == 0 then |
| 218 |
-- Bonus |
| 219 |
self:addTrophy(_S.trophy_room.no_deaths.trophies[math.random(1, 3)], "money", prices.TrophyDeathBonus) |
| 220 |
self.won_amount = self.won_amount + prices.TrophyDeathBonus |
| 221 |
elseif anybody_cured and hosp.num_cured_ty > (hosp.not_cured_ty * 0.9) then |
| 222 |
-- Bonus |
| 223 |
self:addTrophy(_S.trophy_room.many_cured.trophies[math.random(1, 3)], "money", prices.TrophyCuresBonus) |
| 224 |
self.won_amount = self.won_amount + prices.TrophyCuresBonus |
| 225 |
end |
| 226 |
|
| 227 |
|
| 228 |
-------------------- Certificate Awards or Penalties --------------------- |
| 229 |
|
| 230 |
|
| 231 |
-- Reputation |
| 232 |
if anybody_cured and hosp.reputation > prices.ReputationAward then |
| 233 |
-- Bonus |
| 234 |
self:addAward(_S.trophy_room.high_rep.awards[math.random(1, 2)], "money", prices.AwardReputationBonus) |
| 235 |
self.award_won_amount = self.award_won_amount + prices.AwardReputationBonus |
| 236 |
elseif hosp.reputation < prices.ReputationPoor then |
| 237 |
-- Penalty |
| 238 |
self:addAward(_S.trophy_room.high_rep.penalty[math.random(1, 2)], "money", prices.AwardReputationPenalty) |
| 239 |
self.award_won_amount = self.award_won_amount + prices.AwardReputationPenalty |
| 240 |
end |
| 241 |
|
| 242 |
-- Hospital Value |
| 243 |
if anybody_cured and hosp.value > prices.HospValueAward then |
| 244 |
-- Bonus |
| 245 |
local win_value = prices.HospValueBonus * math.random(1, 15) |
| 246 |
self:addAward(_S.trophy_room.hosp_value.awards[1], "reputation", win_value) |
| 247 |
self.rep_amount = self.rep_amount + win_value |
| 248 |
elseif hosp.value < prices.HospValuePoor then |
| 249 |
-- Penalty |
| 250 |
local lose_value = prices.HospValuePenalty * math.random(1, 15) |
| 251 |
self:addAward(_S.trophy_room.hosp_value.penalty[1], "reputation", lose_value) |
| 252 |
self.rep_amount = self.rep_amount + lose_value |
| 253 |
end |
| 254 |
|
| 255 |
-- Should these next few be linked so that you can only get one or should you get more than one if you met the targets? |
| 256 |
|
| 257 |
-- Cures |
| 258 |
if anybody_cured and hosp.num_cured_ty > prices.CuresAward then |
| 259 |
-- Bonus |
| 260 |
self:addAward(_S.trophy_room.many_cured.awards[math.random(1, 2)], "money", prices.CuresBonus) |
| 261 |
self.award_won_amount = self.award_won_amount + prices.CuresBonus |
| 262 |
elseif hosp.num_cured_ty < prices.CuresPoor then |
| 263 |
-- Penalty |
| 264 |
self:addAward(_S.trophy_room.many_cured.penalty[math.random(1, 2)], "money", prices.CuresPenalty) |
| 265 |
self.award_won_amount = self.award_won_amount + prices.CuresPenalty |
| 266 |
end |
| 267 |
|
| 268 |
-- Deaths |
| 269 |
if anybody_cured and hosp.num_deaths_this_year == 0 and hosp.not_cured_ty == 0 then |
| 270 |
-- Bonus |
| 271 |
self:addAward(_S.trophy_room.no_deaths.awards[1], "money", prices.AllCuresBonus) |
| 272 |
self.award_won_amount = self.award_won_amount + prices.AllCuresBonus |
| 273 |
elseif anybody_cured and hosp.num_deaths_this_year < prices.DeathsAward then |
| 274 |
-- Bonus |
| 275 |
self:addAward(_S.trophy_room.no_deaths.awards[math.random(1, 2)], "money", prices.DeathsBonus) |
| 276 |
self.award_won_amount = self.award_won_amount + prices.DeathsBonus |
| 277 |
elseif hosp.num_deaths_this_year > prices.DeathsPoor then |
| 278 |
-- Penalty |
| 279 |
self:addAward(_S.trophy_room.no_deaths.penalty[math.random(1, 2)], "money", prices.DeathsPenalty) |
| 280 |
self.award_won_amount = self.award_won_amount + prices.DeathsPenalty |
| 281 |
end |
| 282 |
|
| 283 |
-- Cures V Deaths |
| 284 |
-- This value is not really a ratio since the level files cannot contain decimal values. |
| 285 |
local cure_ratio = 100 |
| 286 |
if hosp.num_deaths_this_year > 0 then |
| 287 |
cure_ratio = hosp.num_cured_ty / hosp.num_deaths_this_year |
| 288 |
end |
| 289 |
if anybody_cured and cure_ratio > prices.CuresVDeathsAward then |
| 290 |
-- Bonus |
| 291 |
self:addAward(_S.trophy_room.curesvdeaths.awards[1], "money", prices.CuresVDeathsBonus) |
| 292 |
self.award_won_amount = self.award_won_amount + prices.CuresVDeathsBonus |
| 293 |
elseif cure_ratio <= prices.CuresVDeathsPoor then |
| 294 |
-- Penalty |
| 295 |
self:addAward(_S.trophy_room.curesvdeaths.penalty[1], "money", prices.CuresVDeathsPenalty) |
| 296 |
self.award_won_amount = self.award_won_amount + prices.CuresVDeathsPenalty |
| 297 |
end |
| 298 |
end |
| 299 |
end |
| 300 |
|
| 301 |
function UIAnnualReport:updateAwards() |
| 302 |
-- Now apply the won/lost values. |
| 303 |
local hosp = self.ui.hospital |
| 304 |
if self.won_amount ~= 0 then |
| 305 |
hosp:receiveMoney(self.won_amount, _S.transactions.eoy_trophy_bonus) |
| 306 |
end |
| 307 |
if self.award_won_amount ~= 0 then |
| 308 |
hosp:receiveMoney(self.award_won_amount, _S.transactions.eoy_bonus_penalty) |
| 309 |
end |
| 310 |
if self.rep_amount ~= 0 then |
| 311 |
hosp:changeReputation("year_end", nil, math.floor(self.rep_amount)) |
| 312 |
end |
| 313 |
end |
| 314 |
|
| 315 |
-- A table defining which type of shadow each award should have. |
| 316 |
local award_shadows = { |
| 317 |
{ shadow = 4 }, |
| 318 |
{ shadow = 4 }, |
| 319 |
{ shadow = 4 }, |
| 320 |
{ shadow = 7 }, |
| 321 |
{ shadow = 7 }, |
| 322 |
{ shadow = 9 }, |
| 323 |
} |
| 324 |
|
| 325 |
-- Another table defining some properties of the three trophies. |
| 326 |
local trophy_prop = { |
| 327 |
{ |
| 328 |
sprite = 12, |
| 329 |
x = 142, |
| 330 |
y = 324, |
| 331 |
w = 61, |
| 332 |
h = 144, |
| 333 |
}, |
| 334 |
{ |
| 335 |
sprite = 14, |
| 336 |
x = 466, |
| 337 |
y = 331, |
| 338 |
w = 72, |
| 339 |
h = 145, |
| 340 |
}, |
| 341 |
{ |
| 342 |
sprite = 13, |
| 343 |
x = 407, |
| 344 |
y = 324, |
| 345 |
w = 60, |
| 346 |
h = 144, |
| 347 |
}, |
| 348 |
} |
| 349 |
|
| 350 |
--! Adds a trophy figure with some text if the player clicks on it. |
| 351 |
--!param text (string) The text to show as motivation. |
| 352 |
--!param award_type (string) Should be one of "reputation" or "money" |
| 353 |
--!param amount (integer) How much the player got/lost. |
| 354 |
function UIAnnualReport:addTrophy(text, award_type, amount) |
| 355 |
local no = self.no_trophies + 1 |
| 356 |
-- Only show up to three trophies visually. |
| 357 |
if no <= 3 then |
| 358 |
local prop = trophy_prop[no] |
| 359 |
-- The actual figure and a button on it. |
| 360 |
local trophy_parts = {} |
| 361 |
trophy_parts.is_table = true |
| 362 |
-- Insert the info for later reference |
| 363 |
trophy_parts.info = { |
| 364 |
text = text, |
| 365 |
award_type = award_type, |
| 366 |
amount = math.floor(amount) |
| 367 |
} |
| 368 |
|
| 369 |
local --[[persistable:annual_report_show_trophy_motivation]] function change() self:showTrophyMotivation(no) end |
| 370 |
trophy_parts[1] = self:addPanel(prop.sprite, prop.x, prop.y) |
| 371 |
trophy_parts[2] = trophy_parts[1]:makeButton(0, 0, prop.w, prop.h, prop.sprite, change) |
| 372 |
|
| 373 |
setActive(trophy_parts, false) |
| 374 |
self.trophies[no] = trophy_parts |
| 375 |
end |
| 376 |
self.no_trophies = no |
| 377 |
end |
| 378 |
|
| 379 |
--! Adds an award frame with some text if the player clicks on it. |
| 380 |
--!param text (string) The text to show as motivation. |
| 381 |
--!param award_type (string) Should be one of "reputation" or "money" |
| 382 |
--!param amount (integer) How much the player got/lost. |
| 383 |
function UIAnnualReport:addAward(text, award_type, amount) |
| 384 |
-- How many awards the player has got up to this point. |
| 385 |
local no = self.no_awards + 1 |
| 386 |
if no <= 6 then |
| 387 |
-- Only visually show the first six awards. |
| 388 |
-- Add them one column at a time from the left. |
| 389 |
local x = no <= 3 and 16 or 525 |
| 390 |
local y = 74 |
| 391 |
if no % 3 == 2 then |
| 392 |
y = 189 |
| 393 |
elseif no % 3 == 0 then |
| 394 |
y = 304 |
| 395 |
end |
| 396 |
local award_parts = {} |
| 397 |
award_parts.is_table = true |
| 398 |
-- Insert the info for later reference |
| 399 |
award_parts.info = { |
| 400 |
text = text, |
| 401 |
award_type = award_type, |
| 402 |
amount = math.floor(amount) |
| 403 |
} |
| 404 |
|
| 405 |
-- The plaque |
| 406 |
if amount > 0 then |
| 407 |
-- A positive award |
| 408 |
award_parts[1] = self:addPanel(10, x + 12, y + 11) |
| 409 |
else |
| 410 |
-- A bad award |
| 411 |
award_parts[1] = self:addPanel(11, x + 12, y + 11) |
| 412 |
end |
| 413 |
-- The frame |
| 414 |
award_parts[2] = self:addPanel(23, x, y) |
| 415 |
-- The shadow |
| 416 |
award_parts[3] = self:addPanel(award_shadows[no].shadow, x, y) |
| 417 |
-- Make a button so that the player can click and see the motivation |
| 418 |
local --[[persistable:annual_report_show_award_motivation]] function change() self:showAwardMotivation(no) end |
| 419 |
award_parts[4] = award_parts[3]:makeButton(0, 0, 105, 103, award_shadows[no].shadow, change) |
| 420 |
self.awards[no] = award_parts |
| 421 |
setActive(award_parts, false) |
| 422 |
end |
| 423 |
|
| 424 |
-- The economic part of the award. |
| 425 |
self.no_awards = no |
| 426 |
end |
| 427 |
|
| 428 |
--! Activates the motivation scroll with the given text on it. |
| 429 |
--!param text_index_to_show The index of the award to show info from. |
| 430 |
function UIAnnualReport:showAwardMotivation(text_index_to_show) |
| 431 |
if text_index_to_show then |
| 432 |
-- Make sure no trophy motivation is shown |
| 433 |
self:showTrophyMotivation() |
| 434 |
setActive(self.scroll, true) |
| 435 |
-- Possibly hide the black award symbol |
| 436 |
if self.awards[text_index_to_show].info.amount > 0 then |
| 437 |
setActive(self.scroll[4], false) |
| 438 |
end |
| 439 |
setActive(self.fourth_close, true) |
| 440 |
setActive(self.third_change, false) |
| 441 |
self.award_motivation = text_index_to_show |
| 442 |
else |
| 443 |
setActive(self.scroll, false) |
| 444 |
setActive(self.fourth_close, false) |
| 445 |
setActive(self.third_change, true) |
| 446 |
self.award_motivation = nil |
| 447 |
end |
| 448 |
end |
| 449 |
|
| 450 |
--! Activates the motivation plaque with the given text on it. |
| 451 |
--!param text_index_to_show The index of the trophy to show info from. |
| 452 |
function UIAnnualReport:showTrophyMotivation(text_index_to_show) |
| 453 |
if text_index_to_show then |
| 454 |
-- Make sure no award motivation is shown |
| 455 |
self:showAwardMotivation() |
| 456 |
setActive(self.plaque, true) |
| 457 |
setActive(self.third_close, true) |
| 458 |
setActive(self.third_change, false) |
| 459 |
self.trophy_motivation = text_index_to_show |
| 460 |
else |
| 461 |
setActive(self.plaque, false) |
| 462 |
setActive(self.third_close, false) |
| 463 |
setActive(self.third_change, true) |
| 464 |
self.trophy_motivation = nil |
| 465 |
end |
| 466 |
end |
| 467 |
|
| 468 |
--! Overridden close function. The game should be unpaused again when closing the dialog. |
| 469 |
function UIAnnualReport:close() |
| 470 |
if TheApp.world:getLocalPlayerHospital().game_won then |
| 471 |
TheApp.video:setBlueFilterActive(false) |
| 472 |
end |
| 473 |
self:updateAwards() |
| 474 |
Window.close(self) |
| 475 |
self.ui.app.world:checkIfGameWon() |
| 476 |
end |
| 477 |
|
| 478 |
--! Changes the page of the annual report |
| 479 |
--!param page_no The page to go to, either page 1, 2 or 3. Default is currently page 2. |
| 480 |
function UIAnnualReport:changePage(page_no) |
| 481 |
-- Can only go to page 2 from page 1, and then only between page 2 and 3 |
| 482 |
--setActive(self.first_close, false) |
| 483 |
setActive(self.second_close, true) |
| 484 |
self.second_close.visible = true |
| 485 |
if page_no == 2 or not page_no then -- Statistics page. |
| 486 |
self.background = self.stat_background |
| 487 |
setActive(self.third_change, false) |
| 488 |
setActive(self.second_change, true) |
| 489 |
for i, _ in ipairs(self.trophies) do |
| 490 |
setActive(self.trophies[i], false) |
| 491 |
end |
| 492 |
for i, _ in ipairs(self.awards) do |
| 493 |
setActive(self.awards[i], false) |
| 494 |
end |
| 495 |
self.state = 2 |
| 496 |
else -- Awards and trophies |
| 497 |
self.background = self.award_background |
| 498 |
setActive(self.third_change, true) |
| 499 |
setActive(self.second_change, false) |
| 500 |
-- Show awards given. |
| 501 |
for i, _ in ipairs(self.awards) do |
| 502 |
setActive(self.awards[i], true) |
| 503 |
end |
| 504 |
-- And trophies given. |
| 505 |
for i, _ in ipairs(self.trophies) do |
| 506 |
setActive(self.trophies[i], true) |
| 507 |
end |
| 508 |
self.state = 3 |
| 509 |
end |
| 510 |
end |
| 511 |
|
| 512 |
function UIAnnualReport:draw(canvas, x, y) |
| 513 |
local s = TheApp.config.ui_scale |
| 514 |
canvas:scale(s, "bitmap") |
| 515 |
self.background:draw(canvas, self.x * s + x, self.y * s + y) |
| 516 |
canvas:scale(1, "bitmap") |
| 517 |
|
| 518 |
UIFullscreen.draw(self, canvas, x, y) |
| 519 |
|
| 520 |
x, y = self.x * s + x, self.y * s + y |
| 521 |
local font = self.stat_font |
| 522 |
local world = self.ui.app.world |
| 523 |
|
| 524 |
if self.state == 1 then -- Fame/Shame screen (High Scores) |
| 525 |
-- TODO: This screen should be displayed at the start of the annual report, but currently |
| 526 |
-- it is not shown, likely as the code for this being unfinished. When implemented |
| 527 |
-- we only show this screen at the very start, and once they go to the next screen |
| 528 |
-- it no longer becomes accessible. |
| 529 |
|
| 530 |
-- Title and column names |
| 531 |
font:draw(canvas, _S.high_score.best_scores, x + 220 * s, y + 104 * s, 200 * s, 0) |
| 532 |
font:draw(canvas, _S.high_score.pos, x + 218 * s, y + 132 * s) |
| 533 |
font:draw(canvas, _S.high_score.player, x + 260 * s, y + 132 * s) |
| 534 |
font:draw(canvas, _S.high_score.score, x + 360 * s, y + 132 * s) |
| 535 |
|
| 536 |
-- Players and their score |
| 537 |
local i = 1 |
| 538 |
local dy = 0 |
| 539 |
--for i = 1, 10 do |
| 540 |
font:draw(canvas, i .. ".", x + 220 * s, y + 160 * s + dy) |
| 541 |
font:draw(canvas, world:getLocalPlayerHospital().name:upper(), x + 260 * s, y + 160 * s + dy) |
| 542 |
font:draw(canvas, "NA", x + 360 * s, y + 160 * s + dy) |
| 543 |
-- dy = dy + 25 |
| 544 |
--end |
| 545 |
elseif self.state == 2 then -- Statistics screen |
| 546 |
self:drawStatisticsScreen(canvas, x, y) |
| 547 |
else -- Award and trophy screen |
| 548 |
-- Note: Each 'amount' is wrapped by string.format("%.0f", x) to persist integer notation |
| 549 |
-- Write out motivation if appropriate |
| 550 |
if self.trophy_motivation then |
| 551 |
-- If it is a plaque showing we write in stone text. |
| 552 |
local info = self.trophies[self.trophy_motivation].info |
| 553 |
self.stone_font:drawWrapped(canvas, info.text, x + 225 * s, y + 105 * s, 185 * s, "center") |
| 554 |
-- Type of award |
| 555 |
local award_type = _S.trophy_room.cash |
| 556 |
if info.award_type == "reputation" then |
| 557 |
award_type = _S.trophy_room.reputation |
| 558 |
end |
| 559 |
self.stone_font:draw(canvas, award_type, x + 220 * s, y + 330 * s, 200 * s, 0) |
| 560 |
-- Amount won/lost |
| 561 |
self.stone_font:draw(canvas, string.format("+%.0f", info.amount), x + 220 * s, y + 355 * s, 200 * s, 0) |
| 562 |
elseif self.award_motivation then |
| 563 |
local info = self.awards[self.award_motivation].info |
| 564 |
self.write_font:drawWrapped(canvas, info.text, x + 235 * s, y + 125 * s, 165 * s, "center") |
| 565 |
-- Type of award |
| 566 |
local award_type = _S.trophy_room.cash |
| 567 |
if info.award_type == "reputation" then |
| 568 |
award_type = _S.trophy_room.reputation |
| 569 |
end |
| 570 |
self.write_font:draw(canvas, award_type, x + 220 * s, y + 290 * s, 200 * s, 0) |
| 571 |
-- The amount won/lost |
| 572 |
self.write_font:draw(canvas, string.format("%+.0f", info.amount), x + 220 * s, y + 315 * s, 200 * s, 0) |
| 573 |
end |
| 574 |
end |
| 575 |
end |
| 576 |
|
| 577 |
function UIAnnualReport:drawStatisticsScreen(canvas, x, y) |
| 578 |
|
| 579 |
local font = self.stat_font |
| 580 |
local world = self.ui.app.world |
| 581 |
local s = TheApp.config.ui_scale |
| 582 |
|
| 583 |
-- Draw titles |
| 584 |
-- world date year is + 1, so adding it to 1998 realigns it |
| 585 |
font:draw(canvas, _S.menu.charts .. " " .. (world:date():year() + 1998), x + 210 * s, y + 30 * s, 200 * s, 0) |
| 586 |
font:draw(canvas, _S.high_score.categories.money, x + 140 * s, y + 98 * s, 170 * s, 0) |
| 587 |
font:draw(canvas, _S.high_score.categories.salary, x + 328 * s, y + 98 * s, 170 * s, 0) |
| 588 |
font:draw(canvas, _S.high_score.categories.cures, x + 140 * s, y + 205 * s, 170 * s, 0) |
| 589 |
font:draw(canvas, _S.high_score.categories.deaths, x + 328 * s, y + 205 * s, 170 * s, 0) |
| 590 |
font:draw(canvas, _S.high_score.categories.visitors, x + 140 * s, y + 310 * s, 170 * s, 0) |
| 591 |
font:draw(canvas, _S.high_score.categories.total_value, x + 328 * s, y + 310 * s, 170 * s, 0) |
| 592 |
|
| 593 |
-- TODO: Add possibility to right align text. |
| 594 |
|
| 595 |
-- Helper function to find where the person is in the array. |
| 596 |
-- TODO: This whole sorting thing, it should be possible to do it in a better way? |
| 597 |
local getindex = function(tablename, val) |
| 598 |
for ind, value in ipairs(tablename) do |
| 599 |
if value['hosp_index'] == val then |
| 600 |
return ind |
| 601 |
end |
| 602 |
end |
| 603 |
end |
| 604 |
|
| 605 |
local row_y = 128 * s |
| 606 |
local row_dy = 15 * s |
| 607 |
local col_x = 190 * s |
| 608 |
local row_no_y = 106 * s |
| 609 |
|
| 610 |
for i, hospital in ipairs(world.hospitals) do |
| 611 |
local name = hospital.name |
| 612 |
|
| 613 |
-- Note: Each 'value' is wrapped by string.format("%.0f", x) to persist integer notation |
| 614 |
-- Most Money |
| 615 |
local index_m = getindex(self.money_sort, i) |
| 616 |
-- index_* is the returned value of the sorted place for this player. |
| 617 |
-- However there might be many players with the same value, so each iteration a |
| 618 |
-- duplicate has been found, one additional row lower is the right place to be. |
| 619 |
font:draw(canvas, name:upper(), x + 140 * s, |
| 620 |
y + row_y + row_dy * (index_m - 1)) |
| 621 |
font:draw(canvas, string.format("%.0f", self.money_sort[index_m].value), x + 240 * s, |
| 622 |
y + row_y + row_dy * (index_m - 1), 70 * s, 0, "right") |
| 623 |
|
| 624 |
-- Highest Salary |
| 625 |
local index_s = getindex(self.salary_sort, i) |
| 626 |
font:draw(canvas, name:upper(), x + 140 * s + col_x, |
| 627 |
y + row_y + row_dy * (index_s - 1)) |
| 628 |
font:draw(canvas, string.format("%.0f", self.salary_sort[index_s].value), x + 240 * s + col_x, |
| 629 |
y + row_y + row_dy * (index_s - 1), 70 * s, 0, "right") |
| 630 |
|
| 631 |
-- Most Cures |
| 632 |
local index_c = getindex(self.cures_sort, i) |
| 633 |
font:draw(canvas, name:upper(), x + 140 * s, |
| 634 |
y + row_y + row_no_y + row_dy * (index_c - 1)) |
| 635 |
font:draw(canvas, string.format("%.0f", self.cures_sort[index_c].value), x + 240 * s, |
| 636 |
y + row_y + row_no_y + row_dy * (index_c - 1), 70 * s, 0, "right") |
| 637 |
|
| 638 |
-- Most Deaths |
| 639 |
local index_d = getindex(self.deaths_sort, i) |
| 640 |
font:draw(canvas, name:upper(), x + 140 * s + col_x, |
| 641 |
y + row_y + row_no_y + row_dy * (index_d - 1)) |
| 642 |
font:draw(canvas, string.format("%.0f", self.deaths_sort[index_d].value), x + 240 * s + col_x, |
| 643 |
y + row_y + row_no_y + row_dy * (index_d - 1), 70 * s, 0, "right") |
| 644 |
|
| 645 |
-- Most Visitors |
| 646 |
local index_v = getindex(self.visitors_sort, i) |
| 647 |
font:draw(canvas, name:upper(), x + 140 * s, |
| 648 |
y + row_y + row_no_y * 2 + row_dy * (index_v - 1)) |
| 649 |
font:draw(canvas, string.format("%.0f", self.visitors_sort[index_v].value), x + 240 * s, |
| 650 |
y + row_y + row_no_y * 2 + row_dy * (index_v - 1), 70 * s, 0, "right") |
| 651 |
|
| 652 |
-- Highest Value |
| 653 |
local index_v2 = getindex(self.value_sort, i) |
| 654 |
font:draw(canvas, name:upper(), x + 140 * s + col_x, |
| 655 |
y + row_y + row_no_y * 2 + row_dy * (index_v2 - 1)) |
| 656 |
font:draw(canvas, string.format("%.0f", self.value_sort[index_v2].value), x + 240 * s + col_x, |
| 657 |
y + row_y + row_no_y * 2 + row_dy * (index_v2 - 1), 70 * s, 0, "right") |
| 658 |
end |
| 659 |
end |
| 660 |
|
| 661 |
function UIAnnualReport:afterLoad(old, new) |
| 662 |
if old < 236 then |
| 663 |
local gfx = TheApp.gfx |
| 664 |
|
| 665 |
local palette = gfx:getPalette("Award02V.pal") |
| 666 |
self.award_background = gfx:loadRaw("Award01V", 640, 480) |
| 667 |
self.stat_background = gfx:loadRaw("Award02V", 640, 480, "QData", "QData", "Award02V.pal", true) |
| 668 |
self.background = self.stat_background |
| 669 |
local stone_text_color = { red = 80, green = 60, blue = 35 } |
| 670 |
self.stat_font = gfx:loadFontAndSpriteTable("QData", "Font45V", false, palette, { apply_ui_scale = true }) |
| 671 |
self.write_font = gfx:loadFontAndSpriteTable("QData", "Font47V", false, palette, { apply_ui_scale = true }) |
| 672 |
self.stone_font = gfx:loadFontAndSpriteTable("QData", "Font46V", false, palette, {ttf_color = stone_text_color, apply_ui_scale = true }) |
| 673 |
self.panel_sprites = gfx:loadSpriteTable("QData", "Award03V", true, palette) |
| 674 |
end |
| 675 |
|
| 676 |
UIFullscreen.afterLoad(self, old, new) |
| 677 |
end |