IEnumerator buttonPromptEnumerable(string button) { while (Input.anyKey == false || Input.GetMouseButton(0)) { yield return(null); } Debug.Log("Any Key pressed"); KeyCode curKey = getCurrentlyPressedKey(); if (curKey == KeyCode.None) { yield break; } Debug.Log("Key is: " + curKey.ToString()); switch (button) { case "P1Up": InputDefinitions.ChangeP1Up(curKey); break; case "P1Down": InputDefinitions.ChangeP1Down(curKey); break; case "P2Up": InputDefinitions.ChangeP2Up(curKey); break; case "P2Down": InputDefinitions.ChangeP2Down(curKey); break; } }
public virtual Button CheckClick(Point point, InputDefinitions input, StyleSheet[] sheets = null) { foreach (IComponent component in components) { if (component.bounds.Contains(point)) { if (component is Button) { } if (component is PageButton) { ((PageButton)component).Click(Game, sheets[((PageButton)component).PageOrder], this); return((Button)component); } else if (component is InputButton) { ((InputButton)component).Click(input, Game); return((Button)component); } else if (component is Button) { ((Button)component).Click(Game); return((Button)component); } } } return(null); }
public GameInput() { AssembleValidKeyCodes(); defs = new InputDefinitions(); defs.Init(); }
public bool IsEqual(StepTemplate stepTemplate, out BaseException exception) { if (stepTemplate.InputDefinitions.Count() != InputDefinitions.Count()) { exception = new ConflictingStepTemplateException("Found existing template with conflicting inputs, the number of inputs is different."); return(false); } if (stepTemplate.AllowDynamicInputs != AllowDynamicInputs) { exception = new ConflictingStepTemplateException("Found existing template with conflicting settings, Allow dynamics input is different."); return(false); } if ((stepTemplate.OutputDefinitions == null && OutputDefinitions != null) || (stepTemplate.OutputDefinitions != null && OutputDefinitions == null) || (stepTemplate.OutputDefinitions.Count() != OutputDefinitions.Count())) { exception = new ConflictingStepTemplateException("Found existing template with conflicting inputs, the number of inputs is different."); return(false); } foreach (var input in stepTemplate.InputDefinitions) { var foundInputs = InputDefinitions.Where(i => i.Key == input.Key); if (foundInputs.Count() == 0) { exception = new ConflictingStepTemplateException("Missing input " + input.Key + " in existing template."); return(false); } if (foundInputs.First().Value.Type != input.Value.Type) { exception = new ConflictingStepTemplateException("Non matching type for input " + input.Key + "."); return(false); } } foreach (var output in stepTemplate.OutputDefinitions) { var foundOutputs = OutputDefinitions.Where(i => i.Key == output.Key); if (foundOutputs.Count() == 0) { exception = new ConflictingStepTemplateException("Missing output " + output.Key + " in existing template."); return(false); } if (foundOutputs.First().Value.Type != output.Value.Type) { exception = new ConflictingStepTemplateException("Non matching type for output " + output.Key + "."); return(false); } } exception = null; return(true); }
public Step GenerateStep(string stepTemplateId, string name = "", string description = "", Dictionary <string, object> inputs = null, List <string> stepTestTemplateIds = null, int?stepRefId = null, Guid?sequenceId = null) { var newStep = new Step(); newStep.Name = name; newStep.Description = description; newStep.StepTemplateId = stepTemplateId; newStep.Inputs = new Dictionary <string, object>(); if (inputs != null) { if (inputs.Count() > InputDefinitions.Count() && !AllowDynamicInputs) { throw new InvalidStepInputException("Too many step inputs for step template " + Id + " were given, expected " + InputDefinitions.Count() + " got " + inputs.Count()); } if (InputDefinitions.Count() > inputs.Count()) { string missingInputs = ""; foreach (var id in InputDefinitions) { if (!inputs.Select(i => i.Key).Contains(id.Key)) { missingInputs += id.Key + " "; } } throw new InvalidStepInputException("Missing step inputs for step template " + Id + ", expected " + InputDefinitions.Count() + " got " + inputs.Count() + " missing "); } foreach (var input in inputs) { var foundTemplate = InputDefinitions.Where(tp => tp.Key == input.Key).FirstOrDefault(); if (!IsStepInputValid(input)) { throw new InvalidStepInputException("Step input " + input.Key + " is not found in the template definition."); } if (AllowDynamicInputs && !InputDefinitions.ContainsKey(input.Key)) { newStep.Inputs.Add(input.Key, input.Value); } else { newStep.Inputs.Add(input.Key, input.Value); } } } else if (inputs == null && InputDefinitions.Count() > 0) { throw new InvalidStepInputException("No inputs were specified however step template " + Id + " has " + InputDefinitions.Count() + " inputs."); } newStep.Tests = stepTestTemplateIds; newStep.StepRefId = stepRefId; newStep.SequenceId = sequenceId; newStep.CreatedOn = DateTime.UtcNow; return(newStep); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. TutorialWorld tl = new TutorialWorld(Game, "Game"); CommandComponent cp = new CommandComponent(Game, tl); InputDefinitions input = InputDefinitions.CreateInput(Game); Camera cam = new Camera(Game, input, tl); // TODO: use this.Content to load your game content here }
public CommandProccesor(Game game, List <IUnit> startingUnits, WorldHandler wh, InputDefinitions input, CommandComponent command, Camera camera) : base(game) { this.cc = command; this.wh = wh; this.input = input; this.camera = camera; commands = new List <ICommand>(); buttons = new List <CommandButton>(); }
public Step GenerateStep(string stepTemplateId, string createdBy, string name = "", string description = "", Dictionary <string, object> inputs = null, List <string> stepTestTemplateIds = null, Guid?workflowId = null, string encryptionKey = "", Guid?executionTemplateId = null, Guid?executionScheduleId = null) { var verifiedInputs = new Dictionary <string, object>(); if (inputs != null) { if (inputs.Count() > InputDefinitions.Count() && !AllowDynamicInputs) { throw new InvalidStepInputException("Too many step inputs for step template " + Id + " were given, expected " + InputDefinitions.Count() + " got " + inputs.Count()); } if (InputDefinitions.Count() > inputs.Count()) { string missingInputs = ""; foreach (var id in InputDefinitions) { if (!inputs.Select(i => i.Key).Contains(id.Key)) { inputs.Add(id.Key, null); //missingInputs += id.Key + " "; } } //throw new InvalidStepInputException("Missing step inputs for step template " + Id + ", expected " + InputDefinitions.Count() + " got " + inputs.Count() + " missing "); } foreach (var input in inputs) { var foundTemplate = InputDefinitions.Where(tp => tp.Key == input.Key).FirstOrDefault(); if (!IsStepInputValid(input)) { throw new InvalidStepInputException("Step input " + input.Key + " is not found in the template definition."); } if ((AllowDynamicInputs && !InputDefinitions.ContainsKey(input.Key)) || InputDefinitions.ContainsKey(input.Key)) { if (InputDefinitions.ContainsKey(input.Key) && InputDefinitions[input.Key].Type == InputDataTypes.Secret && !InputDataUtility.IsInputReference(input, out _, out _)) { verifiedInputs.Add(input.Key.ToLower(), SecurityUtility.SymmetricallyEncrypt((string)input.Value, encryptionKey)); } else { verifiedInputs.Add(input.Key.ToLower(), input.Value); } } } } else if (inputs == null && InputDefinitions.Count() > 0) { throw new InvalidStepInputException("No inputs were specified however step template " + Id + " has " + InputDefinitions.Count() + " inputs."); } var newStep = new Step(Guid.NewGuid(), name, description, stepTemplateId, createdBy, verifiedInputs, encryptionKey, workflowId, executionTemplateId, executionScheduleId); return(newStep); }
public Overlay(Game game, InputDefinitions input, WorldHandler world, CommandProccesor command) : base(game) { cp = command; this.world = world; this.input = input; cp.overlay = this; ZeroVector = Vector2.Zero; currentCursorTexture = TextureValue.Cursor; tile = world.GetTile(input.InputPos); ClickTime = 0; }
public Camera(Game game, InputDefinitions input, WorldHandler worldHandler, Vector2 startPoint) : base(game) { Tile.Zoom = 3; MoveSpeed = 6.25f; this.position = startPoint; this.ViewPort = new Rectangle(position.ToPoint(), new Point(30, 16)); this.input = input; Dir = new Vector2(0, 0); this.world = worldHandler; bounds = new Rectangle(new Vector2(0, 0).ToPoint(), (world.GetSize()).ToPoint()); Zero = Vector2.Zero; }
private bool IsStepInputValid(KeyValuePair <string, object> input) { try { var foundTemplate = InputDefinitions.Where(tp => tp.Key == input.Key).First(); if (!InputDefinitions.ContainsKey(input.Key) && !AllowDynamicInputs) { return(false); } return(true); } catch (Exception e) { return(false); } }
void Awake() { if (inputDefinitions == null) { DontDestroyOnLoad(gameObject); // Persistent between scenes inputDefinitions = this; // Additional initialisation P1Up = StringToKeyCode(PlayerPrefs.GetString("P1Up", "Q")); P1Down = StringToKeyCode(PlayerPrefs.GetString("P1Down", "A")); P2Up = StringToKeyCode(PlayerPrefs.GetString("P2Up", "O")); P2Down = StringToKeyCode(PlayerPrefs.GetString("P2Down", "L")); } else if (inputDefinitions != this) { Destroy(gameObject); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { base.LoadContent(); // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here mainMenuBackground = this.Content.Load <Texture2D>("MainMenu"); settingMenuBackground = this.Content.Load <Texture2D>("SettingsPage"); lostPage = this.Content.Load <Texture2D>("LossPage"); wonPage = this.Content.Load <Texture2D>("WinPage"); Cursor = this.Content.Load <Texture2D>("Cursor"); inputDef = InputDefinitions.CreateInput(this); MouseKeyboard keyboard = new MouseKeyboard(this); mK = new MouseKeyboard(this); canv = new Canvas(this); ss = new StyleSheet(); canv.Initialize(); if (!File.Exists("MainMenu.ss")) { GenerateStyleSheet("MainMenu"); } if (!File.Exists("SettingsPage.ss")) { GenerateStyleSheet("SettingsPage"); } if (!File.Exists("EndScreen.ss")) { GenerateStyleSheet("EndScreen"); } LoadCanvas("MainMenu.ss", 0); currentPage = "Main Menu"; PlayedGame = new ActualGame(this, "World"); }
/// <summary> /// Handles updates to the control preferences /// </summary> /// <param name="key">The new key to assign to the controls</param> /// <param name="control">The control being modified</param> public void UpdateControls(KeyCode key, string control) { InputDefinitions newControls = Controls; switch (control) { case "Ship_Forward": newControls.Ship_Forward = key; break; case "Ship_Reverse": newControls.Ship_Reverse = key; break; case "Ship_CW": newControls.Ship_CW = key; break; case "Ship_CCW": newControls.Ship_CCW = key; break; case "Ship_Fire": newControls.Ship_Fire = key; break; case "Menu_Pause": newControls.Menu_Pause = key; break; case "Ship_Dampener": newControls.Ship_Dampener = key; break; } prefs.Controls = newControls; }
public override Button CheckClick(Point point, InputDefinitions input, StyleSheet[] sheets) { return(base.CheckClick(point, input)); }
private void SetUpGame() { WinValue = 0; if (world != null) { world.ResetWorld(Game); } //Create a new world else { world = new WorldHandler(Game, "TempWorld"); } //318,98 - Temp spawn point until I randomize it Vector2 startPoint = new Vector2(318, 98); collision = new CollisionHandler(Game, world); world.AddCollision(collision); //Probably could be moved to a save file to setup templates for start #region Resource Setup //Initialize the new wallet to start with....this can probably be moved to a file Wallet startingResources = new Wallet(new Dictionary <IResource, float>() { { new Wood(), 500 }, { new Steel(), 500 }, { new Money(), 500 }, { new Likes(), 500 }, { new Iron(), 500 }, { new Energy(), 500 } }); #endregion #region util setup if (newGame) { //creates a new input handler instance input = InputDefinitions.CreateInput(Game); cam = new Camera(Game, input, world, startPoint); } #endregion projectileManager = new ProjectileManager(Game, cam, collision); #region componenets //Game components cc = new CommandComponent(Game, startingResources, world); process = new CommandProccesor(Game, new List <IUnit>(), world, input, cc, cam); overlay = new Overlay(Game, input, world, process); #endregion //Wave handler wave = new WaveManager(Game, world, projectileManager); //Adds a unit to start #region startUnits List <IUnit> units = new List <IUnit>(); units.Add(new Civilian("Base unit", new Vector2(1, 1), 100, 100, startPoint + new Vector2(4, 5), BaseUnitState.Idle, TextureValue.Civilian, TextureValue.Civilian, 1, projectileManager, cc.TeamStats).AddQueueables()); world.AddMob(units[0]); ((BasicUnit)units[0]).SetTeam(1); #endregion #region buildingPlacement #region Allies //Center Center center = new Center(TextureValue.Center, startPoint, TextureValue.CenterIcon, projectileManager, cc.TeamStats); center.AddQueueables(); center.SetTeam(cc.Team); center.SetSpawn(startPoint + center.Size + new Vector2(0, 1)); center.PlacedTile(GraphicsDevice); world.Place(center, startPoint); center.Subscribe((IBuildingObserver)cc); center.Damage(-5000); #endregion #region Enemies //Portal startPoint = new Vector2(82, 190); for (int i = 0; i < 3; i++) { Portal portal = new Portal(TextureValue.Portal, startPoint, TextureValue.Portal, projectileManager, wave.TeamStats, wave); startPoint += new Vector2(i * 8, 0); portal.SetTeam(cc.Team + 1); portal.SetSpawn(startPoint + portal.Size + new Vector2(0, 1)); portal.PlacedTile(GraphicsDevice); world.Place(portal, startPoint); portal.Subscribe((IBuildingObserver)cc); } #endregion #endregion CommandButton exit = new CommandButton(GraphicsDevice, new ExitGameCommand(), new Vector2(GraphicsDevice.Viewport.Width - 50, 0), TextureValue.None, new Point(50, 30)); exit.Scale = 1; exit.color = Color.SlateGray; exit.Text = "Exit"; exit.Draw(GraphicsDevice); overlay.AddComponent(exit); //Initializer overlay.Initialize(); newGame = false; }
public Camera(Game game, InputDefinitions input, WorldHandler worldHandler) : this(game, input, worldHandler, new Vector2(0, 0)) { }
public void LoadInputs() { FileStream fs; if (!ConfigFileExists()) { fs = File.Create(configsPath); fs.Close(); return; } else { fs = File.OpenRead(configsPath); } InputDefinitions c = new InputDefinitions(); XmlSerializer xml = new XmlSerializer(typeof(InputDefinitions)); using (TextReader reader = new StreamReader(fs)) { c = (InputDefinitions)xml.Deserialize(reader); } defs.InputDefs.Clear(); defs.InputDefs.AddRange(c.InputDefs); /*foreach (InputDef def in c.InputDefs) { defs[def.InputName] = def.InputKey; }*/ c = null; }
public InputButton(GraphicsDevice gd, Vector2 position, Point size, Color color, string text, Game game, Controls control, InputDefinitions input) : this(position, size, color, text, game) { this.control = control; }
public void SaveInputs() { FileStream fs; if (!ConfigFileExists()) { fs = File.Create(configsPath); } else { File.WriteAllText(configsPath, string.Empty); fs = File.OpenWrite(configsPath); } InputDefinitions c = new InputDefinitions(); c.InputDefs = new List<InputDef>(defs.InputDefs); XmlSerializer xml = new XmlSerializer(typeof(InputDefinitions)); using (TextWriter writer = new StreamWriter(fs)) { xml.Serialize(writer, c); } c = null; }
/// <summary> /// Sets up the preferences when Awake is called /// </summary> private void Awake() { #region Preferences // Define prefs prefs = new PlayerPreferences(); // Enter the preferences directory string prefsPath = Application.persistentDataPath; DirectoryInfo prefsDir = new DirectoryInfo(prefsPath); FileInfo[] prefsFiles = prefsDir.GetFiles("*.*", SearchOption.AllDirectories); bool prefsFound = false; // Find the preferences file foreach (FileInfo file in prefsFiles) { if (file.Name.Contains("preferences.xml")) { prefsFound = true; } } // If found, read from it if (prefsFound) { prefs = ReadFromPreferences(); } // Otherwise, create one else { // Define controls InputDefinitions input = new InputDefinitions { Menu_Pause = KeyCode.Escape, Ship_Forward = KeyCode.W, Ship_Reverse = KeyCode.S, Ship_CW = KeyCode.D, Ship_CCW = KeyCode.A, Ship_Fire = KeyCode.Space, Ship_Dampener = KeyCode.Q }; prefs.Controls = input; // Define graphics GraphicSettings graphics = new GraphicSettings { AntiAliasingMode = 0, PostProcessingPreset = 0, TargetFramerate = 60, UseVsync = true }; prefs.Graphics = graphics; // Define misc settings prefs.CurrentTheme = 0; prefs.TargetLockForce = 0.5f; prefs.DoDamageFlashing = false; WriteToPreferences(); } #endregion #region Graphics // Post processing for (int i = 0; i < ppPresets.Length; i++) { if (prefs.Graphics.PostProcessingPreset == i) { ppPresets[i].SetActive(true); } else { ppPresets[i].SetActive(false); } } camLayer.antialiasingMode = (PostProcessLayer.Antialiasing)prefs.Graphics.AntiAliasingMode; // Framerate if (prefs.Graphics.UseVsync) { QualitySettings.vSyncCount = 1; } else { QualitySettings.vSyncCount = 0; } Application.targetFrameRate = prefs.Graphics.TargetFramerate; #endregion #region Themes Themes = new List <Theme>(); // Enter the themes directory string path = Application.streamingAssetsPath + "/Themes"; DirectoryInfo directoryInfo = new DirectoryInfo(path); FileInfo[] allFiles = null; if (directoryInfo.Exists) { allFiles = directoryInfo.GetFiles("*.*", SearchOption.AllDirectories); // Read all the themes in the directory foreach (FileInfo file in allFiles) { if (file.Extension.Contains("theme")) { Themes.Add(ThemeReader.GetTheme(file)); } } // If there are none, create a default theme if (Themes.Count == 0) { Themes.Add(new Theme("Default")); } } else { directoryInfo.Create(); Themes.Add(new Theme("Default")); } #endregion }
public void Click(InputDefinitions input, Game game) { this.input = input; this.Click(game); }