A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat: add hex color text input to color editors
esenginead8c378e81c2
diff --git a/editor/src/property/buttonTransitionEditor.ts b/editor/src/property/buttonTransitionEditor.tsindex 3bcb66e82..4378fbe26 100644--- a/editor/src/property/buttonTransitionEditor.ts+++ b/editor/src/property/buttonTransitionEditor.ts@@ -95,6 +95,7 @@ export function createButtonTransitionEditor(interface ColorRowRef {colorInput: HTMLInputElement;+ hexInput: HTMLInputElement;alphaInput: HTMLInputElement;}@@ -115,6 +116,10 @@ export function createButtonTransitionEditor(colorInput.type = 'color';colorInput.className = 'es-input es-input-color';+ const hexInput = document.createElement('input');+ hexInput.type = 'text';+ hexInput.className = 'es-input es-input-hex';+const alphaInput = document.createElement('input');alphaInput.type = 'number';alphaInput.className = 'es-input es-input-number es-input-alpha';@@ -126,6 +131,7 @@ export function createButtonTransitionEditor(if (!current) return;const newColor = hexToColor(colorInput.value);newColor.a = parseFloat(alphaInput.value) || 1;+ hexInput.value = colorInput.value.toUpperCase();current = { ...current!, [field.key]: newColor };onChange(current);};@@ -133,14 +139,31 @@ export function createButtonTransitionEditor(colorInput.addEventListener('change', onColorChange);alphaInput.addEventListener('change', onColorChange);+ hexInput.addEventListener('keydown', (e) => {+ if (e.key !== 'Enter' || !current) return;+ let hex = hexInput.value.trim();+ if (!hex.startsWith('#')) hex = '#' + hex;+ if (/^#[0-9a-fA-F]{6}$/.test(hex)) {+ colorInput.value = hex;+ hexInput.value = hex.toUpperCase();+ const newColor = hexToColor(hex);+ newColor.a = parseFloat(alphaInput.value) || 1;+ current = { ...current!, [field.key]: newColor };+ onChange(current);+ } else {+ hexInput.value = colorInput.value.toUpperCase();+ }+ });+editorCell.appendChild(colorInput);+ editorCell.appendChild(hexInput);editorCell.appendChild(alphaInput);row.appendChild(label);row.appendChild(editorCell);content.appendChild(row);- colorRefs.push({ colorInput, alphaInput });+ colorRefs.push({ colorInput, hexInput, alphaInput });}section.appendChild(content);@@ -153,6 +176,7 @@ export function createButtonTransitionEditor(for (let i = 0; i < COLOR_FIELDS.length; i++) {const color = current![COLOR_FIELDS[i].key];colorRefs[i].colorInput.value = colorToHex(color);+ colorRefs[i].hexInput.value = colorToHex(color).toUpperCase();colorRefs[i].alphaInput.value = String(color.a);}} else {diff --git a/editor/src/property/editors.ts b/editor/src/property/editors.tsindex 98eb9812f..29d381580 100644--- a/editor/src/property/editors.ts+++ b/editor/src/property/editors.ts@@ -388,6 +388,11 @@ function createColorEditor(colorInput.className = 'es-input es-input-color';colorInput.value = colorToHex(color);+ const hexInput = document.createElement('input');+ hexInput.type = 'text';+ hexInput.className = 'es-input es-input-hex';+ hexInput.value = colorToHex(color).toUpperCase();+const alphaInput = document.createElement('input');alphaInput.type = 'number';alphaInput.className = 'es-input es-input-number es-input-alpha';@@ -396,17 +401,36 @@ function createColorEditor(alphaInput.step = '0.01';alphaInput.value = String(color.a);- const updateColor = () => {- const hex = colorInput.value;+ const applyColor = (hex: string, alpha: number) => {const newColor = hexToColor(hex);- newColor.a = parseFloat(alphaInput.value) || 1;+ newColor.a = alpha;onChange(newColor);};- colorInput.addEventListener('change', updateColor);- alphaInput.addEventListener('change', updateColor);+ colorInput.addEventListener('change', () => {+ hexInput.value = colorInput.value.toUpperCase();+ applyColor(colorInput.value, parseFloat(alphaInput.value) || 1);+ });++ alphaInput.addEventListener('change', () => {+ applyColor(colorInput.value, parseFloat(alphaInput.value) || 1);+ });++ hexInput.addEventListener('keydown', (e) => {+ if (e.key !== 'Enter') return;+ let hex = hexInput.value.trim();+ if (!hex.startsWith('#')) hex = '#' + hex;+ if (/^#[0-9a-fA-F]{6}$/.test(hex)) {+ colorInput.value = hex;+ hexInput.value = hex.toUpperCase();+ applyColor(hex, parseFloat(alphaInput.value) || 1);+ } else {+ hexInput.value = colorInput.value.toUpperCase();+ }+ });wrapper.appendChild(colorInput);+ wrapper.appendChild(hexInput);wrapper.appendChild(alphaInput);container.appendChild(wrapper);@@ -414,6 +438,7 @@ function createColorEditor(update(v: unknown) {const newColor = (v as { r: number; g: number; b: number; a: number }) ?? { r: 1, g: 1, b: 1, a: 1 };colorInput.value = colorToHex(newColor);+ hexInput.value = colorToHex(newColor).toUpperCase();alphaInput.value = String(newColor.a);},dispose() {diff --git a/editor/src/styles/editor.css b/editor/src/styles/editor.cssindex cedab0c27..5a37b952b 100644--- a/editor/src/styles/editor.css+++ b/editor/src/styles/editor.css@@ -1468,6 +1468,14 @@ svg {border: none;}+.es-input-hex {+ flex: 2;+ min-width: 60px;+ font-family: monospace;+ font-size: 11px;+ text-transform: uppercase;+}+.es-input-alpha {flex: 1;min-width: 40px;