Skip to content

Commit

Permalink
[TGUI] Prize Counter (ParadiseSS13#24079)
Browse files Browse the repository at this point in the history
* PrizeCounterUI 1.0

Update PrizeCounter.scss

Update prize_counter.dm

UI work

It just works

* Image layout fix

* Better names

* Tooltip

* Unused code and disable button

* That's not necessary either

* Search

* Maybe that's all

* Stack.Divider, wow, universal component

* Rebuild

* Rebuild

* Turn off auto-update

* Ooops

* Code style

* Rebuild

* Ah... yes... rebuild

* Ticket icon like on screenshot
  • Loading branch information
AyIong authored Mar 21, 2024
1 parent 34d4b93 commit 38f009b
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 236 deletions.
202 changes: 59 additions & 143 deletions code/modules/arcade/prize_counter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
density = TRUE
anchored = TRUE
idle_power_consumption = 40

/// Amount of arcade tickets in the prize counter.
var/tickets = 0

/obj/machinery/prize_counter/Initialize(mapload)
Expand All @@ -20,6 +20,58 @@
component_parts += new /obj/item/stack/sheet/glass(null)
RefreshParts()

/obj/machinery/prize_counter/ui_state(mob/user)
return GLOB.default_state

/obj/machinery/prize_counter/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "PrizeCounter", name)
ui.set_autoupdate(FALSE)
ui.open()

/obj/machinery/prize_counter/ui_assets(mob/user)
return list(
get_asset_datum(/datum/asset/spritesheet/prize_counter)
)

/obj/machinery/prize_counter/ui_data(mob/user)
var/list/data = list()
data["tickets"] = tickets
return data

/obj/machinery/prize_counter/ui_static_data(mob/user)
var/list/static_data = list()

var/list/prizes = list()
for(var/datum/prize_item/prize in GLOB.global_prizes.prizes)
prizes += list(list(
"name" = initial(prize.name),
"desc" = initial(prize.desc),
"cost" = prize.cost,
"itemID" = GLOB.global_prizes.prizes.Find(prize),
"imageID" = replacetext(replacetext("[prize.typepath]", "/obj/item/", ""), "/", "-"),
))
static_data["prizes"] = prizes

return static_data

/obj/machinery/prize_counter/ui_act(action, params, datum/tgui/ui)
if(..())
return
. = TRUE

add_fingerprint(usr)
switch(action)
if("purchase")
var/itemID = text2num(params["purchase"])
if(!GLOB.global_prizes.PlaceOrder(src, itemID))
return
return TRUE
if("eject")
print_tickets(usr)
return TRUE

/obj/machinery/prize_counter/update_icon_state()
if(stat & BROKEN)
icon_state = "prize_counter-broken"
Expand All @@ -30,11 +82,12 @@
else
icon_state = "prize_counter-on"

/obj/machinery/prize_counter/attackby(obj/item/O as obj, mob/user as mob, params)
/obj/machinery/prize_counter/attackby(obj/item/O, mob/user, params)
if(istype(O, /obj/item/stack/tickets))
var/obj/item/stack/tickets/T = O
if(user.unEquip(T)) //Because if you can't drop it for some reason, you shouldn't be increasing the tickets var
tickets += T.amount
SStgui.update_uis(src)
qdel(T)
else
to_chat(user, "<span class='warning'>\The [T] seems stuck to your hand!</span>")
Expand All @@ -59,155 +112,18 @@
update_icon(UPDATE_ICON_STATE)
return TRUE

/obj/machinery/prize_counter/attack_hand(mob/user as mob)
/obj/machinery/prize_counter/attack_hand(mob/user)
if(..())
return
add_fingerprint(user)
interact(user)

/obj/machinery/prize_counter/interact(mob/user as mob)
user.set_machine(src)

if(stat & (BROKEN|NOPOWER))
return

