Restore the schematic-shape drawer's texture, aspect and hardpoint tints (Cut 10)
On Studio 1.3.1, drawers are handed the owning record read-only as
CultInspector.Record. InspectableSchematicShapeDrawer reads the item from it
and restores what the Database Tools drawer did (d3db1730,
AetheriaInspectors.cs ShapeSchematicInspector):
- the item's schematic texture drawn under the toggle grid;
- the height derived from the texture's aspect when a texture exists;
- hull hardpoint cells tinted with HardpointData.TintColor.
The drawer never writes to the record. The comment saying these waited on
the Studio exposing the open record is gone.
Verified by the Unity batchmode compile (no error CS). The visual check is
in the operator's Studio click-through.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
65a007e509
commit
1951b39a95
1 changed files with 36 additions and 8 deletions
|
|
@ -87,28 +87,56 @@ public sealed class InspectableTemperatureDrawer : ICultInspectorDrawer
|
|||
}
|
||||
}
|
||||
|
||||
// A size and a toggle per cell. The Database Tools drawer also laid the item's schematic texture under the grid,
|
||||
// derived the height from its aspect, and tinted hull hardpoints. Those read the document the shape belongs to, and a
|
||||
// Studio drawer is handed only the value, so they wait on the Studio exposing the open record.
|
||||
// A size and a toggle per cell. When the owning item has a schematic texture, the texture lies under the grid and the
|
||||
// height follows its aspect; a hull's hardpoint cells are tinted. Both read the owning record through
|
||||
// inspector.Record, which is a read-only copy: nothing here writes to it.
|
||||
[CultInspectorDrawer(typeof(InspectableSchematicShapeAttribute))]
|
||||
public sealed class InspectableSchematicShapeDrawer : ICultInspectorDrawer
|
||||
{
|
||||
private static Material _schematicMaterial;
|
||||
|
||||
public object Draw(CultInspector inspector, string label, Type type, object value, MemberInfo member)
|
||||
{
|
||||
if (type != typeof(Shape)) return inspector.DrawDefault(label, type, value, member);
|
||||
var shape = value as Shape ?? new Shape();
|
||||
var item = inspector.Record as EquippableItemData;
|
||||
var hull = item as HullData;
|
||||
var schematic = string.IsNullOrEmpty(item?.Schematic) ? null : AssetDatabase.LoadAssetAtPath<Texture2D>(item.Schematic);
|
||||
|
||||
EditorGUILayout.LabelField(label);
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
var width = max(EditorGUILayout.DelayedIntField("Width", shape.Width), 1);
|
||||
var height = max(EditorGUILayout.DelayedIntField("Height", shape.Height), 1);
|
||||
int height;
|
||||
if (schematic == null) height = max(EditorGUILayout.DelayedIntField("Height", shape.Height), 1);
|
||||
else
|
||||
{
|
||||
height = max(Mathf.RoundToInt(width * ((float) schematic.height / schematic.width)), 1);
|
||||
EditorGUILayout.LabelField("Height", height.ToString());
|
||||
}
|
||||
if (width != shape.Width || height != shape.Height) shape.Resize(width, height);
|
||||
}
|
||||
|
||||
for (var y = shape.Height - 1; y >= 0; y--)
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
for (var x = 0; x < shape.Width; x++)
|
||||
shape[int2(x, y)] = GUILayout.Toggle(shape[int2(x, y)], GUIContent.none, GUILayout.Width(16));
|
||||
using (var grid = new EditorGUILayout.VerticalScope())
|
||||
{
|
||||
if (schematic != null && Event.current.type == EventType.Repaint)
|
||||
{
|
||||
_schematicMaterial ??= new Material(Shader.Find("Legacy Shaders/Particles/Additive"));
|
||||
EditorGUI.DrawPreviewTexture(grid.rect, schematic, _schematicMaterial);
|
||||
}
|
||||
|
||||
for (var y = shape.Height - 1; y >= 0; y--)
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
for (var x = 0; x < shape.Width; x++)
|
||||
{
|
||||
var hardpoint = hull?.Hardpoints.FirstOrDefault(hp => hp.Shape.Coordinates
|
||||
.Any(v => v.x + hp.Position.x == x && v.y + hp.Position.y == y));
|
||||
var previous = GUI.backgroundColor;
|
||||
if (hardpoint != null) GUI.backgroundColor = hardpoint.TintColor.ToColor();
|
||||
shape[int2(x, y)] = GUILayout.Toggle(shape[int2(x, y)], GUIContent.none, GUILayout.Width(16));
|
||||
GUI.backgroundColor = previous;
|
||||
}
|
||||
}
|
||||
return shape;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue