-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add_Decal_Painter * Seperate TGUI file * Decal painter DmIcon * Fix some merge errors * I don't know why this merge is so incredibly fucked * Update TGUI bundle * I swear to god * Fixes DmIcon * TGUI bundle build * Remove implicit var * Final cleanup * Add decal_painter sprite * Update code/game/objects/items/devices/painter/decal_painter.dm Co-authored-by: Luc <[email protected]> Signed-off-by: Chap <[email protected]> * Add helper proc for deleting all components of a type from a datum * Added comments to cycle_style * Elementized decal fixes * Use the new decal system * TGUI bundle --------- Signed-off-by: Chap <[email protected]> Co-authored-by: Adrer <[email protected]> Co-authored-by: Luc <[email protected]> Co-authored-by: Burzah <[email protected]>
- Loading branch information
1 parent
3cc903c
commit f0ac13b
Showing
13 changed files
with
311 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
code/game/objects/items/devices/painter/decal_painter.dm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/datum/painter/decal | ||
module_name = "decal painter" | ||
module_state = "decal_painter" | ||
/// icon that contains the decal sprites | ||
var/decal_icon = 'icons/turf/decals.dmi' | ||
/// icon_state of the selected decal | ||
var/decal_state = "warn_box" | ||
var/decal_dir = SOUTH | ||
/// When removal_mode is TRUE the decal painter will remove decals instead | ||
var/removal_mode = FALSE | ||
var/max_decals = 3 | ||
var/static/list/decal_blacklist = typecacheof( | ||
list( | ||
/obj/effect/turf_decal/raven, | ||
/obj/effect/turf_decal/weather, | ||
/obj/effect/turf_decal/stripes/asteroid, | ||
/obj/effect/turf_decal/tile, | ||
/obj/effect/turf_decal/sand | ||
) | ||
) | ||
/// Assoc list with icon_state of the decal as the key, and decal path as the value. | ||
var/static/list/lookup_cache_decals = list() | ||
|
||
/datum/painter/decal/New(obj/item/painter/parent_painter) | ||
. = ..() | ||
if(!length(lookup_cache_decals)) | ||
for(var/D in subtypesof(/obj/effect/turf_decal)) | ||
var/obj/effect/turf_decal/decal = D | ||
if(decal in decal_blacklist) | ||
continue | ||
lookup_cache_decals[decal::icon_state] = decal | ||
|
||
/datum/painter/decal/paint_atom(atom/target, mob/user) | ||
if(!istype(target, /turf/simulated/floor)) | ||
to_chat(user, "<span class='warning'>[holder] can only be used on flooring.</span>") | ||
return FALSE | ||
var/turf/target_turf = get_turf(target) | ||
var/list/datum/element/decal/decals = target_turf.get_decals() | ||
if(removal_mode) | ||
remove_decals(target) | ||
return TRUE | ||
if(length(decals) >= max_decals) | ||
to_chat(user, "<span class='warning'>You can't fit more decals on [target].</span>") | ||
return FALSE | ||
var/typepath = lookup_cache_decals[decal_state] | ||
new typepath(target_turf, decal_dir) | ||
return TRUE | ||
|
||
/datum/painter/decal/pick_color(mob/user) | ||
if(!user) | ||
return | ||
ui_interact(user) | ||
|
||
/datum/painter/decal/ui_state(mob/user) | ||
return GLOB.inventory_state | ||
|
||
/datum/painter/decal/ui_interact(mob/user, datum/tgui/ui = null) | ||
ui = SStgui.try_update_ui(user, src, ui) | ||
if(!ui) | ||
ui = new(user, src, "DecalPainter", module_name) | ||
ui.set_autoupdate(FALSE) | ||
ui.open() | ||
|
||
/datum/painter/decal/ui_data(mob/user) | ||
var/list/data = list() | ||
data["selectedStyle"] = decal_state | ||
data["selectedDir"] = decal_dir | ||
data["removalMode"] = removal_mode | ||
|
||
return data | ||
|
||
|
||
/datum/painter/decal/ui_static_data(mob/user) | ||
var/list/data = list() | ||
data["icon"] = decal_icon | ||
data["availableStyles"] = list() | ||
for(var/decal in lookup_cache_decals) | ||
data["availableStyles"] += decal | ||
|
||
return data | ||
|
||
/datum/painter/decal/ui_act(action, params) | ||
if(..()) | ||
return | ||
|
||
if(action == "select_style") | ||
var/new_style = params["style"] | ||
if(lookup_cache_decals.Find(new_style) != 0) | ||
decal_state = new_style | ||
removal_mode = FALSE | ||
|
||
if(action == "cycle_style") // Cycles through the available styles one at a time | ||
var/index = lookup_cache_decals.Find(decal_state) // Find the index of the currently selected style in the lookup cache | ||
index += params["offset"] // Offset is either -1 or 1. Add this to the index to get the style before or after the current style. | ||
if(index < 1) // If the index is below 1, loop back to the last item in the cache. | ||
index = length(lookup_cache_decals) | ||
if(index > length(lookup_cache_decals)) // If the index is above the length of the cache, loop back to the first item in the cache. | ||
index = 1 | ||
decal_state = lookup_cache_decals[index] // Then set our state to the index | ||
removal_mode = FALSE | ||
|
||
if(action == "select_direction") | ||
var/dir = params["direction"] | ||
removal_mode = FALSE | ||
if(dir != 0) | ||
decal_dir = dir | ||
|
||
if(action == "removal_mode") | ||
removal_mode = !removal_mode | ||
return TRUE | ||
|
||
/datum/painter/decal/proc/remove_decals(atom/target) | ||
var/turf/target_turf = get_turf(target) | ||
var/list/datum/element/decal/decals = target_turf.get_decals() | ||
for(var/datum/element/decal/dcl in decals) | ||
dcl.Detach(target) | ||
target_turf.RemoveElement(/datum/element/decal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { useBackend, useLocalState } from '../backend'; | ||
import { Button, LabeledList, Section, Table, Dropdown, Flex, Icon, Box, DmIcon } from '../components'; | ||
import { Window } from '../layouts'; | ||
|
||
const SelectableTile = (props, context) => { | ||
const { act, data } = useBackend(context); | ||
const { icon_state, direction, isSelected, onSelect } = props; | ||
|
||
return ( | ||
<DmIcon | ||
icon={data.icon} | ||
icon_state={icon_state} | ||
direction={direction} | ||
onClick={onSelect} | ||
style={{ | ||
'border-style': (isSelected && 'solid') || 'none', | ||
'border-width': '2px', | ||
'border-color': 'orange', | ||
padding: (isSelected && '0px') || '2px', | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
const Dir = { | ||
NORTH: 1, | ||
SOUTH: 2, | ||
EAST: 4, | ||
WEST: 8, | ||
}; | ||
|
||
export const DecalPainter = (props, context) => { | ||
const { act, data } = useBackend(context); | ||
const { availableStyles, selectedStyle, selectedDir, removalMode } = data; | ||
return ( | ||
<Window width={405} height={475}> | ||
<Window.Content scrollable> | ||
<Section title="Decal setup"> | ||
<Flex> | ||
<Flex.Item> | ||
<Button icon="chevron-left" onClick={() => act('cycle_style', { offset: -1 })} /> | ||
</Flex.Item> | ||
<Flex.Item> | ||
<Dropdown | ||
options={availableStyles} | ||
selected={selectedStyle} | ||
width="150px" | ||
height="20px" | ||
ml="2px" | ||
mr="2px" | ||
nochevron | ||
onSelected={(val) => act('select_style', { style: val })} | ||
/> | ||
</Flex.Item> | ||
<Flex.Item> | ||
<Button icon="chevron-right" onClick={() => act('cycle_style', { offset: 1 })} /> | ||
</Flex.Item> | ||
<Flex.Item> | ||
<Button icon="eraser" color={removalMode ? 'green' : 'transparent'} onClick={() => act('removal_mode')}> | ||
Remove decals | ||
</Button> | ||
</Flex.Item> | ||
</Flex> | ||
|
||
<Box mt="5px" mb="5px"> | ||
<Flex | ||
overflowY="auto" // scroll | ||
maxHeight="220px" // a bit more than half of all tiles fit in this box at once. | ||
wrap="wrap" | ||
> | ||
{availableStyles.map((style) => ( | ||
<Flex.Item key={style}> | ||
<SelectableTile | ||
icon_state={style} | ||
isSelected={selectedStyle === style && !removalMode} | ||
onSelect={() => act('select_style', { style: style })} | ||
/> | ||
</Flex.Item> | ||
))} | ||
</Flex> | ||
</Box> | ||
|
||
<LabeledList> | ||
<LabeledList.Item label="Direction"> | ||
<Table style={{ display: 'inline' }}> | ||
{[Dir.NORTH, null, Dir.SOUTH].map((latitude) => ( | ||
<Table.Row key={latitude}> | ||
{[latitude + Dir.WEST, latitude, latitude + Dir.EAST].map((dir) => ( | ||
<Table.Cell | ||
key={dir} | ||
style={{ | ||
'vertical-align': 'middle', | ||
'text-align': 'center', | ||
}} | ||
> | ||
{dir === null ? ( | ||
<Icon name="arrows-alt" size={3} /> | ||
) : ( | ||
<SelectableTile | ||
icon_state={selectedStyle} | ||
direction={dir} | ||
isSelected={dir === selectedDir && !removalMode} | ||
onSelect={() => act('select_direction', { direction: dir })} | ||
/> | ||
)} | ||
</Table.Cell> | ||
))} | ||
</Table.Row> | ||
))} | ||
</Table> | ||
</LabeledList.Item> | ||
</LabeledList> | ||
</Section> | ||
</Window.Content> | ||
</Window> | ||
); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.