public override void Update() { m_nameLabel.Text = (string.IsNullOrEmpty(m_design.Name) ? m_design.GetDefaultName() : m_design.Name); m_designWidget2d.Mode = (FurnitureDesignWidget.ViewMode)m_axis; m_designWidget3d.Mode = FurnitureDesignWidget.ViewMode.Perspective; if (m_designWidget2d.Mode == FurnitureDesignWidget.ViewMode.Side) { m_axisButton.Text = LanguageControl.Get(fName, 4); } if (m_designWidget2d.Mode == FurnitureDesignWidget.ViewMode.Top) { m_axisButton.Text = LanguageControl.Get(fName, 5); } if (m_designWidget2d.Mode == FurnitureDesignWidget.ViewMode.Front) { m_axisButton.Text = LanguageControl.Get(fName, 6); } m_leftButton.IsEnabled = IsShiftPossible(DirectionAxisToDelta(0, m_axis)); m_rightButton.IsEnabled = IsShiftPossible(DirectionAxisToDelta(1, m_axis)); m_upButton.IsEnabled = IsShiftPossible(DirectionAxisToDelta(2, m_axis)); m_downButton.IsEnabled = IsShiftPossible(DirectionAxisToDelta(3, m_axis)); m_decreaseResolutionButton.IsEnabled = IsDecreaseResolutionPossible(); m_increaseResolutionButton.IsEnabled = IsIncreaseResolutionPossible(); m_resolutionLabel.Text = $"{m_design.Resolution}"; m_buildButton.IsEnabled = m_isValid; if (m_nameButton.IsClicked) { List <Tuple <string, Action> > list = new List <Tuple <string, Action> >(); if (m_sourceDesign != null) { list.Add(new Tuple <string, Action>(LanguageControl.Get(fName, 7), delegate { Dismiss(result: false); DialogsManager.ShowDialog(base.ParentWidget, new TextBoxDialog(LanguageControl.Get(fName, 10), m_sourceDesign.Name, 20, delegate(string s) { try { if (s != null) { m_sourceDesign.Name = s; } } catch (Exception ex3) { DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog(LanguageControl.Get("Usual", "error"), ex3.Message, LanguageControl.Get("Usual", "ok"), null, null)); } })); })); list.Add(new Tuple <string, Action>(LanguageControl.Get(fName, 8), delegate { DialogsManager.ShowDialog(base.ParentWidget, new TextBoxDialog(LanguageControl.Get(fName, 11), m_design.Name, 20, delegate(string s) { try { if (s != null) { m_design.Name = s; } } catch (Exception ex2) { DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog(LanguageControl.Get("Usual", "error"), ex2.Message, LanguageControl.Get("Usual", "ok"), null, null)); } })); })); } else { list.Add(new Tuple <string, Action>(LanguageControl.Get(fName, 9), delegate { DialogsManager.ShowDialog(base.ParentWidget, new TextBoxDialog(LanguageControl.Get(fName, 11), m_design.Name, 20, delegate(string s) { try { if (s != null) { m_design.Name = s; } } catch (Exception ex) { DialogsManager.ShowDialog(base.ParentWidget, new MessageDialog(LanguageControl.Get("Usual", "error"), ex.Message, LanguageControl.Get("Usual", "ok"), null, null)); } })); })); } if (list.Count == 1) { list[0].Item2(); } else { DialogsManager.ShowDialog(base.ParentWidget, new ListSelectionDialog(LanguageControl.Get(fName, 11), list, 64f, (object t) => ((Tuple <string, Action>) t).Item1, delegate(object t) { ((Tuple <string, Action>)t).Item2(); })); } } if (m_axisButton.IsClicked) { m_axis = (m_axis + 1) % 3; } if (m_leftButton.IsClicked) { Shift(DirectionAxisToDelta(0, m_axis)); } if (m_rightButton.IsClicked) { Shift(DirectionAxisToDelta(1, m_axis)); } if (m_upButton.IsClicked) { Shift(DirectionAxisToDelta(2, m_axis)); } if (m_downButton.IsClicked) { Shift(DirectionAxisToDelta(3, m_axis)); } if (m_mirrorButton.IsClicked) { m_design.Mirror(m_axis); } if (m_turnRightButton.IsClicked) { m_design.Rotate(m_axis, 1); } if (m_decreaseResolutionButton.IsClicked) { DecreaseResolution(); } if (m_increaseResolutionButton.IsClicked) { IncreaseResolution(); } if (m_buildButton.IsClicked && m_isValid) { Dismiss(result: true); } if (base.Input.Back || m_cancelButton.IsClicked) { Dismiss(result: false); } }
public void ScanDesign(CellFace start, Vector3 direction, ComponentMiner componentMiner) { FurnitureDesign design = null; FurnitureDesign furnitureDesign = null; Dictionary <Point3, int> valuesDictionary = new Dictionary <Point3, int>(); Point3 point = start.Point; Point3 point2 = start.Point; int startValue = base.SubsystemTerrain.Terrain.GetCellValue(start.Point.X, start.Point.Y, start.Point.Z); int num = Terrain.ExtractContents(startValue); if (BlocksManager.Blocks[num] is FurnitureBlock) { int designIndex = FurnitureBlock.GetDesignIndex(Terrain.ExtractData(startValue)); furnitureDesign = GetDesign(designIndex); if (furnitureDesign == null) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false); return; } design = furnitureDesign.Clone(); design.LinkedDesign = null; design.InteractionMode = FurnitureInteractionMode.None; valuesDictionary.Add(start.Point, startValue); } else { Stack <Point3> val = new Stack <Point3>(); val.Push(start.Point); while (val.Count > 0) { Point3 key = val.Pop(); if (valuesDictionary.ContainsKey(key)) { continue; } int cellValue = base.SubsystemTerrain.Terrain.GetCellValue(key.X, key.Y, key.Z); if (IsValueDisallowed(cellValue)) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Unsuitable block found", Color.White, blinking: true, playNotificationSound: false); return; } if (IsValueAllowed(cellValue)) { if (key.X < point.X) { point.X = key.X; } if (key.Y < point.Y) { point.Y = key.Y; } if (key.Z < point.Z) { point.Z = key.Z; } if (key.X > point2.X) { point2.X = key.X; } if (key.Y > point2.Y) { point2.Y = key.Y; } if (key.Z > point2.Z) { point2.Z = key.Z; } if (MathUtils.Abs(point.X - point2.X) >= 16 || MathUtils.Abs(point.Y - point2.Y) >= 16 || MathUtils.Abs(point.Z - point2.Z) >= 16) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Furniture design is too large", Color.White, blinking: true, playNotificationSound: false); return; } valuesDictionary[key] = cellValue; val.Push(new Point3(key.X - 1, key.Y, key.Z)); val.Push(new Point3(key.X + 1, key.Y, key.Z)); val.Push(new Point3(key.X, key.Y - 1, key.Z)); val.Push(new Point3(key.X, key.Y + 1, key.Z)); val.Push(new Point3(key.X, key.Y, key.Z - 1)); val.Push(new Point3(key.X, key.Y, key.Z + 1)); } } if (valuesDictionary.Count == 0) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("No suitable blocks found", Color.White, blinking: true, playNotificationSound: false); return; } design = new FurnitureDesign(base.SubsystemTerrain); Point3 point3 = point2 - point; int num2 = MathUtils.Max(MathUtils.Max(point3.X, point3.Y, point3.Z) + 1, 2); int[] array = new int[num2 * num2 * num2]; foreach (KeyValuePair <Point3, int> item in valuesDictionary) { Point3 point4 = item.Key - point; array[point4.X + point4.Y * num2 + point4.Z * num2 * num2] = item.Value; } design.SetValues(num2, array); int steps = (start.Face > 3) ? CellFace.Vector3ToFace(direction, 3) : CellFace.OppositeFace(start.Face); design.Rotate(1, steps); Point3 location = design.Box.Location; Point3 point5 = new Point3(design.Resolution) - (design.Box.Location + design.Box.Size); Point3 delta = new Point3((point5.X - location.X) / 2, -location.Y, (point5.Z - location.Z) / 2); design.Shift(delta); } BuildFurnitureDialog dialog = new BuildFurnitureDialog(design, furnitureDesign, delegate(bool result) { if (result) { design = TryAddDesign(design); if (design == null) { componentMiner.ComponentPlayer?.ComponentGui.DisplaySmallMessage("Too many different furniture designs", Color.White, blinking: true, playNotificationSound: false); } else { if (m_subsystemGameInfo.WorldSettings.GameMode != 0) { foreach (KeyValuePair <Point3, int> item2 in valuesDictionary) { base.SubsystemTerrain.DestroyCell(0, item2.Key.X, item2.Key.Y, item2.Key.Z, 0, noDrop: true, noParticleSystem: true); } } int value = Terrain.MakeBlockValue(227, 0, FurnitureBlock.SetDesignIndex(0, design.Index, design.ShadowStrengthFactor, design.IsLightEmitter)); int num3 = MathUtils.Clamp(design.Resolution, 4, 8); Matrix matrix = componentMiner.ComponentCreature.ComponentBody.Matrix; Vector3 position = matrix.Translation + 1f * matrix.Forward + 1f * Vector3.UnitY; m_subsystemPickables.AddPickable(value, num3, position, null, null); componentMiner.DamageActiveTool(1); componentMiner.Poke(forceRestart: false); for (int i = 0; i < 3; i++) { Time.QueueTimeDelayedExecution(Time.FrameStartTime + (double)((float)i * 0.25f), delegate { m_subsystemSoundMaterials.PlayImpactSound(startValue, new Vector3(start.Point), 1f); }); } if (componentMiner.ComponentCreature.PlayerStats != null) { componentMiner.ComponentCreature.PlayerStats.FurnitureItemsMade += num3; } } } }); if (componentMiner.ComponentPlayer != null) { DialogsManager.ShowDialog(componentMiner.ComponentPlayer.GuiWidget, dialog); } }