Skip to content

Commit

Permalink
convert holoposter to TGUI
Browse files Browse the repository at this point in the history
  • Loading branch information
intercepti0n committed Nov 26, 2023
1 parent d077489 commit 2bf87d4
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 31 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
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
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)
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 { Box, 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>
);
};

0 comments on commit 2bf87d4

Please sign in to comment.