Ported code from /tg/station to make brig timer panels and status displays use maptext instead of expensive icon procs.

Signed-off-by: Mloc-Argent <colmohici@gmail.com>
This commit is contained in:
Mloc-Argent
2013-10-07 20:13:39 +01:00
parent 06df06a0a3
commit be8bffbc5b
2 changed files with 113 additions and 165 deletions

View File

@@ -1,3 +1,8 @@
#define CHARS_PER_LINE 5
#define FONT_SIZE "5pt"
#define FONT_COLOR "#09f"
#define FONT_STYLE "Arial Black"
//This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:31 //This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:31
/////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////
@@ -23,6 +28,8 @@
var/list/obj/machinery/targets = list() var/list/obj/machinery/targets = list()
var/timetoset = 0 // Used to set releasetime upon starting the timer var/timetoset = 0 // Used to set releasetime upon starting the timer
maptext_height = 26
maptext_width = 32
/obj/machinery/door_timer/New() /obj/machinery/door_timer/New()
..() ..()
@@ -271,13 +278,14 @@
set_picture("ai_bsod") set_picture("ai_bsod")
return return
if(src.timing) if(src.timing)
var/disp1 = uppertext(id) var/disp1 = id
var/timeleft = timeleft() var/timeleft = timeleft()
var/disp2 = "[add_zero(num2text((timeleft / 60) % 60),2)]~[add_zero(num2text(timeleft % 60), 2)]" var/disp2 = "[add_zero(num2text((timeleft / 60) % 60),2)]~[add_zero(num2text(timeleft % 60), 2)]"
spawn( 5 ) if(length(disp2) > CHARS_PER_LINE)
disp2 = "Error"
update_display(disp1, disp2) update_display(disp1, disp2)
else else
update_display("SET","TIME") if(maptext) maptext = ""
return return
@@ -291,16 +299,9 @@
//Checks to see if there's 1 line or 2, adds text-icons-numbers/letters over display //Checks to see if there's 1 line or 2, adds text-icons-numbers/letters over display
// Stolen from status_display // Stolen from status_display
/obj/machinery/door_timer/proc/update_display(var/line1, var/line2) /obj/machinery/door_timer/proc/update_display(var/line1, var/line2)
if(line2 == null) // single line display var/new_text = {"<div style="font-size:[FONT_SIZE];color:[FONT_COLOR];font:'[FONT_STYLE]';text-align:center;" valign="top">[line1]<br>[line2]</div>"}
overlays.Cut() if(maptext != new_text)
overlays += texticon(line1, 23, -13) maptext = new_text
else // dual line display
overlays.Cut()
overlays += texticon(line1, 23, -9)
overlays += texticon(line2, 23, -17)
// return an icon of a time text string (tn)
// valid characters are 0-9 and :
// px, py are pixel offsets
//Actual string input to icon display for loop, with 5 pixel x offsets for each letter. //Actual string input to icon display for loop, with 5 pixel x offsets for each letter.
@@ -360,3 +361,8 @@
id = "Cell 6" id = "Cell 6"
dir = 4 dir = 4
pixel_x = 32 pixel_x = 32
#undef FONT_SIZE
#undef FONT_COLOR
#undef FONT_STYLE
#undef CHARS_PER_LINE

View File

