Skip to content

Commit 2ec48e7

Browse files
committed
🚧 Implement basic Display Panel node config functionality.
Currently only partially works, and does not apply user-changed values. Does support undo / redo though! That was a huke pain in the 🍑.
1 parent 62c5d44 commit 2ec48e7

File tree

4 files changed

+421
-141
lines changed

4 files changed

+421
-141
lines changed

src/lang/en.yml

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,42 @@ dialog:
8989
label: Storage-based
9090
description: 42% Slower than function-based, but creates far fewer function files.
9191

92+
panel:
93+
display:
94+
title: Display
95+
96+
common:
97+
label: Common
98+
options:
99+
billboard: Billboard
100+
brightnessOverride: Brightness
101+
glowColor: Glow Color
102+
glowing: Glowing
103+
inheritSettings: Inherit Settings
104+
invisible: Invisible
105+
nbt: NBT
106+
overrideBrightness: Override Brightness
107+
overrideGlowColor: Override Glow Color
108+
shadowRadius: Shadow Radius
109+
shadowStrength: Shadow Strength
110+
useNBT: Use NBT
111+
112+
animated_java:text_display:
113+
label: Text Display
114+
options:
115+
alignment: Alignment
116+
backgroundColor: Background Color
117+
lineWidth: Line Width
118+
seeThrough: See Through
119+
shadow: Shadow
120+
textComponent: Text Component
121+
122+
animated_java:item_display:
123+
label: Item Display
124+
125+
animated_java:block_display:
126+
label: Block Display
127+
92128
# ----------------------------------------
93129
# OLD TRANSLATIONS
94130
# ----------------------------------------
@@ -105,10 +141,10 @@ animated_java.action.export.name: Export
105141
animated_java.action.extract.name: Extract
106142
animated_java.action.extract.confirm: Confirm Extraction
107143
animated_java.action.create_text_display.title: Add Text Display
108-
animated_java.action.create_vanilla_item_display.title: Add Item Display
109-
animated_java.action.create_vanilla_block_display.title: Add Block Display
110-
animated_java.action.open_vanilla_item_display_config.name: Item Display Config
111-
animated_java.action.open_vanilla_block_display_config.name: Block Display Config
144+
animated_java.action.create_item_display.title: Add Item Display
145+
animated_java.action.create_block_display.title: Add Block Display
146+
animated_java.action.open_item_display_config.name: Item Display Config
147+
animated_java.action.open_block_display_config.name: Block Display Config
112148

113149
### Popups
114150
animated_java.popup.loading.loading: Loading Animated Java...
@@ -411,8 +447,8 @@ animated_java.dialog.locator_config.ticking_commands.description: |-
411447
## Text Display Config Dialog
412448
animated_java.dialog.text_display_config.title: Text Display Config
413449

414-
animated_java.dialog.bone_config.vanilla_item_model.title: Vanilla Item Model
415-
animated_java.dialog.bone_config.vanilla_item_model.description: |-
450+
animated_java.dialog.bone_config.item_model.title: Vanilla Item Model
451+
animated_java.dialog.bone_config.item_model.description: |-
416452
If set, the bone will render as a vanilla item model.
417453
This will overwrite the bone's existing cubes.
418454
@@ -464,26 +500,26 @@ animated_java.dialog.text_display_config.billboard.options.horizontal: Horizonta
464500
animated_java.dialog.text_display_config.billboard.options.center: Center
465501

466502
## Block Display Config Dialog
467-
animated_java.dialog.vanilla_block_display_config.title: Block Display Config
468-
animated_java.dialog.vanilla_block_display.custom_name.title: Custom Name
469-
animated_java.dialog.vanilla_block_display.custom_name.description: The custom name of the block display.
470-
animated_java.dialog.vanilla_block_display.custom_name.invalid_json.error: |-
503+
animated_java.dialog.block_display_config.title: Block Display Config
504+
animated_java.dialog.block_display.custom_name.title: Custom Name
505+
animated_java.dialog.block_display.custom_name.description: The custom name of the block display.
506+
animated_java.dialog.block_display.custom_name.invalid_json.error: |-
471507
Invalid JSON Text!
472508
{0}
473509
474-
animated_java.dialog.vanilla_block_display.custom_name_visible.title: Custom Name Visible
475-
animated_java.dialog.vanilla_block_display.custom_name_visible.description: Whether or not the custom name should always be visible.
510+
animated_java.dialog.block_display.custom_name_visible.title: Custom Name Visible
511+
animated_java.dialog.block_display.custom_name_visible.description: Whether or not the custom name should always be visible.
476512

