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].")
|
||||
playsound(src, O.usesound, 50, 1)
|
||||
update_icon()
|
||||
SSnanoui.update_uis(src)
|
||||
return
|
||||
|
||||
if(wrenchable && default_unfasten_wrench(user, O, 20))
|
||||
@@ -263,7 +262,6 @@
|
||||
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>")
|
||||
|
||||
|
||||
else if(istype(O, /obj/item/weapon/storage/bag))
|
||||
var/obj/item/weapon/storage/bag/P = O
|
||||
var/plants_loaded = 0
|
||||
@@ -309,11 +307,11 @@
|
||||
var/datum/stored_item/item = new/datum/stored_item(src, O.type, O.name)
|
||||
item.add_product(O)
|
||||
item_records.Add(item)
|
||||
SSnanoui.update_uis(src)
|
||||
SStgui.update_uis(src)
|
||||
|
||||
/obj/machinery/smartfridge/proc/vend(datum/stored_item/I)
|
||||
I.get_product(get_turf(src))
|
||||
SSnanoui.update_uis(src)
|
||||
SStgui.update_uis(src)
|
||||
|
||||
/obj/machinery/smartfridge/attack_ai(mob/user as mob)
|
||||
attack_hand(user)
|
||||
@@ -322,66 +320,59 @@
|
||||
if(stat & (NOPOWER|BROKEN))
|
||||
return
|
||||
wires.Interact(user)
|
||||
ui_interact(user)
|
||||
tgui_interact(user)
|
||||
|
||||
/*******************
|
||||
* SmartFridge Menu
|
||||
********************/
|
||||
/obj/machinery/smartfridge/tgui_interact(mob/user, datum/tgui/ui)
|
||||
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)
|
||||
user.set_machine(src)
|
||||
/obj/machinery/smartfridge/tgui_data(mob/user)
|
||||
. = list()
|
||||
|
||||
var/data[0]
|
||||
data["contents"] = null
|
||||
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/list/items = list()
|
||||
for(var/i=1 to length(item_records))
|
||||
var/datum/stored_item/I = item_records[i]
|
||||
var/count = I.get_amount()
|
||||
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)
|
||||
data["contents"] = items
|
||||
.["contents"] = items
|
||||
.["name"] = name
|
||||
.["locked"] = locked
|
||||
.["secure"] = is_secure
|
||||
|
||||
ui = SSnanoui.try_update_ui(user, src, ui_key, ui, data, force_open)
|
||||
if(!ui)
|
||||
ui = new(user, src, ui_key, "smartfridge.tmpl", src.name, 400, 500)
|
||||
ui.set_initial_data(data)
|
||||
ui.open()
|
||||
/obj/machinery/smartfridge/tgui_act(action, params)
|
||||
if(..())
|
||||
return TRUE
|
||||
|
||||
/obj/machinery/smartfridge/Topic(href, href_list)
|
||||
if(..()) return 0
|
||||
add_fingerprint(usr)
|
||||
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
|
||||
|
||||
if(QDELETED(src) || QDELETED(usr) || !usr.Adjacent(src))
|
||||
return FALSE
|
||||
|
||||
var/index = text2num(params["index"])
|
||||
var/datum/stored_item/I = item_records[index]
|
||||
var/count = I.get_amount()
|
||||
|
||||
var/mob/user = usr
|
||||
var/datum/nanoui/ui = SSnanoui.get_open_ui(user, src, "main")
|
||||
// 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)
|
||||
|
||||
src.add_fingerprint(user)
|
||||
|
||||
if(href_list["close"])
|
||||
user.unset_machine()
|
||||
ui.close()
|
||||
return 0
|
||||
|
||||
if(href_list["vend"])
|
||||
var/index = text2num(href_list["vend"])
|
||||
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
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
/obj/machinery/smartfridge/proc/throw_item()
|
||||
var/obj/throw_item = null
|
||||
@@ -400,17 +391,18 @@
|
||||
spawn(0)
|
||||
throw_item.throw_at(target,16,3,src)
|
||||
src.visible_message("<span class='warning'>[src] launches [throw_item.name] at [target.name]!</span>")
|
||||
SStgui.update_uis(src)
|
||||
return 1
|
||||
|
||||
/************************
|
||||
* Secure SmartFridges
|
||||
*************************/
|
||||
|
||||
/obj/machinery/smartfridge/secure/Topic(href, href_list)
|
||||
/obj/machinery/smartfridge/secure/tgui_act(action, params)
|
||||
if(stat & (NOPOWER|BROKEN))
|
||||
return 0
|
||||
return TRUE
|
||||
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>")
|
||||
return 0
|
||||
return TRUE
|
||||
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