mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 02:09:41 +00:00
TGUI Smartfridge
This commit is contained in:
@@ -243,7 +243,6 @@
|
|||||||
user.visible_message("[user] [panel_open ? "opens" : "closes"] the maintenance panel of \the [src].", "You [panel_open ? "open" : "close"] the maintenance panel of \the [src].")
|
user.visible_message("[user] [panel_open ? "opens" : "closes"] the maintenance panel of \the [src].", "You [panel_open ? "open" : "close"] the maintenance panel of \the [src].")
|
||||||
playsound(src, O.usesound, 50, 1)
|
playsound(src, O.usesound, 50, 1)
|
||||||
update_icon()
|
update_icon()
|
||||||
SSnanoui.update_uis(src)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if(wrenchable && default_unfasten_wrench(user, O, 20))
|
if(wrenchable && default_unfasten_wrench(user, O, 20))
|
||||||
@@ -263,7 +262,6 @@
|
|||||||
stock(O)
|
stock(O)
|
||||||
user.visible_message("<span class='notice'>[user] has added \the [O] to \the [src].</span>", "<span class='notice'>You add \the [O] to \the [src].</span>")
|
user.visible_message("<span class='notice'>[user] has added \the [O] to \the [src].</span>", "<span class='notice'>You add \the [O] to \the [src].</span>")
|
||||||
|
|
||||||
|
|
||||||
else if(istype(O, /obj/item/weapon/storage/bag))
|
else if(istype(O, /obj/item/weapon/storage/bag))
|
||||||
var/obj/item/weapon/storage/bag/P = O
|
var/obj/item/weapon/storage/bag/P = O
|
||||||
var/plants_loaded = 0
|
var/plants_loaded = 0
|
||||||
@@ -309,11 +307,11 @@
|
|||||||
var/datum/stored_item/item = new/datum/stored_item(src, O.type, O.name)
|
var/datum/stored_item/item = new/datum/stored_item(src, O.type, O.name)
|
||||||
item.add_product(O)
|
item.add_product(O)
|
||||||
item_records.Add(item)
|
item_records.Add(item)
|
||||||
SSnanoui.update_uis(src)
|
SStgui.update_uis(src)
|
||||||
|
|
||||||
/obj/machinery/smartfridge/proc/vend(datum/stored_item/I)
|
/obj/machinery/smartfridge/proc/vend(datum/stored_item/I)
|
||||||
I.get_product(get_turf(src))
|
I.get_product(get_turf(src))
|
||||||
SSnanoui.update_uis(src)
|
SStgui.update_uis(src)
|
||||||
|
|
||||||
/obj/machinery/smartfridge/attack_ai(mob/user as mob)
|
/obj/machinery/smartfridge/attack_ai(mob/user as mob)
|
||||||
attack_hand(user)
|
attack_hand(user)
|
||||||
@@ -322,66 +320,59 @@
|
|||||||
if(stat & (NOPOWER|BROKEN))
|
if(stat & (NOPOWER|BROKEN))
|
||||||
return
|
return
|
||||||
wires.Interact(user)
|
wires.Interact(user)
|
||||||
ui_interact(user)
|
tgui_interact(user)
|
||||||
|
|
||||||
/*******************
|
/obj/machinery/smartfridge/tgui_interact(mob/user, datum/tgui/ui)
|
||||||
* SmartFridge Menu
|
ui = SStgui.try_update_ui(user, src, ui)
|
||||||
********************/
|
if(!ui)
|
||||||
|
ui = new(user, src, "SmartVend", name)
|
||||||
|
ui.set_autoupdate(FALSE)
|
||||||
|
ui.open()
|
||||||
|
|
||||||
/obj/machinery/smartfridge/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
|
/obj/machinery/smartfridge/tgui_data(mob/user)
|
||||||
user.set_machine(src)
|
. = list()
|
||||||
|
|
||||||
var/data[0]
|
var/list/items = list()
|
||||||
data["contents"] = null
|
for(var/i=1 to length(item_records))
|
||||||
data["electrified"] = seconds_electrified > 0
|
|
||||||
data["shoot_inventory"] = shoot_inventory
|
|
||||||
data["locked"] = locked
|
|
||||||
data["secure"] = is_secure
|
|
||||||
|
|
||||||
var/list/items[0]
|
|
||||||
for (var/i=1 to length(item_records))
|
|
||||||
var/datum/stored_item/I = item_records[i]
|
var/datum/stored_item/I = item_records[i]
|
||||||
var/count = I.get_amount()
|
var/count = I.get_amount()
|
||||||
if(count > 0)
|
if(count > 0)
|
||||||
items.Add(list(list("display_name" = html_encode(capitalize(I.item_name)), "vend" = i, "quantity" = count)))
|
items.Add(list(list("name" = html_encode(capitalize(I.item_name)), "index" = i, "amount" = count)))
|
||||||
|
|
||||||
if(items.len > 0)
|
.["contents"] = items
|
||||||
data["contents"] = items
|
.["name"] = name
|
||||||
|
.["locked"] = locked
|
||||||
|
.["secure"] = is_secure
|
||||||
|
|
||||||
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
|
/obj/machinery/smartfridge/tgui_act(action, params)
|
||||||
if(!ui)
|
if(..())
|
||||||
ui = new(user, src, ui_key, "smartfridge.tmpl", src.name, 400, 500)
|
return TRUE
|
||||||
ui.set_initial_data(data)
|
|
||||||
ui.open()
|
|
||||||
|
|
||||||
/obj/machinery/smartfridge/Topic(href, href_list)
|
add_fingerprint(usr)
|
||||||
if(..()) return 0
|
switch(action)
|
||||||
|
if("Release")
|
||||||
|
var/amount = 0
|
||||||
|
if(params["amount"])
|
||||||
|
amount = params["amount"]
|
||||||
|
else
|
||||||
|
amount = input("How many items?", "How many items would you like to take out?", 1) as num|null
|
||||||
|
|
||||||
var/mob/user = usr
|
if(QDELETED(src) || QDELETED(usr) || !usr.Adjacent(src))
|
||||||
var/datum/nanoui/ui = SSnanoui.get_open_ui(user, src, "main")
|
return FALSE
|
||||||
|
|
||||||
src.add_fingerprint(user)
|
var/index = text2num(params["index"])
|
||||||
|
var/datum/stored_item/I = item_records[index]
|
||||||
|
var/count = I.get_amount()
|
||||||
|
|
||||||
if(href_list["close"])
|
// Sanity check, there are probably ways to press the button when it shouldn't be possible.
|
||||||
user.unset_machine()
|
if(count > 0)
|
||||||
ui.close()
|
if((count - amount) < 0)
|
||||||
return 0
|
amount = count
|
||||||
|
for(var/i = 1 to amount)
|
||||||
|
vend(I)
|
||||||
|
|
||||||
if(href_list["vend"])
|
return TRUE
|
||||||
var/index = text2num(href_list["vend"])
|
return FALSE
|
||||||
var/amount = text2num(href_list["amount"])
|
|
||||||
var/datum/stored_item/I = item_records[index]
|
|
||||||
var/count = I.get_amount()
|
|
||||||
|
|
||||||
// Sanity check, there are probably ways to press the button when it shouldn't be possible.
|
|
||||||
if(count > 0)
|
|
||||||
if((count - amount) < 0)
|
|
||||||
amount = count
|
|
||||||
for(var/i = 1 to amount)
|
|
||||||
vend(I)
|
|
||||||
|
|
||||||
return 1
|
|
||||||
return 0
|
|
||||||
|
|
||||||
/obj/machinery/smartfridge/proc/throw_item()
|
/obj/machinery/smartfridge/proc/throw_item()
|
||||||
var/obj/throw_item = null
|
var/obj/throw_item = null
|
||||||
@@ -400,17 +391,18 @@
|
|||||||
spawn(0)
|
spawn(0)
|
||||||
throw_item.throw_at(target,16,3,src)
|
throw_item.throw_at(target,16,3,src)
|
||||||
src.visible_message("<span class='warning'>[src] launches [throw_item.name] at [target.name]!</span>")
|
src.visible_message("<span class='warning'>[src] launches [throw_item.name] at [target.name]!</span>")
|
||||||
|
SStgui.update_uis(src)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
/************************
|
/************************
|
||||||
* Secure SmartFridges
|
* Secure SmartFridges
|
||||||
*************************/
|
*************************/
|
||||||
|
|
||||||
/obj/machinery/smartfridge/secure/Topic(href, href_list)
|
/obj/machinery/smartfridge/secure/tgui_act(action, params)
|
||||||
if(stat & (NOPOWER|BROKEN))
|
if(stat & (NOPOWER|BROKEN))
|
||||||
return 0
|
return TRUE
|
||||||
if(usr.contents.Find(src) || (in_range(src, usr) && istype(loc, /turf)))
|
if(usr.contents.Find(src) || (in_range(src, usr) && istype(loc, /turf)))
|
||||||
if(!allowed(usr) && !emagged && locked != -1 && href_list["vend"])
|
if(!allowed(usr) && !emagged && locked != -1 && action == "Release")
|
||||||
to_chat(usr, "<span class='warning'>Access denied.</span>")
|
to_chat(usr, "<span class='warning'>Access denied.</span>")
|
||||||
return 0
|
return TRUE
|
||||||
return ..()
|
return ..()
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
<div class='item'>
|
|
||||||
{{:helper.link('Close', 'gear', {'close' : 1}, null, 'fixedLeft')}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="item">
|
|
||||||
<h2>Storage</h2>
|
|
||||||
{{if data.secure}}
|
|
||||||
<span class='notice'>
|
|
||||||
{{:data.locked == -1 ? "Sec.re ACC_** //):securi_nt.diag=>##'or 1=1'%($..." : "Secure Access: Please have your identification ready."}}
|
|
||||||
</span>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
<div class='item'>
|
|
||||||
{{if data.contents}}
|
|
||||||
{{for data.contents}}
|
|
||||||
<div class='item'>
|
|
||||||
<span class='highlight'>{{:value.display_name}} ({{:value.quantity}} available)</span>
|
|
||||||
<div style="float: left;">Vend: </div> {{:helper.link('x1', 'circle-arrow-s', { "vend" : value.vend, "amount" : 1 }, null, 'statusValue')}}
|
|
||||||
{{if value.quantity >= 5}}
|
|
||||||
{{:helper.link('x5', 'circle-arrow-s', { "vend" : value.vend, "amount" : 5 }, null, 'statusValue')}}
|
|
||||||
{{/if}}
|
|
||||||
{{if value.quantity >= 10}}
|
|
||||||
{{:helper.link('x10', 'circle-arrow-s', { "vend" : value.vend, "amount" : 10 }, null, 'statusValue')}}
|
|
||||||
{{/if}}
|
|
||||||
{{if value.quantity >= 25}}
|
|
||||||
{{:helper.link('x25', 'circle-arrow-s', { "vend" : value.vend, "amount" : 25 }, null, 'statusValue')}}
|
|
||||||
{{/if}}
|
|
||||||
{{if value.quantity > 1}}
|
|
||||||
{{:helper.link('All', 'circle-arrow-s', { "vend" : value.vend, "amount" : value.quantity }, null, 'statusValue')}}
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
{{/for}}
|
|
||||||
{{else}}
|
|
||||||
<span class='average'>No products loaded.</span>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
|
||||||
77
tgui/packages/tgui/interfaces/SmartVend.js
Normal file
77
tgui/packages/tgui/interfaces/SmartVend.js
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import { map } from 'common/collections';
|
||||||
|
import { useBackend } from '../backend';
|
||||||
|
import { Button, Box, NoticeBox, Section, Table } from '../components';
|
||||||
|
import { Window } from '../layouts';
|
||||||
|
|
||||||
|
export const SmartVend = (props, context) => {
|
||||||
|
const { act, config, data } = useBackend(context);
|
||||||
|
return (
|
||||||
|
<Window
|
||||||
|
width={440}
|
||||||
|
height={550}
|
||||||
|
resizable>
|
||||||
|
<Window.Content scrollable>
|
||||||
|
<Section title="Storage">
|
||||||
|
{data.secure && (
|
||||||
|
<NoticeBox>
|
||||||
|
{data.locked === -1 ? (
|
||||||
|
<Box color="bad">Sec.re ACC_** //):securi_nt.diag=>##'or 1=1'%($...</Box>
|
||||||
|
) : (
|
||||||
|
<Box color="average">Secure Access: Please have your identification ready.</Box>
|
||||||
|
)}
|
||||||
|
</NoticeBox>
|
||||||
|
) || null}
|
||||||
|
{data.contents.length === 0 && (
|
||||||
|
<NoticeBox>
|
||||||
|
Unfortunately, this {config.title} is empty.
|
||||||
|
</NoticeBox>
|
||||||
|
) || (
|
||||||
|
<Table>
|
||||||
|
<Table.Row header>
|
||||||
|
<Table.Cell>
|
||||||
|
Item
|
||||||
|
</Table.Cell>
|
||||||
|
<Table.Cell collapsing />
|
||||||
|
<Table.Cell collapsing textAlign="center">
|
||||||
|
Dispense
|
||||||
|
</Table.Cell>
|
||||||
|
</Table.Row>
|
||||||
|
{map((value, key) => (
|
||||||
|
<Table.Row key={key}>
|
||||||
|
<Table.Cell>
|
||||||
|
{value.name}
|
||||||
|
</Table.Cell>
|
||||||
|
<Table.Cell collapsing textAlign="right">
|
||||||
|
{value.amount}
|
||||||
|
</Table.Cell>
|
||||||
|
<Table.Cell collapsing>
|
||||||
|
<Button
|
||||||
|
content="One"
|
||||||
|
disabled={value.amount < 1}
|
||||||
|
onClick={() => act('Release', {
|
||||||
|
index: value.index,
|
||||||
|
amount: 1,
|
||||||
|
})} />
|
||||||
|
<Button
|
||||||
|
content="Many"
|
||||||
|
disabled={value.amount <= 1}
|
||||||
|
onClick={() => act('Release', {
|
||||||
|
index: value.index,
|
||||||
|
})} />
|
||||||
|
<Button
|
||||||
|
content="All"
|
||||||
|
disabled={value.amount < 1}
|
||||||
|
onClick={() => act('Release', {
|
||||||
|
index: value.index,
|
||||||
|
amount: value.amount,
|
||||||
|
})} />
|
||||||
|
</Table.Cell>
|
||||||
|
</Table.Row>
|
||||||
|
))(data.contents)}
|
||||||
|
</Table>
|
||||||
|
)}
|
||||||
|
</Section>
|
||||||
|
</Window.Content>
|
||||||
|
</Window>
|
||||||
|
);
|
||||||
|
};
|
||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user