Beispiel #1
0
        public static void try_register_handlers()
        {
            if (!_UI_handlers_registered && MyAPIGateway.Utilities != null)
            {
                MyAPIGateway.Utilities.MessageEntered += command_handler;
                register_HUD_notification(THRUST_LOSS, "Thrust loss indication", false, false, set_min_thrust_loss_percentage);
                register_HUD_notification(VERTICAL_SPEED, "Vertical speed readout", true, false);
                register_HUD_notification(ORBITAL_ELEMENTS, "Orbit information", false, false, set_displayed_orbital_elements);
                register_HUD_notification(PLANE_ALIGNMENT, "Plane alignment aid", false, true, set_target_plane);
                _UI_handlers_registered = true;
            }

            if (!_local_settings_loaded && _UI_handlers_registered && sync_helper.network_handlers_registered && (local_player != null || sync_helper.running_on_server))
            {
                if (MyAPIGateway.Utilities.FileExistsInLocalStorage(settings_file, typeof(OSESettings)))
                {
                    OSESettings stored_settings = new OSESettings
                    {
                        AllowScriptsToInspectOrbitOfAnyShip = true,
                        DisableTorque         = false,
                        ShowThrustReduction   = true,
                        ShowVerticalSpeed     = false,
                        MinDisplayedReduction = 10
                    };

                    try
                    {
                        TextReader input = MyAPIGateway.Utilities.ReadFileInLocalStorage(settings_file, typeof(OSESettings));
                        stored_settings = MyAPIGateway.Utilities.SerializeFromXML <OSESettings>(input.ReadToEnd());
                        input.Close();
                    }
                    catch (Exception error)
                    {
                        MyLog.Default.WriteLine(error);
                    }

                    _HUD_messages[THRUST_LOSS].toggled_on    = stored_settings.ShowThrustReduction;
                    _HUD_messages[VERTICAL_SPEED].toggled_on = stored_settings.ShowVerticalSpeed;
                    _min_displayed_reduction = stored_settings.MinDisplayedReduction;
                    if (sync_helper.running_on_server)
                    {
                        scripts_can_inspect_orbit_of_any_ship = stored_settings.AllowScriptsToInspectOrbitOfAnyShip;
                        torque_disabled = stored_settings.DisableTorque;
                    }
                    else
                    {
                        _message[0] = 0;
                        sync_helper.encode_unsigned(local_player.SteamUserId, 8, _message, 1);
                        sync_helper.send_message_to_server(sync_helper.message_types.GLOBAL_MODES, null, _message, 9);
                    }
                }
                command_handler(null, ref _local_settings_loaded);
                _local_settings_loaded = true;
                if (sync_helper.running_on_server)
                {
                    _server_settings_loaded = true;
                }
            }
        }
Beispiel #2
0
        private static void command_handler(string message, ref bool dummy)
        {
            string command, parameter;

            if (message != null)
            {
                extract_command_and_parameter(message, out command, out parameter);
                if (command == ORBIT_REFERENCE)
                {
                    string new_reference = gravity_and_physics.set_current_reference(local_controller_grid, parameter);
                    if (new_reference != null)
                    {
                        MyAPIGateway.Utilities.ShowMessage("OSE", "Changed reference body to " + new_reference);
                    }
                    return;
                }
                if (!_HUD_messages.ContainsKey(command))
                {
                    return;
                }
                if (_parameter_handlers.ContainsKey(command) && parameter.Length > 0)
                {
                    _parameter_handlers[command](parameter);
                }
                else if (!_requires_natural_gravity.Contains(command) || gravity_and_physics.world_has_gravity)
                {
                    _HUD_messages[command].toggled_on = !_HUD_messages[command].toggled_on;
                    MyAPIGateway.Utilities.ShowMessage("OSE", string.Format("{0} is now {1}", _HUD_messages[command].screen_description, _HUD_messages[command].toggled_on ? "visible" : "hidden"));
                    if (command == PLANE_ALIGNMENT && !_HUD_messages[PLANE_ALIGNMENT].toggled_on)
                    {
                        gravity_and_physics.clear_target_plane(local_controller_grid);
                    }
                }
                else
                {
                    MyAPIGateway.Utilities.ShowMessage("OSE", string.Format("{0} cannot be toggled in zero-g worlds", _HUD_messages[command].screen_description));
                }
            }

            try
            {
                OSESettings stored_settings = new OSESettings
                {
                    AllowScriptsToInspectOrbitOfAnyShip = scripts_can_inspect_orbit_of_any_ship,
                    DisableTorque         = torque_disabled,
                    ShowThrustReduction   = _HUD_messages[THRUST_LOSS].toggled_on,
                    ShowVerticalSpeed     = _HUD_messages[VERTICAL_SPEED].toggled_on,
                    MinDisplayedReduction = _min_displayed_reduction
                };
                TextWriter output = MyAPIGateway.Utilities.WriteFileInLocalStorage(settings_file, typeof(OSESettings));
                output.Write(MyAPIGateway.Utilities.SerializeToXML(stored_settings));
                output.Close();
            }
            catch (Exception error)
            {
                MyLog.Default.WriteLine(error);
            }
        }