Пример #1
0
        public static void CreateTerminalUi <T>(Session session) where T : IMyTerminalBlock
        {
            try
            {
                var obs = new HashSet <Type>();

                if (typeof(T) == typeof(IMyLargeTurretBase))
                {
                    if (!session.BaseControlsActions)
                    {
                        TerminalHelpers.AlterActions <IMyUserControllableGun>();
                        TerminalHelpers.AlterControls <IMyUserControllableGun>();
                        session.BaseControlsActions = true;
                    }

                    CreateShootClick <T>();

                    TerminalHelpers.AlterActions <T>();
                    TerminalHelpers.AlterControls <T>();

                    obs.Add(new MyObjectBuilder_LargeMissileTurret().GetType());
                    obs.Add(new MyObjectBuilder_InteriorTurret().GetType());
                    obs.Add(new MyObjectBuilder_LargeGatlingTurret().GetType());
                }
                else if (typeof(T) == typeof(IMySmallMissileLauncher) || typeof(T) == typeof(IMySmallGatlingGun))
                {
                    if (!session.BaseControlsActions)
                    {
                        TerminalHelpers.AlterActions <IMyUserControllableGun>();
                        TerminalHelpers.AlterControls <IMyUserControllableGun>();

                        session.BaseControlsActions = true;
                    }

                    CreateShootClick <T>();


                    obs.Add(new MyObjectBuilder_SmallMissileLauncher().GetType());
                    obs.Add(new MyObjectBuilder_SmallMissileLauncherReload().GetType());
                    obs.Add(new MyObjectBuilder_SmallGatlingGun().GetType());
                }
                else if (typeof(T) == typeof(IMyConveyorSorter))
                {
                    obs.Add(new MyObjectBuilder_ConveyorSorter().GetType());
                    TerminalHelpers.AlterActions <T>();
                    TerminalHelpers.AlterControls <T>();

                    CreateShootClick <T>();
                }

                TerminalHelpers.AddSlider <T>(-5, "WC_Range", "Aiming Radius", "Range", WepUi.GetRange, WepUi.SetRange, WepUi.ShowRange, WepUi.GetMinRange, WepUi.GetMaxRange);

                if (obs.Count == 0)
                {
                    return;
                }

                var wepIDs = new HashSet <int>();
                foreach (KeyValuePair <MyStringHash, WeaponStructure> wp in session.WeaponPlatforms)
                {
                    foreach (KeyValuePair <MyStringHash, WeaponSystem> ws in session.WeaponPlatforms[wp.Key].WeaponSystems)
                    {
                        MyDefinitionId   defId;
                        MyDefinitionBase def = null;

                        Type type = null;
                        if (session.ReplaceVanilla && session.VanillaCoreIds.TryGetValue(wp.Key, out defId))
                        {
                            if (!MyDefinitionManager.Static.TryGetDefinition(defId, out def))
                            {
                                return;
                            }
                            type = defId.TypeId;
                        }
                        else
                        {
                            foreach (var tmpdef in session.AllDefinitions)
                            {
                                if (tmpdef.Id.SubtypeId == wp.Key)
                                {
                                    type = tmpdef.Id.TypeId;
                                    def  = tmpdef;
                                    break;
                                }
                            }
                            if (type == null)
                            {
                                return;
                            }
                        }

                        try
                        {
                            //var ob = def.GetObjectBuilder();
                            if (obs.Contains(type))
                            {
                                var wepName   = ws.Value.WeaponName;
                                var wepIdHash = ws.Value.WeaponIdHash;

                                if (!wepIDs.Contains(wepIdHash))
                                {
                                    wepIDs.Add(wepIdHash);
                                }
                                else
                                {
                                    continue;
                                }
                                if (!ws.Value.DesignatorWeapon)
                                {
                                    CreateShootActionSet <T>(wepName, wepIdHash);

                                    if (ws.Value.WeaponAmmoTypes.Length > 1)
                                    {
                                        var c = 0;
                                        for (int i = 0; i < ws.Value.WeaponAmmoTypes.Length; i++)
                                        {
                                            if (ws.Value.WeaponAmmoTypes[i].AmmoDef.HardPointUsable)
                                            {
                                                c++;
                                            }
                                        }
                                        if (c > 1)
                                        {
                                            CreateCycleAmmoOptions <T>(wepName, wepIdHash, session.ModPath());
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Line($"Keen Broke it: {e}");
                        }
                    }
                }
            }
            catch (Exception ex) { Log.Line($"Exception in CreateControlUi: {ex}"); }
        }