477513
## Item Display Config Dialog
478-
animated_java.dialog.vanilla_item_display_config.title: Item Display Config
479-
animated_java.dialog.vanilla_item_display.custom_name.title: Custom Name
480-
animated_java.dialog.vanilla_item_display.custom_name.description: The custom name of the item display.
481-
animated_java.dialog.vanilla_item_display.custom_name.invalid_json.error: |-
514+
animated_java.dialog.item_display_config.title: Item Display Config
515+
animated_java.dialog.item_display.custom_name.title: Custom Name
516+
animated_java.dialog.item_display.custom_name.description: The custom name of the item display.
517+
animated_java.dialog.item_display.custom_name.invalid_json.error: |-
482518
Invalid JSON Text!
483519
{0}
484520
485-
animated_java.dialog.vanilla_item_display.custom_name_visible.title: Custom Name Visible
486-
animated_java.dialog.vanilla_item_display.custom_name_visible.description: Whether or not the custom name should always be visible.
521+
animated_java.dialog.item_display.custom_name_visible.title: Custom Name Visible
522+
animated_java.dialog.item_display.custom_name_visible.description: Whether or not the custom name should always be visible.
487523

488524
## Variant Config Dialog
489525
animated_java.dialog.variant_config.title: Variant Config
@@ -659,8 +695,8 @@ animated_java.tool.text_display.see_through.title: See Through
659695
animated_java.tool.text_display.see_through.description: Whether or not the text display should be visible through blocks.
660696

661697
# Item Display Panel
662-
animated_java.panel.vanilla_item_display.title: Displayed Item
663-
animated_java.panel.vanilla_item_display.description: The item to display.
698+
animated_java.panel.item_display.title: Displayed Item
699+
animated_java.panel.item_display.description: The item to display.
664700
animated_java.tool.item_display.item_display.title: Item Display Mode
665701
animated_java.tool.item_display.item_display.description: Which item model transform to apply to the item (as defined in display field in model JSON).
666702
animated_java.tool.item_display.item_display.options.none: None
@@ -674,12 +710,12 @@ animated_java.tool.item_display.item_display.options.ground: Ground
674710
animated_java.tool.item_display.item_display.options.fixed: Fixed
675711

676712
# Block Display Panel
677-
animated_java.panel.vanilla_block_display.title: Displayed Block
678-
animated_java.panel.vanilla_block_display.description: The block to display. Supports block states!
713+
animated_java.panel.block_display.title: Displayed Block
714+
animated_java.panel.block_display.description: The block to display. Supports block states!
679715

680716
### Custom Elements
681717
## Item Display
682-
animated_java.vanilla_item_display.title: Item Display
718+
animated_java.item_display.title: Item Display
683719

684720
## Block Display
685721

src/ui/panels/display-panel/displayPanel.svelte

