mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-21 11:07:12 +01:00
NanoUI traitor uplink
This commit is contained in:
@@ -9,133 +9,134 @@ A list of items and costs is stored under the datum of every game mode, alongsid
|
||||
var/list/world_uplinks = list()
|
||||
|
||||
/obj/item/device/uplink
|
||||
var/welcome // Welcoming menu message
|
||||
var/uses // Numbers of crystals
|
||||
// List of items not to shove in their hands.
|
||||
var/purchase_log = ""
|
||||
var/show_description = null
|
||||
var/active = 0
|
||||
var/job = null
|
||||
var/welcome // Welcoming menu message
|
||||
var/uses // Numbers of crystals
|
||||
var/list/ItemsCategory // List of categories with lists of items
|
||||
var/list/ItemsReference // List of references with an associated item
|
||||
var/list/nanoui_items // List of items for NanoUI use
|
||||
var/nanoui_menu = 0 // The current menu we are in
|
||||
var/list/nanoui_data = new // Additional data for NanoUI use
|
||||
|
||||
var/list/purchase_log = new
|
||||
var/uplink_owner = null//text-only
|
||||
var/used_TC = 0
|
||||
|
||||
var/job = null
|
||||
var/show_descriptions = 0
|
||||
|
||||
/obj/item/device/uplink/New()
|
||||
..()
|
||||
world_uplinks+=src
|
||||
welcome = ticker.mode.uplink_welcome
|
||||
uses = ticker.mode.uplink_uses
|
||||
ItemsCategory = get_uplink_items()
|
||||
|
||||
/obj/item/device/uplink/Destroy()
|
||||
world_uplinks-=src
|
||||
return ..()
|
||||
world_uplinks += src
|
||||
|
||||
//Let's build a menu!
|
||||
/obj/item/device/uplink/Del()
|
||||
world_uplinks -= src
|
||||
..()
|
||||
|
||||
/obj/item/device/uplink/proc/generate_items(mob/user as mob)
|
||||
var/datum/nano_item_lists/IL = generate_item_lists(user)
|
||||
nanoui_items = IL.items_nano
|
||||
ItemsReference = IL.items_reference
|
||||
|
||||
// BS12 no longer use this menu but there are forks that do, hency why we keep it
|
||||
/obj/item/device/uplink/proc/generate_menu(mob/user as mob)
|
||||
if(!job)
|
||||
job = user.mind.assigned_role
|
||||
|
||||
var/dat = "<B>[src.welcome]</B><BR>"
|
||||
dat += "Tele-Crystals left: [src.uses]<BR>"
|
||||
dat += "<HR>"
|
||||
dat += "<B>Request item:</B><BR>"
|
||||
dat += "<I>Each item costs a number of tele-crystals as indicated by the number following their name.</I><br>"
|
||||
|
||||
// AUTOFIXED BY fix_string_idiocy.py
|
||||
// C:\Users\Rob\Documents\Projects\vgstation13\code\game\objects\items\devices\uplinks.dm:26: dat += "Tele-Crystals left: [src.uses]<BR>"
|
||||
dat += {"Tele-Crystals left: [src.uses]<BR>
|
||||
<HR>
|
||||
<B>Request item:</B><BR>
|
||||
<I>Each item costs a number of tele-crystals as indicated by the number following their name.</I><br><BR>"}
|
||||
// END AUTOFIX
|
||||
var/list/buyable_items = get_uplink_items()
|
||||
|
||||
// Loop through categories
|
||||
var/index = 0
|
||||
for(var/category in buyable_items)
|
||||
|
||||
index++
|
||||
var/category_items = 1
|
||||
for(var/category in ItemsCategory)
|
||||
if(category_items < 1)
|
||||
dat += "<i>We apologize, as you could not afford anything from this category.</i><br>"
|
||||
dat += "<br>"
|
||||
dat += "<b>[category]</b><br>"
|
||||
category_items = 0
|
||||
|
||||
var/i = 0
|
||||
|
||||
// Loop through items in category
|
||||
for(var/datum/uplink_item/item in buyable_items[category])
|
||||
i++
|
||||
|
||||
var/cost_text = ""
|
||||
var/desc = "[item.desc]"
|
||||
if(item.job && item.job.len)
|
||||
if(!(item.job.Find(job)))
|
||||
//world.log << "Skipping job item that doesn't match"
|
||||
for(var/datum/uplink_item/I in ItemsCategory[category])
|
||||
if(I.cost > uses)
|
||||
continue
|
||||
if(I.job && I.job.len)
|
||||
if(!(I.job.Find(job)))
|
||||
continue
|
||||
else
|
||||
//world.log << "Found matching job item"
|
||||
if(item.cost > 0)
|
||||
cost_text = "([item.cost])"
|
||||
if(item.cost <= uses)
|
||||
dat += "<A href='byond://?src=\ref[src];buy_item=[category]:[i];'>[item.name]</A> [cost_text] "
|
||||
else
|
||||
dat += "<font color='grey'><i>[item.name] [cost_text] </i></font>"
|
||||
if(item.desc)
|
||||
if(show_description == 2)
|
||||
dat += "<A href='byond://?src=\ref[src];show_desc=1'><font size=2>\[-\]</font></A><BR><font size=2>[desc]</font>"
|
||||
else
|
||||
dat += "<A href='byond://?src=\ref[src];show_desc=2'><font size=2>\[?\]</font></A>"
|
||||
dat += "<BR>"
|
||||
|
||||
// Break up the categories, if it isn't the last.
|
||||
if(buyable_items.len != index)
|
||||
dat += "<br>"
|
||||
dat += "<A href='byond://?src=\ref[src];buy_item=[I.reference];cost=[I.cost]'>[I.name]</A> ([I.cost])<BR>"
|
||||
category_items++
|
||||
|
||||
dat += "<A href='byond://?src=\ref[src];buy_item=random'>Random Item (??)</A><br>"
|
||||
dat += "<HR>"
|
||||
return dat
|
||||
|
||||
// Interaction code. Gathers a list of items purchasable from the paren't uplink and displays it. It also adds a lock button.
|
||||
/obj/item/device/uplink/interact(mob/user as mob)
|
||||
/*
|
||||
Built the item lists for use with NanoUI
|
||||
*/
|
||||
/obj/item/device/uplink/proc/generate_item_lists(mob/user as mob)
|
||||
if(!job)
|
||||
job = user.mind.assigned_role
|
||||
|
||||
var/list/nano = new
|
||||
var/list/reference = new
|
||||
|
||||
var/dat = "<body link='yellow' alink='white' bgcolor='#601414'><font color='white'>"
|
||||
dat += src.generate_menu(user)
|
||||
for(var/category in ItemsCategory)
|
||||
nano[++nano.len] = list("Category" = category, "items" = list())
|
||||
for(var/datum/uplink_item/I in ItemsCategory[category])
|
||||
if(I.job && I.job.len)
|
||||
if(!(I.job.Find(job)))
|
||||
continue
|
||||
nano[nano.len]["items"] += list(list("Name" = I.name, "Description" = I.description(),"Cost" = I.cost, "obj_path" = I.reference))
|
||||
reference[I.reference] = I
|
||||
|
||||
// AUTOFIXED BY fix_string_idiocy.py
|
||||
// C:\Users\Rob\Documents\Projects\vgstation13\code\game\objects\items\devices\uplinks.dm:72: dat += "<A href='byond://?src=\ref[src];lock=1'>Lock</a>"
|
||||
dat += {"<A href='byond://?src=\ref[src];lock=1'>Lock</a>
|
||||
</font></body>"}
|
||||
// END AUTOFIX
|
||||
user << browse(dat, "window=hidden")
|
||||
onclose(user, "hidden")
|
||||
return
|
||||
var/datum/nano_item_lists/result = new
|
||||
result.items_nano = nano
|
||||
result.items_reference = reference
|
||||
return result
|
||||
|
||||
//If 'random' was selected
|
||||
/obj/item/device/uplink/proc/chooseRandomItem()
|
||||
if(uses <= 0)
|
||||
return
|
||||
|
||||
var/list/random_items = new
|
||||
for(var/IR in ItemsReference)
|
||||
var/datum/uplink_item/UI = ItemsReference[IR]
|
||||
if(UI.cost <= uses)
|
||||
random_items += UI
|
||||
return pick(random_items)
|
||||
|
||||
/obj/item/device/uplink/Topic(href, href_list)
|
||||
if(..())
|
||||
return 1
|
||||
|
||||
if(!active)
|
||||
if(href_list["buy_item"] == "random")
|
||||
var/datum/uplink_item/UI = chooseRandomItem()
|
||||
href_list["buy_item"] = UI.reference
|
||||
return buy(UI, "RN")
|
||||
else
|
||||
var/datum/uplink_item/UI = ItemsReference[href_list["buy_item"]]
|
||||
return buy(UI, UI ? UI.reference : "")
|
||||
return 0
|
||||
|
||||
/obj/item/device/uplink/proc/buy(var/datum/uplink_item/UI, var/reference)
|
||||
if(!UI)
|
||||
return
|
||||
UI.buy(src,usr)
|
||||
nanomanager.update_uis(src)
|
||||
|
||||
/* var/list/L = UI.spawn_item(get_turf(usr),src)
|
||||
if(ishuman(usr))
|
||||
var/mob/living/carbon/human/A = usr
|
||||
for(var/obj/I in L)
|
||||
A.put_in_any_hand_if_possible(I)
|
||||
|
||||
if (href_list["buy_item"])
|
||||
purchase_log[UI] = purchase_log[UI] + 1 */
|
||||
|
||||
var/item = href_list["buy_item"]
|
||||
var/list/split = text2list(item, ":") // throw away variable
|
||||
|
||||
if(split.len == 2)
|
||||
// Collect category and number
|
||||
var/category = split[1]
|
||||
var/number = text2num(split[2])
|
||||
|
||||
var/list/buyable_items = get_uplink_items()
|
||||
|
||||
var/list/uplink = buyable_items[category]
|
||||
if(uplink && uplink.len >= number)
|
||||
var/datum/uplink_item/I = uplink[number]
|
||||
if(I)
|
||||
I.buy(src, usr)
|
||||
else
|
||||
var/text = "[key_name(usr)] tried to purchase an uplink item that doesn't exist"
|
||||
var/textalt = "[key_name(usr)] tried to purchase an uplink item that doesn't exist [item]"
|
||||
message_admins(text)
|
||||
log_game(textalt)
|
||||
admin_log.Add(textalt)
|
||||
|
||||
else if(href_list["show_desc"])
|
||||
show_description = text2num(href_list["show_desc"])
|
||||
interact(usr)
|
||||
return 1
|
||||
|
||||
// HIDDEN UPLINK - Can be stored in anything but the host item has to have a trigger for it.
|
||||
/* How to create an uplink in 3 easy steps!
|
||||
@@ -150,16 +151,16 @@ var/list/world_uplinks = list()
|
||||
*/
|
||||
|
||||
/obj/item/device/uplink/hidden
|
||||
name = "Hidden Uplink."
|
||||
name = "hidden uplink"
|
||||
desc = "There is something wrong if you're examining this."
|
||||
var/active = 0
|
||||
|
||||
/obj/item/device/uplink/hidden/Topic(href, href_list)
|
||||
if(..())
|
||||
return 1
|
||||
if(href_list["lock"])
|
||||
toggle()
|
||||
usr << browse(null, "window=hidden")
|
||||
return 1
|
||||
// The hidden uplink MUST be inside an obj/item's contents.
|
||||
/obj/item/device/uplink/hidden/New()
|
||||
spawn(2)
|
||||
if(!istype(src.loc, /obj/item))
|
||||
del(src)
|
||||
..()
|
||||
|
||||
// Toggles the uplink on and off. Normally this will bypass the item's normal functions and go to the uplink menu, if activated.
|
||||
/obj/item/device/uplink/hidden/proc/toggle()
|
||||
@@ -180,66 +181,97 @@ var/list/world_uplinks = list()
|
||||
return 1
|
||||
return 0
|
||||
|
||||
/*
|
||||
/*
|
||||
NANO UI FOR UPLINK WOOP WOOP
|
||||
*/
|
||||
/obj/item/device/uplink/hidden/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
|
||||
var/title = "Syndicate Uplink"
|
||||
var/title = "Remote Uplink"
|
||||
var/data[0]
|
||||
|
||||
data["crystals"] = uses
|
||||
data["nano_items"] = nanoui_items
|
||||
data["welcome"] = welcome
|
||||
data["crystals"] = uses
|
||||
data["menu"] = nanoui_menu
|
||||
data["descriptions"] = show_descriptions
|
||||
if(!nanoui_items)
|
||||
generate_items(user)
|
||||
data["nano_items"] = nanoui_items
|
||||
data += nanoui_data
|
||||
|
||||
// update the ui if it exists, returns null if no ui is passed/found
|
||||
ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open)
|
||||
if (!ui)
|
||||
// the ui does not exist, so we'll create a new() one
|
||||
// for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm
|
||||
ui = new(user, src, ui_key, "uplink.tmpl", title, 450, 600)
|
||||
ui = new(user, src, ui_key, "uplink.tmpl", title, 700, 600)
|
||||
// when the ui is first opened this is the data it will use
|
||||
ui.set_initial_data(data)
|
||||
// open the new ui window
|
||||
ui.open()
|
||||
|
||||
|
||||
// Interaction code. Gathers a list of items purchasable from the paren't uplink and displays it. It also adds a lock button.
|
||||
/obj/item/device/uplink/hidden/interact(mob/user)
|
||||
|
||||
ui_interact(user)
|
||||
|
||||
// The purchasing code.
|
||||
/obj/item/device/uplink/hidden/Topic(href, href_list)
|
||||
if (usr.stat || usr.restrained())
|
||||
return
|
||||
return 1
|
||||
|
||||
if (!( istype(usr, /mob/living/carbon/human)))
|
||||
return 0
|
||||
return 1
|
||||
var/mob/user = usr
|
||||
var/datum/nanoui/ui = nanomanager.get_open_ui(user, src, "main")
|
||||
if ((usr.contents.Find(src.loc) || (in_range(src.loc, usr) && istype(src.loc.loc, /turf))))
|
||||
usr.set_machine(src)
|
||||
if(href_list["lock"])
|
||||
if(..(href, href_list))
|
||||
return 1
|
||||
else if(href_list["lock"])
|
||||
toggle()
|
||||
ui.close()
|
||||
return 1
|
||||
if(href_list["return"])
|
||||
nanoui_menu = round(nanoui_menu/10)
|
||||
update_nano_data()
|
||||
if(href_list["menu"])
|
||||
nanoui_menu = text2num(href_list["menu"])
|
||||
update_nano_data(href_list["id"])
|
||||
if(href_list["menu"])
|
||||
nanoui_menu = text2num(href_list["menu"])
|
||||
update_nano_data(href_list["id"])
|
||||
if(href_list["descriptions"])
|
||||
show_descriptions = !show_descriptions
|
||||
update_nano_data()
|
||||
|
||||
if(..(href, href_list) == 1)
|
||||
|
||||
if(!(href_list["buy_item"] in valid_items))
|
||||
return
|
||||
|
||||
var/path_obj = text2path(href_list["buy_item"])
|
||||
|
||||
var/obj/I = new path_obj(get_turf(usr))
|
||||
if(ishuman(usr))
|
||||
var/mob/living/carbon/human/A = usr
|
||||
A.put_in_any_hand_if_possible(I)
|
||||
purchase_log += "[usr] ([usr.ckey]) bought [I]."
|
||||
interact(usr)
|
||||
nanomanager.update_uis(src)
|
||||
return 1
|
||||
|
||||
*/
|
||||
/obj/item/device/uplink/hidden/proc/update_nano_data(var/id)
|
||||
if(nanoui_menu == 1)
|
||||
var/permanentData[0]
|
||||
for(var/datum/data/record/L in sortRecord(data_core.general))
|
||||
permanentData[++permanentData.len] = list(Name = L.fields["name"],"id" = L.fields["id"])
|
||||
nanoui_data["exploit_records"] = permanentData
|
||||
|
||||
if(nanoui_menu == 11)
|
||||
nanoui_data["exploit_exists"] = 0
|
||||
|
||||
for(var/datum/data/record/L in data_core.general)
|
||||
if(L.fields["id"] == id)
|
||||
nanoui_data["exploit"] = list() // Setting this to equal L.fields passes it's variables that are lists as reference instead of value.
|
||||
// We trade off being able to automatically add shit for more control over what gets passed to json
|
||||
// and if it's sanitized for html.
|
||||
nanoui_data["exploit"]["nanoui_exploit_record"] = html_encode(L.fields["exploit_record"]) // Change stuff into html
|
||||
nanoui_data["exploit"]["nanoui_exploit_record"] = replacetext(nanoui_data["exploit"]["nanoui_exploit_record"], "\n", "<br>") // change line breaks into <br>
|
||||
nanoui_data["exploit"]["name"] = html_encode(L.fields["name"])
|
||||
nanoui_data["exploit"]["sex"] = html_encode(L.fields["sex"])
|
||||
nanoui_data["exploit"]["age"] = html_encode(L.fields["age"])
|
||||
nanoui_data["exploit"]["species"] = html_encode(L.fields["species"])
|
||||
nanoui_data["exploit"]["rank"] = html_encode(L.fields["rank"])
|
||||
nanoui_data["exploit"]["fingerprint"] = html_encode(L.fields["fingerprint"])
|
||||
|
||||
nanoui_data["exploit_exists"] = 1
|
||||
break
|
||||
|
||||
// I placed this here because of how relevant it is.
|
||||
// You place this in your uplinkable item to check if an uplink is active or not.
|
||||
@@ -252,7 +284,7 @@ var/list/world_uplinks = list()
|
||||
src.hidden_uplink.trigger(user)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
|
||||
//Refund proc for the borg teleporter (later I'll make a general refund proc if there is demand for it)
|
||||
/obj/item/device/radio/uplink/attackby(obj/item/weapon/W as obj, mob/user as mob, params)
|
||||
if(istype(W, /obj/item/weapon/antag_spawner/borg_tele))
|
||||
|
||||
Reference in New Issue
Block a user