tgui uplinks; repath uplinks

This commit is contained in:
Bjorn Neergaard
2016-01-18 14:22:00 -06:00
parent 624b48ba09
commit ff5d6292c8
9 changed files with 107 additions and 154 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ var/global/image/fire_overlay = image("icon" = 'icons/effects/fire.dmi', "icon_s
var/list/armor = list(melee = 0, bullet = 0, laser = 0,energy = 0, bomb = 0, bio = 0, rad = 0)
var/armour_penetration = 0 //percentage of armour effectiveness to remove
var/list/allowed = null //suit storage stuff.
var/obj/item/device/uplink/hidden/hidden_uplink = null // All items can have an uplink hidden inside, just remember to add the triggers.
var/obj/item/device/uplink/hidden_uplink = null // All items can have an uplink hidden inside, just remember to code the UI triggers.
var/strip_delay = 40
var/put_on_delay = 20
var/list/materials = list()
+76 -144
View File
@@ -1,179 +1,103 @@
//This could either be split into the proper DM files or placed somewhere else all together, but it'll do for now -Nodrak
/*
A list of items and costs is stored under the datum of every game mode, alongside the number of crystals, and the welcoming message.
*/
var/list/world_uplinks = list()
/obj/item/device/uplink
var/welcome = "Syndicate Uplink Console:" // Welcoming menu message
var/uses = 20 // Numbers of crystals
// List of items not to shove in their hands.
var/purchase_log = ""
var/show_description = null
var/active = 0
var/uplink_owner = null//text-only
/* How to create an uplink in 3 easy steps!
1. All obj/item 's have a hidden_uplink var. By default it's null. Give the item one with "new(src)", it must be in it's contents. Feel free to add "uses".
2. Code in the triggers. Use check_trigger for this; the var/value is the value that will be compared with the var/target. If they are equal it will activate the menu.
3. If you want the menu to stay until the users locks his uplink, add an active_uplink_check(mob/user as mob) in your interact/attack_hand proc.
Then check if it's true, if true return. This will stop the normal menu appearing and will instead show the uplink menu.
*/
/obj/item/device/uplink
name = "syndicate uplink"
desc = "There is something wrong if you're examining this."
var/active = 0
var/uses = 20
var/used_TC = 0
var/uplink_owner = null
var/purchase_log = ""
var/mode_override = null
/obj/item/device/uplink/New()
..()
world_uplinks+=src
world_uplinks += src
/obj/item/device/uplink/Destroy()
world_uplinks-=src
world_uplinks -= src
return ..()
//Let's build a menu!
/obj/item/device/uplink/proc/generate_menu()
/obj/item/device/uplink/attack_self(mob/user)
trigger(user)
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><BR>"
/obj/item/device/uplink/interact(mob/user)
ui_interact(user)
/obj/item/device/uplink/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = 0, \
datum/tgui/master_ui = null, datum/ui_state/state = inventory_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "uplink", name, 400, 200, master_ui, state)
ui.set_style("syndicate")
ui.open()
/obj/item/device/uplink/get_ui_data(mob/user)
var/list/data = list()
data["uses"] = uses
var/list/buyable = list()
var/list/buyable_items = get_uplink_items(mode_override)
var/list/category
for(var/category_name in buyable_items)
category = list()
category["name"] = category_name
var/i
for(var/datum/uplink_item/item in buyable_items[category_name])
category["items"] += list(list(
"name" = item.name,
"cost" = item.cost,
"desc" = item.desc,
"index" = ++i
))
buyable[++buyable.len] = category
data["buyable"] = buyable
return data
// Loop through categories
var/index = 0
for(var/category in buyable_items)
index++
dat += "<b>[category]</b><br>"
var/i = 0
// Loop through items in category
for(var/datum/uplink_item/item in buyable_items[category])
i++
var/desc = "[item.desc]"
var/cost_text = ""
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 == item.type)
dat += "<A href='byond://?src=\ref[src];show_desc=0'><font size=2>\[-\]</font></A><BR><font size=2>[desc]</font>"
else
dat += "<A href='byond://?src=\ref[src];show_desc=[item.type]'><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 += "<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)
var/dat = "<body link='yellow' alink='white' bgcolor='#601414'><font color='white'>"
dat += src.generate_menu()
dat += "<A href='byond://?src=\ref[src];lock=1'>Lock</a>"
dat += "</font></body>"
user << browse(dat, "window=hidden")
onclose(user, "hidden")
return
/obj/item/device/uplink/Topic(href, href_list)
..()
/obj/item/device/uplink/ui_act(action, params)
if(!active)
return
if (href_list["buy_item"])
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])
switch(action)
if("buy")
var/category = params["category"]
var/index = text2num(params["index"])
var/list/buyable_items = get_uplink_items(mode_override)
var/list/uplink = buyable_items[category]
if(uplink && uplink.len >= number)
var/datum/uplink_item/I = uplink[number]
if(I)
I.buy(src, usr)
var/datum/uplink_item/I = buyable_items[category][index]
I.buy(src, usr)
if("lock")
active = FALSE
SStgui.close_uis(src)
return 1
else if(href_list["show_desc"])
/obj/item/device/uplink/ui_host()
return loc
var/type = text2path(href_list["show_desc"])
show_description = type
interact(usr)
// 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!
1. All obj/item 's have a hidden_uplink var. By default it's null. Give the item one with "new(src)", it must be in it's contents. Feel free to add "uses".
2. Code in the triggers. Use check_trigger for this, I recommend closing the item's menu with "usr << browse(null, "window=windowname") if it returns true.
The var/value is the value that will be compared with the var/target. If they are equal it will activate the menu.
3. If you want the menu to stay until the users locks his uplink, add an active_uplink_check(mob/user as mob) in your interact/attack_hand proc.
Then check if it's true, if true return. This will stop the normal menu appearing and will instead show the uplink menu.
*/
/obj/item/device/uplink/hidden
name = "hidden uplink."
desc = "There is something wrong if you're examining this."
/obj/item/device/uplink/hidden/Topic(href, href_list)
if(usr.stat || usr.restrained() || usr.paralysis || usr.stunned || usr.weakened)
return 0 // To stop people using their uplink when they shouldn't be able to
..()
if(href_list["lock"])
toggle()
usr << browse(null, "window=hidden")
return 1
// 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()
active = !active
// Directly trigger the uplink. Turn on if it isn't already.
/obj/item/device/uplink/hidden/proc/trigger(mob/user)
// Directly trigger an uplink.
/obj/item/device/uplink/proc/trigger(mob/user)
if(!active)
toggle()
active = TRUE
interact(user)
// Checks to see if the value meets the target. Like a frequency being a traitor_frequency, in order to unlock a headset.
// If true, it accesses trigger() and returns 1. If it fails, it returns false. Use this to see if you need to close the
// current item's menu.
/obj/item/device/uplink/hidden/proc/check_trigger(mob/user, value, target)
// Helper to try and unlock/use an uplink.
/obj/item/device/uplink/proc/check_trigger(mob/user, value, target)
if(value == target)
trigger(user)
return 1
return 0
// 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.
// If it is, it will display the uplink menu and return 1, else it'll return false.
// If it returns true, I recommend closing the item's normal menu with "user << browse(null, "window=name")"
/obj/item/proc/active_uplink_check(mob/user as mob)
// Activates the uplink if it's active
if(src.hidden_uplink)
if(src.hidden_uplink.active)
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)
// Refund certain items by hitting the uplink with it.
/obj/item/device/radio/uplink/attackby(obj/item/weapon/W, mob/user, params)
if(istype(W))
for(var/path in subtypesof(/datum/uplink_item))
@@ -185,6 +109,15 @@ var/list/world_uplinks = list()
qdel(W)
return
// Helper to open an uplink if present and active.
/obj/item/proc/active_uplink_check(mob/user as mob)
// Activates the uplink if it's active
if(src.hidden_uplink)
if(src.hidden_uplink.active)
src.hidden_uplink.trigger(user)
return 1
return 0
// PRESET UPLINKS
// A collection of preset uplinks.
//
@@ -212,4 +145,3 @@ var/list/world_uplinks = list()
/obj/item/device/radio/headset/uplink/New()
..()
hidden_uplink = new(src)
hidden_uplink.uses = 20