var/dat = {"
<html><meta charset='utf-8'>
<head>
<title>Arcade Ticket Exchange</title>
<style type="text/css">
* {
font-family:sans-serif;
font-size:x-small;
}
html {
background:#333;
color:#999;
}

table {background:#303030;border:1px solid #262626;}

caption {text-align:left;}

.button {
color:#cfcfcf;
text-decoration:none;
font-weight:bold;
text-align:center;
width:75px;
padding:21px;
box-sizing:border-box;
background:none;
border:none;
display: inline-block;
}
.button:hover {color:#ffffff;}

a {
color:#cfcfcf;
text-decoration:none;
font-weight:bold;
}
a:hover {color:#ffffff;}

p {margin:0;}

tr.dark {background:#303030;}

tr.light {background:#3f3f3f;}

td,th {padding:15px;border-bottom:1px solid #262626;}

th.cost{padding:0px;border-left:1px solid #262626;}

th.cost.affordable {background:green;}

th.cost.toomuch {background:maroon;}

</style>
</head>
<body>
<p style="float:right"><b>Tickets: [tickets]</b> | <a href='byond://?src=[UID()];eject=1'>Eject Tickets</a></p>
<h1>Arcade Ticket Exchange</h1>
<p>
<b>Exchange that pile of tickets for a pile of cool prizes!</b>
</p>
<br>
<table cellspacing="0" cellpadding="0">
<caption><b>Available Prizes:</b></caption>
<thead>
<th>#</th>
<th>Name/Description</th>
<th>Tickets</th>
</thead>
<tbody>
"}

for(var/datum/prize_item/item in GLOB.global_prizes.prizes)
var/cost_class="affordable"
if(item.cost>tickets)
cost_class="toomuch"
var/itemID = GLOB.global_prizes.prizes.Find(item)
var/row_color="light"
if(itemID%2 == 0)
row_color="dark"
dat += {"
<tr class="[row_color]">
<th>
[itemID]
</th>
<td>
<p><b>[item.name]</b></p>
<p>[item.desc]</p>
</td>
"}
dat += {"
<th class="cost [cost_class]">
<a href="byond://?src=[UID()];buy=[itemID]" class="button">[item.cost]</a>
</th>
</tr>
"}

dat += {"
</tbody>
</table>
</body>
</html>"}
user << browse(dat, "window=prize_counter;size=440x600;can_resize=0")
onclose(user, "prize_counter")
return

/obj/machinery/prize_counter/Topic(href, href_list)
if(..())
return 1

add_fingerprint(usr)

if(href_list["eject"])
print_tickets()

if(href_list["buy"])
var/itemID = text2num(href_list["buy"])
var/datum/prize_item/item = GLOB.global_prizes.prizes[itemID]
var/sure = tgui_alert(usr,"Are you sure you wish to purchase [item.name] for [item.cost] tickets?", "You sure?", list("Yes","No"))
if(sure == "No")
updateUsrDialog()
return
if(!GLOB.global_prizes.PlaceOrder(src, itemID))
to_chat(usr, "<span class='warning'>Unable to complete the exchange.</span>")
else
to_chat(usr, "<span class='notice'>You've successfully purchased the item.</span>")
ui_interact(user)

interact(usr)
return
/obj/machinery/prize_counter/attack_ghost(mob/user)
ui_interact(user)

/obj/machinery/prize_counter/proc/print_tickets()
if(!tickets)
return
if(tickets >= 9999)
new /obj/item/stack/tickets(get_turf(src), 9999) //max stack size
tickets -= 9999
print_tickets()
else
new /obj/item/stack/tickets(get_turf(src), tickets)
tickets = 0
22 changes: 8 additions & 14 deletions code/modules/arcade/prize_datums.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,16 @@ GLOBAL_DATUM_INIT(global_prizes, /datum/prizes, new())
prizes += new itempath()

/datum/prizes/proc/PlaceOrder(obj/machinery/prize_counter/prize_counter, itemID)
if(!prize_counter.Adjacent(usr))
to_chat(usr, "<span class='warning'>You need to be closer!</span>")
return
if(!prize_counter)
return 0
var/datum/prize_item/item = GLOB.global_prizes.prizes[itemID]
if(!prize_counter)
return
if(!item)
return 0
if(prize_counter.tickets >= item.cost)
new item.typepath(prize_counter.loc)
prize_counter.tickets -= item.cost
to_chat(usr, "<span class='notice'>Enjoy your prize!</span>")
return TRUE
else
to_chat(usr, "<span class='warning'>Not enough tickets!</span>")
return FALSE
return

new item.typepath(prize_counter.loc)
prize_counter.tickets -= item.cost
to_chat(usr, "<span class='notice'>Enjoy your prize!</span>")
playsound(prize_counter, 'sound/machines/machine_vend.ogg', 50, TRUE)

//////////////////////////////////////
// prize_item datum //
Expand Down
13 changes: 13 additions & 0 deletions code/modules/asset_cache/assets/asset_prize_counter.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/datum/asset/spritesheet/prize_counter
name = "prize_counter"

/datum/asset/spritesheet/prize_counter/create_spritesheets()
for(var/datum/prize_item/prize in GLOB.global_prizes.prizes)
var/obj/item/prize_item = prize.typepath
var/prize_icon = icon(icon = initial(prize_item.icon), icon_state = initial(prize_item.icon_state))
var/imgid = replacetext(replacetext("[prize_item]", "/obj/item/", ""), "/", "-")
Insert(imgid, prize_icon)

/datum/asset/spritesheet/prize_counter/ModifyInserted(icon/pre_asset)
pre_asset.Scale(64, 64)
return pre_asset
1 change: 1 addition & 0 deletions paradise.dme
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,7 @@
#include "code\modules\asset_cache\assets\asset_nanomap.dm"
#include "code\modules\asset_cache\assets\asset_panels.dm"
#include "code\modules\asset_cache\assets\asset_paper.dm"
#include "code\modules\asset_cache\assets\asset_prize_counter.dm"
#include "code\modules\asset_cache\assets\asset_rpd.dm"
#include "code\modules\asset_cache\assets\asset_safe.dm"
#include "code\modules\asset_cache\assets\asset_tgui.dm"
Expand Down
Loading

0 comments on commit 38f009b

Please sign in to comment.