Skip to content

Commit be1b904

Browse files
committed
🚧 Text Display Improvements / Fixes
- Added #234 - Fixed text displays not saving or exporting `shadow` toggle. - Fixed text displays not saving or exporting `background`.
1 parent d2116bd commit be1b904

File tree

8 files changed

+75
-5
lines changed

8 files changed

+75
-5
lines changed

src/components/textDisplayElementPanel.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
TEXT_DISPLAY_BACKGROUND_COLOR_PICKER,
99
TEXT_DISPLAY_SHADOW_TOGGLE,
1010
TEXT_DISPLAY_ALIGNMENT_SELECT,
11+
TEXT_DISPLAY_SEE_THROUGH_TOGGLE,
1112
} from '../interface/textDisplayElementPanel'
1213
import { floatToHex } from '../util/misc'
1314
import { translate } from '../util/translation'
@@ -30,6 +31,7 @@
3031
let backgroundColorSlot: HTMLDivElement
3132
let shadowSlot: HTMLDivElement
3233
let alignmentSlot: HTMLDivElement
34+
let seeThroughSlot: HTMLDivElement
3335
let codeJar: CodeJar
3436
3537
events.UPDATE_SELECTION.subscribe(() => {
@@ -46,13 +48,15 @@
4648
TEXT_DISPLAY_BACKGROUND_COLOR_PICKER.set(color)
4749
TEXT_DISPLAY_SHADOW_TOGGLE.set(selected.shadow)
4850
TEXT_DISPLAY_ALIGNMENT_SELECT.set(selected.align)
51+
TEXT_DISPLAY_SEE_THROUGH_TOGGLE.set(selected.seeThrough)
4952
})
5053
5154
requestAnimationFrame(() => {
5255
lineWidthSlot.appendChild(TEXT_DISPLAY_WIDTH_SLIDER.node)
5356
backgroundColorSlot.appendChild(TEXT_DISPLAY_BACKGROUND_COLOR_PICKER.node)
5457
shadowSlot.appendChild(TEXT_DISPLAY_SHADOW_TOGGLE.node)
5558
alignmentSlot.appendChild(TEXT_DISPLAY_ALIGNMENT_SELECT.node)
59+
seeThroughSlot.appendChild(TEXT_DISPLAY_SEE_THROUGH_TOGGLE.node)
5660
forceNoWrap()
5761
})
5862
@@ -72,6 +76,7 @@
7276
<div class="content" bind:this={backgroundColorSlot}></div>
7377
<div class="content" bind:this={shadowSlot}></div>
7478
<div class="content" bind:this={alignmentSlot}></div>
79+
<div class="content" bind:this={seeThroughSlot}></div>
7580
</div>
7681

7782
<div

