예제 #1
0
        private void try_register_handlers()
        {
            sync_helper.try_register_handlers();
            screen_info.try_register_handlers();
            if (!_entity_events_set && screen_info.settings_loaded && MyAPIGateway.Entities != null)
            {
                var existing_entities = new HashSet <IMyEntity>();
                MyAPIGateway.Entities.GetEntities(existing_entities);
                foreach (IMyEntity cur_entity in existing_entities)
                {
                    on_entity_added(cur_entity);
                }
                MyAPIGateway.Entities.OnEntityAdd    += on_entity_added;
                MyAPIGateway.Entities.OnEntityRemove += on_entity_removed;
                _entity_events_set = true;
            }

            if (!screen_info.settings_loaded || MyAPIGateway.TerminalControls == null)
            {
                return;
            }

            if (!_ship_controller_controls_set)
            {
                if (_sample_controller?.GetProperty("DampenersOverride") == null)
                {
                    return;
                }
                create_controller_widgets <IMyCockpit>();
                create_controller_widgets <IMyRemoteControl>();
                _ship_controller_controls_set = true;
                _sample_controller            = null;
            }

            if (!_thruster_controls_set)
            {
                if (!screen_info.torque_disabled && _sample_thruster?.GetProperty("Override") == null)
                {
                    return;
                }
                _thruster_controls_set = true;
                _sample_thruster       = null;
                if (screen_info.torque_disabled)
                {
                    return;
                }
                IMyTerminalControlSeparator thruster_line = MyAPIGateway.TerminalControls.CreateControl <IMyTerminalControlSeparator, IMyThrust>("TTDTWM_LINE1");
                MyAPIGateway.TerminalControls.AddControl <IMyThrust>(thruster_line);
                create_switch <IMyThrust>("ActiveControl", "Steering", null, "On", "Off", "On", "Off", thruster_and_grid_tagger.is_under_active_control, thruster_and_grid_tagger.set_active_control, thruster_and_grid_tagger.is_active_control_available);
                create_switch <IMyThrust>("AntiSlip", "Thrust Trimming", null, "On", "Off", "On", "Off", thruster_and_grid_tagger.is_anti_slip, thruster_and_grid_tagger.set_anti_slip, thruster_and_grid_tagger.is_anti_slip_available);
                create_checkbox <IMyThrust>("DisableLinearInput", "Disable linear input", null, "On", "Off", thruster_and_grid_tagger.is_rotational_only, thruster_and_grid_tagger.toggle_linear_input, thruster_and_grid_tagger.is_active_control_available);
                create_switch <IMyThrust>("StaticLimit", "Thrust Limiter", null, "On", "Off", "On", "Off", thruster_and_grid_tagger.is_thrust_limiter_on, thruster_and_grid_tagger.set_thrust_limiter, thruster_and_grid_tagger.is_thrust_limiter_available);
                create_slider <IMyThrust>("ManualThrottle", "Manual throttle",
                                          thruster_and_grid_tagger.get_manual_throttle, thruster_and_grid_tagger.set_manual_throttle, thruster_and_grid_tagger.throttle_status,
                                          0.0f, 100.0f, 5.0f, "IncreaseThrottle", "DecreaseThrottle", "Increase Manual Throttle", "Decrease Manual Throttle");
                create_PB_property <float, IMyThrust>("BalancedLevel", thruster_and_grid_tagger.get_thrust_limit);
            }

            if (!_programmable_block_properties_set)
            {
                if (_sample_PB?.GetProperty("ShowInToolbarConfig") == null)
                {
                    return;
                }
                create_PB_property <Func <string, string, bool>, IMyProgrammableBlock>("ComputeOrbitElements", get_ship_elements_calculator);
                create_PB_property <Func <string, Vector3D, Vector3D, bool>, IMyProgrammableBlock>("ComputeOrbitElementsFromVectors", get_vector_elements_calculator);
                create_PB_property <Func <string>, IMyProgrammableBlock>("GetReferenceBodyName", get_reference_name_fetcher);
                create_PB_property <Action <Dictionary <string, Vector3D> >, IMyProgrammableBlock>("GetPrimaryVectors", get_vector_fetcher);
                create_PB_property <Action <Dictionary <string, double> >, IMyProgrammableBlock>("GetPrimaryScalars", get_scalar_fetcher);
                create_PB_property <Action <Dictionary <string, double> >, IMyProgrammableBlock>("GetDerivedElements", get_derived_fetcher);
                create_PB_property <Action <double?, Dictionary <string, double> >, IMyProgrammableBlock>("GetPositionalElements", get_positional_fetcher);
                create_PB_property <Action <double, Dictionary <string, Vector3D> >, IMyProgrammableBlock>("GetStateVectors", get_state_vector_fetcher);

                create_PB_property <Func <double, double, double>, IMyProgrammableBlock>("ConvertTrueAnomalyToMean", get_true_to_mean_converter);
                create_PB_property <Func <double, double, double>, IMyProgrammableBlock>("ConvertMeanAnomalyToTrue", get_mean_to_true_converter);
                create_PB_property <Func <double, double, Vector3D>, IMyProgrammableBlock>("ComputeOrbitNormal", get_orbit_normal_calculator);
                create_PB_property <Func <Vector3D, Vector3D, Vector3D, double, double>, IMyProgrammableBlock>("ConvertRadialToTtrueAnomaly", get_radius_to_anomaly_converter);
                create_PB_property <Func <double, double, double, double, double, double, ValueTuple <double, double>?>, IMyProgrammableBlock>
                    ("ComputeOrbitIntersections", get_intersection_calculator);
                _programmable_block_properties_set = true;
                _sample_PB = null;
            }

            _setup_complete = _ship_controller_controls_set && _thruster_controls_set && _programmable_block_properties_set && _entity_events_set &&
                              screen_info.settings_loaded && sync_helper.network_handlers_registered;
        }