| 1 |
--[[ Copyright (c) 2010 Miika-Petteri Matikainen |
| 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 |
|
| 22 |
--! Dialog for staff member requesting a salaray raise. |
| 23 |
class "UIStaffRise" (Window) |
| 24 |
|
| 25 |
---@type UIStaffRise |
| 26 |
local UIStaffRise = _G["UIStaffRise"] |
| 27 |
|
| 28 |
function UIStaffRise:UIStaffRise(ui, staff, rise_amount) |
| 29 |
self:Window() |
| 30 |
local app = ui.app |
| 31 |
local profile = staff.profile |
| 32 |
|
| 33 |
self.esc_closes = false -- Do not allow closing the dialog with esc |
| 34 |
self.staff = staff |
| 35 |
self.ui = ui |
| 36 |
self.rise_amount = rise_amount |
| 37 |
self.on_top = true |
| 38 |
|
| 39 |
local final_wage = self.staff.profile.wage + rise_amount |
| 40 |
self.text = _S.pay_rise.regular.__random:format(rise_amount, final_wage) -- Random complaint text |
| 41 |
|
| 42 |
self.width = 362 |
| 43 |
self.height = 288 |
| 44 |
|
| 45 |
-- Center the dialog |
| 46 |
self:setDefaultPosition(0.5, 0.5) |
| 47 |
|
| 48 |
self.panel_sprites = app.gfx:loadSpriteTable("QData", "Req12V", true) |
| 49 |
self.white_font = app.gfx:loadFontAndSpriteTable("QData", "Font01V", nil, nil, { apply_ui_scale = true }) |
| 50 |
self.black_font = app.gfx:loadFontAndSpriteTable("QData", "Font00V", nil, nil, { apply_ui_scale = true }) |
| 51 |
self.face_parts = app.gfx:loadRaw("Face01V", 65, 1350, nil, "Data", "MPalette.dat", false, { flags = DrawFlags.Nearest }) |
| 52 |
|
| 53 |
-- Left hand side |
| 54 |
self:addPanel(280, 0, 0) |
| 55 |
self:addPanel(281, 0, 54) |
| 56 |
self:addPanel(281, 0, 64) |
| 57 |
self:addPanel(281, 0, 64) |
| 58 |
self:addPanel(281, 0, 74) |
| 59 |
self:addPanel(281, 0, 84) |
| 60 |
self:addPanel(281, 0, 94) |
| 61 |
self:addPanel(281, 0, 104) |
| 62 |
self:addPanel(282, 0, 114) |
| 63 |
self:addPanel(283, 0, 171) |
| 64 |
self:addPanel(284, 0, 214) |
| 65 |
self:addColourPanel(96, 44, 72, 81, 211, 255, 255) -- Portrait background |
| 66 |
|
| 67 |
-- Right hand side |
| 68 |
self:addPanel(285, 180, 0) |
| 69 |
self:addPanel(286, 180, 20) |
| 70 |
self:addPanel(286, 180, 48) |
| 71 |
self:addPanel(286, 180, 76) |
| 72 |
self:addPanel(286, 180, 104) |
| 73 |
self:addPanel(286, 180, 132) |
| 74 |
self:addPanel(286, 180, 160) |
| 75 |
self:addPanel(287, 180, 188) |
| 76 |
self:addPanel(288, 180, 233):makeButton(0, 0, 90, 45, 289, self.increaseSalary):setTooltip(_S.tooltip.pay_rise_window.accept) |
| 77 |
self:addPanel(290, 270, 233):makeButton(0, 0, 90, 45, 291, self.fireStaff):setTooltip(_S.tooltip.pay_rise_window.decline) |
| 78 |
|
| 79 |
self:makeTooltip(_S.tooltip.staff_window.name, 14, 15, 169, 38) |
| 80 |
self:makeTooltip(_S.tooltip.staff_window.face, 96, 44, 168, 125) |
| 81 |
self:makeTooltip(_S.tooltip.staff_window.salary, 14, 171, 168, 193) |
| 82 |
self:makeTooltip(_S.tooltip.staff_window.ability, 12, 213, 89, 243) |
| 83 |
|
| 84 |
if class.is(staff, Doctor) then |
| 85 |
self:makeTooltip(_S.tooltip.staff_window.doctor_seniority, 89, 197, 168, 243) |
| 86 |
self:makeTooltip(_S.tooltip.staff_window.skills, 14, 132, 47, 166) |
| 87 |
|
| 88 |
-- NB: should be sufficient here to check only once, not make a dynamic tooltip |
| 89 |
if profile.is_surgeon >= 1.0 then |
| 90 |
self:makeTooltip(_S.tooltip.staff_window.surgeon, 72, 133, 87, 164) |
| 91 |
end |
| 92 |
if profile.is_psychiatrist >= 1.0 then |
| 93 |
self:makeTooltip(_S.tooltip.staff_window.psychiatrist, 87, 133, 116, 164) |
| 94 |
end |
| 95 |
if profile.is_researcher >= 1.0 then |
| 96 |
self:makeTooltip(_S.tooltip.staff_window.researcher, 116, 133, 146, 164) |
| 97 |
end |
| 98 |
else |
| 99 |
-- Hide doctor specific information |
| 100 |
self:addColourPanel(10, 130, 160, 40, 60, 174, 203) |
| 101 |
self:addColourPanel(89, 198, 81, 45, 60, 174, 203) |
| 102 |
end |
| 103 |
end |
| 104 |
|
| 105 |
-- Staff raise requests pause game |
| 106 |
function UIStaffRise:mustPause() |
| 107 |
return true |
| 108 |
end |
| 109 |
|
| 110 |
function UIStaffRise:getStaffPosition(dx, dy) |
| 111 |
local staff = self.staff |
| 112 |
local x, y = self.ui.app.map:WorldToScreen(staff.tile_x, staff.tile_y) |
| 113 |
local px, py = staff.th:getSecondaryMarker() |
| 114 |
return x + px - (dx or 0), y + py - (dy or 0) |
| 115 |
end |
| 116 |
|
| 117 |
function UIStaffRise:draw(canvas, x, y) |
| 118 |
Window.draw(self, canvas, x, y) |
| 119 |
local profile = self.staff.profile |
| 120 |
local s = TheApp.config.ui_scale |
| 121 |
x, y = self.x * s + x, self.y * s + y |
| 122 |
local px, py = self:getStaffPosition(37, 61) |
| 123 |
local font = self.white_font |
| 124 |
|
| 125 |
profile:drawFace(canvas, x + 99 * s, y + 47 * s, self.face_parts, s) -- Portrait |
| 126 |
canvas:scale(s) |
| 127 |
self.ui.app.map:draw(canvas, px, py, 71, 81, math.floor(x / s) + 16, math.floor(y / s) + 44) -- Viewport |
| 128 |
canvas:scale(1) |
| 129 |
|
| 130 |
font:draw(canvas, profile:getFullName(), x + 20 * s, y + 20 * s) -- Name |
| 131 |
font:draw(canvas, "$" .. profile.wage, x + 60 * s, y + 178 * s) -- Wage |
| 132 |
|
| 133 |
-- Ability |
| 134 |
-- Note: The bar looks like "attention to detail", but actually ability level |
| 135 |
-- is displayed here. This was the same in TH, and makes more sense. |
| 136 |
-- However at some point we should fix the graphics to look like an ability bar. |
| 137 |
local ability_bar_width = math.floor(profile.skill * 40 * s + 0.5) |
| 138 |
if ability_bar_width ~= 0 then |
| 139 |
for dx = 0, ability_bar_width - 1 do |
| 140 |
self.panel_sprites:draw(canvas, 295, x + 42 * s + dx, y + 230 * s, { scaleFactor = s }) |
| 141 |
end |
| 142 |
end |
| 143 |
|
| 144 |
if class.is(self.staff, Doctor) then |
| 145 |
self:drawDoctorAttributes(canvas) |
| 146 |
end |
| 147 |
|
| 148 |
-- Complaint text |
| 149 |
self.black_font:drawWrapped(canvas, self.text, x + 200 * s, y + 20 * s, 140 * s) |
| 150 |
end |
| 151 |
|
| 152 |
function UIStaffRise:drawDoctorAttributes(canvas) |
| 153 |
local profile = self.staff.profile |
| 154 |
local s = TheApp.config.ui_scale |
| 155 |
local x, y = self.x * s, self.y * s |
| 156 |
|
| 157 |
-- Junior / Doctor / Consultant marker |
| 158 |
local marker_x = x + 98 * s |
| 159 |
if profile.is_consultant then |
| 160 |
marker_x = marker_x + 52 * s |
| 161 |
elseif not profile.is_junior then |
| 162 |
marker_x = marker_x + 22 * s |
| 163 |
end |
| 164 |
|
| 165 |
self.panel_sprites:draw(canvas, 296, marker_x, y + 230 * s, { scaleFactor = s }) |
| 166 |
|
| 167 |
-- Ability markers |
| 168 |
if profile.is_surgeon >= 1.0 then |
| 169 |
self.panel_sprites:draw(canvas, 292, x + 74 * s, y + 133 * s, { scaleFactor = s }) |
| 170 |
end |
| 171 |
if profile.is_psychiatrist >= 1.0 then |
| 172 |
self.panel_sprites:draw(canvas, 293, x + 90 * s, y + 139 * s, { scaleFactor = s }) |
| 173 |
end |
| 174 |
if profile.is_researcher >= 1.0 then |
| 175 |
self.panel_sprites:draw(canvas, 294, x + 120 * s, y + 138 * s, { scaleFactor = s}) |
| 176 |
end |
| 177 |
end |
| 178 |
|
| 179 |
function UIStaffRise:fireStaff() |
| 180 |
self.staff.message_callback = nil |
| 181 |
self.staff:fire() |
| 182 |
self:close() |
| 183 |
end |
| 184 |
|
| 185 |
function UIStaffRise:increaseSalary() |
| 186 |
self.staff.message_callback = nil |
| 187 |
self.staff:increaseWage(self.rise_amount) |
| 188 |
self.staff.quitting_in = nil |
| 189 |
self:close() |
| 190 |
end |
| 191 |
|
| 192 |
function UIStaffRise:afterLoad(old, new) |
| 193 |
Window.afterLoad(self, old, new) |
| 194 |
if old < 236 then |
| 195 |
self.white_font = TheApp.gfx:loadFontAndSpriteTable("QData", "Font01V", nil, nil, { apply_ui_scale = true }) |
| 196 |
self.black_font = TheApp.gfx:loadFontAndSpriteTable("QData", "Font00V", nil, nil, { apply_ui_scale = true }) |
| 197 |
self.face_parts = TheApp.gfx:loadRaw("Face01V", 65, 1350, nil, "Data", "MPalette.dat", false, { flags = DrawFlags.Nearest }) |
| 198 |
end |
| 199 |
end |