Esempio n. 1
0
    void Awake()
    {
        instance                 = (SimulationPanel)Singleton.Setup(this, instance);
        activeComponents         = new List <BaseComponent>();
        activeFluidConnectors    = new List <Connector>();
        activeElectricConnectors = new List <Connector>();
        activeWires              = new List <Wire>();
        activeCoils              = new List <Coil>();
        activeSensors            = new List <Sensor>();
        activeSolenoids          = new List <ElectricSolenoid>();

        activeSelectables   = new List <ISelectable>();
        activeDraggables    = new List <IDraggable>();
        activeConfigurables = new List <IConfigurable>();
    }
 void OnEnable()
 {
     simPanel = target as SimulationPanel;
 }
Esempio n. 3
0
        //TODO: Think about moving rendering from graphic timer to game loop and render each n-th simulation step in the buffer, using graphic timer to only render that
        /// <summary>
        /// Handler for graphic timer ticks, starts drawing of our map (via triggering the map paint method)
        /// and also sets unfocused inputs to current values
        /// </summary>
        private void GraphicTimer_Tick(object sender, EventArgs e)
        {
            //Render the world
            var       graphics  = SimulationPanel.CreateGraphics();
            Rectangle rectangle = new Rectangle(0, 0, SimulationPanel.Width, SimulationPanel.Height);

            SimulationPanel_Paint(sender, new PaintEventArgs(graphics, rectangle));

            //If field is selected, we allow its editing, otherwise we lock the controls
            if (world.SelectedField != null)
            {
                TileInitialTemperature.Enabled = true;
                TileTemperatureOffset.Enabled  = true;
                TileHeight.Enabled             = true;
                TileCalories.Enabled           = true;
                TileCoordinates.Text           = world.SelectedFieldX.ToString() + "X, " + world.SelectedFieldY.ToString() + "Y";
                TileTemperature.Text           = world.SelectedField.Temperature.ToString() + "/" + Field.MaxValue.ToString();
                TileMaxCalories.Text           = world.SelectedField.MaxCalories.ToString() + "/" + Field.MaxValue.ToString();
                if (!TileInitialTemperature.Focused)
                {
                    TileInitialTemperature.Value = world.SelectedField.InitialTemperature;
                }
                if (!TileTemperatureOffset.Focused)
                {
                    TileTemperatureOffset.Value = world.SelectedField.TemperatureOffset;
                }
                if (!TileHeight.Focused)
                {
                    TileHeight.Value = world.SelectedField.Height;
                }
                if (!TileCalories.Focused)
                {
                    TileCalories.Value = (int)world.SelectedField.Calories;
                }
            }
            else
            {
                TileInitialTemperature.Enabled = false;
                TileTemperatureOffset.Enabled  = false;
                TileHeight.Enabled             = false;
                TileCalories.Enabled           = false;
            }

            //If a creature is selected, we allow its editing, otherwise we lock the controls
            if (world.SelectedCreature != null)
            {
                CreatureX.Enabled                   = true;
                CreatureY.Enabled                   = true;
                CreatureRotation.Enabled            = true;
                CreatureSize.Enabled                = true;
                CreatureVisionAngle.Enabled         = true;
                CreatureVisionDistance.Enabled      = true;
                CreatureMutability.Enabled          = true;
                CreatureExcitability.Enabled        = true;
                CreatureHeightAffinity.Enabled      = true;
                CreatureTemperatureAffinity.Enabled = true;
                CreatureAge.Enabled                 = true;
                if (!CreatureX.Focused)
                {
                    CreatureX.Value = (decimal)world.SelectedCreature.X;
                }
                if (!CreatureY.Focused)
                {
                    CreatureY.Value = (decimal)world.SelectedCreature.Y;
                }
                if (!CreatureRotation.Focused)
                {
                    CreatureRotation.Value = (decimal)world.SelectedCreature.Rotation;
                }
                if (!CreatureSize.Focused)
                {
                    CreatureSize.Value = (decimal)world.SelectedCreature.Size;
                }
                if (!CreatureVisionAngle.Focused)
                {
                    CreatureVisionAngle.Value = (decimal)world.SelectedCreature.VisionAngle;
                }
                if (!CreatureVisionDistance.Focused)
                {
                    CreatureVisionDistance.Value = (decimal)world.SelectedCreature.VisionDistance;
                }
                if (!CreatureMutability.Focused)
                {
                    CreatureMutability.Value = (decimal)world.SelectedCreature.Mutability;
                }
                if (!CreatureExcitability.Focused)
                {
                    CreatureExcitability.Value = (decimal)world.SelectedCreature.Excitability;
                }
                if (!CreatureHeightAffinity.Focused)
                {
                    CreatureHeightAffinity.Value = (decimal)world.SelectedCreature.HeightAffinity;
                }
                if (!CreatureTemperatureAffinity.Focused)
                {
                    CreatureTemperatureAffinity.Value = (decimal)world.SelectedCreature.TemperatureAffinity;
                }
                if (!CreatureAge.Focused)
                {
                    CreatureAge.Value = (decimal)world.SelectedCreature.LifeLength;
                }
                //Draw creature brains if it is selected
                var       brainGraphics  = CreatureBrainCanvas.CreateGraphics();
                Rectangle brainRectangle = new Rectangle(0, 0, CreatureBrainCanvas.Width, CreatureBrainCanvas.Height);
                CreatureBrainCanvas_Paint(sender, new PaintEventArgs(brainGraphics, brainRectangle));
            }
            else
            {
                CreatureX.Enabled                   = false;
                CreatureY.Enabled                   = false;
                CreatureRotation.Enabled            = false;
                CreatureSize.Enabled                = false;
                CreatureVisionAngle.Enabled         = false;
                CreatureVisionDistance.Enabled      = false;
                CreatureMutability.Enabled          = false;
                CreatureExcitability.Enabled        = false;
                CreatureHeightAffinity.Enabled      = false;
                CreatureTemperatureAffinity.Enabled = false;
                CreatureAge.Enabled                 = false;
            }
        }