Lines changed: 210 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22
import { BlockDisplay } from '@aj/blockbench-additions/outliner-elements/blockDisplay'
33
import { ItemDisplay } from '@aj/blockbench-additions/outliner-elements/itemDisplay'
44
import { TextDisplay } from '@aj/blockbench-additions/outliner-elements/textDisplay'
5+
import { CommonDisplayConfig } from '@aj/systems/node-configs'
56
import EVENTS from '@aj/util/events'
7+
import { translate } from '@aj/util/translation'
8+
import { slide } from 'svelte/transition'
9+
import { MODE_ICONS, type CommonOptionMode } from '.'
610
import TextDisplayPage from './textDisplayPage.svelte'
711
8-
// Fix for svelte not recognizing global Blockbench types
9-
// eslint-disable-next-line @typescript-eslint/naming-convention
10-
const Group = Blockbench.Group
11-
1212
let selectedThing: TextDisplay | BlockDisplay | ItemDisplay | Group | undefined
13+
let commonConfig: CommonDisplayConfig | undefined
14+
let commonOptionModes: Map<string, CommonOptionMode>
15+
let commonTabSelected: boolean
1316
1417
EVENTS.UPDATE_SELECTION.subscribe(() => {
18+
selectedThing = undefined
19+
commonConfig = undefined
20+
commonOptionModes = new Map()
21+
1522
if (Group.first_selected) {
1623
selectedThing = Group.first_selected
1724
} else if (TextDisplay.selected.length > 0) {
@@ -20,23 +27,210 @@
2027
selectedThing = BlockDisplay.selected.at(0)
2128
} else if (ItemDisplay.selected.length > 0) {
2229
selectedThing = ItemDisplay.selected.at(0)
23-
} else {
24-
selectedThing = undefined
30+
}
31+
32+
if (selectedThing) {
33+
commonConfig = new CommonDisplayConfig().fromJSON(selectedThing?.commonConfig)
34+
commonOptionModes = new Map<string, CommonOptionMode>(
35+
commonConfig.keys().map(key => {
36+
if (commonConfig!.getKeyInheritance(key)) {
37+
return [key, 'inherit']
38+
} else if (commonConfig!.get(key, 'local') != undefined) {
39+
return [key, 'custom']
40+
}
41+
return [key, 'default']
42+
})
43+
)
2544
}
2645
})
46+
47+
// Key is a string, but I need it to be any to make TypeScript happy when indexing into the config object.
48+
function cycleCommonMode(key: any) {
49+
if (!selectedThing) {
50+
console.error('Attempted to cycle common mode without a selected thing')
51+
return
52+
}
53+
if (!commonConfig || !commonOptionModes) {
54+
console.error('Attempted to cycle common mode without a common config')
55+
return
56+
}
57+
58+
const mode = commonOptionModes.get(key)
59+
if (mode === 'default') {
60+
commonOptionModes.set(key, 'custom')
61+
commonConfig.makeDefault(key)
62+
} else if (mode === 'custom') {
63+
commonOptionModes.set(key, 'inherit')
64+
commonConfig.set(key, undefined)
65+
commonConfig.setKeyInheritance(key, true)
66+
} else {
67+
commonOptionModes.set(key, 'default')
68+
commonConfig.set(key, undefined)
69+
commonConfig.setKeyInheritance(key, false)
70+
}
71+
72+
console.log('Set', key, 'inheritance mode to', mode?.toUpperCase())
73+
Undo.initEdit({ elements: [selectedThing] })
74+
selectedThing.commonConfig = commonConfig.toJSON()
75+
Undo.finishEdit(`Set ${key} inheritance mode to ${mode?.toUpperCase()}`, {
76+
elements: [selectedThing],
77+
})
78+
79+
commonConfig = commonConfig
80+
}
2781
</script>
2882

