| 1 |
--[[ Copyright (c) 2009 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 |
local math_floor = math.floor |
| 22 |
|
| 23 |
--! Staff management screen |
| 24 |
class "UIStaffManagement" (UIFullscreen) |
| 25 |
|
| 26 |
---@type UIStaffManagement |
| 27 |
local UIStaffManagement = _G["UIStaffManagement"] |
| 28 |
|
| 29 |
function UIStaffManagement:UIStaffManagement(ui) |
| 30 |
self:UIFullscreen(ui) |
| 31 |
local gfx = ui.app.gfx |
| 32 |
if not pcall(function() |
| 33 |
self.background = gfx:loadRaw("Staff01V", 640, 480, "QData", "QData", "Staff01V.pal", true) |
| 34 |
local palette = gfx:getPalette("Staff01V.pal") |
| 35 |
self.panel_sprites = gfx:loadSpriteTable("QData", "Staff02V", true, palette) |
| 36 |
self.title_font = gfx:loadFontAndSpriteTable("QData", "Font01V", false, palette, { apply_ui_scale = true }) |
| 37 |
self.blue_font = gfx:loadFontAndSpriteTable("QData", "Font02V", false, palette, { apply_ui_scale = true }) |
| 38 |
self.face_parts = gfx:loadRaw("Face01V", 65, 1350, nil, "Data", "MPalette.dat", false, { flags = DrawFlags.Nearest }) |
| 39 |
end) then |
| 40 |
ui:addWindow(UIInformation(ui, {_S.errors.dialog_missing_graphics})) |
| 41 |
self:close() |
| 42 |
return |
| 43 |
end |
| 44 |
|
| 45 |
local hosp = ui.hospital |
| 46 |
self.ui = ui |
| 47 |
self.hospital = hosp |
| 48 |
|
| 49 |
-- Order the staff |
| 50 |
self:updateStaffList() |
| 51 |
|
| 52 |
self.default_button_sound = "selectx.wav" |
| 53 |
self.hover_id = 0 |
| 54 |
self.visual_hover_id = 0 |
| 55 |
self.hover_sound = nil; |
| 56 |
|
| 57 |
|
| 58 |
-- Close button |
| 59 |
self:addPanel(0, 603, 443):makeButton(0, 0, 26, 26, 10, self.close):setTooltip(_S.tooltip.staff_list.close) |
| 60 |
|
| 61 |
-- Top categories |
| 62 |
local --[[persistable:staff_management_category]] function category(name) |
| 63 |
self:setCategory(name) |
| 64 |
end |
| 65 |
self.categories = { |
| 66 |
self:addPanel(0, 53, 15):makeToggleButton(0, 0, 58, 58, 1, category, "Doctor"):setTooltip(_S.tooltip.staff_list.doctors), |
| 67 |
self:addPanel(0, 119, 15):makeToggleButton(0, 0, 58, 58, 1, category, "Nurse"):setTooltip(_S.tooltip.staff_list.nurses), |
| 68 |
self:addPanel(0, 185, 15):makeToggleButton(0, 0, 58, 58, 1, category, "Handyman"):setTooltip(_S.tooltip.staff_list.handymen), |
| 69 |
self:addPanel(0, 251, 15):makeToggleButton(0, 0, 58, 58, 1, category, "Receptionist"):setTooltip(_S.tooltip.staff_list.receptionists), |
| 70 |
} |
| 71 |
-- Other buttons |
| 72 |
self:addPanel(0, 12, 86):makeButton(0, 0, 31, 74, 2, self.scrollUp):setTooltip(_S.tooltip.staff_list.prev_person) |
| 73 |
self:addPanel(0, 12, 274):makeButton(0, 0, 31, 74, 3, self.scrollDown):setTooltip(_S.tooltip.staff_list.next_person) |
| 74 |
-- Disable the default sounds on the the following three buttons as their sounds are implemented in the callback. |
| 75 |
self:addPanel(0, 319, 372):makeButton(0, 0, 112, 39, 7, self.payBonus):setTooltip(_S.tooltip.staff_list.bonus):setSound() |
| 76 |
self:addPanel(0, 319, 418):makeButton(0, 0, 112, 39, 8, self.increaseSalary):setTooltip(_S.tooltip.staff_list.pay_rise):setSound() |
| 77 |
self:addPanel(0, 438, 372):makeButton(0, 0, 45, 85, 9, self.fire):setTooltip(_S.tooltip.staff_list.sack):setSound() |
| 78 |
|
| 79 |
-- "Arrow" to show title of doctors |
| 80 |
self.arrow = self:addPanel(12, 259, 397) |
| 81 |
self.arrow_position = 259 |
| 82 |
self.arrow.visible = false |
| 83 |
|
| 84 |
-- Scroll bar dot |
| 85 |
self.scroll_dot = self:addPanel(11, 21, 168) |
| 86 |
self.scroll_dot.visible = false |
| 87 |
|
| 88 |
-- Doctors' skills or progress towards them |
| 89 |
self.progress_surgeon = self:addPanel(17, 188, 408) |
| 90 |
self.progress_surgeon.visible = false |
| 91 |
self.qualified_surgeon = self:addPanel(20, 188, 408):setTooltip(_S.tooltip.staff_list.surgeon) |
| 92 |
self.qualified_surgeon.visible = false |
| 93 |
self.progress_psychiatrist = self:addPanel(18, 228, 408) |
| 94 |
self.progress_psychiatrist.visible = false |
| 95 |
self.qualified_psychiatrist = self:addPanel(21, 228, 408):setTooltip(_S.tooltip.staff_list.psychiatrist) |
| 96 |
self.qualified_psychiatrist.visible = false |
| 97 |
self.progress_researcher = self:addPanel(19, 268, 408) |
| 98 |
self.progress_researcher.visible = false |
| 99 |
self.qualified_researcher = self:addPanel(22, 268, 408):setTooltip(_S.tooltip.staff_list.researcher) |
| 100 |
self.qualified_researcher.visible = false |
| 101 |
|
| 102 |
-- Blankers for each row |
| 103 |
local row_blankers = {} |
| 104 |
for i = 1, 10 do |
| 105 |
row_blankers[i] = self:addColourPanel(50, 55 + i*27, 580, 27, 60, 174, 203) |
| 106 |
end |
| 107 |
self.row_blankers = row_blankers |
| 108 |
|
| 109 |
-- Extra background for the portrait |
| 110 |
self.portrait_back = self:addColourPanel(65, 374, 71, 81, 210, 255, 255) |
| 111 |
self.portrait_back.visible = false |
| 112 |
|
| 113 |
-- Doctor skill blankers |
| 114 |
self.title_blanker = self:addColourPanel(225, 365, 90, 39, 57, 166, 198) |
| 115 |
self.skill_blanker = self:addColourPanel(142, 406, 168, 54, 57, 166, 198) |
| 116 |
|
| 117 |
-- Tooltip regions |
| 118 |
self:makeTooltip(_S.tooltip.staff_list.happiness, 321, 51, 421, 75) |
| 119 |
self:makeTooltip(_S.tooltip.staff_list.tiredness, 426, 51, 526, 75) |
| 120 |
self:makeTooltip(_S.tooltip.staff_list.ability, 530, 51, 629, 75) |
| 121 |
self:makeTooltip(_S.tooltip.staff_list.detail, 146, 367, 226, 407) |
| 122 |
self:makeTooltip(_S.tooltip.staff_list.view_staff, 495, 371, 583, 458) |
| 123 |
|
| 124 |
self.row_tooltips = {} |
| 125 |
for line_num = 1, 10 do |
| 126 |
self.row_tooltips[line_num] = { |
| 127 |
self:makeTooltip(_S.tooltip.staff_list.salary, 193, 84 + 27 * (line_num - 1), 313, 108 + 27 * (line_num - 1)), |
| 128 |
self:makeTooltip(_S.tooltip.staff_list.happiness_2, 321, 84 + 27 * (line_num - 1), 421, 108 + 27 * (line_num - 1)), |
| 129 |
self:makeTooltip(_S.tooltip.staff_list.tiredness_2, 425, 84 + 27 * (line_num - 1), 525, 108 + 27 * (line_num - 1)), |
| 130 |
self:makeTooltip(_S.tooltip.staff_list.ability_2, 529, 84 + 27 * (line_num - 1), 628, 108 + 27 * (line_num - 1)), |
| 131 |
} |
| 132 |
end |
| 133 |
|
| 134 |
self.seniority_tooltip = |
| 135 |
self:makeTooltip(_S.tooltip.staff_list.doctor_seniority, 230, 367, 310, 407) |
| 136 |
self.skills_tooltip = |
| 137 |
self:makeTooltip(_S.tooltip.staff_list.skills, 146, 406, 186, 460) |
| 138 |
|
| 139 |
self:setCategory("Doctor") |
| 140 |
|
| 141 |
self:registerKeyHandlers() |
| 142 |
end |
| 143 |
|
| 144 |
function UIStaffManagement:registerKeyHandlers() |
| 145 |
-- Hotkeys. |
| 146 |
self:addKeyHandler("ingame_scroll_left", self.previousCategory) |
| 147 |
self:addKeyHandler("ingame_scroll_right", self.nextCategory) |
| 148 |
self:addKeyHandler("ingame_scroll_up", self.previousStaff) |
| 149 |
self:addKeyHandler("ingame_scroll_down", self.nextStaff) |
| 150 |
end |
| 151 |
|
| 152 |
function UIStaffManagement:updateTooltips() |
| 153 |
self.seniority_tooltip.enabled = self.category == "Doctor" |
| 154 |
self.skills_tooltip.enabled = self.category == "Doctor" |
| 155 |
|
| 156 |
for i, tooltips in ipairs(self.row_tooltips) do |
| 157 |
local state = 10 * (self.page - 1) + i <= #self.staff_members[self.category] |
| 158 |
for _, tooltip in ipairs(tooltips) do |
| 159 |
tooltip.enabled = state |
| 160 |
end |
| 161 |
end |
| 162 |
end |
| 163 |
|
| 164 |
function UIStaffManagement:updateStaffList(staff_member_removed) |
| 165 |
local selected_staff |
| 166 |
if staff_member_removed then |
| 167 |
-- The update was issued because someone was removed from the list, we need to handle this. |
| 168 |
selected_staff = self.staff_members[self.category][self.selected_staff] |
| 169 |
if self.staff_members[self.category][self.selected_staff] == staff_member_removed then |
| 170 |
self.selected_staff = nil |
| 171 |
selected_staff = nil |
| 172 |
end |
| 173 |
end |
| 174 |
|
| 175 |
local hosp = self.hospital |
| 176 |
local staff_members = { |
| 177 |
Doctor = {}, |
| 178 |
Nurse = {}, |
| 179 |
Handyman = {}, |
| 180 |
Receptionist = {}, |
| 181 |
} |
| 182 |
for i, staff in ipairs(hosp.staff) do |
| 183 |
staff.hire_order = i |
| 184 |
local list = staff_members[staff.profile.humanoid_class] |
| 185 |
list[#list + 1] = staff |
| 186 |
-- The selected staff might have been moved because someone else was removed from the list. |
| 187 |
if selected_staff == staff then |
| 188 |
self.selected_staff = #list |
| 189 |
end |
| 190 |
end |
| 191 |
-- Sort staff tables by attribute and direction |
| 192 |
for _, staff_tbl in pairs(staff_members) do |
| 193 |
table.sort(staff_tbl, function(left, right) |
| 194 |
local ascending = self.list_direction == "up" |
| 195 |
local a = ascending and left or right |
| 196 |
local b = not ascending and left or right |
| 197 |
if self.list_order == "hire" then |
| 198 |
return a.hire_order > b.hire_order |
| 199 |
elseif self.list_order == "morale" then |
| 200 |
return a:getAttribute("happiness") > b:getAttribute("happiness") |
| 201 |
elseif self.list_order == "tiredness" then |
| 202 |
return a:getAttribute("fatigue") > b:getAttribute("fatigue") |
| 203 |
elseif self.list_order == "skill" then |
| 204 |
return a.profile.skill > b.profile.skill |
| 205 |
end |
| 206 |
end) |
| 207 |
end |
| 208 |
self.staff_members = staff_members |
| 209 |
if staff_member_removed then |
| 210 |
self:updateTooltips() |
| 211 |
-- If we're viewing a page that no longer exists, go back a page |
| 212 |
if self.page > math.ceil(#self.staff_members[self.category] / 10) then |
| 213 |
self:scrollUp() |
| 214 |
end |
| 215 |
self:updateScrollDotVisibility() |
| 216 |
end |
| 217 |
end |
| 218 |
|
| 219 |
function UIStaffManagement:setCategory(name) |
| 220 |
|
| 221 |
self.skill_blanker.visible = name ~= "Doctor" |
| 222 |
self.title_blanker.visible = name ~= "Doctor" |
| 223 |
self.category = name |
| 224 |
for _, btn in ipairs(self.categories) do |
| 225 |
local should_be_toggled = btn.on_click_self == name |
| 226 |
if btn.toggled ~= should_be_toggled then |
| 227 |
btn:toggle() |
| 228 |
end |
| 229 |
end |
| 230 |
self.selected_staff = nil |
| 231 |
self.page = 1 |
| 232 |
self:updateScrollDotVisibility() |
| 233 |
|
| 234 |
self:updateTooltips() |
| 235 |
end |
| 236 |
|
| 237 |
-- Function to select given list index in the current category. |
| 238 |
-- Includes jumping to correct page. |
| 239 |
function UIStaffManagement:selectIndex(idx) |
| 240 |
if idx > #self.staff_members[self.category] or idx <= 0 then |
| 241 |
return |
| 242 |
end |
| 243 |
self.page = math.floor((idx - 1) / 10) + 1 |
| 244 |
self.selected_staff = idx |
| 245 |
end |
| 246 |
|
| 247 |
-- Function to select a given staff member. |
| 248 |
-- Includes switching to correct category and page. |
| 249 |
function UIStaffManagement:selectStaff(staff) |
| 250 |
self:setCategory(staff.profile.humanoid_class) |
| 251 |
for i, s in ipairs(self.staff_members[self.category]) do |
| 252 |
if s == staff then |
| 253 |
self:selectIndex(i) |
| 254 |
break |
| 255 |
end |
| 256 |
end |
| 257 |
end |
| 258 |
|
| 259 |
function UIStaffManagement:draw(canvas, x, y) |
| 260 |
local s = TheApp.config.ui_scale |
| 261 |
canvas:scale(s, "bitmap") |
| 262 |
self.background:draw(canvas, self.x * s + x, self.y * s + y) |
| 263 |
canvas:scale(1, "bitmap") |
| 264 |
UIFullscreen.draw(self, canvas, x, y) |
| 265 |
x, y = self.x * s + x, self.y * s + y |
| 266 |
local titles = self.title_font |
| 267 |
|
| 268 |
-- Titles |
| 269 |
local ty = y + 31 * s |
| 270 |
local tw = 95 * s |
| 271 |
titles:draw(canvas, _S.staff_list.morale, x + 323 * s, ty, tw, 0) |
| 272 |
titles:draw(canvas, _S.staff_list.tiredness, x + 427 * s, ty, tw, 0) |
| 273 |
titles:draw(canvas, _S.staff_list.skill, x + 530 * s, ty, tw, 0) |
| 274 |
|
| 275 |
-- Number of employees |
| 276 |
local ney = y + 57 * s |
| 277 |
titles:draw(canvas, #self.staff_members["Doctor"], x + 79 * s, ney) |
| 278 |
titles:draw(canvas, #self.staff_members["Nurse"], x + 145 * s, ney) |
| 279 |
titles:draw(canvas, #self.staff_members["Handyman"], x + 211 * s, ney) |
| 280 |
titles:draw(canvas, #self.staff_members["Receptionist"], x + 277 * s, ney) |
| 281 |
|
| 282 |
local total_happiness = 0 |
| 283 |
local total_fatigue = 0 |
| 284 |
local total_skill = 0 |
| 285 |
-- Draw each listing |
| 286 |
local staff_list = self.staff_members[self.category] |
| 287 |
for i, staff in ipairs(staff_list) do |
| 288 |
if not staff then |
| 289 |
break |
| 290 |
end |
| 291 |
-- Morale, tiredness and skill, used to draw the average at the end too. |
| 292 |
local happiness_bar_width = 0 |
| 293 |
if staff:getAttribute("happiness") then |
| 294 |
happiness_bar_width = math_floor(staff:getAttribute("happiness") * 40 * s + 0.5) |
| 295 |
total_happiness = total_happiness + staff:getAttribute("happiness") |
| 296 |
end |
| 297 |
local fatigue_bar_width = 40.5 * s |
| 298 |
if staff:getAttribute("fatigue") then |
| 299 |
total_fatigue = total_fatigue + staff:getAttribute("fatigue") |
| 300 |
fatigue_bar_width = math_floor((1 - staff:getAttribute("fatigue")) * 40 * s + 0.5) |
| 301 |
end |
| 302 |
local skill_bar_width = math_floor(staff.profile.skill * 40 * s + 0.5) |
| 303 |
total_skill = total_skill + staff.profile.skill |
| 304 |
-- Is this staff member on the visible page? Then draw him/her |
| 305 |
if i > (self.page-1)*10 and i <= self.page*10 then |
| 306 |
local row_no = i - (self.page-1)*10 |
| 307 |
self.row_blankers[row_no].visible = false |
| 308 |
titles:draw(canvas, row_no + 10*(self.page-1), x + 58 * s, y + 63 * s + row_no * 27 * s) |
| 309 |
local font = self.title_font |
| 310 |
if i == self.visual_hover_id then |
| 311 |
font = self.blue_font |
| 312 |
end |
| 313 |
local row_y = y + 63 * s + row_no * 27 * s |
| 314 |
font:draw(canvas, staff.profile:getFullName(), |
| 315 |
x + 88 * s, row_y) |
| 316 |
font:draw(canvas, "$" .. staff.profile.wage, x + 230 * s, row_y, 80 * s, 0) |
| 317 |
|
| 318 |
-- Draw the morale, tiredness and skill for this staff member |
| 319 |
if happiness_bar_width ~= 0 then |
| 320 |
for dx = 0, happiness_bar_width - 1 do |
| 321 |
self.panel_sprites:draw(canvas, 16, x + 351 * s + dx, row_y + 2 * s, { scaleFactor = s }) |
| 322 |
end |
| 323 |
end |
| 324 |
if fatigue_bar_width ~= 0 then |
| 325 |
for dx = 0, fatigue_bar_width - 1 do |
| 326 |
self.panel_sprites:draw(canvas, 15, x + 456 * s + dx, row_y + 2 * s, { scaleFactor = s }) |
| 327 |
end |
| 328 |
end |
| 329 |
if skill_bar_width ~= 0 then |
| 330 |
for dx = 0, skill_bar_width - 1 do |
| 331 |
self.panel_sprites:draw(canvas, 14, x + 559 * s + dx, row_y + 2 * s, { scaleFactor = s }) |
| 332 |
end |
| 333 |
end |
| 334 |
end |
| 335 |
end |
| 336 |
|
| 337 |
-- Make sure the other ones are not visible |
| 338 |
for i = #staff_list + 1 - (self.page-1)*10, 10 do |
| 339 |
self.row_blankers[i].visible = true |
| 340 |
end |
| 341 |
-- Draw the average morale, tiredness and skill |
| 342 |
if #staff_list ~= 0 then |
| 343 |
local happiness_bar_width = math_floor((total_happiness/#staff_list) * 40 * s + 0.5) |
| 344 |
if happiness_bar_width ~= 0 then |
| 345 |
for dx = 0, happiness_bar_width - 1 do |
| 346 |
self.panel_sprites:draw(canvas, 16, x + 351 * s + dx, y + 59 * s, { scaleFactor = s }) |
| 347 |
end |
| 348 |
end |
| 349 |
|
| 350 |
local fatigue_bar_width = math_floor((1 - (total_fatigue/#staff_list)) * 40 * s + 0.5) |
| 351 |
if fatigue_bar_width ~= 0 then |
| 352 |
for dx = 0, fatigue_bar_width - 1 do |
| 353 |
self.panel_sprites:draw(canvas, 15, x + 456 * s + dx, y + 59 * s, { scaleFactor = s }) |
| 354 |
end |
| 355 |
end |
| 356 |
local skill_bar_width = math_floor((total_skill/#staff_list) * 40 + 0.5) |
| 357 |
if skill_bar_width ~= 0 then |
| 358 |
for dx = 0, skill_bar_width - 1 do |
| 359 |
self.panel_sprites:draw(canvas, 14, x + 559 * s + dx, y + 59 * s, { scaleFactor = s }) |
| 360 |
end |
| 361 |
end |
| 362 |
end |
| 363 |
-- Reset |
| 364 |
self.progress_surgeon.visible = false |
| 365 |
self.qualified_surgeon.visible = false |
| 366 |
self.progress_psychiatrist.visible = false |
| 367 |
self.qualified_psychiatrist.visible = false |
| 368 |
self.progress_researcher.visible = false |
| 369 |
self.qualified_researcher.visible = false |
| 370 |
self.arrow.visible = false |
| 371 |
self.portrait_back.visible = false |
| 372 |
-- If a staff member is selected, draw picture, skill etc |
| 373 |
if self.selected_staff then |
| 374 |
local staff = self.staff_members[self.category][self.selected_staff] |
| 375 |
local profile = staff.profile |
| 376 |
-- Draw the red rectangle TODO: Make a neater function in C? |
| 377 |
local red = canvas:mapRGB(221, 83, 0) |
| 378 |
local y_pos = self.selected_staff - (self.page - 1)*10 |
| 379 |
canvas:drawRect(red, x + 49 * s, y + y_pos * 27 * s + 54 * s, 581 * s, s) |
| 380 |
canvas:drawRect(red, x + 49 * s, y + y_pos * 27 * s + 81 * s, 581 * s, s) |
| 381 |
canvas:drawRect(red, x + 49 * s, y + y_pos * 27 * s + 54 * s, s, 28 * s) |
| 382 |
canvas:drawRect(red, x + 630 * s, y + y_pos * 27 * s + 54 * s, s, 28 * s) |
| 383 |
|
| 384 |
-- Current position in the game world |
| 385 |
local px, py = self:getStaffPosition(37, 61) |
| 386 |
canvas:scale(s) |
| 387 |
self.ui.app.map:draw(canvas, px, py, 83, 82, math.floor(x / s) + 497, math.floor(y / s) + 373) |
| 388 |
canvas:scale(1) |
| 389 |
-- Portrait |
| 390 |
self.portrait_back.visible = true |
| 391 |
profile:drawFace(canvas, x + 68 * s, y + 377 * s, self.face_parts, s) |
| 392 |
|
| 393 |
-- 10 % increase in salary or a bonus: |
| 394 |
local max_salary = self.hospital.world.map.level_config.payroll.MaxSalary |
| 395 |
local new_salary = math.min(math.floor(profile.wage * 1.1), max_salary) |
| 396 |
titles:draw(canvas, "$" .. math_floor(profile.wage*0.1), x + 377 * s, y + 387 * s, 45 * s, 0) |
| 397 |
titles:draw(canvas, "$" .. new_salary, x + 377 * s, y + 432 * s, 45 * s, 0) |
| 398 |
|
| 399 |
-- Attention to detail |
| 400 |
local attention_bar_width = math_floor(profile.attention_to_detail * 40 * s + 0.5) |
| 401 |
if attention_bar_width ~= 0 then |
| 402 |
for dx = 0, attention_bar_width - 1 do |
| 403 |
self.panel_sprites:draw(canvas, 13, x + 178 * s + dx, y + 387 * s, { scaleFactor = s }) |
| 404 |
end |
| 405 |
end |
| 406 |
-- If it is a doctor, draw skills etc. |
| 407 |
if self.category == "Doctor" then |
| 408 |
if profile.is_surgeon > 0 then |
| 409 |
if profile.is_surgeon >= 1.0 then |
| 410 |
self.qualified_surgeon.visible = true |
| 411 |
elseif not profile.is_consultant then |
| 412 |
self.progress_surgeon.visible = true |
| 413 |
self.progress_surgeon:setTooltip(_S.tooltip.staff_list.surgeon_train:format(math_floor(profile.is_surgeon * 100))) |
| 414 |
local progress = math_floor(profile.is_surgeon * 23 * s + 0.5) |
| 415 |
for dx = 0, progress - 1 do |
| 416 |
self.panel_sprites:draw(canvas, 13, x + 196 * s + dx, y + 447 * s, { scaleFactor = s }) |
| 417 |
end |
| 418 |
end |
| 419 |
end |
| 420 |
if profile.is_psychiatrist > 0 then |
| 421 |
if profile.is_psychiatrist >= 1.0 then |
| 422 |
self.qualified_psychiatrist.visible = true |
| 423 |
elseif not profile.is_consultant then |
| 424 |
self.progress_psychiatrist.visible = true |
| 425 |
self.progress_psychiatrist:setTooltip(_S.tooltip.staff_list.psychiatrist_train:format(math_floor(profile.is_psychiatrist * 100))) |
| 426 |
local progress = math_floor(profile.is_psychiatrist * 23 * s + 0.5) |
| 427 |
for dx = 0, progress - 1 do |
| 428 |
self.panel_sprites:draw(canvas, 13, x + 236 * s + dx, y + 447 * s, { scaleFactor = s }) |
| 429 |
end |
| 430 |
end |
| 431 |
end |
| 432 |
if profile.is_researcher > 0 then |
| 433 |
if profile.is_researcher >= 1.0 then |
| 434 |
self.qualified_researcher.visible = true |
| 435 |
elseif not profile.is_consultant then |
| 436 |
self.progress_researcher.visible = true |
| 437 |
self.progress_researcher:setTooltip(_S.tooltip.staff_list.researcher_train:format(math_floor(profile.is_researcher * 100))) |
| 438 |
local progress = math_floor(profile.is_researcher * 23 * s + 0.5) |
| 439 |
for dx = 0, progress - 1 do |
| 440 |
self.panel_sprites:draw(canvas, 13, x + 276 * s + dx, y + 447 * s, { scaleFactor = s }) |
| 441 |
end |
| 442 |
end |
| 443 |
end |
| 444 |
-- Draw type of doctor |
| 445 |
self.arrow.visible = true |
| 446 |
if profile.is_consultant then |
| 447 |
self.arrow.x = self.arrow_position + 29 |
| 448 |
elseif profile.is_junior then |
| 449 |
self.arrow.x = self.arrow_position - 23 |
| 450 |
else |
| 451 |
self.arrow.x = self.arrow_position |
| 452 |
end |
| 453 |
end |
| 454 |
end |
| 455 |
end |
| 456 |
|
| 457 |
function UIStaffManagement:onMouseDown(code, x, y) |
| 458 |
if code == "left" then |
| 459 |
local s = TheApp.config.ui_scale |
| 460 |
local inside_staff_list_area = (x > 50 * s and x < 624 * s) and (y > 82 * s and y < 351 * s) |
| 461 |
local inside_header_area = (x > 321 * s and x < 629 * s) and (y > 22 * s and y < 46 * s) |
| 462 |
if inside_staff_list_area then |
| 463 |
-- Hit staff row |
| 464 |
if #self.staff_members[self.category] - (self.page - 1)*10 > math_floor((y - 81 * s)/(27 * s)) then |
| 465 |
self.selected_staff = math_floor((y - 81 * s)/(27 * s)) + 1 + (self.page - 1)*10 |
| 466 |
TheApp.audio:playSound("selectx.wav") |
| 467 |
end |
| 468 |
elseif inside_header_area then |
| 469 |
local function order_by(attribute) |
| 470 |
if self.list_order == attribute then -- Change direction |
| 471 |
if not self.list_direction or self.list_direction == "down" then |
| 472 |
self.list_direction = "up" |
| 473 |
else |
| 474 |
self.list_order = "hire" |
| 475 |
self.list_direction = "down" |
| 476 |
end |
| 477 |
else |
| 478 |
self.list_order = attribute -- Switch order attribute |
| 479 |
end |
| 480 |
self:updateStaffList() |
| 481 |
end |
| 482 |
if x < 422 * s then order_by("morale") |
| 483 |
elseif x > 425 * s and x < 527 * s then order_by("tiredness") |
| 484 |
elseif x > 529 * s then order_by("skill") |
| 485 |
end |
| 486 |
else |
| 487 |
local inside_view_of_the_staff_area = (x > 497 * s and x < 580 * s) and (y > 373 * s and y < 455 * s) |
| 488 |
if inside_view_of_the_staff_area and self.selected_staff then |
| 489 |
return false -- on false window dragging won't work |
| 490 |
end |
| 491 |
end |
| 492 |
end |
| 493 |
return UIFullscreen.onMouseDown(self, code, x, y) |
| 494 |
end |
| 495 |
|
| 496 |
function UIStaffManagement:onMouseMove(x, y, dx, dy) |
| 497 |
local s = TheApp.config.ui_scale |
| 498 |
local current_hover_id |
| 499 |
local inside_staff_list_area |
| 500 |
local header_height = 81 * s |
| 501 |
local row_height = 27 * s |
| 502 |
local active_hover_id = math_floor((y - header_height)/row_height) |
| 503 |
if self.page*10 > #self.staff_members[self.category] then |
| 504 |
-- Make sure area contains no hollow space |
| 505 |
inside_staff_list_area = (x > 50 * s and x < 624 * s) and |
| 506 |
(y > header_height and y < header_height + row_height * (#self.staff_members[self.category] % 10)) |
| 507 |
else |
| 508 |
inside_staff_list_area = (x > 50 * s and x < 624 * s) and (y > header_height and y < 351 * s) |
| 509 |
end |
| 510 |
|
| 511 |
if inside_staff_list_area then |
| 512 |
if #self.staff_members[self.category] - (self.page - 1)*10 > active_hover_id then |
| 513 |
current_hover_id = active_hover_id + 1 + (self.page - 1)*10 |
| 514 |
if self.hover_id ~= current_hover_id then |
| 515 |
if self.hover_sound then |
| 516 |
self.ui:stopSound(self.hover_sound) |
| 517 |
end |
| 518 |
self.hover_sound = self.ui:playSound("Hlight5.wav") |
| 519 |
self.hover_id = current_hover_id |
| 520 |
self.visual_hover_id = current_hover_id |
| 521 |
end |
| 522 |
end |
| 523 |
else |
| 524 |
self.hover_id = nil |
| 525 |
self.visual_hover_id = nil |
| 526 |
end |
| 527 |
return Window:onMouseMove(x, y, dx, dy) |
| 528 |
end |
| 529 |
|
| 530 |
function UIStaffManagement:onMouseUp(code, x, y) |
| 531 |
if code == "left" then |
| 532 |
local s = TheApp.config.ui_scale |
| 533 |
local inside_view_of_the_staff_area = (x > 497 * s and x < 580 * s) and (y > 373 * s and y < 455 * s) |
| 534 |
if inside_view_of_the_staff_area and self.selected_staff then |
| 535 |
-- Hit in the view of the staff. |
| 536 |
local ui = self.ui |
| 537 |
ui:scrollMapTo(self:getStaffPosition()) |
| 538 |
ui:addWindow(UIStaff(ui, self.staff_members[self.category][self.selected_staff])) |
| 539 |
self:close() |
| 540 |
end |
| 541 |
end |
| 542 |
return UIFullscreen.onMouseUp(self, code, x, y) |
| 543 |
end |
| 544 |
|
| 545 |
function UIStaffManagement:onMouseWheel(x, y) |
| 546 |
if not UIFullscreen.onMouseWheel(self, x, y) then |
| 547 |
if self:hitTest(self.cursor_x, self.cursor_y) then |
| 548 |
if y > 0 then |
| 549 |
self:scrollUp() |
| 550 |
return true |
| 551 |
else |
| 552 |
self:scrollDown() |
| 553 |
return true |
| 554 |
end |
| 555 |
end |
| 556 |
return false |
| 557 |
else |
| 558 |
return true |
| 559 |
end |
| 560 |
end |
| 561 |
|
| 562 |
function UIFullscreen:getStaffPosition(dx, dy) |
| 563 |
local staff = self.staff_members[self.category][self.selected_staff] |
| 564 |
local x, y = self.ui.app.map:WorldToScreen(staff.tile_x, staff.tile_y) |
| 565 |
local px, py = staff.th:getSecondaryMarker() |
| 566 |
return x + px - (dx or 0), y + py - (dy or 0) |
| 567 |
end |
| 568 |
|
| 569 |
function UIStaffManagement:previousCategory() |
| 570 |
if self.category == "Nurse" then |
| 571 |
self:setCategory("Doctor") |
| 572 |
elseif self.category == "Handyman" then |
| 573 |
self:setCategory("Nurse") |
| 574 |
elseif self.category == "Receptionist" then |
| 575 |
self:setCategory("Handyman") |
| 576 |
end |
| 577 |
end |
| 578 |
|
| 579 |
function UIStaffManagement:nextCategory() |
| 580 |
if self.category == "Doctor" then |
| 581 |
self:setCategory("Nurse") |
| 582 |
elseif self.category == "Nurse" then |
| 583 |
self:setCategory("Handyman") |
| 584 |
elseif self.category == "Handyman" then |
| 585 |
self:setCategory("Receptionist") |
| 586 |
end |
| 587 |
end |
| 588 |
|
| 589 |
function UIStaffManagement:previousStaff() |
| 590 |
-- If nothing currently selected, select the last one, otherwise the previous. |
| 591 |
if self.selected_staff == nil then |
| 592 |
self:selectIndex(#self.staff_members[self.category]) |
| 593 |
else |
| 594 |
self:selectIndex(self.selected_staff - 1) |
| 595 |
end |
| 596 |
end |
| 597 |
|
| 598 |
function UIStaffManagement:nextStaff() |
| 599 |
-- If nothing currently selected, select the first one, otherwise the next. |
| 600 |
if self.selected_staff == nil then |
| 601 |
self:selectIndex(1) |
| 602 |
else |
| 603 |
self:selectIndex(self.selected_staff + 1) |
| 604 |
end |
| 605 |
end |
| 606 |
|
| 607 |
function UIStaffManagement:scrollUp() |
| 608 |
if self.scroll_dot.visible and self.page > 1 then |
| 609 |
self.selected_staff = nil |
| 610 |
self.page = self.page - 1 |
| 611 |
self:updateScrollDot() |
| 612 |
end |
| 613 |
self:updateTooltips() |
| 614 |
end |
| 615 |
|
| 616 |
function UIStaffManagement:scrollDown() |
| 617 |
if self.scroll_dot.visible and self.page*10 < #self.staff_members[self.category] then |
| 618 |
self.selected_staff = nil |
| 619 |
self.page = self.page + 1 |
| 620 |
self:updateScrollDot() |
| 621 |
end |
| 622 |
self:updateTooltips() |
| 623 |
end |
| 624 |
|
| 625 |
--! Updates the position of the paging scroll indicator |
| 626 |
function UIStaffManagement:updateScrollDot() |
| 627 |
local numPages = math.ceil(#self.staff_members[self.category] / 10) |
| 628 |
local yOffset = math_floor(83 * ((self.page - 1) / (numPages - 1))) |
| 629 |
self.scroll_dot.y = 168 + yOffset |
| 630 |
end |
| 631 |
|
| 632 |
--! Updates whether the paging scroll indicator is visible and its position if visible |
| 633 |
function UIStaffManagement:updateScrollDotVisibility() |
| 634 |
if #self.staff_members[self.category] > 10 then |
| 635 |
self.scroll_dot.visible = true |
| 636 |
self:updateScrollDot() |
| 637 |
else |
| 638 |
self.scroll_dot.visible = false |
| 639 |
end |
| 640 |
end |
| 641 |
|
| 642 |
function UIStaffManagement:payBonus() |
| 643 |
local staff = self.staff_members[self.category][self.selected_staff] |
| 644 |
if self.selected_staff and self.hospital.balance > math_floor(staff.profile.wage*0.1) then |
| 645 |
staff:changeAttribute("happiness", 0.5) |
| 646 |
self.hospital:spendMoney(math_floor(staff.profile.wage*0.1), _S.transactions.personal_bonus) |
| 647 |
self.ui:playSound("cashreg.wav") |
| 648 |
return |
| 649 |
end |
| 650 |
self.ui:playSound("wrong2.wav") |
| 651 |
end |
| 652 |
|
| 653 |
function UIStaffManagement:increaseSalary() |
| 654 |
if self.selected_staff then |
| 655 |
local staff = self.staff_members[self.category][self.selected_staff] |
| 656 |
if staff:increaseWage(math_floor(staff.profile.wage * 0.1)) then |
| 657 |
return |
| 658 |
end |
| 659 |
end |
| 660 |
self.ui:playSound("wrong2.wav") |
| 661 |
end |
| 662 |
|
| 663 |
function UIStaffManagement:fire() |
| 664 |
if self.selected_staff then |
| 665 |
self.ui:playSound(self.default_button_sound) |
| 666 |
self.ui:addWindow(UIConfirmDialog(self.ui, false, _S.confirmation.sack_staff, --[[persistable:staff_management_confirm_sack]] function() |
| 667 |
local current_category = self.staff_members[self.category] |
| 668 |
current_category[self.selected_staff]:fire() |
| 669 |
-- Close the staff window if open |
| 670 |
local staff_window = self.ui:getWindow(UIStaff) |
| 671 |
if staff_window and staff_window.staff == current_category[self.selected_staff] then |
| 672 |
staff_window:close() |
| 673 |
end |
| 674 |
-- Update the staff list |
| 675 |
self:updateStaffList(current_category[self.selected_staff]) |
| 676 |
end)) -- End of confirmation dialog |
| 677 |
else |
| 678 |
self.ui:playSound("wrong2.wav") |
| 679 |
end |
| 680 |
end |
| 681 |
|
| 682 |
function UIStaffManagement:close() |
| 683 |
UIFullscreen.close(self) |
| 684 |
self.ui:getWindow(UIBottomPanel):updateButtonStates() |
| 685 |
end |
| 686 |
|
| 687 |
function UIStaffManagement:afterLoad(old, new) |
| 688 |
self:registerKeyHandlers() |
| 689 |
|
| 690 |
if old < 175 then |
| 691 |
self:close() |
| 692 |
end |
| 693 |
if old < 236 then |
| 694 |
local gfx = TheApp.gfx |
| 695 |
self.background = gfx:loadRaw("Staff01V", 640, 480, "QData", "QData", "Staff01V.pal", true) |
| 696 |
local palette = gfx:getPalette("Staff01V.pal") |
| 697 |
self.panel_sprites = gfx:loadSpriteTable("QData", "Staff02V", true, palette, { apply_ui_scale = true }) |
| 698 |
self.title_font = gfx:loadFontAndSpriteTable("QData", "Font01V", false, palette, { apply_ui_scale = true }) |
| 699 |
self.face_parts = gfx:loadRaw("Face01V", 65, 1350, nil, "Data", "MPalette.dat", false, { flags = DrawFlags.Nearest }) |
| 700 |
end |
| 701 |
|
| 702 |
UIFullscreen.afterLoad(self, old, new) |
| 703 |
end |