/******************************************** ****** METHODES SPECIFIQUES AU WIDGET ****** ********************************************/ /// <summary> /// base menu constructor /// </summary> public TeamSelection() : base(new Rect(0, 0, Screen.width * DIM_WIDTH, Screen.height * DIM_HEIGHT)) { this.Background = BACKGROUND_COLOR; team_selector = new Selector(new Rect(this.area.width * (1 - DIM_SELECTOR_WIDTH) / 2, (this.area.height - 2 * DIM_SELECTOR_HEIGHT) / 3, DIM_SELECTOR_WIDTH * this.area.width, DIM_SELECTOR_HEIGHT), (int)(DIM_SELECTOR_DROP_HEIGHT_1 * this.area.height), this); unit_selector = new Selector(new Rect(this.area.width * (1 - DIM_SELECTOR_WIDTH) / 2, (this.area.height - 2 * DIM_SELECTOR_HEIGHT) * 2 / 3 + DIM_SELECTOR_HEIGHT, DIM_SELECTOR_WIDTH * this.area.width, DIM_SELECTOR_HEIGHT), (int)(DIM_SELECTOR_DROP_HEIGHT_2 * this.area.height), this); this.AddChild(unit_selector); this.AddChild(team_selector); team_selector.SelectItem += OnSelectItem; team_selector.DeployOrTuck += OnDeployOrTuck; unit_selector.SelectItem += OnSelectItem; XMLInterpreter interpreter = new XMLInterpreter(); // A SUPPRIMER team_selector.Elements = interpreter.allTeamsInXmlFiles(Constants.teamsDirectory).ToArray(); List <string> units = new List <string> (); foreach (BotType t in BotType.GetValues(typeof(BotType))) { units.Add(BotTypes.WarType(t)); } unit_selector.Elements = units.ToArray(); }
/// <summary> /// Brand new Editor with the specified teamName and unitName. /// </summary> /// <param name="teamName">Team name.</param> /// <param name="unitName">Unit name.</param> public void Set(string teamName, string unitName) { this.RemoveAllChilds(); cancel_stack = new Stack <List <Instruction> >(); XMLInterpreter interpreter = new XMLInterpreter(); List <Instruction> instructions = interpreter.xmlToUnitBehavior(teamName, Constants.teamsDirectory, unitName); this.Set(instructions); }
/// <summary> /// Create a new team. /// </summary> /// <param name="teamName">The name of the new team.</param> public static void CreateNewTeam(string teamName) { XMLInterpreter xml = new XMLInterpreter(); xml.generateEmptyFile(teamName, Constants.teamsDirectory); MainLayout.Actual.Team_selection.Reload(); MainLayout.Actual.Team_selection.Team_selector.Selection = teamName; MainLayout.Actual.Editor.Set(teamName, WarBots.BotType.WarBase.ToString()); MainLayout.Actual.Primitives_collection = new PrimitivesCollection(MainLayout.Actual.Team_selection.Unit_selector.Selection); MainLayout.Actual.DisplayUI = false; GameObject.Find("InputField_Team").GetComponent <UnityEngine.UI.InputField>().text = ""; }
/******************************************** ****** METHODES SPECIFIQUES AU WIDGET ****** ********************************************/ /// <summary> /// Initializes a new instance of the <see cref="WarBotEngine.Editeur.BehaviorEditor"/> class. /// </summary> /// <param name="teamName">Team name.</param> /// <param name="unitName">Unit name.</param> public BehaviorEditor(string teamName, string unitName) : base(new Rect(Screen.width * TeamSelection.DIM_WIDTH, 0, Screen.width * (1 - TeamSelection.DIM_WIDTH), Screen.height)) { BehaviorEditor.actual = this; if (teamName != "") { XMLInterpreter interpreter = new XMLInterpreter(); List <Instruction> instructions = interpreter.xmlToUnitBehavior(teamName, Constants.teamsDirectory, unitName); this.Set(instructions); cancel_stack = new Stack <List <Instruction> >(); cancel_stack.Push(instructions); } }
/// <summary> /// Save instruction list for the unit of this team /// </summary> /// <param name="push_cancel">Indicate if we have to save the instructions in the stack</param> public void Save(bool push_cancel = true) { Maj(); XMLInterpreter interpreter = new XMLInterpreter(); List <Instruction> instructions = this.behavior(); interpreter.behaviorToXml(MainLayout.Actual.Team_selection.Team_selector.Selection, Constants.teamsDirectory, MainLayout.Actual.Team_selection.Unit_selector.Selection, instructions); if (push_cancel) { List <Instruction> copy = new List <Instruction>(); foreach (Instruction ins in instructions) { copy.Add(ins.Clone()); } cancel_stack.Push(copy); } }
/// <summary> /// Reload this instance. /// </summary> public void Reload() { XMLInterpreter interpreter = new XMLInterpreter(); team_selector.Elements = interpreter.allTeamsInXmlFiles(Constants.teamsDirectory).ToArray(); List <string> units = new List <string>(); foreach (BotType t in BotType.GetValues(typeof(BotType))) { units.Add(BotTypes.WarType(t)); } unit_selector.Elements = units.ToArray(); if (team_selector.Elements.Length > 0) { GameObject.Find("Button_Return").GetComponent <UnityEngine.UI.Button>().interactable = true; } }