mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-21 02:57:48 +01:00
Converts the PDA Painter to TGUI (#19974)
* pda painter TGUI * clean up extra stuff * build tgui correctly * less negative space * sirryan review * sirryan request * sirryan review 2 * Update code/game/machinery/PDApainter.dm Co-authored-by: Sirryan2002 <80364400+Sirryan2002@users.noreply.github.com> * Update code/game/machinery/PDApainter.dm Co-authored-by: Sirryan2002 <80364400+Sirryan2002@users.noreply.github.com> Co-authored-by: Sirryan2002 <80364400+Sirryan2002@users.noreply.github.com>
This commit is contained in:
co-authored by
Sirryan2002
parent
1af590a05c
commit
0cfa287220
@@ -7,7 +7,12 @@
|
||||
anchored = TRUE
|
||||
max_integrity = 200
|
||||
var/obj/item/pda/storedpda = null
|
||||
/// List of possible PDA colors to choose from
|
||||
var/list/colorlist = list()
|
||||
/// The preview to show of what the new paint will look like
|
||||
var/preview_icon_state = "pda"
|
||||
/// Cache of the icon state of the currently inserted PDA
|
||||
var/cached_icon_state
|
||||
|
||||
/obj/machinery/pdapainter/update_icon_state()
|
||||
if(stat & BROKEN)
|
||||
@@ -27,14 +32,27 @@
|
||||
|
||||
/obj/machinery/pdapainter/Initialize(mapload)
|
||||
. = ..()
|
||||
var/blocked = list(/obj/item/pda/silicon/ai, /obj/item/pda/silicon/robot, /obj/item/pda/silicon/pai, /obj/item/pda/heads,
|
||||
/obj/item/pda/clear, /obj/item/pda/syndicate, /obj/item/pda/chameleon, /obj/item/pda/chameleon/broken)
|
||||
var/blocked = list(
|
||||
/obj/item/pda/silicon,
|
||||
/obj/item/pda/silicon/ai,
|
||||
/obj/item/pda/silicon/robot,
|
||||
/obj/item/pda/silicon/pai,
|
||||
/obj/item/pda/heads,
|
||||
/obj/item/pda/clear,
|
||||
/obj/item/pda/syndicate,
|
||||
/obj/item/pda/chameleon,
|
||||
/obj/item/pda/chameleon/broken
|
||||
)
|
||||
|
||||
for(var/thing in typesof(/obj/item/pda) - blocked)
|
||||
var/obj/item/pda/P = thing
|
||||
colorlist[initial(P.icon_state)] = initial(P.desc)
|
||||
|
||||
// Icon state for TGUI, only select the first frame
|
||||
var/pda_icon_state = "[icon2base64(icon(initial(P.icon), initial(P.icon_state), frame = 1))]"
|
||||
colorlist[initial(P.icon_state)] = list(pda_icon_state, initial(P.desc))
|
||||
|
||||
/obj/machinery/pdapainter/Destroy()
|
||||
on_pda_qdel()
|
||||
QDEL_NULL(storedpda)
|
||||
return ..()
|
||||
|
||||
@@ -58,17 +76,7 @@
|
||||
power_change()
|
||||
return
|
||||
if(istype(I, /obj/item/pda))
|
||||
if(storedpda)
|
||||
to_chat(user, "There is already a PDA inside.")
|
||||
return
|
||||
else
|
||||
var/obj/item/pda/P = user.get_active_hand()
|
||||
if(istype(P))
|
||||
if(user.drop_item())
|
||||
storedpda = P
|
||||
P.forceMove(src)
|
||||
P.add_fingerprint(user)
|
||||
update_icon()
|
||||
insertpda(user)
|
||||
else
|
||||
return ..()
|
||||
|
||||
@@ -84,42 +92,105 @@
|
||||
stat |= BROKEN
|
||||
update_icon()
|
||||
|
||||
/obj/machinery/pdapainter/attack_hand(mob/user as mob)
|
||||
/obj/machinery/pdapainter/attack_hand(mob/user)
|
||||
if(..())
|
||||
return 1
|
||||
return TRUE
|
||||
|
||||
src.add_fingerprint(user)
|
||||
ui_interact(user)
|
||||
|
||||
/obj/machinery/pdapainter/ui_interact(mob/user, ui_key, datum/tgui/ui, force_open, datum/tgui/master_ui, datum/ui_state/state)
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
ui = new(user, src, ui_key, "PdaPainter", "PDA Painter", 510, 510)
|
||||
ui.open()
|
||||
|
||||
/obj/machinery/pdapainter/ui_data(mob/user)
|
||||
var/list/data = list()
|
||||
data["has_pda"] = storedpda ? TRUE : FALSE
|
||||
if(storedpda)
|
||||
var/obj/item/pda/P
|
||||
P = input(user, "Select your color!", "PDA Painting") as null|anything in colorlist
|
||||
if(!P)
|
||||
return
|
||||
if(!in_range(src, user))
|
||||
return
|
||||
data["current_appearance"] = cached_icon_state
|
||||
|
||||
storedpda.icon_state = P
|
||||
storedpda.desc = colorlist[P]
|
||||
var/icon/preview_sprite = icon(storedpda.icon, preview_icon_state, frame = 1)
|
||||
data["preview_appearance"] = icon2base64(preview_sprite)
|
||||
|
||||
else
|
||||
to_chat(user, "<span class='notice'>[src] is empty.</span>")
|
||||
return data
|
||||
|
||||
/obj/machinery/pdapainter/ui_static_data(mob/user)
|
||||
var/list/data = list()
|
||||
data["pda_colors"] = colorlist
|
||||
return data
|
||||
|
||||
/obj/machinery/pdapainter/verb/ejectpda()
|
||||
set name = "Eject PDA"
|
||||
set category = "Object"
|
||||
set src in oview(1)
|
||||
|
||||
if(usr.incapacitated())
|
||||
/obj/machinery/pdapainter/ui_act(action, params, datum/tgui/ui)
|
||||
if(..())
|
||||
return
|
||||
|
||||
if(storedpda)
|
||||
storedpda.loc = get_turf(src.loc)
|
||||
storedpda = null
|
||||
update_icon()
|
||||
else
|
||||
to_chat(usr, "<span class='notice'>[src] is empty.</span>")
|
||||
. = TRUE
|
||||
|
||||
switch(action)
|
||||
if("insert_pda")
|
||||
insertpda(ui.user)
|
||||
if("eject_pda")
|
||||
ejectpda(ui.user)
|
||||
if("choose_pda")
|
||||
preview_icon_state = params["selectedPda"]
|
||||
if("paint_pda")
|
||||
paintpda()
|
||||
|
||||
if(.)
|
||||
add_fingerprint(ui.user)
|
||||
|
||||
/obj/machinery/pdapainter/proc/insertpda(mob/user)
|
||||
if(storedpda)
|
||||
to_chat(user, "There is already a PDA inside.")
|
||||
return
|
||||
if(!ishuman(user))
|
||||
return
|
||||
|
||||
var/obj/item/pda/P = user.get_active_hand()
|
||||
|
||||
if(istype(P))
|
||||
if(user.drop_item())
|
||||
storedpda = P
|
||||
RegisterSignal(P, COMSIG_PARENT_QDELETING, PROC_REF(on_pda_qdel))
|
||||
P.forceMove(src)
|
||||
P.add_fingerprint(usr)
|
||||
update_icon()
|
||||
update_pda_cache()
|
||||
|
||||
/obj/machinery/pdapainter/proc/ejectpda(mob/user)
|
||||
if(!storedpda)
|
||||
to_chat(usr, "<span class='notice'>[src] is empty.</span>")
|
||||
return
|
||||
storedpda.forceMove(get_turf(src))
|
||||
if(ishuman(user))
|
||||
var/mob/living/carbon/human/H = user
|
||||
H.put_in_hands(storedpda)
|
||||
|
||||
UnregisterSignal(storedpda, COMSIG_PARENT_QDELETING)
|
||||
storedpda = null
|
||||
update_icon()
|
||||
|
||||
/obj/machinery/pdapainter/proc/paintpda()
|
||||
if(storedpda)
|
||||
storedpda.icon_state = preview_icon_state
|
||||
storedpda.desc = colorlist[preview_icon_state][2]
|
||||
playsound(loc, 'sound/effects/spray.ogg', 5, 1, 5)
|
||||
update_pda_cache()
|
||||
|
||||
/obj/machinery/pdapainter/proc/update_pda_cache()
|
||||
if(!storedpda)
|
||||
cached_icon_state = null
|
||||
return
|
||||
var/icon/pda_sprite = icon(storedpda.icon, storedpda.icon_state, frame = 1)
|
||||
cached_icon_state = icon2base64(pda_sprite)
|
||||
SStgui.update_uis(src)
|
||||
|
||||
/obj/machinery/pdapainter/proc/on_pda_qdel()
|
||||
if(!storedpda)
|
||||
return
|
||||
UnregisterSignal(storedpda, COMSIG_PARENT_QDELETING)
|
||||
storedpda = null
|
||||
update_icon()
|
||||
|
||||
/obj/machinery/pdapainter/power_change()
|
||||
..()
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
import { useBackend } from '../backend';
|
||||
import {
|
||||
Button,
|
||||
Flex,
|
||||
Icon,
|
||||
Section,
|
||||
Table,
|
||||
} from '../components';
|
||||
import { Window } from '../layouts';
|
||||
|
||||
export const PdaPainter = (props, context) => {
|
||||
const { data } = useBackend(context);
|
||||
const { has_pda } = data;
|
||||
return (
|
||||
<Window>
|
||||
<Window.Content>
|
||||
{!has_pda ? (
|
||||
<PdaInsert/>
|
||||
) : (
|
||||
<PdaMenu />
|
||||
)}
|
||||
</Window.Content>
|
||||
</Window>
|
||||
);
|
||||
}
|
||||
|
||||
const PdaInsert = (props, context) => {
|
||||
const { act } = useBackend(context);
|
||||
return (
|
||||
<Section height="100%" stretchContents>
|
||||
<Flex height="100%" align="center" justify="center">
|
||||
<Flex.Item
|
||||
bold
|
||||
grow="1"
|
||||
textAlign="center"
|
||||
align="center"
|
||||
color="silver"
|
||||
>
|
||||
<Icon
|
||||
name="download"
|
||||
size={5}
|
||||
mb="10px"
|
||||
/>
|
||||
<br/>
|
||||
<Button
|
||||
width="160px"
|
||||
textAlign="center"
|
||||
content="Insert PDA"
|
||||
onClick={() => act('insert_pda')}
|
||||
/>
|
||||
</Flex.Item>
|
||||
</Flex>
|
||||
</Section>
|
||||
)
|
||||
}
|
||||
|
||||
const PdaMenu = (props, context) => {
|
||||
const { act, data } = useBackend(context);
|
||||
const { pda_colors } = data;
|
||||
return (
|
||||
<Flex height = "100%">
|
||||
<Flex.Item width="180px" mr="3px">
|
||||
<PdaImage/>
|
||||
</Flex.Item>
|
||||
<Flex.Item width="65%" mr="3px">
|
||||
<Flex direction="column" height="100%" flex="1">
|
||||
<Section height="100%" flexGrow="1">
|
||||
<Table className='PdaPainter__list'>
|
||||
{Object.keys(pda_colors).map((sprite_name) => (
|
||||
<Table.Row
|
||||
key={sprite_name}
|
||||
onClick={() =>
|
||||
act('choose_pda', { selectedPda: sprite_name })
|
||||
}
|
||||
>
|
||||
<Table.Cell collapsing>
|
||||
<img
|
||||
src={`data:image/png;base64,${pda_colors[sprite_name][0]}`}
|
||||
style={{
|
||||
'vertical-align': 'middle',
|
||||
width: '32px',
|
||||
margin: '0px',
|
||||
'margin-left': '0px',
|
||||
'-ms-interpolation-mode': 'nearest-neighbor',
|
||||
}} />
|
||||
</Table.Cell>
|
||||
<Table.Cell>{sprite_name}</Table.Cell>
|
||||
</Table.Row>
|
||||
))}
|
||||
</Table>
|
||||
</Section>
|
||||
</Flex>
|
||||
</Flex.Item>
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
|
||||
const PdaImage = (props, context) => {
|
||||
const { act, data } = useBackend(context);
|
||||
const { current_appearance, preview_appearance } = data;
|
||||
return (
|
||||
<Flex.Item>
|
||||
<Section title = "Current PDA">
|
||||
<img
|
||||
src={`data:image/jpeg;base64,${current_appearance}`}
|
||||
style={{
|
||||
'vertical-align': 'middle',
|
||||
width: '160px',
|
||||
margin: '0px',
|
||||
'margin-left': '0px',
|
||||
'-ms-interpolation-mode': 'nearest-neighbor'
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
fluid
|
||||
textAlign="center"
|
||||
icon="eject"
|
||||
content="Eject"
|
||||
color = "green"
|
||||
onClick={() => act('eject_pda')}
|
||||
/>
|
||||
<Button
|
||||
fluid
|
||||
textAlign="center"
|
||||
icon="paint-roller"
|
||||
content="Paint PDA"
|
||||
onClick={() => act('paint_pda')}
|
||||
/>
|
||||
</Section>
|
||||
<Section title = "Preview">
|
||||
<img
|
||||
src={`data:image/jpeg;base64,${preview_appearance}`}
|
||||
style={{
|
||||
'vertical-align': 'middle',
|
||||
width: '160px',
|
||||
margin: '0px',
|
||||
'margin-left': '0px',
|
||||
'-ms-interpolation-mode': 'nearest-neighbor'
|
||||
}}
|
||||
/>
|
||||
</Section>
|
||||
</Flex.Item>
|
||||
)
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,21 @@
|
||||
@use '../base.scss';
|
||||
@use '../colors.scss';
|
||||
@use '../functions.scss' as *;
|
||||
|
||||
.PdaPainter__list {
|
||||
tr > td {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
tr {
|
||||
height: 24px;
|
||||
line-height: 24px;
|
||||
cursor: pointer;
|
||||
|
||||
transition: background-color 50ms;
|
||||
&:hover,
|
||||
&:focus {
|
||||
background-color: rgba(base.$color-bg, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@
|
||||
@include meta.load-css('./interfaces/NuclearBomb.scss');
|
||||
@include meta.load-css('./interfaces/OreRedemption.scss');
|
||||
@include meta.load-css('./interfaces/PDA.scss');
|
||||
@include meta.load-css('./interfaces/PdaPainter.scss');
|
||||
@include meta.load-css('./interfaces/PoolController.scss');
|
||||
@include meta.load-css('./interfaces/RndConsole.scss');
|
||||
@include meta.load-css('./interfaces/Roulette.scss');
|
||||
|
||||
Reference in New Issue
Block a user