/
status_display.dm
567 lines (471 loc) · 17.3 KB
/
status_display.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
// Status display
#define MAX_STATIC_WIDTH 22
#define FONT_STYLE "12pt 'TinyUnicode'"
#define SCROLL_RATE (0.04 SECONDS) // time per pixel
#define SCROLL_PADDING 2 // how many pixels we chop to make a smooth loop
#define LINE1_X 1
#define LINE1_Y -4
#define LINE2_X 1
#define LINE2_Y -11
#define STATUS_DISPLAY_FONT_DATUM /datum/font/tiny_unicode/size_12pt
/// Status display which can show images and scrolling text.
/obj/machinery/status_display
name = "status display"
desc = null
icon = 'icons/obj/machines/status_display.dmi'
icon_state = "frame"
verb_say = "beeps"
verb_ask = "beeps"
verb_exclaim = "beeps"
density = FALSE
layer = ABOVE_WINDOW_LAYER
var/obj/effect/overlay/status_display_text/message1_overlay
var/obj/effect/overlay/status_display_text/message2_overlay
var/current_picture = ""
var/current_mode = SD_BLANK
var/message1 = ""
var/message2 = ""
/// Normal text color
var/text_color = COLOR_DISPLAY_BLUE
/// Color for headers, eg. "- ETA -"
var/header_text_color = COLOR_DISPLAY_PURPLE
/obj/item/wallframe/status_display
name = "status display frame"
desc = "Used to build status displays, just secure to the wall."
icon_state = "unanchoredstatusdisplay"
custom_materials = list(/datum/material/iron= SHEET_MATERIAL_AMOUNT * 7, /datum/material/glass= SHEET_MATERIAL_AMOUNT * 4)
result_path = /obj/machinery/status_display/evac
pixel_shift = 32
//makes it go on the wall when built
/obj/machinery/status_display/Initialize(mapload, ndir, building)
. = ..()
update_appearance()
/obj/machinery/status_display/wrench_act_secondary(mob/living/user, obj/item/tool)
. = ..()
balloon_alert(user, "[anchored ? "un" : ""]securing...")
tool.play_tool_sound(src)
if(tool.use_tool(src, user, 6 SECONDS))
playsound(loc, 'sound/items/deconstruct.ogg', 50, TRUE)
balloon_alert(user, "[anchored ? "un" : ""]secured")
deconstruct()
return TRUE
/obj/machinery/status_display/welder_act(mob/living/user, obj/item/tool)
if(user.combat_mode)
return
if(atom_integrity >= max_integrity)
balloon_alert(user, "it doesn't need repairs!")
return TRUE
user.balloon_alert_to_viewers("repairing display...", "repairing...")
if(!tool.use_tool(src, user, 4 SECONDS, amount = 0, volume=50))
return TRUE
balloon_alert(user, "repaired")
atom_integrity = max_integrity
set_machine_stat(machine_stat & ~BROKEN)
update_appearance()
return TRUE
/obj/machinery/status_display/on_deconstruction(disassembled)
if(!disassembled)
new /obj/item/stack/sheet/iron(drop_location(), 2)
new /obj/item/shard(drop_location())
new /obj/item/shard(drop_location())
else
new /obj/item/wallframe/status_display(drop_location())
/// Immediately change the display to the given picture.
/obj/machinery/status_display/proc/set_picture(state)
if(state != current_picture)
current_picture = state
update_appearance()
/// Immediately change the display to the given two lines.
/obj/machinery/status_display/proc/set_messages(line1, line2)
line1 = uppertext(line1)
line2 = uppertext(line2)
var/message_changed = FALSE
if(line1 != message1)
message1 = line1
message_changed = TRUE
if(line2 != message2)
message2 = line2
message_changed = TRUE
if(message_changed)
update_appearance()
/**
* Remove both message objs and null the fields.
* Don't call this in subclasses.
*/
/obj/machinery/status_display/proc/remove_messages()
if(message1_overlay)
QDEL_NULL(message1_overlay)
if(message2_overlay)
QDEL_NULL(message2_overlay)
/**
* Create/update message overlay.
* They must be handled as real objects for the animation to run.
* Don't call this in subclasses.
* Arguments:
* * overlay - the current /obj/effect/overlay/status_display_text instance
* * line_y - The Y offset to render the text.
* * x_offset - Used to offset the text on the X coordinates, not usually needed.
* * message - the new message text.
* Returns new /obj/effect/overlay/status_display_text or null if unchanged.
*/
/obj/machinery/status_display/proc/update_message(obj/effect/overlay/status_display_text/overlay, line_y, message, x_offset, line_pair)
if(overlay && message == overlay.message)
return null
if(overlay)
qdel(overlay)
var/obj/effect/overlay/status_display_text/new_status_display_text = new(src, line_y, message, text_color, header_text_color, x_offset, line_pair)
// Draw our object visually "in front" of this display, taking advantage of sidemap
new_status_display_text.pixel_y = -32
new_status_display_text.pixel_z = 32
vis_contents += new_status_display_text
return new_status_display_text
/obj/machinery/status_display/update_appearance(updates=ALL)
. = ..()
if( \
(machine_stat & (NOPOWER|BROKEN)) || \
(current_mode == SD_BLANK) || \
(current_mode != SD_PICTURE && message1 == "" && message2 == "") \
)
set_light(0)
return
set_light(1.5, 0.7, LIGHT_COLOR_FAINT_CYAN) // blue light
/obj/machinery/status_display/update_overlays(updates)
. = ..()
if(machine_stat & (NOPOWER|BROKEN))
remove_messages()
return
switch(current_mode)
if(SD_BLANK)
remove_messages()
// Turn off backlight.
return
if(SD_PICTURE)
remove_messages()
. += mutable_appearance(icon, current_picture)
if(current_picture == AI_DISPLAY_DONT_GLOW) // If the thing's off, don't display the emissive yeah?
return .
else
var/line1_metric
var/line2_metric
var/line_pair
var/datum/font/display_font = new STATUS_DISPLAY_FONT_DATUM()
line1_metric = display_font.get_metrics(message1)
line2_metric = display_font.get_metrics(message2)
line_pair = (line1_metric > line2_metric ? line1_metric : line2_metric)
var/overlay = update_message(message1_overlay, LINE1_Y, message1, LINE1_X, line_pair)
if(overlay)
message1_overlay = overlay
overlay = update_message(message2_overlay, LINE2_Y, message2, LINE2_X, line_pair)
if(overlay)
message2_overlay = overlay
// Turn off backlight if message is blank
if(message1 == "" && message2 == "")
return
. += emissive_appearance(icon, "outline", src, alpha = src.alpha)
// Timed process - performs nothing in the base class
/obj/machinery/status_display/process()
if(machine_stat & NOPOWER)
// No power, no processing.
update_appearance()
return PROCESS_KILL
/// Update the display and, if necessary, re-enable processing.
/obj/machinery/status_display/proc/update()
if (process(SSMACHINES_DT) != PROCESS_KILL)
START_PROCESSING(SSmachines, src)
/obj/machinery/status_display/power_change()
. = ..()
update()
/obj/machinery/status_display/emp_act(severity)
. = ..()
if(machine_stat & (NOPOWER|BROKEN) || . & EMP_PROTECT_SELF)
return
current_mode = SD_PICTURE
set_picture("ai_bsod")
/obj/machinery/status_display/examine(mob/user)
. = ..()
if (message1_overlay || message2_overlay)
. += "The display says:"
if (message1_overlay.message)
. += "\t<tt>[html_encode(message1_overlay.message)]</tt>"
if (message2_overlay.message)
. += "\t<tt>[html_encode(message2_overlay.message)]</tt>"
// Helper procs for child display types.
/obj/machinery/status_display/proc/display_shuttle_status(obj/docking_port/mobile/shuttle)
if(!shuttle)
// the shuttle is missing - no processing
set_messages("shutl","not in service")
return PROCESS_KILL
else if(shuttle.timer)
var/line1 = shuttle.getModeStr()
var/line2 = shuttle.getTimerStr()
set_messages(line1, line2)
else
// don't kill processing, the timer might turn back on
set_messages("", "")
/obj/machinery/status_display/Destroy()
remove_messages()
return ..()
/**
* Nice overlay to make text smoothly scroll with no client updates after setup.
*/
/obj/effect/overlay/status_display_text
icon = 'icons/obj/machines/status_display.dmi'
vis_flags = VIS_INHERIT_LAYER | VIS_INHERIT_PLANE | VIS_INHERIT_ID
/// The message this overlay is displaying.
var/message
// If the line is short enough to not marquee, and it matches this, it's a header.
var/static/regex/header_regex = regex("^-.*-$")
/obj/effect/overlay/status_display_text/Initialize(mapload, yoffset, line, text_color, header_text_color, xoffset = 0, line_pair)
. = ..()
maptext_y = yoffset
message = line
var/datum/font/display_font = new STATUS_DISPLAY_FONT_DATUM()
var/line_width = display_font.get_metrics(line)
if(line_width > MAX_STATIC_WIDTH)
// Marquee text
var/marquee_message = "[line] [line] [line]"
// Width of full content. Must of these is never revealed unless the user inputted a single character.
var/full_marquee_width = display_font.get_metrics("[marquee_message] ")
// We loop after only this much has passed.
var/looping_marquee_width = (display_font.get_metrics("[line] ]") - SCROLL_PADDING)
maptext = generate_text(marquee_message, center = FALSE, text_color = text_color)
maptext_width = full_marquee_width
maptext_x = 0
// Mask off to fit in screen.
add_filter("mask", 1, alpha_mask_filter(icon = icon(icon, "outline")))
// Scroll.
var/time = line_pair * SCROLL_RATE
animate(src, maptext_x = (-looping_marquee_width) + MAX_STATIC_WIDTH, time = time, loop = -1)
animate(maptext_x = MAX_STATIC_WIDTH, time = 0)
else
// Centered text
var/color = header_regex.Find(line) ? header_text_color : text_color
maptext = generate_text(line, center = TRUE, text_color = color)
maptext_x = xoffset //Defaults to 0, this would be centered unless overided
/**
* Generate the actual maptext.
* Arguments:
* * text - the text to display
* * center - center the text if TRUE, otherwise right-align (the direction the text is coming from)
* * text_color - the text color
*/
/obj/effect/overlay/status_display_text/proc/generate_text(text, center, text_color)
return {"<div style="color:[text_color];font:[FONT_STYLE][center ? ";text-align:center" : "text-align:right"]" valign="top">[text]</div>"}
/// Evac display which shows shuttle timer or message set by Command.
/obj/machinery/status_display/evac
current_mode = SD_EMERGENCY
var/frequency = FREQ_STATUS_DISPLAYS
var/friendc = FALSE // track if Friend Computer mode
var/last_picture // For when Friend Computer mode is undone
MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/status_display/evac, 32)
/obj/machinery/status_display/evac/Initialize(mapload)
. = ..()
// register for radio system
SSradio.add_object(src, frequency)
// Circuit USB
AddComponent(/datum/component/usb_port, list(
/obj/item/circuit_component/status_display,
))
find_and_hang_on_wall()
/obj/machinery/status_display/evac/Destroy()
SSradio.remove_object(src,frequency)
return ..()
/obj/machinery/status_display/evac/process()
if(machine_stat & NOPOWER)
// No power, no processing.
update_appearance()
return PROCESS_KILL
if(friendc) //Makes all status displays except supply shuttle timer display the eye -- Urist
current_mode = SD_PICTURE
set_picture("ai_friend")
return PROCESS_KILL
switch(current_mode)
if(SD_BLANK)
return PROCESS_KILL
if(SD_EMERGENCY)
return display_shuttle_status(SSshuttle.emergency)
if(SD_MESSAGE)
return PROCESS_KILL
if(SD_PICTURE)
set_picture(last_picture)
return PROCESS_KILL
/obj/machinery/status_display/evac/receive_signal(datum/signal/signal)
switch(signal.data["command"])
if("blank")
current_mode = SD_BLANK
update_appearance()
if("shuttle")
current_mode = SD_EMERGENCY
set_messages("", "")
if("message")
current_mode = SD_MESSAGE
set_messages(signal.data["top_text"] || "", signal.data["bottom_text"] || "")
if("alert")
current_mode = SD_PICTURE
last_picture = signal.data["picture_state"]
set_picture(last_picture)
if("friendcomputer")
friendc = !friendc
update()
/// Supply display which shows the status of the supply shuttle.
/obj/machinery/status_display/supply
name = "supply display"
current_mode = SD_MESSAGE
text_color = COLOR_DISPLAY_ORANGE
header_text_color = COLOR_DISPLAY_YELLOW
/obj/machinery/status_display/supply/process()
if(machine_stat & NOPOWER)
// No power, no processing.
update_appearance()
return PROCESS_KILL
var/line1
var/line2
if(!SSshuttle.supply)
// Might be missing in our first update on initialize before shuttles
// have loaded. Cross our fingers that it will soon return.
line1 = "shutl"
line2 = "not in service"
else if(SSshuttle.supply.mode == SHUTTLE_IDLE)
if(is_station_level(SSshuttle.supply.z))
line1 = "CARGO"
line2 = "Docked"
else
line1 = ""
line2 = ""
else
line1 = SSshuttle.supply.getModeStr()
line2 = SSshuttle.supply.getTimerStr()
set_messages(line1, line2)
/// General-purpose shuttle status display.
/obj/machinery/status_display/shuttle
name = "shuttle display"
current_mode = SD_MESSAGE
var/shuttle_id
text_color = COLOR_DISPLAY_GREEN
header_text_color = COLOR_DISPLAY_CYAN
/obj/machinery/status_display/shuttle/process()
if(!shuttle_id || (machine_stat & NOPOWER))
// No power, no processing.
update_appearance()
return PROCESS_KILL
return display_shuttle_status(SSshuttle.getShuttle(shuttle_id))
/obj/machinery/status_display/shuttle/vv_edit_var(var_name, var_value)
. = ..()
if(!.)
return
switch(var_name)
if(NAMEOF(src, shuttle_id))
update()
/obj/machinery/status_display/shuttle/connect_to_shuttle(mapload, obj/docking_port/mobile/port, obj/docking_port/stationary/dock)
if(port)
shuttle_id = port.shuttle_id
update()
/// Pictograph display which the AI can use to emote.
/obj/machinery/status_display/ai
name = "\improper AI display"
desc = "A small screen which the AI can use to present itself."
current_mode = SD_PICTURE
var/emotion = AI_DISPLAY_DONT_GLOW
MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/status_display/ai, 32)
/obj/machinery/status_display/ai/attack_ai(mob/living/silicon/ai/user)
if(!isAI(user))
return
var/list/choices = list()
for(var/emotion_const in GLOB.ai_status_display_emotes)
var/icon_state = GLOB.ai_status_display_emotes[emotion_const]
choices[emotion_const] = image(icon = 'icons/obj/machines/status_display.dmi', icon_state = icon_state)
var/emotion_result = show_radial_menu(user, src, choices, tooltips = TRUE)
for(var/_emote in typesof(/datum/emote/ai/emotion_display))
var/datum/emote/ai/emotion_display/emote = _emote
if(initial(emote.emotion) == emotion_result)
user.emote(initial(emote.key))
break
/obj/machinery/status_display/ai/process()
if(machine_stat & NOPOWER)
update_appearance()
return PROCESS_KILL
set_picture(GLOB.ai_status_display_emotes[emotion])
return PROCESS_KILL
/obj/item/circuit_component/status_display
display_name = "Status Display"
desc = "Output text and pictures to a status display."
circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL|CIRCUIT_FLAG_OUTPUT_SIGNAL
var/datum/port/input/option/command
var/datum/port/input/option/picture
var/datum/port/input/message1
var/datum/port/input/message2
var/obj/machinery/status_display/connected_display
var/list/command_map
var/list/picture_map
/obj/item/circuit_component/status_display/populate_ports()
message1 = add_input_port("Message 1", PORT_TYPE_STRING)
message2 = add_input_port("Message 2", PORT_TYPE_STRING)
/obj/item/circuit_component/status_display/populate_options()
var/static/list/command_options = list(
"Blank" = "blank",
"Shuttle" = "shuttle",
"Message" = "message",
"Alert" = "alert"
)
var/static/list/picture_options = list(
"Default" = "default",
"Delta Alert" = "deltaalert",
"Red Alert" = "redalert",
"Blue Alert" = "bluealert",
"Green Alert" = "greenalert",
"Biohazard" = "biohazard",
"Lockdown" = "lockdown",
"Radiation" = "radiation",
"Happy" = "ai_happy",
"Neutral" = "ai_neutral",
"Very Happy" = "ai_veryhappy",
"Sad" = "ai_sad",
"Unsure" = "ai_unsure",
"Confused" = "ai_confused",
"Surprised" = "ai_surprised",
"BSOD" = "ai_bsod"
)
command = add_option_port("Command", command_options)
command_map = command_options
picture = add_option_port("Picture", picture_options)
picture_map = picture_options
/obj/item/circuit_component/status_display/register_usb_parent(atom/movable/shell)
. = ..()
if(istype(shell, /obj/machinery/status_display))
connected_display = shell
/obj/item/circuit_component/status_display/unregister_usb_parent(atom/movable/parent)
connected_display = null
return ..()
/obj/item/circuit_component/status_display/input_received(datum/port/input/port)
// Just use command handling built into status display.
// The option inputs thankfully sanitize command and picture for us.
if(!connected_display)
return
var/command_value = command_map[command.value]
var/datum/signal/status_signal = new(list("command" = command_value))
switch(command_value)
if("message")
status_signal.data["top_text"] = message1.value
status_signal.data["bottom_text"] = message2.value
if("alert")
status_signal.data["picture_state"] = picture_map[picture.value]
connected_display.receive_signal(status_signal)
/obj/machinery/status_display/random_message
current_mode = SD_MESSAGE
/// list to pick the first line from
var/list/firstline_to_secondline = list()
/obj/machinery/status_display/random_message/Initialize(mapload, ndir, building)
if(firstline_to_secondline?.len)
message1 = pick(firstline_to_secondline)
message2 = firstline_to_secondline[message1]
return ..() // status displays call update appearance on init so i suppose we should set the messages before calling parent as to not call it twice
MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/status_display/random_message, 32)
#undef MAX_STATIC_WIDTH
#undef FONT_STYLE
#undef SCROLL_RATE
#undef LINE1_X
#undef LINE1_Y
#undef LINE2_X
#undef LINE2_Y
#undef STATUS_DISPLAY_FONT_DATUM
#undef SCROLL_PADDING