Skip to content

Commit

Permalink
convert holoposter to TGUI (#8377)
Browse files Browse the repository at this point in the history
* fix perk asset datum path

* tweak GameIcon component & update Vending layout

* convert holoposter to TGUI

* update TGUI Bundle

* Update tgui/packages/tgui/interfaces/Holoposter.tsx
  • Loading branch information
intercepti0n authored Dec 1, 2023
1 parent 8814ec9 commit 54171ec
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 61 deletions.
1 change: 1 addition & 0 deletions cev_eris.dme
Original file line number Diff line number Diff line change
Expand Up @@ -2756,6 +2756,7 @@
#include "code\modules\tgui\tgui_window.dm"
#include "code\modules\tgui\states\always.dm"
#include "code\modules\tgui\states\hands.dm"
#include "code\modules\tgui\states\holoposter.dm"
#include "code\modules\tgui\states\machinery.dm"
#include "code\modules\tgui\states\notcontained.dm"
#include "code\modules\tips_and_tricks\gameplay.dm"
Expand Down
2 changes: 1 addition & 1 deletion code/datums/mob_stats_menu.dm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/datum/stat_holder/ui_assets(mob/user)
return list(
get_asset_datum(/datum/asset/spritesheet/simple/perks)
get_asset_datum(/datum/asset/spritesheet/perks)
)

/datum/stat_holder/ui_static_data(mob/user)
Expand Down
104 changes: 73 additions & 31 deletions code/game/machinery/holoposter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@
use_power = IDLE_POWER_USE
idle_power_usage = 80
power_channel = STATIC_ENVIRON
var/icon_forced = FALSE
var/seclevel = ""
var/last_launch = 0

var/list/postertypes = list(
var/static/list/poster_types = list(
"ironhammer" = COLOR_LIGHTING_BLUE_BRIGHT,
"frozenstar" = COLOR_LIGHTING_BLUE_BRIGHT,
"neotheology" = COLOR_LIGHTING_ORANGE_BRIGHT,
"asters" = COLOR_LIGHTING_GREEN_BRIGHT,
"tehnomancers" = COLOR_LIGHTING_ORANGE_BRIGHT,
"moebius" = COLOR_LIGHTING_PURPLE_BRIGHT,
"med" = COLOR_LIGHTING_GREEN_BRIGHT,
"med" = COLOR_LIGHTING_GREEN_BRIGHT
)

var/selected_icon = "moebius"
var/icon_forced = FALSE
var/last_launch = 0

/obj/machinery/holoposter/update_icon()
if(stat & NOPOWER)
icon_state = "off"
set_light(0)
return

var/new_color = COLOR_LIGHTING_DEFAULT_BRIGHT
if(stat & BROKEN)
icon_state = "glitch"
Expand All @@ -35,38 +37,21 @@
if(security_state.current_security_level_is_same_or_higher_than(security_state.high_security_level))
icon_state = "attention"
new_color = "#AA7039"
else if(icon_state in postertypes)
new_color = postertypes[icon_state]
else if(selected_icon)
new_color = poster_types[selected_icon]

set_light(l_range = 2, l_power = 2, l_color = new_color)

/obj/machinery/holoposter/proc/set_rand_sprite()
icon_state = pick(postertypes)
update_icon()

/obj/machinery/holoposter/attackby(obj/item/W as obj, mob/user as mob)
/obj/machinery/holoposter/attackby(obj/item/W, mob/user)
src.add_fingerprint(user)
if(stat & (NOPOWER))
return
if (istype(W, /obj/item/tool/multitool))
var/selected_icon_state
playsound(user.loc, 'sound/items/multitool_pulse.ogg', 60, 1)
selected_icon_state = input("Available Posters", "Holographic Poster") as null|anything in postertypes + "random"
if(!selected_icon_state)
return
else
icon_state = selected_icon_state
if(icon_state == "random")
stat &= ~BROKEN
icon_forced = FALSE
set_rand_sprite()
return
icon_forced = TRUE
stat &= ~BROKEN
update_icon()

if(istype(W, /obj/item/tool/multitool))
ui_interact(user)
return

/obj/machinery/holoposter/attack_ai(mob/user as mob)
/obj/machinery/holoposter/attack_ai(mob/user)
return attack_hand(user)

/obj/machinery/holoposter/power_change()
Expand All @@ -82,6 +67,63 @@
/obj/machinery/holoposter/Process()
if(stat & (NOPOWER|BROKEN))
return
if((world.time > last_launch + 1 MINUTES) && (!icon_forced))
set_rand_sprite()

if(!icon_forced && world.time > last_launch + 1 MINUTES)
last_launch = world.time
select_icon(null)
update_icon()

/obj/machinery/holoposter/ui_state(mob/user)
return GLOB.holoposter_state

/obj/machinery/holoposter/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "Holoposter", name)
ui.open()

/obj/machinery/holoposter/ui_static_data(mob/user)
return list(
"posterTypes" = poster_types,
)

/obj/machinery/holoposter/ui_data(mob/user)
var/static/list/icon_chache
if(!icon_chache)
for(var/icon_state as anything in poster_types)
LAZYADD(icon_chache, icon_state)
icon_chache[icon_state] = icon(icon, icon_state, frame = 1)

return list(
"isRandom" = !icon_forced,
"selected" = selected_icon,
"icon" = icon2base64html(icon_chache[selected_icon])
)

/obj/machinery/holoposter/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
. = ..()
if(.)
return

switch(action)
if("change")
change(params["value"])
. = TRUE

if("random")
random()
. = TRUE

/obj/machinery/holoposter/proc/change(new_icon_state)
select_icon(new_icon_state)
stat &= ~BROKEN
update_icon()

/obj/machinery/holoposter/proc/random()
icon_forced = !icon_forced
stat &= ~BROKEN

/obj/machinery/holoposter/proc/select_icon(new_icon)
selected_icon = (new_icon in poster_types) ? new_icon : pick(poster_types)
icon_forced = !isnull(new_icon)
icon_state = selected_icon
1 change: 0 additions & 1 deletion code/modules/asset_cache/assets/sheetmaterials.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
InsertAll("", 'icons/obj/stack/material.dmi')
// Special case on RCD objects
Insert("rcd", 'icons/obj/ammo.dmi', "rcd")

4 changes: 2 additions & 2 deletions code/modules/asset_cache/assets/stats.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/datum/asset/spritesheet/simple/perks
/datum/asset/spritesheet/perks
name = "perks"

/datum/asset/spritesheet/simple/perks/create_spritesheets()
/datum/asset/spritesheet/perks/create_spritesheets()
InsertAll("", 'icons/effects/perks.dmi')
15 changes: 15 additions & 0 deletions code/modules/tgui/states/holoposter.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
GLOBAL_DATUM_INIT(holoposter_state, /datum/ui_state/holoposter_state, new)

/datum/ui_state/holoposter_state/can_use_topic(obj/machinery/holoposter/src_object, mob/user)
ASSERT(istype(src_object))

if(src_object.stat & NOPOWER)
return UI_CLOSE

if(isobserver(user) || issilicon(user))
return user.default_can_use_topic(src_object)

if(!istype(user.get_active_hand(), /obj/item/tool/multitool))
return UI_CLOSE

return user.default_can_use_topic(src_object)
5 changes: 4 additions & 1 deletion tgui/packages/tgui/components/GameIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Box } from './Box';