Esempio n. 4
0
 private void SimulationTimer_Tick(object sender, EventArgs e)
 {
     PeopleInteract();
     RefreshLabels();
     SimulationPanel.Invalidate();
 }
Esempio n. 5
0
    void ProcessMouseInput()
    {
        EditorInput     input    = EditorInput.instance;
        SimulationPanel simPanel = SimulationPanel.instance;

        if (FloatingSelection.instance.HasFloatingComponent())
        {
            if (input.singleClick)
            {
                FloatingSelection.instance.PlaceFloatingComponent();
            }
        }
        else
        {
            if (input.singleClick)
            {
                if (!Input.GetKey(KeyCode.LeftShift))
                {
                    SelectedObjects.instance.ClearSelection();
                }
                foreach (var selectable in simPanel.GetActiveSelectables())
                {
                    if (selectable.RequestedSelect())
                    {
                        SelectedObjects.instance.SelectObject(selectable);
                        break;
                    }
                }
            }
            if (input.doubleClick)
            {
                foreach (var configurable in simPanel.GetActiveConfigurables())
                {
                    if (configurable.RequestedConfig())
                    {
                        SelectedObjects.instance.ClearSelection();
                        configurable.OpenConfigWindow();
                        break;
                    }
                }
            }
            if (input.mouseDragStart)
            {
                foreach (var draggable in simPanel.GetActiveDraggables())
                {
                    if (draggable.RequestedDrag())
                    {
                        draggable.StartDragging();
                        currentDraggable = draggable;
                        break;
                    }
                }
                if (currentDraggable == null)
                {
                    BoxSelection.instance.StartSelecting();
                }
            }
            if (input.mouseDragEnd)
            {
                if (currentDraggable != null)
                {
                    currentDraggable.StopDragging();
                    currentDraggable = null;
                }
                else
                {
                    BoxSelection.instance.StopSelecting();
                }
            }
        }
    }