public EditMemoryBankDialog(MemoryBankData memoryBankData, Action handler) { XElement node = ContentManager.Get <XElement>("Dialogs/EditMemoryBankDialog"); LoadContents(this, node); m_linearPanel = Children.Find <Widget>("EditMemoryBankDialog.LinearPanel"); m_gridPanel = Children.Find <Widget>("EditMemoryBankDialog.GridPanel"); m_okButton = Children.Find <ButtonWidget>("EditMemoryBankDialog.OK"); m_cancelButton = Children.Find <ButtonWidget>("EditMemoryBankDialog.Cancel"); m_switchViewButton = Children.Find <ButtonWidget>("EditMemoryBankDialog.SwitchViewButton"); m_linearTextBox = Children.Find <TextBoxWidget>("EditMemoryBankDialog.LinearText"); for (int i = 0; i < 16; i++) { m_lineTextBoxes[i] = Children.Find <TextBoxWidget>("EditMemoryBankDialog.Line" + i.ToString()); } m_handler = handler; m_memoryBankData = memoryBankData; m_tmpMemoryBankData = (MemoryBankData)m_memoryBankData.Copy(); m_linearPanel.IsVisible = false; for (int j = 0; j < 16; j++) { m_lineTextBoxes[j].TextChanged += TextBox_TextChanged; } m_linearTextBox.TextChanged += TextBox_TextChanged; }
public MemoryBankElectricElement(SubsystemElectricity subsystemElectricity, CellFace cellFace) : base(subsystemElectricity, cellFace) { m_subsystemMemoryBankBlockBehavior = subsystemElectricity.Project.FindSubsystem <SubsystemMemoryBankBlockBehavior>(throwOnError: true); MemoryBankData blockData = m_subsystemMemoryBankBlockBehavior.GetBlockData(cellFace.Point); if (blockData != null) { m_voltage = (float)(int)blockData.LastOutput / 15f; } }
public void TextBox_TextChanged(TextBoxWidget textBox) { if (m_ignoreTextChanges) { return; } if (textBox == m_linearTextBox) { m_tmpMemoryBankData = new MemoryBankData(); m_tmpMemoryBankData.LoadString(m_linearTextBox.Text); return; } string text = string.Empty; for (int i = 0; i < 16; i++) { text += m_lineTextBoxes[i].Text; } m_tmpMemoryBankData = new MemoryBankData(); m_tmpMemoryBankData.LoadString(text); }
public EditMemeryDialogB(MemoryBankData memoryBankData, Action onCancel) { memory = memoryBankData; Data.Clear(); Data.AddRange(memory.Data); CanvasWidget canvasWidget = new CanvasWidget() { Size = new Vector2(600f, float.PositiveInfinity), HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center }; RectangleWidget rectangleWidget = new RectangleWidget() { FillColor = new Color(0, 0, 0, 255), OutlineColor = new Color(128, 128, 128, 128), OutlineThickness = 2 }; StackPanelWidget stackPanel = new StackPanelWidget() { Direction = LayoutDirection.Vertical }; LabelWidget labelWidget = new LabelWidget() { Text = "M 板编辑器", HorizontalAlignment = WidgetAlignment.Center, Margin = new Vector2(0, 10) }; StackPanelWidget stackPanelWidget = new StackPanelWidget() { Direction = LayoutDirection.Horizontal, HorizontalAlignment = WidgetAlignment.Near, VerticalAlignment = WidgetAlignment.Near, Margin = new Vector2(10f, 10f) }; Children.Add(canvasWidget); canvasWidget.Children.Add(rectangleWidget); canvasWidget.Children.Add(stackPanel); stackPanel.Children.Add(labelWidget); stackPanel.Children.Add(stackPanelWidget); stackPanelWidget.Children.Add(initData()); stackPanelWidget.Children.Add(initButton()); MainView = stackPanel; this.onCancel = onCancel; lastvalue = memory.Read(0); }
public override bool Simulate() { float voltage = m_voltage; bool flag = false; bool flag2 = false; bool flag3 = false; float num = 0f; int num2 = 0; int num3 = 0; int rotation = base.Rotation; foreach (ElectricConnection connection in base.Connections) { if (connection.ConnectorType != ElectricConnectorType.Output && connection.NeighborConnectorType != 0) { ElectricConnectorDirection?connectorDirection = SubsystemElectricity.GetConnectorDirection(base.CellFaces[0].Face, rotation, connection.ConnectorFace); if (connectorDirection.HasValue) { if (connectorDirection == ElectricConnectorDirection.Right) { num2 = (int)MathUtils.Round(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace) * 15f); } else if (connectorDirection == ElectricConnectorDirection.Left) { num3 = (int)MathUtils.Round(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace) * 15f); } else if (connectorDirection == ElectricConnectorDirection.Bottom) { int num4 = (int)MathUtils.Round(connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace) * 15f); flag = (num4 >= 8); flag3 = (num4 > 0 && num4 < 8); flag2 = true; } else if (connectorDirection == ElectricConnectorDirection.In) { num = connection.NeighborElectricElement.GetOutputVoltage(connection.NeighborConnectorFace); } } } } MemoryBankData memoryBankData = m_subsystemMemoryBankBlockBehavior.GetBlockData(base.CellFaces[0].Point); int address = num2 + (num3 << 4); if (flag2) { if (flag && m_clockAllowed) { m_clockAllowed = false; m_voltage = ((memoryBankData != null) ? ((float)(int)memoryBankData.Read(address) / 15f) : 0f); } else if (flag3 && m_writeAllowed) { m_writeAllowed = false; if (memoryBankData == null) { memoryBankData = new MemoryBankData(); m_subsystemMemoryBankBlockBehavior.SetBlockData(base.CellFaces[0].Point, memoryBankData); } memoryBankData.Write(address, (byte)MathUtils.Round(num * 15f)); } } else { m_voltage = ((memoryBankData != null) ? ((float)(int)memoryBankData.Read(address) / 15f) : 0f); } if (!flag) { m_clockAllowed = true; } if (!flag3) { m_writeAllowed = true; } if (memoryBankData != null) { memoryBankData.LastOutput = (byte)MathUtils.Round(m_voltage * 15f); } return(m_voltage != voltage); }