@@ -1,3 +1,9 @@
#define CHARS_PER_LINE 5
#define FONT_SIZE "5pt"
#define FONT_COLOR "#09f"
#define FONT_STYLE "Arial Black"
#define SCROLL_SPEED 2
// Status display // Status display
// (formerly Countdown timer display) // (formerly Countdown timer display)
@@ -25,15 +31,14 @@
var/index1 // display index for scrolling messages or 0 if non-scrolling var/index1 // display index for scrolling messages or 0 if non-scrolling
var/index2 var/index2
var/lastdisplayline1 = "" // the cached last displays
var/lastdisplayline2 = ""
var/frequency = 1435 // radio frequency var/frequency = 1435 // radio frequency
var/supply_display = 0 // true if a supply shuttle display var/supply_display = 0 // true if a supply shuttle display
var/repeat_update = 0 // true if we are going to update again this ptick
var/friendc = 0 // track if Friend Computer mode var/friendc = 0 // track if Friend Computer mode
maptext_height = 26
maptext_width = 32
// new display // new display
// register for radio system // register for radio system
New() New()
@@ -47,9 +52,8 @@
process() process()
if(stat & NOPOWER) if(stat & NOPOWER)
overlays.Cut() remove_display()
return return
update() update()
emp_act(severity) emp_act(severity)
@@ -62,173 +66,114 @@
// set what is displayed // set what is displayed
proc/update() proc/update()
if(friendc && mode!=4) //Makes all status displays except supply shuttle timer display the eye -- Urist if(friendc && mode!=4) //Makes all status displays except supply shuttle timer display the eye -- Urist
set_picture("ai_friend") set_picture("ai_friend")
return return
if(mode==0) switch(mode)
overlays.Cut() if(0) //blank
return remove_display()
if(1) //emergency shuttle timer
if(mode==3) // alert picture, no change
return
if(mode==1) // shuttle timer
if(emergency_shuttle.online) if(emergency_shuttle.online)
var/displayloc var/line1
var/line2 = get_shuttle_timer()
if(emergency_shuttle.location == 1) if(emergency_shuttle.location == 1)
displayloc = "ETD " line1 = "-ETD-"
else else
displayloc = "ETA " line1 = "-ETA-"
if(length(line2) > CHARS_PER_LINE)
var/displaytime = get_shuttle_timer() line2 = "Error!"
if(lentext(displaytime) > 5) update_display(line1, line2)
displaytime = "**~**"
update_display(displayloc, displaytime)
return
else else
overlays.Cut() remove_display()
return if(2) //custom messages
if(mode==4) // supply shuttle timer
var/disp1
var/disp2
if(supply_shuttle.moving)
disp1 = "SPPLY"
disp2 = get_supply_shuttle_timer()
if(lentext(disp1) > 5)
disp1 = "**~**"
else
if(supply_shuttle.at_station)
disp1 = "SPPLY"
disp2 = "STATN"
else
disp1 = "SPPLY"
disp2 = "AWAY"
update_display(disp1, disp2)
if(mode==2)
var/line1 var/line1
var/line2 var/line2
if(!index1) if(!index1)
line1 = message1 line1 = message1
else else
line1 = copytext(message1+message1, index1, index1+5) line1 = copytext(message1+"|"+message1, index1, index1+CHARS_PER_LINE)
if(index1++ > (lentext(message1))) var/message1_len = length(message1)
index1 = 1 index1 += SCROLL_SPEED
if(index1 > message1_len)
index1 -= message1_len
if(!index2) if(!index2)
line2 = message2 line2 = message2
else else
line2 = copytext(message2+message2, index2, index2+5) line2 = copytext(message2+"|"+message2, index2, index2+CHARS_PER_LINE)
if(index2++ > (lentext(message2))) var/message2_len = length(message2)
index2 = 1 index2 += SCROLL_SPEED
if(index2 > message2_len)
index2 -= message2_len
update_display(line1, line2)
if(4) // supply shuttle timer
var/line1 = "SUPPLY"
var/line2
if(supply_shuttle.moving)
line2 = get_supply_shuttle_timer()
if(lentext(line2) > CHARS_PER_LINE)
line2 = "Error"
else
if(supply_shuttle.at_station)
line2 = "Docked"
else
line1 = ""
update_display(line1, line2) update_display(line1, line2)
// the following allows 2 updates per process, giving faster scrolling examine()
if((index1 || index2) && repeat_update) // if either line is scrolling set src in view()
// and we haven't forced an update yet . = ..()
switch(mode)
if(1,2,4)
usr << "The display says:<br>\t<xmp>[message1]</xmp><br>\t<xmp>[message2]</xmp>"
spawn(5)
repeat_update = 0
update() // set to update again in 5 ticks
repeat_update = 1
proc/set_message(var/m1, var/m2) proc/set_message(m1, m2)
if(m1) if(m1)
index1 = (lentext(m1) > 5) index1 = (length(m1) > CHARS_PER_LINE)
message1 = uppertext(m1) message1 = m1
else else
message1 = "" message1 = ""
index1 = 0 index1 = 0
if(m2) if(m2)
index2 = (lentext(m2) > 5) index2 = (length(m2) > CHARS_PER_LINE)
message2 = uppertext(m2) message2 = m2
else else
message2 = null message2 = ""
index2 = 0 index2 = 0
repeat_update = 1
proc/set_picture(var/state) proc/set_picture(state)
picture_state = state picture_state = state
overlays.Cut() remove_display()
overlays += image('icons/obj/status_display.dmi', icon_state=picture_state) overlays += image('icons/obj/status_display.dmi', icon_state=picture_state)
proc/update_display(var/line1, var/line2) proc/update_display(line1, line2)
var/new_text = {"<div style="font-size:[FONT_SIZE];color:[FONT_COLOR];font:'[FONT_STYLE]';text-align:center;" valign="top">[line1]<br>[line2]</div>"}
if(line1 == lastdisplayline1 && line2 == lastdisplayline2) if(maptext != new_text)
return // no change, no need to update maptext = new_text
lastdisplayline1 = line1
lastdisplayline2 = line2
if(line2 == null) // single line display
overlays.Cut()
overlays += texticon(line1, 23, -13)
else // dual line display
overlays.Cut()
overlays += texticon(line1, 23, -9)
overlays += texticon(line2, 23, -17)
// return shuttle timer as text
proc/get_shuttle_timer() proc/get_shuttle_timer()
var/timeleft = emergency_shuttle.timeleft() var/timeleft = emergency_shuttle.timeleft()
if(timeleft) if(timeleft)
return "[add_zero(num2text((timeleft / 60) % 60),2)]~[add_zero(num2text(timeleft % 60), 2)]" return "[add_zero(num2text((timeleft / 60) % 60),2)]:[add_zero(num2text(timeleft % 60), 2)]"
// note ~ translates into a blinking :
return "" return ""
proc/get_supply_shuttle_timer() proc/get_supply_shuttle_timer()
if(supply_shuttle.moving) if(supply_shuttle.moving)
var/timeleft = round((supply_shuttle.eta_timeofday - world.timeofday) / 10,1) var/timeleft = round((supply_shuttle.eta_timeofday - world.timeofday) / 10,1)
return "[add_zero(num2text((timeleft / 60) % 60),2)]~[add_zero(num2text(timeleft % 60), 2)]" if(timeleft < 0)
// note ~ translates into a blinking : return "Late"
return "[add_zero(num2text((timeleft / 60) % 60),2)]:[add_zero(num2text(timeleft % 60), 2)]"
return "" return ""
proc/remove_display()
if(overlays.len)
overlays.Cut()
// return an icon of a time text string (tn) if(maptext)
// valid characters are 0-9 and : maptext = ""
// px, py are pixel offsets
proc/texticon(var/tn, var/px = 0, var/py = 0)
var/image/I = image('icons/obj/status_display.dmi', "blank")
var/len = lentext(tn)
for(var/d = 1 to len)
var/char = copytext(tn, len-d+1, len-d+2)
if(char == " ")
continue
var/image/ID = image('icons/obj/status_display.dmi', icon_state=char)
ID.pixel_x = -(d-1)*5 + px
ID.pixel_y = py
I.overlays += ID
return I
receive_signal(datum/signal/signal) receive_signal(datum/signal/signal)
@@ -318,16 +263,6 @@
set_picture("ai_facepalm") set_picture("ai_facepalm")
if("Friend Computer") if("Friend Computer")
set_picture("ai_friend") set_picture("ai_friend")
if("Tribunal")
set_picture("tribunal")
if("Beer mug")
set_picture("ai_beer")
if("Dwarf")
set_picture("ai_dwarf")
if("Fishtank")
set_picture("ai_fishtank")
if("Plump Helmet")
set_picture("ai_plump")
return return
@@ -338,5 +273,12 @@
proc/set_picture(var/state) proc/set_picture(var/state)
picture_state = state picture_state = state
if(overlays.len)
overlays.Cut() overlays.Cut()
overlays += image('icons/obj/status_display.dmi', icon_state=picture_state) overlays += image('icons/obj/status_display.dmi', icon_state=picture_state)
#undef CHARS_PER_LINE
#undef FOND_SIZE
#undef FONT_COLOR
#undef FONT_STYLE
#undef SCROLL_SPEED