type GameIconProps = {
html: string;
className?: string;
Expand All @@ -11,7 +13,8 @@ export const GameIcon = (props: GameIconProps) => {
const iconSrc = html.match('src=["\'](.*)["\']')![1];

return (
<img
<Box
as="img"
key={key}
{...props}
className={`game-icon ${className || ''}`}
Expand Down
69 changes: 69 additions & 0 deletions tgui/packages/tgui/interfaces/Holoposter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { capitalize } from '../../common/string';
import { useBackend } from '../backend';
import { Button, Section, Stack } from '../components';
import { GameIcon } from '../components/GameIcon';
import { Window } from '../layouts';

interface HoloposterProps {
posterTypes: Record<string, string>;
isRandom: boolean;
selected: string;
icon: string;
}

const HoloposterContent = (props: any, context: any) => {
const { act, data } = useBackend<HoloposterProps>(context);
const { posterTypes, isRandom, selected, icon } = data;

return (
<Stack fill justify="space-between">
<Stack.Item
grow
style={{
'display': 'flex',
'align-items': 'center',
'justify-content': 'center',
}}>
<GameIcon
html={icon}
style={{
'height': 'auto',
'width': '100%',
}}
/>
</Stack.Item>
<Stack.Item grow={2}>
<Section
fill
title="Holograms"
buttons={
<Button
icon="random"
selected={isRandom}
tooltip={'Toggle poster rotation.'}
onClick={() => act('random')}
/>
}>
{Object.keys(posterTypes).map((value) => (
<Button
key={value}
content={capitalize(value)}
selected={selected === value}
onClick={() => act('change', { value: value })}
/>
))}
</Section>
</Stack.Item>
</Stack>
);
};

export const Holoposter = (props: any, context: any) => {
return (
<Window width={320} height={180}>
<Window.Content>
<HoloposterContent />
</Window.Content>
</Window>
);
};
53 changes: 32 additions & 21 deletions tgui/packages/tgui/interfaces/Vending.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capitalize } from 'common/string';
import { capitalize } from '../../common/string';
import { useBackend } from '../backend';
import { BlockQuote, Box, Button, Icon, LabeledList, Modal, NoticeBox, Section, Stack } from '../components';
import { GameIcon } from '../components/GameIcon';
Expand Down Expand Up @@ -138,28 +138,39 @@ const product = (product: ProductData, context: any) => {
<Stack.Item grow>
<Button
fluid
ellipsis
onClick={() => act('vend', { key: product.key })}>
<Stack fill align="center">
<Stack.Item>
<GameIcon html={product.icon} className="Vending--game-icon" />
</Stack.Item>
<Stack.Item grow={4} textAlign="left" className="Vending--text">
{product.name}
</Stack.Item>
<Stack.Item grow textAlign="right" className="Vending--text">
{product.amount}
<Icon name="box" pl="0.6em" />
</Stack.Item>
{(product.price > 0 && (
height="100%"
verticalAlignContent="middle"
content={
<Stack fill align="center">
<Stack.Item
style={{
'display': 'flex',
'align-items': 'center',
'justify-content': 'center',
}}>
<GameIcon
html={product.icon}
className="Vending--game-icon"
/>
</Stack.Item>
<Stack.Item grow={4} textAlign="left" className="Vending--text">
{product.name}
</Stack.Item>
<Stack.Item grow textAlign="right" className="Vending--text">
{product.price}
<Icon name="money-bill" pl="0.6em" />
{product.amount}
<Icon name="box" pl="0.6em" />
</Stack.Item>
)) ||
null}
</Stack>
</Button>
{(product.price > 0 && (
<Stack.Item grow textAlign="right" className="Vending--text">
{product.price}
<Icon name="money-bill" pl="0.6em" />
</Stack.Item>
)) ||
null}
</Stack>
}
onClick={() => act('vend', { key: product.key })}
/>
</Stack.Item>
{(data.isManaging && (
<>
Expand Down
4 changes: 2 additions & 2 deletions tgui/packages/tgui/styles/interfaces/Vending.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
height: 5.9ch;
}
&--game-icon {
width: 2.5rem;
align-items: center;
height: 2.5rem;
width: auto;
}
&--modal {
width: 30rem;
Expand Down
2 changes: 1 addition & 1 deletion tgui/public/tgui.bundle.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tgui/public/tgui.bundle.js

Large diffs are not rendered by default.

0 comments on commit 54171ec

Please sign in to comment.