Skip to content

Commit

Permalink
Vending machine lock improvements (ParadiseSS13#28200)
Browse files Browse the repository at this point in the history
* Vending machine lock improvements

* No dumping stuff in when the vendor is locked!

* Fix custom vendor UI height when unlocked.
  • Loading branch information
FunnyMan3595 authored Feb 13, 2025
1 parent 719fe61 commit 5495930
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 103 deletions.
5 changes: 5 additions & 0 deletions code/__DEFINES/vending_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
#define VENDOR_TYPE_SUPPLIES "supplies"
#define VENDOR_TYPE_DEPARTMENTAL "departmental"
#define VENDOR_TYPE_RECREATION "recreation"

// How "locked" is this vendor?
#define VENDOR_UNLOCKED 0
#define VENDOR_LOCKED_FOR_OTHERS 1
#define VENDOR_LOCKED 2
27 changes: 21 additions & 6 deletions code/game/machinery/vendors/custom_vendors.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@
linked_pos = null
return ..()

/obj/machinery/economy/vending/custom/locked()
return isnull(linked_pos) || linked_pos.transaction_locked
/obj/machinery/economy/vending/custom/locked(mob/user)
if(isnull(linked_pos))
return VENDOR_LOCKED
if(!linked_pos.transaction_locked)
return VENDOR_UNLOCKED
// We check loc instead of calling is_holding so that it works in a pocket.
if(linked_pos.loc == user)
return VENDOR_LOCKED_FOR_OTHERS
return VENDOR_LOCKED

/obj/machinery/economy/vending/custom/get_vendor_account()
return linked_pos?.linked_account || ..()
Expand All @@ -24,7 +31,7 @@
if(user.a_intent == INTENT_HARM)
return ..()

if(istype(used, /obj/item/eftpos))
if((isnull(linked_pos) || locked(user) != VENDOR_LOCKED) && istype(used, /obj/item/eftpos))
visible_message("<span class='notice'>[src] beeps as [user] links it to [used].</span>", "<span class='notice'>You hear something beep.</span>")
if(!isnull(linked_pos))
linked_pos.linked_vendors -= src
Expand All @@ -35,7 +42,7 @@
else if(isnull(linked_pos))
to_chat(user, "<span class='warning'>You need to link a point of sale device first!</span>")
return ITEM_INTERACT_COMPLETE
else if(locked())
else if(locked(user) == VENDOR_LOCKED)
return ..()

try_add_stock(user, used)
Expand Down Expand Up @@ -113,6 +120,8 @@
return INSERT_DONE

/obj/machinery/economy/vending/custom/MouseDrop_T(atom/dragged, mob/user, params)
if(locked(user) == VENDOR_LOCKED)
return ..()
if(!istype(dragged, /obj/item/storage))
return ..()

Expand Down Expand Up @@ -143,8 +152,14 @@
return TRUE

/obj/machinery/economy/vending/custom/crowbar_act(mob/user, obj/item/I)
if(!isnull(linked_pos) && linked_pos.transaction_locked)
user.visible_message("<span class='notice'>[user] tries to pry [src] apart, but fails.</span>", "<span class='notice'>The lock on [src] resists your efforts to pry it apart.</span>")
if(!isnull(linked_pos) && locked(user) == VENDOR_LOCKED)
user.visible_message("<span class='notice'>[user] tries to pry [src] apart, but fails.</span>", "<span class='warning'>The lock on [src] resists your efforts to pry it apart.</span>")
return TRUE
return ..()

/obj/machinery/economy/vending/custom/wrench_act(mob/user, obj/item/I)
if(!isnull(linked_pos) && locked(user) == VENDOR_LOCKED)
user.visible_message("<span class='notice'>[user] tries to loosen the bolts on [src], but fails.</span>", "<span class='warning'>The lock on [src] is covering its bolts.</span>")
return TRUE
return ..()

Expand Down
14 changes: 7 additions & 7 deletions code/game/machinery/vendors/vending.dm
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,8 @@
/obj/machinery/economy/vending/ui_data(mob/user)
var/list/data = list()

data["locked"] = locked()
data["chargesMoney"] = locked()
data["locked"] = locked(user) != VENDOR_UNLOCKED
data["bypass_lock"] = locked(user) == VENDOR_LOCKED_FOR_OTHERS
data["usermoney"] = 0
data["inserted_cash"] = cash_transaction
data["user"] = null
Expand Down Expand Up @@ -777,12 +777,12 @@
var/key = text2num(params["inum"])
try_vend(key, user)
if("rename")
if(!locked())
if(locked(user) != VENDOR_LOCKED)
var/new_name = tgui_input_text(user, "Rename the vendor to what?", name)
if(!isnull(new_name))
name = new_name
if("change_appearance")
if(locked())
if(locked(user) == VENDOR_LOCKED)
return
var/possible_icons = list()
var/icon_lookup = list()
Expand Down Expand Up @@ -834,7 +834,7 @@
flick(icon_deny, src)
return

if(!ishuman(user) || currently_vending.price <= 0 || !locked())
if(!ishuman(user) || currently_vending.price <= 0 || locked(user) != VENDOR_LOCKED)
// Either the purchaser is not human, or the item is free.
// Skip all payment logic, and vend without a delay.
vend(currently_vending, user, FALSE)
Expand Down Expand Up @@ -1079,8 +1079,8 @@
mob_hurt = TRUE
return ..()

/obj/machinery/economy/vending/proc/locked()
return TRUE
/obj/machinery/economy/vending/proc/locked(mob/user)
return VENDOR_LOCKED

/obj/machinery/economy/vending/proc/get_vendor_account()
return GLOB.station_money_database.vendor_account
Expand Down
92 changes: 47 additions & 45 deletions tgui/packages/tgui/interfaces/Vending.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ import { Window } from '../layouts';
const VendingRow = (props, context) => {
const { act, data } = useBackend(context);
const { product, productStock, productIcon, productIconState } = props;
const { chargesMoney, user, usermoney, inserted_cash, vend_ready, inserted_item_name } = data;
const free = !chargesMoney || product.price === 0;
const { locked, bypass_lock, user, usermoney, inserted_cash, vend_ready, inserted_item_name } = data;
let buttonText = 'ERROR!';
let rowIcon = '';
if (free) {
if (locked && bypass_lock) {
buttonText = 'FREE (' + product.price + ')';
rowIcon = 'arrow-circle-down';
} else if (!locked) {
buttonText = 'FREE';
rowIcon = 'arrow-circle-down';
} else {
buttonText = product.price;
rowIcon = 'shopping-cart';
}
let buttonDisabled =
!vend_ready || productStock === 0 || (!free && product.price > usermoney && product.price > inserted_cash);
!vend_ready ||
productStock === 0 ||
(locked && !bypass_lock && product.price > usermoney && product.price > inserted_cash);
return (
<Table.Row>
<Table.Cell collapsing>
Expand Down Expand Up @@ -58,7 +62,6 @@ export const Vending = (props, context) => {
user,
usermoney,
inserted_cash,
chargesMoney,
product_records = [],
hidden_records = [],
stock,
Expand All @@ -67,6 +70,7 @@ export const Vending = (props, context) => {
panel_open,
speaker,
locked,
bypass_lock,
} = data;
let inventory;

Expand All @@ -80,11 +84,11 @@ export const Vending = (props, context) => {
<Window
title="Vending Machine"
width={450}
height={Math.min((chargesMoney ? 171 : 89) + inventory.length * 32, 585)}
height={Math.min((!locked || !!bypass_lock ? 230 : 171) + inventory.length * 32, 585)}
>
<Window.Content scrollable>
<Stack fill vertical>
{!locked && (
{(!locked || !!bypass_lock) && (
<Stack.Item>
<Section title="Configuration">
<Stack horizontal>
Expand All @@ -102,46 +106,44 @@ export const Vending = (props, context) => {
</Section>
</Stack.Item>
)}
{!!chargesMoney && (
<Stack.Item>
<Section
title="User"
buttons={
<Stack>
<Stack.Item>
{!!inserted_item_name && (
<Button
fluid
icon="eject"
content={<span style={{ 'text-transform': 'capitalize' }}>{inserted_item_name}</span>}
onClick={() => act('eject_item', {})}
/>
)}
</Stack.Item>
<Stack.Item>
<Stack.Item>
<Section
title="User"
buttons={
<Stack>
<Stack.Item>
{!!inserted_item_name && (
<Button
disabled={!inserted_cash}
icon="money-bill-wave-alt"
content={inserted_cash ? <>{<b>{inserted_cash}</b>} credits</> : 'Dispense Change'}
tooltip={inserted_cash ? 'Dispense Change' : null}
textAlign="left"
onClick={() => act('change')}
fluid
icon="eject"
content={<span style={{ 'text-transform': 'capitalize' }}>{inserted_item_name}</span>}
onClick={() => act('eject_item', {})}
/>
</Stack.Item>
</Stack>
}
>
{user && (
<Box>
Welcome, <b>{user.name}</b>, <b>{user.job || 'Unemployed'}</b>!
<br />
Your balance is <b>{usermoney} credits</b>.
<br />
</Box>
)}
</Section>
</Stack.Item>
)}
)}
</Stack.Item>
<Stack.Item>
<Button
disabled={!inserted_cash}
icon="money-bill-wave-alt"
content={inserted_cash ? <>{<b>{inserted_cash}</b>} credits</> : 'Dispense Change'}
tooltip={inserted_cash ? 'Dispense Change' : null}
textAlign="left"
onClick={() => act('change')}
/>
</Stack.Item>
</Stack>
}
>
{user && (
<Box>
Welcome, <b>{user.name}</b>, <b>{user.job || 'Unemployed'}</b>!
<br />
Your balance is <b>{usermoney} credits</b>.
<br />
</Box>
)}
</Section>
</Stack.Item>
{!!panel_open && (
<Stack.Item>
<Section title="Maintenance">
Expand Down
90 changes: 45 additions & 45 deletions tgui/public/tgui.bundle.js

Large diffs are not rendered by default.

0 comments on commit 5495930

Please sign in to comment.