Пример #1
0
            public static void Display(ComponentInstance[][] instancesArray)
            {
                BorderGroup.Begin("Components:");
                ImGui.Columns(3);
                ImGui.SetColumnWidth(0, 164);
                ImGui.SetColumnWidth(1, 42);
                ImGui.SetColumnWidth(2, 42);
                for (int i = 0; i < instancesArray.Length; i++)
                {
                    for (int j = 0; j < instancesArray[i].Length; j++)
                    {
                        var    instance = instancesArray[i][j];
                        string name     = instance.Name;
                        float  health   = 100 * instance.HealthPercent();

                        ImGui.Text(name);
                        ImGui.NextColumn();

                        ImGui.Text(health + "%%");

                        ImGui.NextColumn();
                        if (instance.IsEnabled)
                        {
                            ImGui.Text("On");
                        }
                        else
                        {
                            ImGui.Text("Off");
                        }
                        ImGui.NextColumn();
                    }
                }
                ImGui.Columns(1);
                BorderGroup.End();
            }
Пример #2
0
        internal override void Display()
        {
            //
            if (!IsActive || _selectedEntitySate == null)
            {
                return;
            }
            ImGui.SetNextWindowSize(new Vector2(1500, 800));
            if (ImGui.Begin("Sensor Display", ref IsActive))
            {
                if (_selectedEntity.HasDataBlob <SensorAbilityDB>())
                {
                    if (_selectedReceverAtb == null || ImGui.Button("refresh"))
                    {
                        SetSensorData();
                    }

                    ImGui.Columns(2);
                    ImGui.SetColumnWidth(0, 300);

                    if (ImGui.Combo("Targets", ref _targetIndex, _potentialTargetNames, _potentialTargetNames.Length))
                    {
                        _targetEntity = _potentialTargetEntities[_targetIndex];
                        SetTargetData();
                    }


                    ImGui.Text("lowest_x: " + lowestWave);
                    ImGui.Text("highest_x: " + highestWave);
                    ImGui.Text("lowest_y: " + lowestMag);
                    ImGui.Text("highest_y: " + highestMag);
                    if (_targetSensorProfile != null)
                    {
                        ImGui.Text("target cross section: " + _targetSensorProfile.TargetCrossSection_msq);
                    }



                    uint borderColour = ImGui.ColorConvertFloat4ToU32(new Vector4(0.5f, 0.5f, 0.5f, 1.0f));

                    uint receverColour = ImGui.ColorConvertFloat4ToU32(new Vector4(0.25f, 1.0f, 0.5f, 1.0f));
                    uint receverFill   = ImGui.ColorConvertFloat4ToU32(new Vector4(0.25f, 1.0f, 0.5f, 0.75f));

                    uint reflectedColour = ImGui.ColorConvertFloat4ToU32(new Vector4(1.0f, 0.0f, 0.5f, 1.0f));
                    uint reflectedFill   = ImGui.ColorConvertFloat4ToU32(new Vector4(1.0f, 0.0f, 0.5f, 0.75f));

                    uint emittedColour = ImGui.ColorConvertFloat4ToU32(new Vector4(1.0f, 0.0f, 0.25f, 1.0f));
                    uint emittedFill   = ImGui.ColorConvertFloat4ToU32(new Vector4(1.0f, 0.0f, 0.25f, 0.5f));

                    uint detectedColour = ImGui.ColorConvertFloat4ToU32(new Vector4(0.0f, 0.0f, 1.0f, 0.75f));

                    ImGui.BeginChild("stuff");

                    BorderGroup.Begin("Recevers:", borderColour);
                    DisplayWavInfo(_receverDat);
                    BorderGroup.End();

                    if (_reflectDat != null)
                    {
                        BorderGroup.Begin("Reflectors:", borderColour);
                        DisplayWavInfo(_reflectDat);
                        BorderGroup.End();
                    }

                    if (_emmittrDat != null)
                    {
                        BorderGroup.Begin("Emmiters:", borderColour);
                        DisplayWavInfo(_emmittrDat);
                        BorderGroup.End();
                    }

                    if (_detectedDat != null)
                    {
                        BorderGroup.Begin("Detected:", borderColour);
                        DisplayWavInfo(_detectedDat);
                        BorderGroup.End();
                    }

                    ImGui.EndChild();

                    ImGui.NextColumn();

                    // ImDrawList API uses screen coordinates!
                    Vector2 canvas_pos    = ImGui.GetCursorScreenPos();
                    Vector2 canvas_size   = ImGui.GetContentRegionAvail();
                    Vector2 canvas_endPos = canvas_pos + canvas_size;
                    Vector2 waveBounds    = new Vector2((float)(highestWave - lowestWave), (float)(highestMag - lowestMag));

                    _scalingFactor.X = 1 / (waveBounds.X / canvas_size.X);
                    _scalingFactor.Y = 1 / (waveBounds.Y / canvas_size.Y);

                    _translation.X = (float)(canvas_pos.X - lowestWave * _scalingFactor.X);
                    _translation.Y = (float)(canvas_pos.Y - lowestMag * _scalingFactor.Y);

                    _draw_list.AddRect(canvas_pos, canvas_endPos, borderColour);

                    ImGui.Text("Scale:");
                    ImGui.Text("X: " + _scalingFactor.X + " Y: " + _scalingFactor.Y);

                    Vector2 p0 = _translation + new Vector2((float)lowestWave, (float)lowestMag) * _scalingFactor;
                    Vector2 p1 = _translation + new Vector2((float)highestWave, (float)highestMag) * _scalingFactor;
                    ImGui.Text("Box From: " + p0);
                    ImGui.Text("Box To:   " + p1);

                    DrawWav(_receverDat, receverFill);

                    if (_reflectDat != null)
                    {
                        DrawWav(_reflectDat, reflectedFill);
                    }
                    if (_emmittrDat != null)
                    {
                        DrawWav(_emmittrDat, emittedFill);
                    }
                    if (_detectedDat != null)
                    {
                        DrawWav(_detectedDat, detectedColour);
                    }
                }
            }

            void DrawWav(WaveDrawData wavesArry, uint colour)
            {
                for (int i = 0; i < wavesArry.Count; i++)
                {
                    Vector2 p0 = _translation + wavesArry.Points[i].p0 * _scalingFactor;
                    Vector2 p1 = _translation + wavesArry.Points[i].p1 * _scalingFactor;
                    Vector2 p2 = _translation + wavesArry.Points[i].p2 * _scalingFactor;
                    if (wavesArry.IsWaveDrawn[i].drawSrc)
                    {
                        //_draw_list.AddLine(p0, p1, colour);
                        //_draw_list.AddLine(p1, p2, colour);
                        _draw_list.AddTriangleFilled(p0, p1, p2, colour);
                    }

                    if (wavesArry.HasAtn && wavesArry.IsWaveDrawn[i].drawAtn)
                    {
                        Vector2 p3 = _translation + wavesArry.Points[i].p3 * _scalingFactor;
                        _draw_list.AddTriangleFilled(p0, p3, p2, colour);
                    }
                }
            }

            void DisplayWavInfo(WaveDrawData wavesArry)
            {
                for (int i = 0; i < wavesArry.Count; i++)
                {
                    if (ImGui.Checkbox("Show Wave##drawbool" + i, ref wavesArry.IsWaveDrawn[i].drawSrc))
                    {
                        ResetBounds();
                    }

                    if (wavesArry.HasAtn)
                    {
                        ImGui.SameLine();
                        if (ImGui.Checkbox("Show Attenuated Wave##drawbool" + i, ref wavesArry.IsWaveDrawn[i].drawAtn))
                        {
                            ResetBounds();
                        }
                    }

                    ImGui.Text("MinWav: " + Stringify.DistanceSmall(wavesArry.Points[i].p0.X));
                    ImGui.SameLine();
                    ImGui.Text("Magnitude: " + Stringify.Power(wavesArry.Points[i].p0.Y));

                    ImGui.Text("AvgWav: " + Stringify.DistanceSmall(wavesArry.Points[i].p1.X));

                    if (wavesArry.HasAtn)
                    {
                        ImGui.SameLine();
                        ImGui.Text(" Magnitude peak/attenuated:");
                        ImGui.Text("   " + Stringify.Power(wavesArry.Points[i].p1.Y) + "/" + Stringify.Power(wavesArry.Points[i].p3.Y));
                    }
                    else
                    {
                        ImGui.SameLine();
                        ImGui.Text(" Magnitude peak:");
                        ImGui.Text("   " + Stringify.Power(wavesArry.Points[i].p1.Y));
                    }

                    ImGui.Text("MaxWav: " + Stringify.DistanceSmall(wavesArry.Points[i].p2.X));
                    ImGui.SameLine();
                    ImGui.Text("Magnitude: " + Stringify.Power(wavesArry.Points[i].p2.Y));
                }
            }

            void ResetBounds()
            {
                lowestWave  = float.PositiveInfinity;
                lowestMag   = float.PositiveInfinity;
                highestMag  = float.NegativeInfinity;
                highestWave = float.NegativeInfinity;

                var dat = _receverDat;

                for (int i = 0; i < dat.Count; i++)
                {
                    if (dat.IsWaveDrawn[i].drawSrc)
                    {
                        float low  = dat.Points[i].p0.X;
                        float high = dat.Points[i].p2.X;
                        float mag1 = dat.Points[i].p0.Y; //recever highest value
                        float mag2 = dat.Points[i].p1.Y; //recever lowest value
                        if (low < lowestWave)
                        {
                            lowestWave = low;
                        }
                        if (high > highestWave)
                        {
                            highestWave = high;
                        }
                        if (mag1 > highestMag)
                        {
                            highestMag = mag1;
                        }
                        if (mag2 < lowestMag)
                        {
                            lowestMag = mag2;
                        }
                    }
                }

                if (_reflectDat != null)
                {
                    ResetTargetBounds(_reflectDat);
                }
                if (_emmittrDat != null)
                {
                    ResetTargetBounds(_emmittrDat);
                }
                if (_detectedDat != null)
                {
                    ResetTargetBounds(_detectedDat);
                }
            }

            void ResetTargetBounds(WaveDrawData dat)
            {
                for (int i = 0; i < dat.Count; i++)
                {
                    if (dat.IsWaveDrawn[i].drawSrc || dat.IsWaveDrawn[i].drawAtn)
                    {
                        float low  = dat.Points[i].p0.X;
                        float high = dat.Points[i].p2.X;
                        float mag1 = dat.Points[i].p0.Y; //xmit lowest value prob 0
                        float mag2 = dat.Points[i].p1.Y; //xmit highest value
                        float mag3 = dat.Points[i].p3.Y; //xmit 2nd highest value

                        if (low < lowestWave)
                        {
                            lowestWave = low;
                        }
                        if (high > highestWave)
                        {
                            highestWave = high;
                        }

                        if (mag1 < lowestMag) //will likely be 0
                        {
                            lowestMag = mag1;
                        }

                        if (dat.IsWaveDrawn[i].drawSrc)
                        {
                            if (mag2 > highestMag)
                            {
                                highestMag = mag2;
                            }
                        }
                        if (dat.IsWaveDrawn[i].drawAtn)
                        {
                            if (mag3 > highestMag)
                            {
                                highestMag = mag3;
                            }
                        }
                    }
                }
            }

            void SetSensorData()
            {
                if (_selectedEntity.GetDataBlob <ComponentInstancesDB>().TryGetComponentsByAttribute <SensorReceverAtbDB>(out var recevers))
                {
                    _receverDat        = new WaveDrawData();
                    _receverDat.HasAtn = false;
                    var points = _receverDat.Points = new (Vector2 p0, Vector2 p1, Vector2 p2, Vector2 p3)[recevers.Count];
                    _receverDat.IsWaveDrawn = new (bool drawSrc, bool drawAtn)[recevers.Count];

                    _selectedReceverAtb             = new SensorReceverAtbDB[recevers.Count];
                    _selectedReceverInstanceAbility = new SensorReceverAbility[recevers.Count];
                    int i = 0;
                    foreach (var recever in recevers)
                    {
                        _selectedReceverAtb[i]             = recever.Design.GetAttribute <SensorReceverAtbDB>();
                        _selectedReceverInstanceAbility[i] = recever.GetAbilityState <SensorReceverAbility>();

                        float low  = (float)_selectedReceverAtb[i].RecevingWaveformCapabilty.WavelengthMin_nm;
                        float mid  = (float)_selectedReceverAtb[i].RecevingWaveformCapabilty.WavelengthAverage_nm;
                        float high = (float)_selectedReceverAtb[i].RecevingWaveformCapabilty.WavelengthMax_nm;

                        float mag1 = (float)_selectedReceverAtb[i].WorstSensitivity_kW;
                        float mag2 = (float)_selectedReceverAtb[i].BestSensitivity_kW;

                        points[i].p0 = new Vector2(low, mag1);
                        points[i].p1 = new Vector2(mid, mag2);
                        points[i].p2 = new Vector2(high, mag1);
                        i++;
                    }

                    var tgts = _selectedStarSys.GetAllEntitiesWithDataBlob <SensorProfileDB>();
                    _potentialTargetNames    = new string[tgts.Count];
                    _potentialTargetEntities = tgts.ToArray();
                    i = 0;
                    foreach (var target in tgts)
                    {
                        string name = target.GetDataBlob <NameDB>().GetName(_uiState.Faction);
                        _potentialTargetNames[i] = name;
                        i++;
                    }

                    for (int j = 0; j < _selectedReceverInstanceAbility.Length; j++)
                    {
                        //SetTargetData();
                        //var foo = _selectedReceverInstanceAbility[i].CurrentContacts;
                        //foreach (SensorProcessorTools.SensorReturnValues val in foo.Values)
                        //{
                        //val.SignalStrength_kW
                        //}
                    }
                }
Пример #3
0
        internal override void Display()
        {
            if (IsActive && ImGui.Begin("Ordnance Design"))
            {
                ImGui.Combo("Current Designs", ref _payloadSelectedIndex, _currentDesignNames, _currentDesignNames.Length);

                ImGui.NewLine();
                BorderGroup.Begin("Payload:");
                if (ImGui.Combo("Payload type", ref _payloadSelectedIndex, _payload, _payload.Length))
                {
                    //_selectedPayload = _payloadTypes[_payloadSelectedIndex].GetAttribute<OrdnancePayloadAtb>();
                    _selectedComponentDesigns[_payloadTypes[_payloadSelectedIndex]] = _payloadCount;
                    RefreshMass();
                }
                if (ImGui.SliderInt("Payload Count", ref _payloadCount, 1, 100))
                {
                    _selectedComponentDesigns[_payloadTypes[_payloadSelectedIndex]] = _payloadCount;
                    RefreshMass();
                }
                var whmass = _payloadTypes[_payloadSelectedIndex].MassPerUnit * _payloadCount;
                ImGui.Text("Mass: " + Stringify.Mass(whmass));
                //ImGui.Text("Payload Trigger Type: " + _selectedPayload.Trigger);
                BorderGroup.End();
                ImGui.NewLine();

                BorderGroup.Begin("Electronics Suite:");
                if (ImGui.Combo("ElectronicsSuite", ref _electronicsSelectedIndex, _electronicsPackage, _electronicsPackage.Length))
                {
                    _selectedComponentDesigns[_eleccPackTypes[_electronicsSelectedIndex]] = 1;
                    RefreshMass();
                }
                var mass = _eleccPackTypes[_electronicsSelectedIndex].MassPerUnit;
                ImGui.Text("Mass: " + Stringify.Mass(mass));
                BorderGroup.End();

                ImGui.NewLine();

                BorderGroup.Begin("Engine:");

                if (ImGui.Combo("Engine Types", ref _engineDesignTypeIndex, _engineTypeNames, _engineTypeNames.Length))
                {
                    _engineDesigner = new ComponentDesigner(_engineTemplates[_engineDesignTypeIndex], _factionTech);
                    _engineDesigner.SetAttributes();
                }

                if (_engineDesigner != null)
                {
                    PartDesignUI.GuiDesignUI(_engineDesigner);
                    _thrusterSizeKG = _engineDesigner.MassValue;
                    RefreshMass();
                }

                if (ImGui.SliderFloat("Fuel", ref _fuelKG, 1, 1000))
                {
                    RefreshMass();
                }

                BorderGroup.End();

                ImGui.NewLine();
                ImGui.Text("Total Mass: " + Stringify.Mass(_totalMass));

                double burnRate  = 0;
                double exaustVel = 0;

                if (_engineDesigner != null)
                {
                    var atb = _engineDesigner.GetAttribute <NewtonionThrustAtb>();
                    burnRate  = atb.FuelBurnRate;
                    exaustVel = atb.ExhaustVelocity;
                }

                double thrustNewtons = burnRate * exaustVel;
                double burnTime      = _fuelKG / burnRate;
                double dv            = OrbitMath.TsiolkovskyRocketEquation(_totalMass, _totalMass - _fuelKG, exaustVel);
                ImGui.Text("Burn Time: " + burnTime + "s");
                ImGui.Text("Thrust: " + Stringify.Thrust(thrustNewtons));
                ImGui.Text("Acceleration (wet): " + Stringify.Velocity(thrustNewtons / _totalMass));
                ImGui.Text("Acceleration (dry): " + Stringify.Velocity(thrustNewtons / (_totalMass - _fuelKG)));
                ImGui.Text("DeltaV: " + Stringify.Velocity(dv));

                ImGui.InputText("Design Name", _designName, (uint)_designName.Length);
                NewDesignButton();
            }
        }