Ports SS220 AutoComplete for Documents (#20481)

* documents_autocomplete

* part 2

* final adjustments

* Removed some comments by accident

* Apply suggestions from code review

Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com>

* Duplicate definition

* fixing runtime

* S43NW review

---------

Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com>
This commit is contained in:
Henri215
2023-03-13 19:16:36 -03:00
committed by GitHub
parent 491a51ecb9
commit 203a508acd
+63 -47
View File
@@ -250,11 +250,11 @@
/obj/item/paper/proc/updateinfolinks()
info_links = info
var/i = 0
for(i=1,i<=fields,i++)
addtofield(i, "<font face=\"[deffont]\"><A href='?src=[UID()];write=[i]'>write</A></font>", 1)
info_links = info_links + "<font face=\"[deffont]\"><A href='?src=[UID()];write=end'>write</A></font>"
for(var/i in 1 to length(fields))
var/write_1 = "<font face=\"[deffont]\"><a href='?src=[UID()];write=[i]'>write</a></font>"
var/write_2 = "<font face=\"[deffont]\"><a href='?src=[UID()];auto_write=[i]'><span style=\"color: #409F47; font-size: 10px\">\[a\]</span></a></font>"
addtofield(i, "[write_1][write_2]", 1)
info_links = info_links + "<font face=\"[deffont]\"><a href='?src=[UID()];write=end'>write</a></font>" + "<font face=\"[deffont]\"><a href='?src=[UID()];auto_write=end'><span style=\"color: #409F47; font-size: 10px\">\[a\]</span></a></font>"
/obj/item/paper/proc/clearpaper()
info = null
@@ -304,53 +304,69 @@
\[time\] : Inserts the current station time in HH:MM:SS.<br>
</BODY></HTML>"}, "window=paper_help")
/obj/item/paper/proc/topic_href_write(id, input_element)
var/obj/item/item_write = usr.get_active_hand() // Check to see if he still got that darn pen, also check if he's using a crayon or pen.
add_hiddenprint(usr) // No more forging nasty documents as someone else, you jerks
if(!istype(item_write, /obj/item/pen) && !istype(item_write, /obj/item/toy/crayon))
return
if(loc != usr && !Adjacent(usr) && !((istype(loc, /obj/item/clipboard) || istype(loc, /obj/item/folder)) && (usr in get_turf(src) || loc.Adjacent(usr))))
return // If paper is not in usr, then it must be near them, or in a clipboard or folder, which must be in or near usr
input_element = parsepencode(input_element, item_write, usr) // Encode everything from pencode to html
if(id != "end")
addtofield(text2num(id), input_element) // He wants to edit a field, let him.
else
info += input_element // Oh, he wants to edit to the end of the file, let him.
populatefields()
updateinfolinks()
item_write.on_write(src, usr)
show_content(usr, forceshow = TRUE, infolinks = TRUE)
update_icon()
/obj/item/paper/Topic(href, href_list)
..()
if(!usr || (usr.stat || usr.restrained()))
return
if(href_list["write"])
if(href_list["auto_write"])
var/id = href_list["auto_write"]
var/const/sign_text = "\[Sign\]"
var/const/time_text = "\[Current time\]"
var/const/date_text = "\[Current date\]"
var/const/num_text = "\[Account number\]"
var/const/pin_text = "\[PIN\]"
var/const/station_text = "\[Station name\]"
var/list/menu_list = list() //text items in the menu
menu_list.Add(usr.real_name) //the real name of the character, even if it is hidden
if(usr.real_name != usr.name || usr.name != "unknown") //if the player is masked or the name is different a new answer option is added
menu_list.Add("[usr.name]")
menu_list.Add(usr.job, //current job
num_text, //account number
pin_text, //pin code number
sign_text, //signature
time_text, //time
date_text, //date
station_text, // station name
usr.gender, //current gender
usr.dna.species //current species
)
var/input_element = input("Select the text you want to add:", "Select item") as null|anything in menu_list
switch(input_element) //format selected menu items in pencode and internal data
if(sign_text)
input_element = "\[sign\]"
if(time_text)
input_element = "\[time\]"
if(date_text)
input_element = "\[date\]"
if(station_text)
input_element = "\[station\]"
if(num_text)
input_element = usr.mind.initial_account.account_number
if(pin_text)
input_element = usr.mind.initial_account.account_pin
topic_href_write(id, input_element)
if(href_list["write"] )
var/id = href_list["write"]
//var/t = strip_html_simple(input(usr, "What text do you wish to add to " + (id=="end" ? "the end of the paper" : "field "+id) + "?", "[name]", null),8192) as message
//var/t = strip_html_simple(input("Enter what you want to write:", "Write", null, null) as message, MAX_MESSAGE_LEN)
var/t = input("Enter what you want to write:", "Write", null, null) as message
var/obj/item/i = usr.get_active_hand() // Check to see if he still got that darn pen, also check if he's using a crayon or pen.
add_hiddenprint(usr) // No more forging nasty documents as someone else, you jerks
if(!is_pen(i))
if(!istype(i, /obj/item/toy/crayon))
return
// if paper is not in usr, then it must be near them, or in a clipboard or folder, which must be in or near usr
if(src.loc != usr && !src.Adjacent(usr) && !((istype(src.loc, /obj/item/clipboard) || istype(src.loc, /obj/item/folder)) && (src.loc.loc == usr || src.loc.Adjacent(usr)) ) )
return
/*
t = checkhtml(t)
// check for exploits
for(var/bad in paper_blacklist)
if(findtext(t,bad))
to_chat(usr, "<span class='notice'>You think to yourself, \</span>"Hm.. this is only paper...\"")
log_admin("PAPER: [key_name(usr)] tried to use forbidden word in [src]: [bad].")
message_admins("PAPER: [key_name_admin(usr)] tried to use forbidden word in [src]: [bad].")
return
*/
t = parsepencode(t, i, usr) // Encode everything from pencode to html
if(id!="end")
addtofield(text2num(id), t) // He wants to edit a field, let him.
else
info += t // Oh, he wants to edit to the end of the file, let him.
populatefields()
updateinfolinks()
i.on_write(src,usr)
show_content(usr, forceshow = 1, infolinks = 1)
update_icon()
var/input_element = input("Enter what you want to write:", "Write", null, null) as message
topic_href_write(id, input_element)
/obj/item/paper/attackby(obj/item/P, mob/living/user, params)
..()