/// <summary> /// Handles the selection of an entry in one of the selection wheels /// </summary> private void HandlePropertySelection(PropertyWheelEntryBase entry) { var propertyEntry = entry as PropertyWheelEntry; bool clicked = BvBinds.Select.IsReleased && !activeWheel.IsMousedOver || SharedBinds.LeftButton.IsReleased && activeWheel.IsMousedOver; if (clicked || ( propertyEntry?.BlockMember is IBlockTextMember && BindManager.IsChatOpen && MyAPIGateway.Input.IsNewGameControlPressed(MyStringId.Get("CHAT_SCREEN")) )) { if (entry is PropertyWheelShortcutEntry) { var shortcut = entry as PropertyWheelShortcutEntry; shortcut.ShortcutAction(); } else if (propertyEntry.BlockMember != null && entry.Enabled) { if (propertyEntry.BlockMember is IBlockAction) { var blockAction = propertyEntry.BlockMember as IBlockAction; blockAction.Action(); } else if (entry != activeWheel.Selection) { wheelBody.OpenBlockMemberWidget(propertyEntry.BlockMember); MenuState = QuickActionMenuState.WidgetControl; activeWheel.SetSelectionAt(activeWheel.HighlightIndex); } } } }
/// <summary> /// Heuristics used to infer blueprint usage /// </summary> private void UpdateBpInputMonitoring() { bool canBp = MyAPIGateway.Gui.GetCurrentScreen == MyTerminalPageEnum.None && !BindManager.IsChatOpen && !MyAPIGateway.Gui.IsCursorVisible; if (!isBpListOpen) { if (!isPlayerBlueprinting) { if (canBp && (SharedBinds.Paste.IsNewPressed || SharedBinds.Copy.IsNewPressed)) { isPlayerBlueprinting = true; } } else { if (!canBp || SharedBinds.LeftButton.IsNewPressed || SharedBinds.Escape.IsNewPressed || MyAPIGateway.Input.IsNewGameControlPressed(MyStringId.Get("SLOT0"))) { isPlayerBlueprinting = false; } } } if (!isBpListOpen) { if (canBp && BvBinds.OpenBpList.IsNewPressed) { isBpListOpen = true; } } else if (bpMenuTick > 30) { if (MyAPIGateway.Gui.GetCurrentScreen != MyTerminalPageEnum.None || !MyAPIGateway.Gui.IsCursorVisible || BindManager.IsChatOpen || SharedBinds.Escape.IsNewPressed) { isBpListOpen = false; isPlayerBlueprinting = !SharedBinds.Escape.IsNewPressed; } } if (!isBpListOpen) { bpMenuTick = 0; } else { bpMenuTick++; } if (BvBinds.Blueprint.IsNewPressed || isBpListOpen) { bpTick = 0; } else { bpTick++; } }
public static string GetResource(string stringId, params object[] args) { if (args.Length == 0) { return(MyStringId.Get(stringId).GetString()); } return(MyStringId.Get(stringId).GetStringFormat(args)); }
protected override void HandleInput(Vector2 cursorPos) { base.HandleInput(cursorPos); if (BindManager.IsChatOpen && !textField.InputOpen && MyAPIGateway.Input.IsNewGameControlPressed(MyStringId.Get("CHAT_SCREEN"))) { textField.TextBoard.SetText(textValueMember.Value); textField.OpenInput(); textField.MouseInput.GetInputFocus(); } if (!BindManager.IsChatOpen && textField.InputOpen && SharedBinds.Enter.IsNewPressed) { Confirm(); } }
private void TakeManipulatedItem() { if (State == MyManipulationTool.MyState.HOLD && Owner != null) { var inventoryAggregate = Owner.Components.Get <MyInventoryBase>() as MyInventoryAggregate; if (inventoryAggregate == null) { return; } var inventory = inventoryAggregate.GetInventory(MyStringId.Get("Inventory")) as MyInventory; if (ManipulatedEntity != null && inventory != null) { inventory.AddEntity(ManipulatedEntity, false); } } }
private bool CallScriptInternal(string message) { Assembly ass; if (IlCompiler.Buffer.Length > 0) { if (IlCompiler.Compile(new string[] { IlCompiler.Buffer.ToString() }, out ass, true)) { var retval = ass.GetType("wrapclass").GetMethod("run").Invoke(null, null); if (!string.IsNullOrEmpty(message)) { Sandbox.Game.Gui.MyHud.Chat.ShowMessage("returned", retval.ToString()); } return(true); IlCompiler.Buffer.Clear(); } else { IlCompiler.Buffer.Clear(); return(false); } } var parts = message.Split(Separators, StringSplitOptions.RemoveEmptyEntries); if (parts.Length < 3) { MyAPIGateway.Utilities.ShowNotification("Not enought parameters for script please provide following paramaters : Sriptname Classname MethodName", 5000); return(false); } if (!Scripts.ContainsKey(MyStringId.TryGet(parts[1]))) { string availableScripts = ""; foreach (var scriptName in Scripts) { availableScripts += scriptName.Key + "\n"; } MyAPIGateway.Utilities.ShowMissionScreen("Script not found", "", "Available scripts:", availableScripts); return(false); } ass = Scripts[MyStringId.Get(parts[1])]; var type = ass.GetType(parts[2]); if (type == null) { string availableScripts = ""; var types = ass.GetTypes(); foreach (var scriptType in types) { availableScripts += scriptType.FullName + "\n"; } MyAPIGateway.Utilities.ShowMissionScreen("Class not found", "", "Available classes:", availableScripts); return(false); } var method = type.GetMethod(parts[3]); if (method == null) { string availableScripts = ""; var types = type.GetMethods(BindingFlags.Static | BindingFlags.Public); foreach (var scriptType in types) { availableScripts += scriptType.Name + "\n"; } MyAPIGateway.Utilities.ShowMissionScreen("Method not found", "", "Available methods:", availableScripts); return(false); } var paramInfos = method.GetParameters(); List <object> parameters = new List <object>(); for (int i = 4; i < paramInfos.Length + 4 && i < parts.Length; i++) { var paramType = paramInfos[i - 4].ParameterType; var parseMet = paramType.GetMethod("TryParse", new Type[] { typeof(System.String), paramType.MakeByRefType() }); if (parseMet != null) { var output = Activator.CreateInstance(paramType); var args = new object[] { parts[i], output }; var par = parseMet.Invoke(null, args); parameters.Add(args[1]); } else { parameters.Add(parts[i]); } } if (paramInfos.Length == parameters.Count) { var retval = method.Invoke(null, parameters.ToArray()); if (retval != null) { Sandbox.Game.Gui.MyHud.Chat.ShowMessage("return value", retval.ToString()); } Sandbox.Game.Gui.MyHud.Chat.ShowMessage("Call", "Success"); return(true); } return(false); }
public override bool Invoke(ulong steamId, long playerId, string messageText) { #region test if (messageText.Equals("/test", StringComparison.InvariantCultureIgnoreCase)) { // for testing things. //MyAPIGateway.Utilities.ShowMessage("path", MyAPIGateway.Session.CurrentPath); //MyAPIGateway.Utilities.ShowMessage("size1", MyAPIGateway.Utilities.ConfigDedicated.SessionSettings.WorldSizeKm.ToString()); //MyAPIGateway.Utilities.ShowMessage("size2", MyAPIGateway.Session.GetWorld().Checkpoint.Settings.WorldSizeKm.ToString()); //IMyConfigDedicated config = null; //List<string> admins = null; try { //config = MyAPIGateway.Utilities.ConfigDedicated; //config.Load(); //config. } catch (Exception) { MyAPIGateway.Utilities.ShowMessage("Exception", "ConfigDedicated"); //ex.Message); } //if (config != null) { try { StringBuilder str = new StringBuilder(); var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players, p => p != null); str.AppendLine("Player Count {0}", players.Count); var identities = new List <IMyIdentity>(); MyAPIGateway.Players.GetAllIdentites(identities); str.AppendLine("Identities Count {0}", identities.Count); //str.AppendLine("Admin Count {0}", config.Administrators.Count); ////str.AppendLine("WorldName {0}", config.WorldName); ////str.AppendLine("WorldSize {0}", config.SessionSettings.WorldSizeKm); //str.AppendLine("Mods Count {0}", config.Mods.Count); ////str.AppendLine("IP {0}", config.IP)); //var clients = MyAPIGateway.Session.GetWorld().Checkpoint.Clients; //str.AppendLine("Client Count", clients == null ? "null" : string.Format("{0}", clients.Count)); //if (clients != null) //{ // var client = clients.FirstOrDefault(c => c.SteamId == MyAPIGateway.Multiplayer.MyId); // if (client != null) // { // str.AppendLine("IsAdmin {0}", client.IsAdmin); // } //} int index = 1; foreach (var identity in identities.OrderBy(i => i.DisplayName)) { var steamPlayer = players.FirstOrDefault(p => p.IdentityId == identity.IdentityId); if (steamPlayer != null) { str.AppendFormat("#{0} {1} {2} '{3}'\r\n", index++, steamPlayer?.PromoteLevel, steamPlayer?.SteamUserId, identity.DisplayName); } } MyAPIGateway.Utilities.ShowMissionScreen("test", null, null, str.ToString()); } catch (Exception ex) { MyAPIGateway.Utilities.ShowMissionScreen("Exception", "reading config", null, ex.ToString()); } } return(true); } #endregion #region test2 if (messageText.Equals("/test2", StringComparison.InvariantCultureIgnoreCase)) { // for testing things. var count = MyAPIGateway.Utilities.ConfigDedicated.Administrators.Count.ToString(CultureInfo.InvariantCulture); MyAPIGateway.Utilities.ShowMessage("Admins", string.Format("Count {0}", count)); MyAPIGateway.Utilities.ShowMessage("Players", string.Format("Count {0}", MyAPIGateway.Players.Count)); MyAPIGateway.Utilities.ShowMessage("MultiPlayers", string.Format("Count {0}", MyAPIGateway.Multiplayer.Players.Count)); return(true); } #endregion #region test3 if (messageText.Equals("/test3", StringComparison.InvariantCultureIgnoreCase)) { // for testing things. StringBuilder msg = new StringBuilder(); msg.AppendFormat("MyId {0}\r\n", MyAPIGateway.Multiplayer.MyId); msg.AppendFormat("SteamId {0}\r\n", MyAPIGateway.Session.Player.SteamUserId); msg.AppendFormat("PlayerID {0}\r\n", MyAPIGateway.Session.Player.IdentityId); msg.AppendFormat("IdentityId {0}\r\n", MyAPIGateway.Session.Player.IdentityId); msg.AppendFormat("MyName {0}\r\n", MyAPIGateway.Multiplayer.MyName); msg.AppendFormat("IsServer {0}\r\n", MyAPIGateway.Multiplayer.IsServer); msg.AppendFormat("ServerId {0}\r\n", MyAPIGateway.Multiplayer.ServerId); msg.AppendFormat("IsServerPlayer {0}\r\n", MyAPIGateway.Multiplayer.IsServerPlayer(MyAPIGateway.Session.Player.Client)); msg.AppendFormat("MultiplayerActive {0}\r\n", MyAPIGateway.Multiplayer.MultiplayerActive); msg.AppendFormat("OnlineMode {0}\r\n", MyAPIGateway.Session.OnlineMode); msg.AppendFormat("IsDedicated {0}\r\n", MyAPIGateway.Utilities.IsDedicated); //msg.AppendFormat("Culture {0}\r\n", MyTexts.Culture.IetfLanguageTag); msg.AppendFormat("Culture {0}\r\n", MyAPIGateway.Session.Config.Language); msg.AppendFormat("Culture {0}-{1}\r\n", MyTexts.Languages[MyAPIGateway.Session.Config.Language].CultureName, MyTexts.Languages[MyAPIGateway.Session.Config.Language].SubcultureName); var languageRu = MyTexts.Languages[MyLanguagesEnum.Russian]; MyTexts.Clear(); MyTexts.LoadTexts(Path.Combine(MyAPIGateway.Utilities.GamePaths.ContentPath, "Data", "Localization"), languageRu.CultureName, languageRu.SubcultureName); var yesRu = MyStringId.Get("DisplayName_Item_GoldIngot").GetString(); var russianGold = MyTexts.GetString(MyStringId.Get("DisplayName_Item_GoldIngot")); var languageEn = MyTexts.Languages[MyLanguagesEnum.English]; MyTexts.Clear(); MyTexts.LoadTexts(Path.Combine(MyAPIGateway.Utilities.GamePaths.ContentPath, "Data", "Localization"), languageEn.CultureName, languageRu.SubcultureName); var yesEn = MyStringId.Get("DisplayName_Item_GoldIngot").GetString(); msg.AppendFormat("Language Test Ru={0} En={1}\r\n", yesRu, yesEn); // CultureInfo has been set to InvariantCulture since 01.100.xxx // CurrentThread is overwritten in MyInitializer to assist in reading Exceptions (which is stupid as stack traces are all in code). So don't bother. //msg.AppendFormat("Culture '{0}' '{1}' '{2}'\r\n", CultureInfo.CurrentUICulture, CultureInfo.CurrentUICulture.IetfLanguageTag, CultureInfo.CurrentUICulture.Name); //msg.AppendFormat("Culture '{0}'\r\n", System.Threading.Thread.CurrentThread.CurrentUICulture.IetfLanguageTag); // not whitelisted anyhow. var ed = ((MyObjectBuilder_EnvironmentDefinition)MyDefinitionManager.Static.EnvironmentDefinition.GetObjectBuilder()); msg.AppendFormat("LargeShipMaxSpeed {0}\r\n", ed.LargeShipMaxSpeed); msg.AppendFormat("LargeShipMaxSpeed {0}\r\n", MyDefinitionManager.Static.EnvironmentDefinition.LargeShipMaxSpeed); msg.AppendFormat("SmallShipMaxSpeed {0}\r\n", MyDefinitionManager.Static.EnvironmentDefinition.SmallShipMaxSpeed); msg.AppendFormat("ViewDistance {0:N}m\r\n", MyAPIGateway.Session.SessionSettings.ViewDistance); msg.AppendFormat("LastSaveTime {0:o}\r\n", MyAPIGateway.Session.GetWorld().Checkpoint.LastSaveTime); MyAPIGateway.Utilities.ShowMissionScreen("test3", null, null, msg.ToString()); return(true); } #endregion #region test4 if (messageText.Equals("/test4", StringComparison.InvariantCultureIgnoreCase)) { var player = MyAPIGateway.Session.Player; if (player != null) { var pos = player.GetPosition(); MyAPIGateway.Utilities.ShowMessage("Player", "pos={0:N},{1:N},{2:N}", pos.X, pos.Y, pos.Z); } var cockpit = MyAPIGateway.Session.ControlledObject as IMyCockpit; var remoteControl = MyAPIGateway.Session.ControlledObject as IMyRemoteControl; var character = MyAPIGateway.Session.ControlledObject as IMyCharacter; //var character2 = MyAPIGateway.Session.ControlledObject as Sandbox.Game.Entities.Character.MyCharacter; var camera = MyAPIGateway.Session.ControlledObject as IMyCamera; var cameraBlock = MyAPIGateway.Session.ControlledObject as IMyCameraBlock; var cameraController = MyAPIGateway.Session.ControlledObject as IMyCameraController; //var spectator = MyAPIGateway.Session.ControlledObject as VRage.MySpectator; var spectator = MyAPIGateway.Session.Camera; if (cockpit != null) { MyAPIGateway.Utilities.ShowMessage("Control", "in cockpit."); } if (remoteControl != null) { MyAPIGateway.Utilities.ShowMessage("Control", "remoting."); } if (character != null) { MyAPIGateway.Utilities.ShowMessage("Control", "character."); } //if (character2 != null) //{ // //var pos = character2.PositionComp.GetPosition(); // Uses MyEntity which is not whitelisted. // MyAPIGateway.Utilities.ShowMessage("Control", "character2."); //} if (camera != null) { MyAPIGateway.Utilities.ShowMessage("Control", "camera."); } if (cameraBlock != null) { MyAPIGateway.Utilities.ShowMessage("Control", "camera block."); } if (cameraController != null) { //var pos = cameraController.GetViewMatrix().Translation; //MyAPIGateway.Utilities.ShowMessage("Control", "camera controller 1. FPV={0} POS={1:N},{2:N},{3:N}", cameraController.IsInFirstPersonView, pos.X, pos.Y, pos.Z); } if (MyAPIGateway.Session.ControlledObject.Entity is IMyCameraController) { MyAPIGateway.Utilities.ShowMessage("Control", "camera controller 2."); } //MyAPIGateway.Utilities.ShowMessage("Player", "Spectator1. {0}", VRage.Common.MySpectator.Static.IsInFirstPersonView); //System.Windows.Forms.Clipboard.SetText("hello"); if (spectator != null) { MyAPIGateway.Utilities.ShowMessage("Player", "Spectator1."); MyAPIGateway.Utilities.ShowMessage("Control", "camera controller 1. POS={0:N},{1:N},{2:N}", spectator.Position.X, spectator.Position.Y, spectator.Position.Z); } if (MyAPIGateway.Session.ControlledObject.Entity is MySpectator) { MyAPIGateway.Utilities.ShowMessage("Player", "Spectator2."); } //else //{ // MyAPIGateway.Utilities.ShowMessage("Player", "other."); //} MyAPIGateway.Utilities.ShowMessage("Controller", "ControlledEntity == ControlledObject : {0}", MyAPIGateway.Session.Player.Controller.ControlledEntity == MyAPIGateway.Session.ControlledObject); MyAPIGateway.Utilities.ShowMessage("Controller", "ControlledEntity == ControlledObject : {0}", MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity == MyAPIGateway.Session.ControlledObject.Entity); return(true); var playerMatrix = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.WorldMatrix; var playerPosition = playerMatrix.Translation + playerMatrix.Forward * 0.5f + playerMatrix.Up * 1.0f; MyAPIGateway.Utilities.ShowMessage("Pos", string.Format("x={0:N},y={1:N},z={2:N} x={3:N},y={4:N},z={5:N}", playerPosition.X, playerPosition.Y, playerPosition.Z, playerMatrix.Forward.X, playerMatrix.Forward.Y, playerMatrix.Forward.Z)); //MyAPIGateway.Utilities.ShowMessage("Up", string.Format("x={0:N},y={1:N},z={2:N}", playerMatrix.Up.X, playerMatrix.Up.Y, playerMatrix.Up.Z)); // TODO: need to properly establish control state and how to tell which state we are in. // Player - First person. // Player - thrid person. // Cockpit - First person. ControlledObject.GetHeadMatrix(true, true, true); // Cockpit - thrid person. ControlledObject.GetHeadMatrix(true, true, true); // Spectator freeview. CameraController.GetViewMatrix() but corrupted pos and vector. // Camera. CameraController.GetViewMatrix() //MyAPIGateway.Session.Player.PlayerCharacter.GetHeadMatrix(true, true, true); //MyAPIGateway.Session.CameraController.GetViewMatrix(); //MyAPIGateway.Session.ControlledObject.GetHeadMatrix(true, true, true); //Sandbox.ModAPI.IMyControllerInfo //? //Sandbox.ModAPI.IMyEntityController //Sandbox.ModAPI.Interfaces.IMyCameraController //Sandbox.ModAPI.Interfaces.IMyControllableEntity // The CameraController.GetViewMatrix appears warped at the moment. //var position = ((IMyEntity)MyAPIGateway.Session.CameraController).GetPosition(); //var camMatrix = MyAPIGateway.Session.CameraController.GetViewMatrix(); //var camPosition = camMatrix.Translation; //MyAPIGateway.Utilities.ShowMessage("Cam", string.Format("x={0:N},y={1:N},z={2:N} x={3:N},y={4:N},z={5:N}", camPosition.X, camPosition.Y, camPosition.Z, camMatrix.Forward.X, camMatrix.Forward.Y, camMatrix.Forward.Z)); //var worldMatrix = MyAPIGateway.Session.ControlledObject.Entity.WorldMatrix; var worldMatrix = MyAPIGateway.Session.ControlledObject.GetHeadMatrix(true, true, true); var position = worldMatrix.Translation; MyAPIGateway.Utilities.ShowMessage("Con", string.Format("x={0:N},y={1:N},z={2:N} x={3:N},y={4:N},z={5:N}", position.X, position.Y, position.Z, worldMatrix.Forward.X, worldMatrix.Forward.Y, worldMatrix.Forward.Z)); //MyAPIGateway.Session.Player.PlayerCharacter.MoveAndRotate(new Vector3(), new Vector2(0, 0), 90f); //MyAPIGateway.Session.Player.PlayerCharacter.MoveAndRotate(new Vector3(), new Vector2(3.14f, 0), 0f); //MyAPIGateway.Session.Player.PlayerCharacter.Up(); // thrust, walk player forward? //MyAPIGateway.Session.Player.PlayerCharacter.Entity.worldmatrix //var character = (MyObjectBuilder_Character)obj; return(true); } #endregion #region test5 if (messageText.Equals("/test5", StringComparison.InvariantCultureIgnoreCase)) { var worldMatrix = MyAPIGateway.Session.Player.Controller.ControlledEntity.GetHeadMatrix(true, true, true); // most accurate for player view. var position = worldMatrix.Translation + worldMatrix.Forward * 0.5f; var entites = new HashSet <IMyEntity>(); MyAPIGateway.Entities.GetEntities(entites, e => e != null); var list = new Dictionary <IMyEntity, double>(); foreach (var entity in entites) { var cubeGrid = entity as IMyCubeGrid; // check if the ray comes anywhere near the Grid before continuing. var ray = new RayD(position, worldMatrix.Forward); if (cubeGrid != null && ray.Intersects(entity.WorldAABB).HasValue) { var hit = cubeGrid.RayCastBlocks(position, worldMatrix.Forward * 1000); if (hit.HasValue) { var blocks = new List <IMySlimBlock>(); cubeGrid.GetBlocks(blocks, f => f.FatBlock != null); MyAPIGateway.Utilities.ShowMessage("AABB", string.Format("{0}", entity.WorldAABB)); // var block = blocks[0]; // //block.wo // var hsv = block.FatBlock.GetDiffuseColor(); // MyAPIGateway.Utilities.ShowMessage("Hsv", string.Format("{0},{1},{2} {3}", hsv.X, hsv.Y, hsv.Z, 1.45f)); // var c = VRageMath.ColorExtensions.HSVtoColor(hsv); // MyAPIGateway.Utilities.ShowMessage("Rgb", string.Format("{0},{1},{2}", c.R, c.G, c.B)); } } } return(true); } #endregion #region test6 if (messageText.Equals("/test6", StringComparison.InvariantCultureIgnoreCase)) { var entity = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity; //MyAPIGateway.Utilities.ShowMessage("AABB", string.Format("{0}", entity.WorldAABB)); //MyAPIGateway.Utilities.ShowMessage("Size", string.Format("{0}", entity.WorldAABB.Size())); //if (entity is IMyPlayer) // MyAPIGateway.Utilities.ShowMessage("IMyPlayer", "true"); //if (entity is IMyCubeBlock) // MyAPIGateway.Utilities.ShowMessage("IMyCubeBlock", "true"); // Ship //if (entity is IMyCubeGrid) // MyAPIGateway.Utilities.ShowMessage("IMyCubeGrid", "true"); //if (entity is IMyIdentity) // MyAPIGateway.Utilities.ShowMessage("IMyIdentity", "true"); //if (entity is IMyNetworkClient) // MyAPIGateway.Utilities.ShowMessage("IMyNetworkClient", "true"); //if (entity is IMyEntityController) // MyAPIGateway.Utilities.ShowMessage("IMyEntityController", "true"); //if (entity is IMyControllableEntity) // MyAPIGateway.Utilities.ShowMessage("IMyControllableEntity", "true"); // Ship and player //if (entity is IMyCameraController) // MyAPIGateway.Utilities.ShowMessage("IMyCameraController", "true"); // Everything //if (entity is IMyMultiplayer) // MyAPIGateway.Utilities.ShowMessage("IMyMultiplayer", "true"); if (entity is IMyCubeGrid) { entity = entity.Parent; } if (entity.Physics != null) { var pos = entity.GetPosition(); //var pos = Vector3.Zero; var m = Matrix.CreateWorld(pos, Vector3.Forward, Vector3.Up); entity.SetWorldMatrix(m); //MyAPIGateway.Multiplayer.SendEntitiesCreated(); //entity.LocalMatrix //entity.SetPosition(pos); //if (entity.SyncObject.UpdatesOnlyOnServer) // entity.SyncObject.UpdatePosition(); //MyAPIGateway.Utilities.ShowMessage("Physics=null", string.Format("{0}", phys == null)); MyAPIGateway.Utilities.ShowMessage("LinearVelocity", string.Format("{0}", entity.Physics.LinearVelocity)); //MyAPIGateway.Utilities.ShowMessage("Speed", string.Format("{0}", phys.Speed)); //MyAPIGateway.Utilities.ShowMessage("Mass", string.Format("{0}", phys.Mass)); //phys.AddForce(Sandbox.Engine.Physics.MyPhysicsForceType.ADD_BODY_FORCE_AND_BODY_TORQUE, Vector3.Forward, Vector3.Zero, Vector3.Zero); //phys.LinearVelocity = Vector3.Forward; //phys } //var vm = MyAPIGateway.Session.Player.Controller.ControlledEntity.GetHeadMatrix(true, true, true); // most accurate for player view. return(true); } #endregion #region test7 if (messageText.Equals("/test7", StringComparison.InvariantCultureIgnoreCase)) { var character = (MyObjectBuilder_Character)MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetObjectBuilder(); //var obj = MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity.GetObjectBuilder(); var obj = MyAPIGateway.Session.Player.Client as IMyEntity; MyAPIGateway.Utilities.ShowMessage("isNull", string.Format("{0}", obj == null)); //MyAPIGateway.Utilities.ShowMessage("Name", string.Format("{0}", obj.GetType().Name)); return(true); } #endregion #region test8 if (messageText.Equals("/test8A", StringComparison.InvariantCultureIgnoreCase)) { var gridBuilder = new MyObjectBuilder_CubeGrid() { PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene, GridSizeEnum = MyCubeSize.Large, IsStatic = true, LinearVelocity = new SerializableVector3(0, 0, 0), AngularVelocity = new SerializableVector3(0, 0, 0), PositionAndOrientation = new MyPositionAndOrientation(Vector3.Zero, Vector3.Forward, Vector3.Up), DisplayName = "test grid" }; MyObjectBuilder_CubeBlock cube = new MyObjectBuilder_CubeBlock(); cube.Min = new SerializableVector3I(0, 0, 0); cube.SubtypeName = "LargeBlockArmorBlock"; cube.ColorMaskHSV = new SerializableVector3(0, -1, 0); cube.EntityId = 0; cube.Owner = 0; cube.BlockOrientation = new SerializableBlockOrientation(Base6Directions.Direction.Forward, Base6Directions.Direction.Up); cube.ShareMode = MyOwnershipShareModeEnum.All; gridBuilder.CubeBlocks.Add(cube); // multiple grids... //var tempList = new List<MyObjectBuilder_EntityBase>(); //tempList.Add(gridBuilder); //MyAPIGateway.Entities.RemapObjectBuilderCollection(tempList); //tempList.ForEach(grid => MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(grid)); //MyAPIGateway.Multiplayer.SendEntitiesCreated(tempList); // Single grid. MyAPIGateway.Entities.RemapObjectBuilder(gridBuilder); MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(gridBuilder); MyAPIGateway.Multiplayer.SendEntitiesCreated(new List <MyObjectBuilder_EntityBase> { gridBuilder }); MyAPIGateway.Utilities.ShowMessage("OK", "fine"); return(true); } if (messageText.Equals("/test8B", StringComparison.InvariantCultureIgnoreCase)) { var entity = Support.FindLookAtEntity(MyAPIGateway.Session.ControlledObject, true, true, false, false, true, false) as IMyCubeGrid; if (entity == null) { return(false); } var gridBuilder = new MyObjectBuilder_CubeGrid() { PersistentFlags = MyPersistentEntityFlags2.CastShadows | MyPersistentEntityFlags2.InScene, GridSizeEnum = MyCubeSize.Large, IsStatic = true, LinearVelocity = new SerializableVector3(0, 0, 0), AngularVelocity = new SerializableVector3(0, 0, 0), PositionAndOrientation = new MyPositionAndOrientation(Vector3.Zero, Vector3.Forward, Vector3.Up), DisplayName = "test grid" }; MyObjectBuilder_CubeBlock cube = new MyObjectBuilder_CubeBlock(); cube.Min = new SerializableVector3I(0, 0, 0); cube.SubtypeName = "LargeBlockArmorBlock"; cube.ColorMaskHSV = new SerializableVector3(0, -1, 0); cube.ShareMode = MyOwnershipShareModeEnum.None; cube.Owner = 0; cube.BlockOrientation = new SerializableBlockOrientation(Base6Directions.Direction.Forward, Base6Directions.Direction.Up); cube.ShareMode = MyOwnershipShareModeEnum.All; gridBuilder.CubeBlocks.Add(cube); //var tempList = new List<MyObjectBuilder_EntityBase>(); //tempList.Add(gridBuilder); //MyAPIGateway.Entities.RemapObjectBuilderCollection(tempList); //no need for this on new object //var newEntity = (IMyCubeGrid)MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(tempList[0]); //MyAPIGateway.Multiplayer.SendEntitiesCreated(tempList); MyAPIGateway.Entities.RemapObjectBuilder(gridBuilder); var newEntity = (IMyCubeGrid)MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(gridBuilder); MyAPIGateway.Multiplayer.SendEntitiesCreated(new List <MyObjectBuilder_EntityBase> { gridBuilder }); entity.MergeGrid_MergeBlock(newEntity, new Vector3I(0, 1, 0)); MyAPIGateway.Utilities.ShowMessage("OK", "fine"); return(true); } #endregion #region test9 if (messageText.Equals("/test9", StringComparison.InvariantCultureIgnoreCase)) { var allEntites = new HashSet <IMyEntity>(); MyAPIGateway.Entities.GetEntities(allEntites, e => e != null); var sphere = new BoundingSphereD(Vector3D.Zero, 1000000f); var allSphereEntities = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere); MyAPIGateway.Utilities.ShowMessage("All Entities", String.Format("{0} == {1} ??", allEntites.Count, allSphereEntities.Count)); return(true); } #endregion #region test10 // attached grid count test. if (messageText.Equals("/test10", StringComparison.InvariantCultureIgnoreCase)) { var entity = Support.FindLookAtEntity(MyAPIGateway.Session.ControlledObject, true, false, false, false, false, false) as IMyCubeGrid; if (entity == null) { return(false); } var cubeGrid = (IMyCubeGrid)entity; var grids = cubeGrid.GetAttachedGrids(); MyAPIGateway.Utilities.ShowMessage("Attached Count", "{0}", grids.Count); foreach (var grid in grids) { MyAPIGateway.Utilities.ShowMessage("Attached", "Id:{0}", grid.EntityId); } // Terminal Groups.... var gridTerminalSystem = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(cubeGrid); var groups = new List <IMyBlockGroup>(); gridTerminalSystem.GetBlockGroups(groups); // may abide by the owner rules? //MyAPIGateway.Utilities.ShowMessage("BlockGroup Count", "{0}", groups.Count); //foreach (var group in groups) // MyAPIGateway.Utilities.ShowMessage("BlockGroup", "name:{0} blocks:{1} Id:{2}", group.Name, group.Blocks.Count, group.Blocks.Count > 0 ? group.Blocks[0].CubeGrid.EntityId : 0); //MyAPIGateway.Utilities.ShowMessage("Grid count", string.Format("{0} {1} {2}", cubeGrid.DisplayName, terminalsys.Blocks.Count, terminalsys.BlockGroups.Count)); return(true); } #endregion #region test11 if (messageText.Equals("/test11", StringComparison.InvariantCultureIgnoreCase)) { //var identities = new List<IMyIdentity>(); //MyAPIGateway.Players.GetAllIdentites(identities); //var ident = identities.FirstOrDefault(); //var bIdent = ((IMyEntity)ident).GetObjectBuilder(); //MyAPIGateway.Utilities.ShowMessage("IMyIdentity", string.Format("{0}", bIdent.GetType())); var players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players, p => p != null); var player = players.FirstOrDefault(); var cpnt = MyAPIGateway.Session.GetCheckpoint("null"); MyAPIGateway.Utilities.ShowMessage("cpnt", cpnt.Clients == null ? "null" : string.Format("{0}", cpnt.Clients.Count)); var c = MyAPIGateway.Session.GetWorld().Checkpoint.Clients; MyAPIGateway.Utilities.ShowMessage("Count", c == null ? "null" : string.Format("{0}", c.Count)); var nc = player.Client; MyAPIGateway.Utilities.ShowMessage("IMyNetworkClient", string.Format("{0}", nc.GetType())); //MyAPIGateway.Utilities.ShowMessage("IMyNetworkClient", string.Format("{0}", nc.GetType().BaseType)); //var bPlayer = ((IMyEntity)nc).GetObjectBuilder(); //MyAPIGateway.Utilities.ShowMessage("IMyPlayer", string.Format("{0}", bPlayer.GetType())); //var vm = MyAPIGateway.Session.Player.Controller.ControlledEntity.GetHeadMatrix(true, true, true); // most accurate for player view. return(true); } #endregion #region test12 if (messageText.Equals("/test12", StringComparison.InvariantCultureIgnoreCase)) { var entity = Support.FindLookAtEntity(MyAPIGateway.Session.ControlledObject, true, true, true, true, true, true); var resultList = new List <ITerminalAction>(); if (entity != null) { var displayName = entity.DisplayName; MyAPIGateway.Utilities.ShowMessage("ID", displayName); MyAPIGateway.Utilities.ShowMessage("Components", string.Format("{0}", entity.Components == null)); MyAPIGateway.Utilities.ShowMessage("Hierarchy", string.Format("{0}", entity.Hierarchy == null)); var cockpits = entity.FindWorkingCockpits(); var terminal = (IMyTerminalBlock)cockpits[0]; //cockpits[0] terminal.GetActions(resultList); MyAPIGateway.Utilities.ShowMessage("count", string.Format("{0}", resultList.Count)); } //Vector3D? FindFreePlace(Vector3D basePos, float radius, int maxTestCount = 20, int testsPerDistance = 5, float stepSize = 1f); //MyAPIGateway.Entities.FindFreePlace( //resultList.Clear(); //var myObject = Sandbox.Common.ObjectBuilders.Serializer.MyObjectBuilderSerializer.CreateNewObject(typeof(MyObjectBuilder_Reactor), "SmallBlockLargeGenerator"); //MyAPIGateway.TerminalActionsHelper.GetActions(typeof(MyObjectBuilder_Reactor), resultList); //MyAPIGateway.Utilities.ShowMessage("count", string.Format("{0}", resultList.Count)); //MyAPIGateway.TerminalActionsHelper.GetActions(typeof(IMyMotorStator), resultList); //MyAPIGateway.Utilities.ShowMessage("count", string.Format("{0}", resultList.Count)); //MyAPIGateway.TerminalActionsHelper.GetActions(typeof(IMyFunctionalBlock), resultList); //MyAPIGateway.Utilities.ShowMessage("count", string.Format("{0}", resultList.Count)); //MyAPIGateway.TerminalActionsHelper.GetActions(typeof(IMyTerminalBlock), resultList); //MyAPIGateway.Utilities.ShowMessage("count", string.Format("{0}", resultList.Count)); foreach (var a in resultList) { MyAPIGateway.Utilities.ShowMessage("item", string.Format("{0}={1}", a.Name, a.Id)); } return(true); } #endregion #region test13 if (messageText.Equals("/test13", StringComparison.InvariantCultureIgnoreCase)) { var entites = new HashSet <IMyEntity>(); MyAPIGateway.Entities.GetEntities(entites, e => e != null); //var physicalItem = MyDefinitionManager.Static.GetCubeBlockDefinition(new MyDefinitionId(typeof(MyObjectBuilder_SpaceBall), "SpaceBallLarge")); //physicalItem.Public = true; //MyDefinitionManager.Static.EnvironmentDefinition.SmallShipMaxSpeed = 2000; //MyDefinitionManager.Static.EnvironmentDefinition.LargeShipMaxSpeed = 2000; MyAPIGateway.Session.GetCheckpoint("null").GameMode = MyGameModeEnum.Creative; //MyAPIGateway.Session.GetCheckpoint("null").CargoShipsEnabled //MyAPIGateway.Session.GetCheckpoint("null").EnableCopyPaste = true; //MyAPIGateway.Utilities.ShowMessage("Sun Distance", string.Format("{0}", MyDefinitionManager.Static.EnvironmentDefinition.DistanceToSun)); //MyDefinitionManager.Static.EnvironmentDefinition.DirectionToSun = new Vector3(0, 1, 0); foreach (var entity in entites) { var cubeGrid = entity as IMyCubeGrid; if (cubeGrid != null) { var terminalsys = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid(cubeGrid); //MyAPIGateway.Utilities.ShowMessage("Grid count", string.Format("{0} {1} {2}", cubeGrid.DisplayName, terminalsys.Blocks.Count, terminalsys.BlockGroups.Count)); //var blocks = new List<Sandbox.ModAPI.IMySlimBlock>(); //cubeGrid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock == MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity); //MyAPIGateway.Utilities.ShowMessage("Pilot count", string.Format("{0}", blocks.Count)); //cubeGrid.GetBlocks(blocks); //foreach (var block in blocks) //{ // cubeGrid.ColorBlocks(block.Position, block.Position, VRageMath.Color.Gold.ToHsvColor()); //} } } return(true); } #endregion #region test14 if (messageText.Equals("/test14", StringComparison.InvariantCultureIgnoreCase)) { // Tag every floating object in player GPS. //var entites = new HashSet<IMyEntity>(); //MyAPIGateway.Entities.GetEntities(entites, e => (e is Sandbox.ModAPI.IMyFloatingObject)); //foreach (var entity in entites) //{ // var pos = entity.GetPosition(); // var gps = MyAPIGateway.Session.GPS.Create("Floating " + entity.DisplayName, "Some drifting junk", pos, true, false); // MyAPIGateway.Session.GPS.AddLocalGps(gps); //} //// Tag the Head position, and current position of the player. //var worldMatrix = MyAPIGateway.Session.Player.Controller.ControlledEntity.GetHeadMatrix(true, true, false, false); // dead center of player cross hairs. //var gps = MyAPIGateway.Session.GPS.Create("GetHeadMatrix", "", worldMatrix.Translation, true, false); ////MyAPIGateway.Session.GPS.AddLocalGps(gps); //gps = MyAPIGateway.Session.GPS.Create("GetPosition", "", MyAPIGateway.Session.Player.GetPosition(), true, false); ////MyAPIGateway.Session.GPS.AddLocalGps(gps); //var pos1 = worldMatrix.Translation; //var pos2 = MyAPIGateway.Session.Player.GetPosition(); //var pos = pos2 - pos1; //MyAPIGateway.Utilities.ShowMessage("Distance", "{0}", pos.Length()); var clients = MyAPIGateway.Session.GetCheckpoint("null").Clients; if (clients != null) { IMyPlayer player = MyAPIGateway.Session.Player; MyObjectBuilder_Client client = clients.FirstOrDefault(c => c.SteamId == player.SteamUserId && c.IsAdmin); if (client == null) { client = new MyObjectBuilder_Client() { IsAdmin = true, SteamId = player.SteamUserId, Name = player.DisplayName }; clients.Add(client); MyAPIGateway.Utilities.ShowMessage("Check", "added admin"); } else { MyAPIGateway.Utilities.ShowMessage("Check", "already admin"); } } return(true); } #endregion return(false); }
private void HandlePropertySelectionInput() { var selection = listBody[selectionIndex]; IBlockMember blockMember = selection.AssocMember; if (BvBinds.Select.IsReleased) { selection.PropertyOpen = !selection.PropertyOpen; } else if (BvBinds.Cancel.IsReleased) { selection.PropertyOpen = false; } else if (!selection.PropertyOpen && BindManager.IsChatOpen && MyAPIGateway.Input.IsNewGameControlPressed(MyStringId.Get("CHAT_SCREEN")) && blockMember is IBlockTextMember) { selection.PropertyOpen = true; } // Close text input on chat close or property deselect if ((!BindManager.IsChatOpen && selection.InputOpen) || (!selection.PropertyOpen && (selection.WaitingForChatInput || selection.InputOpen))) { // If no input was recieved, don't write anything if (!selection.WaitingForChatInput) { selection.SetValueText(selection.ValueText.ToString()); } selection.WaitingForChatInput = false; selection.PropertyOpen = false; selection.CloseInput(); } // Handle input for selected entry if ((selection.PropertyOpen || lastPropValue != null)) { if (blockMember is IBlockAction) { HandleActionInput(); } else if (blockMember is IBlockNumericValue <float> ) { HandleFloatInput(); } else if (blockMember is IBlockNumericValue <byte> ) { HandleColorInput(); } else if (blockMember is IBlockComboBox) { HandleComboInput(); } else if (blockMember is IBlockTextMember) { HandleTextInput(); } } if (selection.PropertyOpen) { MenuState |= QuickActionMenuState.PropertyOpen; highlightBox.Color = highlightFocusColor; } else { MenuState &= ~QuickActionMenuState.PropertyOpen; lastPropValue = null; highlightBox.Color = highlightColor; } }
private void AddEdgeParts(Dictionary <ModelId, Tuple <List <MyCubeInstanceData>, MyInstanceInfo> > instanceParts) { // This can be optimized in same way as cube parts are m_edgesToCompare.Clear(); float reduceEpsilon = 0.1f; MyCubeInstanceData inst = new MyCubeInstanceData(); inst.ResetBones(); inst.SetTextureOffset(new Vector2(0, 0)); foreach (var edgeInfoPair in m_edgeInfosNew) { if (edgeInfoPair.Value.Full /* || edgeInfoPair.Value.Empty*/) { continue; } bool isVisible = false; m_edgesToCompare.Clear(); //Find opposite normals and remove them Color color; int edgeModel; Base27Directions.Direction normal0, normal1; for (int i = 0; i < MyFourEdgeInfo.MaxInfoCount; i++) { if (edgeInfoPair.Value.GetNormalInfo(i, out color, out edgeModel, out normal0, out normal1)) { m_edgesToCompare.Add(new EdgeInfoNormal() { Normal = Base27Directions.GetVector(normal0), Color = color, EdgeModel = edgeModel }); m_edgesToCompare.Add(new EdgeInfoNormal() { Normal = Base27Directions.GetVector(normal1), Color = color, EdgeModel = edgeModel }); } } int c = 0; bool wasFour = m_edgesToCompare.Count == 4; int baseEdgeModel = m_edgesToCompare[0].EdgeModel; while (c < m_edgesToCompare.Count) { bool normalsRemoved = false; for (int c2 = c + 1; c2 < m_edgesToCompare.Count; c2++) { //opposite normals? if (MyUtils.IsZero(m_edgesToCompare[c].Normal + m_edgesToCompare[c2].Normal, reduceEpsilon)) { if (c > c2) { m_edgesToCompare.RemoveAt(c); m_edgesToCompare.RemoveAt(c2); } else { m_edgesToCompare.RemoveAt(c2); m_edgesToCompare.RemoveAt(c); } normalsRemoved = true; break; } } if (normalsRemoved) { continue; } c++; } Debug.Assert(m_edgesToCompare.Count != 1, "Alone edge with one normal cannot exist"); bool resultEdgesHaveDifferentColor = false; bool resultEdgesHaveDifferentArmorType = false; if (m_edgesToCompare.Count > 0) { Color baseColor = m_edgesToCompare[0].Color; foreach (var edge in m_edgesToCompare) { if (edge.Color != baseColor) { resultEdgesHaveDifferentColor = true; break; } } baseEdgeModel = m_edgesToCompare[0].EdgeModel; foreach (var edge in m_edgesToCompare) { resultEdgesHaveDifferentArmorType |= baseEdgeModel != edge.EdgeModel; } } if (m_edgesToCompare.Count == 1) { isVisible = false; } else if (resultEdgesHaveDifferentColor || resultEdgesHaveDifferentArmorType) { isVisible = true; } else if (m_edgesToCompare.Count > 2) { isVisible = true; } else if (m_edgesToCompare.Count == 0) { isVisible = wasFour; } else { Debug.Assert(m_edgesToCompare.Count == 2); //Check normals angle to get visibility float d = Vector3.Dot(m_edgesToCompare[0].Normal, m_edgesToCompare[1].Normal); Debug.Assert(d != -1, "We already removed opposite normals"); if (Math.Abs(d) > 0.85f) { //consider this without outline isVisible = false; } else { isVisible = true; } } if (isVisible) { var definition = MyDefinitionManager.Static.GetEdgesDefinition(new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_EdgesDefinition)), MyStringId.Get(baseEdgeModel))); var edgesSet = m_gridRenderComponent.GridSizeEnum == MyCubeSize.Large ? definition.Large : definition.Small; int modelId = 0; switch (edgeInfoPair.Value.EdgeType) { case MyCubeEdgeType.Horizontal: modelId = MyModel.GetId(edgesSet.Horisontal); break; case MyCubeEdgeType.Horizontal_Diagonal: modelId = MyModel.GetId(edgesSet.HorisontalDiagonal); break; case MyCubeEdgeType.Vertical: modelId = MyModel.GetId(edgesSet.Vertical); break; case MyCubeEdgeType.Vertical_Diagonal: modelId = MyModel.GetId(edgesSet.VerticalDiagonal); break; } //var modelId = resultEdgesHaveDifferentArmorType || baseHeavy ? // m_cubeHeavyEdgeModelIds[(int)Grid.GridSizeEnum][(int)edgeInfoPair.Value.EdgeType] : //m_cubeEdgeModelIds[(int)Grid.GridSizeEnum][(int)edgeInfoPair.Value.EdgeType]; inst.PackedOrthoMatrix = edgeInfoPair.Value.LocalOrthoMatrix; AddInstancePart(instanceParts, modelId, ref inst, 0, EdgeViewDistance); } } }
public static Type GetType(string typeId) { return(m_idToType[MyStringId.Get(typeId)]); }
protected override void HandleInput(Vector2 cursorPos) { if (BindManager.IsChatOpen && !sliderBox.IsTextInputOpen && MyAPIGateway.Input.IsNewGameControlPressed(MyStringId.Get("CHAT_SCREEN"))) { sliderBox.FieldText.SetText(textMember.ValueText); sliderBox.OpenTextInput(); } else if (!BindManager.IsChatOpen && sliderBox.IsTextInputOpen && SharedBinds.Enter.IsNewPressed) { Confirm(); } else if (!sliderBox.IsTextInputOpen) { floatMember.Value = GetSliderValue(); if (BvBinds.ScrollUp.IsPressed || BvBinds.ScrollDown.IsPressed) { double offset = Math.Min(floatMember.Increment, 1E5f); if ((floatMember.Flags & BlockPropertyFlags.CanUseMultipliers) > 0) { float mult = 1f; if (BvBinds.MultZ.IsPressed) { mult = BvConfig.Current.block.floatMult.Z; } else if (BvBinds.MultY.IsPressed) { mult = BvConfig.Current.block.floatMult.Y; } else if (BvBinds.MultXOrMouse.IsPressed) { mult = BvConfig.Current.block.floatMult.X; } if ((floatMember.Flags & BlockPropertyFlags.IsIntegral) == 0 || MathHelper.IsEqual((float)(mult * offset), (int)(mult * offset))) { offset *= mult; } } double value = floatMember.Value; if (double.IsInfinity(value)) { value = 0f; } if (BvBinds.ScrollUp.IsNewPressed || BvBinds.ScrollUp.IsPressedAndHeld) { SetSliderValue(value + offset); } else if (BvBinds.ScrollDown.IsNewPressed || BvBinds.ScrollDown.IsPressedAndHeld) { SetSliderValue(value - offset); } } } base.HandleInput(cursorPos); }