29-
{#if selectedThing instanceof Group}
30-
<div>{selectedThing.name}</div>
31-
{:else if selectedThing instanceof TextDisplay}
32-
<TextDisplayPage textDisplay={selectedThing} />
33-
{:else if selectedThing instanceof BlockDisplay}
34-
<div>{selectedThing.name}</div>
35-
{:else if selectedThing instanceof ItemDisplay}
36-
<div>{selectedThing.name}</div>
37-
{:else}
38-
<div>Unknown type</div>
83+
<!-- Make sure that we update the panel every time selected thing is assigned, even if it's the same value. -->
84+
<!-- This makes certain that we have the most up-to-date properties of the text display from undo / redo events -->
85+
{#if selectedThing}
86+
<div class="tab-buttons" in:slide={{ duration: 200 }}>
87+
<!-- svelte-ignore a11y-click-events-have-key-events -->
88+
<p
89+
class={'tab-button' + (!commonTabSelected ? ' tab-button-selected' : '')}
90+
on:click={() => {
91+
commonTabSelected = false
92+
}}
93+
>
94+
{translate(
95+
`panel.display.${selectedThing && Object.getPrototypeOf(selectedThing).constructor.type}.label`
96+
)}
97+
</p>
98+
<!-- svelte-ignore a11y-click-events-have-key-events -->
99+
<p
100+
class={'tab-button' + (commonTabSelected ? ' tab-button-selected' : '')}
101+
on:click={() => {
102+
commonTabSelected = true
103+
}}
104+
>
105+
{translate('panel.display.common.label')}
106+
</p>
107+
</div>
108+
109+
<div class="option-list-container">
110+
<div>
111+
{#if commonTabSelected && commonConfig}
112+
<ul class="option-list">
113+
{#each commonConfig.keys(true) as key}
114+
<li>
115+
<div>
116+
<div class="option-title">
117+
{translate(`panel.display.common.options.${key}`)}
118+
</div>
119+
<div class="option-mode">{commonOptionModes.get(key)}</div>
120+
<!-- svelte-ignore a11y-click-events-have-key-events -->
121+
<i
122+
on:click={() => cycleCommonMode(key)}
123+
class="material-icons notranslate icon option-mode-toggle"
124+
>
125+
{MODE_ICONS[commonOptionModes.get(key) ?? 'default']}
126+
</i>
127+
</div>
128+
{#if commonOptionModes.get(key) === 'custom'}
129+
<div class="option-value">
130+
<input type="text" value={commonConfig[key]} />
131+
</div>
132+
{/if}
133+
</li>
134+
{/each}
135+
</ul>
136+
{:else}
137+
{#key selectedThing}
138+
<!-- svelte-ignore missing-declaration -->
139+
{#if selectedThing instanceof Group}
140+
<!-- <div>{selectedThing.name}</div> -->
141+
{:else if selectedThing instanceof TextDisplay}
142+
<TextDisplayPage textDisplay={selectedThing} />
143+
{:else if selectedThing instanceof BlockDisplay}
144+
<!-- <div>{selectedThing.name}</div> -->
145+
{:else if selectedThing instanceof ItemDisplay}
146+
<!-- <div>{selectedThing.name}</div> -->
147+
{:else}
148+
<div>Selection has no Display Options</div>
149+
{/if}
150+
{/key}
151+
{/if}
152+
</div>
153+
</div>
39154
{/if}
40155

41156
<style>
157+
:global .panel[id='panel_animated_java:display_panel'] {
158+
& .toolbar {
159+
& .bar_select {
160+
height: 28px;
161+
margin: 1px 0px;
162+
}
163+
& bb-select {
164+
height: 28px;
165+
display: flex;
166+
align-items: center;
167+
padding-top: 0;
168+
}
169+
& .sp-replacer {
170+
padding: 4px 18px;
171+
height: 28px;
172+
margin: 1px 0px;
173+
}
174+
}
175+
176+
& .option-list-container {
177+
max-height: 20rem;
178+
overflow-y: auto;
179+
background-color: var(--color-back);
180+
}
181+
& .option-list {
182+
display: flex;
183+
flex-direction: column;
184+
gap: 8px;
185+
padding: 0 8px;
186+
margin-bottom: 8px;
187+
}
188+
& .option-list > li > div {
189+
display: flex;
190+
flex-direction: row;
191+
align-items: center;
192+
color: var(--color-subtle_text);
193+
justify-content: space-between;
194+
}
195+
& .option-title {
196+
text-align: center;
197+
}
198+
& .option-mode {
199+
flex-grow: 1;
200+
text-align: right;
201+
margin-right: 4px;
202+
text-transform: uppercase;
203+
font-size: 12px;
204+
}
205+
& .option-mode-toggle {
206+
text-align: center;
207+
color: var(--color-text);
208+
}
209+
& .option-mode-toggle:hover {
210+
color: var(--color-light);
211+
}
212+
& .option-value {
213+
border-left: 2px solid var(--color-accent);
214+
padding-left: 8px;
215+
}
216+
217+
& .tab-buttons {
218+
display: grid;
219+
gap: 8px;
220+
padding: 0 8px;
221+
grid-template-columns: 1fr 1fr;
222+
margin-bottom: 8px;
223+
}
224+
& .tab-button {
225+
padding: 4px 8px;
226+
margin: unset;
227+
cursor: pointer;
228+
background-color: var(--color-button);
229+
border-bottom: none;
230+
text-align: center;
231+
}
232+
& .tab-button-selected {
233+
border-bottom: 2px solid var(--color-accent);
234+
}
235+
}
42236
</style>

0 commit comments

Comments
 (0)