src/interface/textDisplayElementPanel.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ TEXT_DISPLAY_BACKGROUND_COLOR_PICKER.set = function (this: ColorPicker, color: s
6868
}
6969
TEXT_DISPLAY_BACKGROUND_COLOR_PICKER.change = function (
7070
this: ColorPicker,
71-
// @ts-ignore
72-
color: tinycolor.Instance
71+
color: InstanceType<typeof tinycolor>
7372
) {
7473
const selected = TextDisplay.selected[0]
7574
if (!selected) return this
@@ -133,3 +132,28 @@ TEXT_DISPLAY_ALIGNMENT_SELECT.set = function (this: BarSelect<Alignment>, value:
133132
selected.align = value
134133
return this
135134
}
135+
136+
export const TEXT_DISPLAY_SEE_THROUGH_TOGGLE = new Toggle(
137+
`${PACKAGE.name}:textDisplaySeeThroughToggle`,
138+
{
139+
name: translate('tool.text_display.see_through.title'),
140+
icon: 'check_box_outline_blank',
141+
description: translate('tool.text_display.see_through.description'),
142+
condition: () => isCurrentFormat() && !!TextDisplay.selected.length,
143+
click() {
144+
//
145+
},
146+
onChange() {
147+
const scope = TEXT_DISPLAY_SEE_THROUGH_TOGGLE
148+
scope.setIcon(scope.value ? 'check_box' : 'check_box_outline_blank')
149+
const selected = TextDisplay.selected[0]
150+
if (!selected) return
151+
selected.seeThrough = TEXT_DISPLAY_SEE_THROUGH_TOGGLE.value
152+
},
153+
}
154+
)
155+
TEXT_DISPLAY_SEE_THROUGH_TOGGLE.set = function (value) {
156+
if (this.value === value) return this
157+
this.click()
158+
return this
159+
}

src/lang/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,9 @@ animated_java.tool.text_display.text_alignment.options.left: Left
486486
animated_java.tool.text_display.text_alignment.options.center: Center
487487
animated_java.tool.text_display.text_alignment.options.right: Right
488488

489+
animated_java.tool.text_display.see_through.title: See Through
490+
animated_java.tool.text_display.see_through.description: Whether or not the text display should be visible through blocks.
491+
489492
# Vanilla Item Display Panel
490493
animated_java.panel.vanilla_item_display.title: Displayed Item
491494
animated_java.panel.vanilla_item_display.description: The item to display.

src/outliner/textDisplay.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class TextDisplay extends ResizableOutlinerElement {
7171
private _newShadow: boolean | undefined
7272
private _align = new Valuable<Alignment>('center')
7373
private _newAlign: Alignment | undefined
74+
public seeThrough = false
7475

7576
constructor(data: TextDisplayOptions, uuid = guid()) {
7677
super(data, uuid)
@@ -367,11 +368,14 @@ new Property(TextDisplay, 'number', 'lineWidth', { default: 200 })
367368
new Property(TextDisplay, 'string', 'backgroundColor', { default: '#000000' })
368369
new Property(TextDisplay, 'number', 'backgroundAlpha', { default: 0.25 })
369370
new Property(TextDisplay, 'string', 'align', { default: 'center' })
371+
new Property(TextDisplay, 'boolean', 'shadow', { default: false })
372+
new Property(TextDisplay, 'boolean', 'seeThrough', { default: false })
370373
new Property(TextDisplay, 'object', 'config', {
371374
get default() {
372375
return new TextDisplayConfig().toJSON()
373376
},
374377
})
378+
375379
OutlinerElement.registerType(TextDisplay, TextDisplay.type)
376380

377381
export const PREVIEW_CONTROLLER = new NodePreviewController(TextDisplay, {

src/systems/datapackCompiler.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import animationMcb from './datapackCompiler/animation.mcb'
55
import { AnyRenderedNode, IRenderedRig } from './rigRenderer'
66
import { IRenderedAnimation } from './animationRenderer'
77
import { Variant } from '../variants'
8-
import { NbtCompound, NbtFloat, NbtInt, NbtList, NbtString } from 'deepslate/lib/nbt'
8+
import { NbtByte, NbtCompound, NbtFloat, NbtInt, NbtList, NbtString } from 'deepslate/lib/nbt'
99
import {
1010
arrayToNbtFloatArray,
1111
matrixToNbtFloatArray,
@@ -24,7 +24,7 @@ import {
2424
} from '../util/minecraftUtil'
2525
import { JsonText } from './minecraft/jsonText'
2626
import { MAX_PROGRESS, PROGRESS, PROGRESS_DESCRIPTION } from '../interface/exportProgressDialog'
27-
import { eulerFromQuaternion, roundTo } from '../util/misc'
27+
import { eulerFromQuaternion, floatToHex, roundTo, tinycolorToDecimal } from '../util/misc'
2828
import { setTimeout } from 'timers'
2929
import { MSLimiter } from '../util/msLimiter'
3030

@@ -316,7 +316,12 @@ async function generateRootEntityPassengers(rig: IRenderedRig, rigHash: string)
316316
'text',
317317
new NbtString(node.text ? node.text.toString() : '"Invalid Text Component"')
318318
)
319+
320+
const color = new tinycolor(node.backgroundColor + floatToHex(node.backgroundAlpha))
321+
passenger.set('background', new NbtInt(tinycolorToDecimal(color)))
319322
passenger.set('line_width', new NbtInt(node.lineWidth))
323+
passenger.set('shadow', new NbtByte(node.shadow ? 1 : 0))
324+
passenger.set('see_through', new NbtByte(node.seeThrough ? 1 : 0))
320325

321326
if (node.config) {
322327
TextDisplayConfig.fromJSON(node.config).toNBT(passenger)

src/systems/rigRenderer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ export interface IRenderedNodes {
119119
backgroundColor: string
120120
backgroundAlpha: number
121121
align: Alignment
122+
shadow: boolean
123+
seeThrough: boolean
122124
scale: number
123125
config?: IBlueprintTextDisplayConfigJSON
124126
}
@@ -520,6 +522,8 @@ function renderTextDisplay(display: TextDisplay, rig: IRenderedRig): INodeStruct
520522
backgroundColor: display.backgroundColor,
521523
backgroundAlpha: display.backgroundAlpha,
522524
align: display.align,
525+
shadow: display.shadow,
526+
seeThrough: display.seeThrough,
523527
scale: 1,
524528
config: display.config,
525529
}

src/util/misc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ export function floatToHex(n: number) {
4444
.padStart(2, '0')
4545
}
4646

47+
export function tinycolorToDecimal(color: InstanceType<typeof tinycolor>) {
48+
const rgba = color.toRgb()
49+
return ((rgba.a * 255) << 24) | (rgba.r << 16) | (rgba.g << 8) | rgba.b
50+
}
51+
4752
export function makeNotZero(vec: THREE.Vector3 | THREE.Euler) {
4853
if (vec.x === 0) vec.x = 0.00001
4954
if (vec.y === 0) vec.y = 0.00001

test_blueprints/armor_stand.ajblueprint

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,25 @@
847847
},
848848
"uuid": "7747736f-85e2-338f-207e-53f8d3d2fa39",
849849
"type": "locator"
850+
},
851+
{
852+
"name": "text_display",
853+
"position": [0, 38, 0],
854+
"rotation": [0, 0, 0],
855+
"scale": [1, 1, 1],
856+
"visibility": true,
857+
"item": "minecraft:diamond",
858+
"config": {},
859+
"block": "minecraft:stone",
860+
"text": "\"Armor Stand\"",
861+
"lineWidth": 200,
862+
"backgroundColor": "#c91515",
863+
"backgroundAlpha": 0.51,
864+
"align": "center",
865+
"shadow": true,
866+
"seeThrough": true,
867+
"uuid": "c2e217f1-b50a-5c9a-b342-71a35e984046",
868+
"type": "animated_java:text_display"
850869
}
851870
],
852871
"outliner": [
@@ -1355,7 +1374,8 @@
13551374
"visibility": true,
13561375
"autouv": 0,
13571376
"children": []
1358-
}
1377+
},
1378+
"c2e217f1-b50a-5c9a-b342-71a35e984046"
13591379
],
13601380
"textures": [
13611381
{

0 commit comments

Comments
 (0)