public override bool duplicateElement(DataControl dataControl) { if (!(dataControl is ActiveAreaDataControl)) { return(false); } ActiveArea newElement = (ActiveArea)(((ActiveArea)(dataControl.getContent())).Clone()); string id; int i = 1; do { id = getDefaultId(0) + i; i++; } while (!controller.isElementIdValid(id, false)); newElement.setId(id); activeAreasList.Add(newElement); activeAreasDataControlList.Add(new ActiveAreaDataControl(sceneDataControl, newElement)); controller.IdentifierSummary.addId <ActiveArea>(id); Controller.Instance.updateVarFlagSummary(); Controller.Instance.DataModified(); return(true); }
public override bool addElement(int type, string id) { bool elementAdded = false; if (type == Controller.ACTIVE_AREA) { // Show a dialog asking for the item id string itemId = id; if (id == null) { itemId = controller.showInputDialog(TC.get("Operation.AddItemTitle"), TC.get("Operation.AddItemMessage"), TC.get("Operation.AddItemDefaultValue")); } // If some value was typed and the identifier is valid if (itemId != null && controller.isElementIdValid(itemId)) { ActiveArea newActiveArea = new ActiveArea(itemId, true, 220, 220, 100, 100); activeAreasList.Add(newActiveArea); ActiveAreaDataControl newActiveAreaDataControl = new ActiveAreaDataControl(sceneDataControl, newActiveArea); activeAreasDataControlList.Add(newActiveAreaDataControl); controller.getIdentifierSummary().addActiveAreaId(itemId); //controller.dataModified( ); elementAdded = true; } } return(elementAdded); }
public void ClearArea(string areaTag, ActiveArea area, CLRScriptBase s) { if (area == null) { area = GetAreaByTag(areaTag); } if (InfestedAreas.Contains(area)) { InfestedAreas.Remove(area); } if (InfestedAreaLevels.ContainsKey(areaTag)) { InfestedAreaLevels.Remove(areaTag); } if (InfestedAreas.Count < 1) { QuestStore.LoadedInfestations.Remove(this); this.Delete(); } int count = 0; uint wp = s.GetLocalObject(area.Id, WayPointArrayName + count.ToString()); s.DeleteLocalString(area.Id, InfestNameVar); while (s.GetIsObjectValid(wp) != CLRScriptBase.FALSE) { int groupNum = 1; string oldGroup = s.GetLocalString(wp, InfestPrefix + GroupVarName + groupNum.ToString()); while (oldGroup != "") { s.SetLocalString(wp, GroupVarName + groupNum.ToString(), oldGroup); groupNum++; oldGroup = s.GetLocalString(wp, InfestPrefix + GroupVarName + groupNum.ToString()); } if (s.GetLocalInt(wp, "ACR_SPAWN_TYPE") != 0) { count++; wp = s.GetLocalObject(area.Id, WayPointArrayName + count.ToString()); continue; } int var = 1; string oldVar = s.GetLocalString(wp, InfestPrefix + SingleVarName + var.ToString()); while (oldVar != "") { s.SetLocalString(wp, SingleVarName + var.ToString(), oldVar); var++; oldVar = s.GetLocalString(wp, InfestPrefix + SingleVarName + var.ToString()); } var = 1; oldVar = s.GetLocalString(wp, InfestPrefix + RandomVarName + var.ToString()); while (oldVar != "") { s.SetLocalString(wp, RandomVarName + var.ToString(), oldVar); var++; oldVar = s.GetLocalString(wp, InfestPrefix + RandomVarName + var.ToString()); } count++; wp = s.GetLocalObject(area.Id, WayPointArrayName + count.ToString()); } }
public void ChangeArea(string areaName, string entryPoint = "deafult") { ActiveArea.HideArea(); ActiveArea = (IArea)Areas[areaName].Clone(); ActiveArea.ShowArea((IPlayer)Player.Clone(), entryPoint);//, Actions, entryPoint); }
public void OpenMenu(string menuName) { ActiveArea.Pause(); // Pause area ActiveMenuRoot = Menus[menuName]; // Open menu NavigateMenu(ActiveMenuRoot); }
public void CloseMenu() { ActiveMenu = null; ActiveMenuRoot = null; ActiveArea.Resume();// Resume area }
//- Operation methods public void Start(string startAreaName = "Start") { if (Player == null) { throw new InvalidOperationException("No player has yet been defined."); } ActiveArea = (IArea)Areas["Start"].Clone(); ActiveArea.ShowArea((IPlayer)Player.Clone());//, Actions); }
/** * Constructor. * * @param sceneDataControl * Parent scene controller * @param activeArea * Exit of the data control structure */ public ActiveAreaDataControl(SceneDataControl sceneDataControl, ActiveArea activeArea) { this.sceneDataControl = sceneDataControl; this.activeArea = activeArea; conditionsController = new ConditionsController(new Conditions()); this.influenceAreaDataControl = new InfluenceAreaDataControl(sceneDataControl, activeArea.getInfluenceArea(), this); descriptionsController = new DescriptionsController(activeArea.getDescriptions()); // Create subcontrollers actionsListDataControl = new ActionsListDataControl(activeArea.getActions(), this); }
public override bool undoTool() { rectangle.getPoints().Insert(oldIndex, oldPoint); if (iadc != null) { ActiveArea aa = (ActiveArea)rectangle; aa.setInfluenceArea(oldInfluenceArea); iadc.setInfluenceArea(oldInfluenceArea); } Controller.getInstance().reloadPanel(); return(true); }
public override bool redoTool() { rectangle.getPoints().Add(newPoint); if (iadc != null) { ActiveArea aa = (ActiveArea)rectangle; aa.setInfluenceArea(newInfluenceArea); iadc.setInfluenceArea(newInfluenceArea); } Controller.getInstance().updatePanel(); return(true); }
public static void InitializeInfestations(CLRScriptBase s) { // If we haven't even started caching areas, no point in starting here. if (ALFA.Shared.Modules.InfoStore.ActiveAreas == null) { s.DelayCommand(30.0f, delegate { InitializeInfestations(s); }); return; } // If we have areas, but haven't added any to ActiveAreas, we can't check on the areas. if (ALFA.Shared.Modules.InfoStore.ActiveAreas.Count == 0) { s.DelayCommand(30.0f, delegate { InitializeInfestations(s); }); return; } // If the first area we loop over hasn't mapped its area transitions, we can't be sure // that we have a complete list of areas. if (ALFA.Shared.Modules.InfoStore.ActiveAreas.First().Value.ExitTransitions == null) { s.DelayCommand(30.0f, delegate { InitializeInfestations(s); }); return; } // Once we know we at least have a complete list of areas, we can deserialize our infestations // and start infesting areas. foreach (string file in Directory.EnumerateFiles(QuestStore.InfestationStoreDirectory)) { using (FileStream stream = new FileStream(file, FileMode.Open)) { DataContractSerializer ser = new DataContractSerializer(typeof(Infestation)); Infestation ret = ser.ReadObject(stream) as Infestation; QuestStore.LoadedInfestations.Add(ret); ret.InfestedAreas = new List <ActiveArea>(); Dictionary <string, ActiveArea> areasToAdjust = new Dictionary <string, ActiveArea>(); foreach (string inf in ret.InfestedAreaLevels.Keys) { ActiveArea ar = GetAreaByTag(inf); if (ar != null) // Areas might be removed during a reset. { ret.InfestedAreas.Add(ar); areasToAdjust.Add(inf, ar); } } foreach (KeyValuePair <string, ActiveArea> area in areasToAdjust) { ret.InfestArea(area.Key, area.Value, ret.InfestedAreaLevels[area.Key], s); } } } }
public override bool doTool() { if (rectangle.isRectangular()) { return(false); } if (rectangle.getPoints().Contains(oldPoint)) { rectangle.getPoints().Remove(oldPoint); if (iadc != null && rectangle.getPoints().Count > 3) { int minX = int.MaxValue; int minY = int.MaxValue; int maxX = 0; int maxY = 0; foreach (Vector2 point in rectangle.getPoints()) { if (point.x > maxX) { maxX = (int)point.x; } if (point.x < minX) { minX = (int)point.x; } if (point.y > maxY) { maxY = (int)point.y; } if (point.y < minY) { minY = (int)point.y; } } newInfluenceArea = new InfluenceArea(); newInfluenceArea.setX(-20); newInfluenceArea.setY(-20); newInfluenceArea.setHeight(maxY - minY + 40); newInfluenceArea.setWidth(maxX - minX + 40); ActiveArea aa = (ActiveArea)rectangle; aa.setInfluenceArea(newInfluenceArea); iadc.setInfluenceArea(newInfluenceArea); } return(true); } return(false); }
/// <summary>返回指定的位置是否在活动区域</summary> private bool GetPositionOnActiveArea(Vector2 position, ActiveArea activeArea) { bool result = true; if (activeArea == ActiveArea.RightScreen) { result = position.x > Screen.width * 0.5f; } else if (activeArea == ActiveArea.LeftScreen) { result = position.x < Screen.width * 0.5f; } return(result); }
private async void Loop() { while (HiddenWindows.ContainsKey(Window) && Window.Exists) { await Task.Delay(100); if (!State && PreviewArea.Contains(Mouse.Position) && Window.IsOnCurrentDesktop) { if (Window.HasAnimation()) { Window.StopAnimation(); Window.Move(HiddenArea); Window.SetOpacity(0); await Task.Yield(); } PreviewShow(); bool flick = await WaitForFlick(); if (flick) { Show(); } else { PreviewHide(); } await WaitForLeave(); } else if (State && (!ActiveArea.Contains(Mouse.Position) || !Window.IsOnCurrentDesktop)) { Hide(); } } Program.OnExit -= Deactivate; if (noCleanup) { return; } if (!Window.Exists) { return; } if (!IsAlwaysOnTop) { Window.SetAlwaysOnTop(false); } Show(); }
public async Task <bool> WaitForFlick() { var watch = Stopwatch.StartNew(); while (watch.ElapsedMilliseconds < previewDelay) { await Task.Delay(10); if (!PeekArea.Contains(Mouse.Position)) { return(watch.ElapsedMilliseconds < flickDelay && ActiveArea.Contains(Mouse.Position)); } } return(false); }
public static Rectangle MoveAreaToTrajectory(this Rectangle area, uAdventure.Runner.TrajectoryHandler trajectory) { var points = area.isRectangular() ? area.ToRect().ToPoints() : area.getPoints().ToArray(); var aa = new ActiveArea("aux", false, 0, 0, 0, 0); var pointsList = aa.getPoints(); var center = points.Aggregate((v1, v2) => v1 + v2) / points.Length; var adjust = -center + trajectory.closestPoint(center); foreach (var p in points) { pointsList.Add(p + adjust); } return(aa); }
private void performAddElement(object sender, string id) { if (!controller.isElementIdValid(id)) { id = controller.makeElementValid(id); } ActiveArea newActiveArea = new ActiveArea(id, true, 220, 220, 100, 100); activeAreasList.Add(newActiveArea); ActiveAreaDataControl newActiveAreaDataControl = new ActiveAreaDataControl(sceneDataControl, newActiveArea); activeAreasDataControlList.Add(newActiveAreaDataControl); controller.IdentifierSummary.addId <ActiveArea>(id); controller.DataModified(); }
public override bool redoTool() { if (rectangle.getPoints().Contains(oldPoint)) { rectangle.getPoints().Remove(oldPoint); if (iadc != null) { ActiveArea aa = (ActiveArea)rectangle; aa.setInfluenceArea(newInfluenceArea); iadc.setInfluenceArea(newInfluenceArea); } Controller.getInstance().reloadPanel(); return(true); } return(false); }
public void ChangeAreaLevel(string areaTag, ActiveArea area, int infestLevel, CLRScriptBase s) { if (area == null) { area = GetAreaByTag(areaTag); } if (!InfestedAreas.Contains(area)) { InfestArea(areaTag, area, infestLevel, s); return; } int count = 0; InfestedAreaLevels[areaTag] = infestLevel; uint wp = s.GetLocalObject(area.Id, WayPointArrayName + count.ToString()); while (s.GetIsObjectValid(wp) != CLRScriptBase.FALSE) { if (s.GetLocalInt(wp, "ACR_SPAWN_TYPE") != 0) { count++; wp = s.GetLocalObject(area.Id, WayPointArrayName + count.ToString()); continue; } int var = 1; string oldVar = s.GetLocalString(wp, SingleVarName + var.ToString()); while (oldVar != "") { s.SetLocalString(wp, SingleVarName + var.ToString(), GetRandomSpawnAtTier(infestLevel)); var++; oldVar = s.GetLocalString(wp, SingleVarName + var.ToString()); } var = 1; oldVar = s.GetLocalString(wp, RandomVarName + var.ToString()); while (oldVar != "") { s.SetLocalString(wp, RandomVarName + var.ToString(), GetRandomSpawnAtTier(infestLevel)); var++; oldVar = s.GetLocalString(wp, RandomVarName + var.ToString()); } count++; wp = s.GetLocalObject(area.Id, WayPointArrayName + count.ToString()); } }
public override bool moveElementDown(DataControl dataControl) { bool elementMoved = false; int elementIndex = activeAreasList.IndexOf((ActiveArea)dataControl.getContent()); if (elementIndex < activeAreasList.Count - 1) { ActiveArea a = activeAreasList[elementIndex]; ActiveAreaDataControl c = activeAreasDataControlList[elementIndex]; activeAreasList.RemoveAt(elementIndex); activeAreasDataControlList.RemoveAt(elementIndex); activeAreasList.Insert(elementIndex + 1, a); activeAreasDataControlList.Insert(elementIndex + 1, c); controller.DataModified(); elementMoved = true; } return(elementMoved); }
public object Clone() { ActiveArea aa = (ActiveArea)base.Clone(); //can not be two identical id string id = aa.getId() + "-" + (new System.Random().Next(1000).ToString()); aa.setId(id); aa.conditions = (conditions != null ? (Conditions)conditions.Clone() : null); aa.height = height; aa.width = width; aa.x = x; aa.y = y; aa.influenceArea = (influenceArea != null ? (InfluenceArea)influenceArea.Clone() : null); aa.rectangular = rectangular; aa.Vector2s = (Vector2s != null ? new List <Vector2>() : null); foreach (Vector2 p in Vector2s) { aa.Vector2s.Add(new Vector2(p.x, p.y)); } return(aa); }
void Start() { if (deleteditems.Count > 0) { Queue <GameObject> que = new Queue <GameObject>(); foreach (GameObject ar in AreaObjects) { for (int i = 1; i < ar.transform.childCount; i++) { if (deleteditems.Contains(ar.transform.GetChild(i).name)) { que.Enqueue(ar.transform.GetChild(i).gameObject); } } } while (que.Count > 0) { GameObject tempor = que.Dequeue(); Destroy(tempor); } } AreaClasses = new Area[AreaObjects.Length]; for (int i = 0; i < AreaClasses.Length; i++) { AreaClasses [i] = new Area(AreaObjects[i]); } //Area1Class = new Area (Area1); //Area2Class = new Area (Area2); //Area[] temp = { Area1Class,Area2Class}; activeArea = new ActiveArea(AreaClasses, AreaClasses.Length, OnLoadActiveArea); temporary = new ObjectToWalkTo(); wasClicked = false; operateObject = ""; if (Inventory == null) { Inventory = GameObject.Find("Inventory").gameObject; } Menu.SetActive(false); }
public override void ParseElement(XmlElement element) { XmlNodeList points = element.SelectNodes("point"), descriptionss = element.SelectNodes("description"), actionss = element.SelectNodes("actions"), conditions = element.SelectNodes("condition"); //, //effects = element.SelectNodes("effect"); string tmpArgVal; int x = 0, y = 0, width = 0, height = 0; string id = null; bool rectangular = true; int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0; bool hasInfluence = false; tmpArgVal = element.GetAttribute("rectangular"); if (!string.IsNullOrEmpty(tmpArgVal)) { rectangular = tmpArgVal.Equals("yes"); } tmpArgVal = element.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("width"); if (!string.IsNullOrEmpty(tmpArgVal)) { width = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("height"); if (!string.IsNullOrEmpty(tmpArgVal)) { height = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { id = tmpArgVal; } tmpArgVal = element.GetAttribute("hasInfluenceArea"); if (!string.IsNullOrEmpty(tmpArgVal)) { hasInfluence = tmpArgVal.Equals("yes"); } tmpArgVal = element.GetAttribute("influenceX"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceX = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("influenceY"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceY = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("influenceWidth"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceWidth = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("influenceHeight"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceHeight = int.Parse(tmpArgVal); } activeArea = new ActiveArea((id == null ? generateId() : id), rectangular, x, y, width, height); if (hasInfluence) { InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); activeArea.setInfluenceArea(influenceArea); } if (element.SelectSingleNode("documentation") != null) { activeArea.setDocumentation(element.SelectSingleNode("documentation").InnerText); } descriptions = new List <Description>(); activeArea.setDescriptions(descriptions); foreach (XmlElement el in descriptionss) { description = new Description(); new DescriptionsSubParser_(description, chapter).ParseElement(el); this.descriptions.Add(description); } foreach (XmlElement el in points) { if (activeArea != null) { int x_ = 0, y_ = 0; tmpArgVal = el.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x_ = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y_ = int.Parse(tmpArgVal); } Vector2 point = new Vector2(x_, y_); activeArea.addVector2(point); } } foreach (XmlElement el in actionss) { new ActionsSubParser_(chapter, activeArea).ParseElement(el); } foreach (XmlElement el in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(el); this.activeArea.setConditions(currentConditions); } scene.addActiveArea(activeArea); }
/** * Adds an active area * * @param activeArea * the active area to add */ public void addActiveArea(ActiveArea activeArea) { activeAreas.Add(activeArea); }
/* * (non-Javadoc) * * @see es.eucm.eadventure.engine.cargador.subparsers.SubParser#startElement(java.lang.string, java.lang.string, * java.lang.string, org.xml.sax.Attributes) */ public override void startElement(string namespaceURI, string sName, string qName, Dictionary <string, string> attrs) { // If no element is being subparsed if (subParsing == SUBPARSING_NONE) { // If it is a object tag, create the new object (with its id) if (qName.Equals("active-area")) { int x = 0, y = 0, width = 0, height = 0; string id = null; bool rectangular = true; int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0; bool hasInfluence = false; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("rectangular")) { rectangular = entry.Value.ToString().Equals("yes"); } if (entry.Key.Equals("x")) { x = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("y")) { y = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("width")) { width = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("height")) { height = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("id")) { id = entry.Value.ToString(); } if (entry.Key.Equals("hasInfluenceArea")) { hasInfluence = entry.Value.ToString().Equals("yes"); } if (entry.Key.Equals("influenceX")) { influenceX = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("influenceY")) { influenceY = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("influenceWidth")) { influenceWidth = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("influenceHeight")) { influenceHeight = int.Parse(entry.Value.ToString()); } } activeArea = new ActiveArea((id == null ? generateId() : id), rectangular, x, y, width, height); if (hasInfluence) { InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); activeArea.setInfluenceArea(influenceArea); } descriptions = new List <Description>(); activeArea.setDescriptions(descriptions); } else if (qName.Equals("point")) { if (activeArea != null) { int x = 0, y = 0; foreach (KeyValuePair <string, string> entry in attrs) { if (entry.Key.Equals("x")) { x = int.Parse(entry.Value.ToString()); } if (entry.Key.Equals("y")) { y = int.Parse(entry.Value.ToString()); } } Vector2 point = new Vector2(x, y); activeArea.addVector2(point); } } // If it is a description tag, create the new description (with its id) else if (qName.Equals("description")) { description = new Description(); subParser = new DescriptionsSubParser(description, chapter); subParsing = SUBPARSING_DESCRIPTION; } else if (qName.Equals("actions")) { subParser = new ActionsSubParser(chapter, activeArea); subParsing = SUBPARSING_ACTIONS; } // If it is a condition tag, create new conditions and switch the state else if (qName.Equals("condition")) { currentConditions = new Conditions(); subParser = new ConditionSubParser(currentConditions, chapter); subParsing = SUBPARSING_CONDITION; } // If it is a effect tag, create new effects and switch the state else if (qName.Equals("effect")) { subParser = new EffectSubParser(currentEffects, chapter); subParsing = SUBPARSING_EFFECT; } } // If it is reading an effect or a condition, spread the call if (subParsing != SUBPARSING_NONE) { subParser.startElement(namespaceURI, sName, qName, attrs); } }
public override void TouchesBegan(NSSet touches, UIEvent evt) { try { if (!_touchDown) { var touch = touches.ToArray <UITouch> ()[0]; if (ActiveArea.Contains(touch.LocationInView(this))) { _touchDown = true; if (!CanCommand()) { if (Def != null && Def.ComponentType == LcarsComponentType.Gray) { Sounds.PlayNotActive(); } return; } var prevState = _selState; if (prevState == LcarsComp.SelectionState.NotSelected) { if (_def.NeedsDoubleTap) { _selState = LcarsComp.SelectionState.Pending; NSTimer.CreateScheduledTimer(ConfirmWait, delegate { _selState = LcarsComp.SelectionState.NotSelected; OnModelChanged(); }); } else { _selState = LcarsComp.SelectionState.Selected; } } else { _selState = LcarsComp.SelectionState.Selected; } if (_selState == LcarsComp.SelectionState.Pending) { Sounds.PlayPendingCommand(); } else { if (prevState == LcarsComp.SelectionState.Pending) { Sounds.PlayConfirmPendingCommand(); } else { PlayConfirmCommand(); } } OnModelChanged(); } } } catch (Exception error) { Log.Error(error); } }
public static Chapter CreateChapter(string xmlPath) { Chapter chapter = new Chapter(); XElement xml = XElement.Load(xmlPath); #region Objects foreach (XElement ele in xml.Elements("object")) { eAdventure.Object obj = new eAdventure.Object(); chapter.Objects.Add(obj); obj.Id = ele.Attribute("id").Value; XElement desc = ele.Element("description"); obj.Description = CreateDescription(desc); #region Resources foreach (XElement resourceEle in ele.Elements("resources")) { ResourceList resList = new ResourceList(); obj.Resources.Add(resList); foreach (XElement assetEle in resourceEle.Elements("asset")) { Asset asset = new Asset(); resList.Assets.Add(asset); asset.Type = assetEle.Attribute("type").Value; asset.Uri = assetEle.Attribute("uri").Value; } XElement conditionEle = resourceEle.Element("condition"); if (conditionEle != null) { resList.Condition = CreateCondition(conditionEle); } } #endregion #region Actions try { foreach (var action in ele.Element("actions").Elements()) { if (action.Name == "custom") { Custom custom = new Custom(); obj.Actions.Add(custom); custom.Name = action.Attribute("name").Value; var eff = action.Element("effect"); if (eff != null) { custom.Effect = CreateEffect(eff); } } else if (action.Name == "examine") { Examine examine = new Examine(); obj.Actions.Add(examine); var eff = action.Element("effect"); if (eff != null) { examine.Effect = CreateEffect(eff); } } else if (action.Name == "use") { Use use = new Use(); obj.Actions.Add(use); obj.Use = use; Effect effect = new Effect(); var effectEle = action.Element("effect"); if (effectEle != null) { use.Effect = CreateEffect(effectEle); } } } } catch { } #endregion } #endregion #region Scenes foreach (XElement sceneEle in xml.Elements("scene")) { Scene scene = new Scene(); chapter.Scenes.Add(scene); scene.Id = sceneEle.Attribute("id").Value; #region ActiveAreas var aaEle = sceneEle.Element("active-areas"); if (aaEle != null) { foreach (var aa in aaEle.Elements("active-area")) { ActiveArea a = new ActiveArea(); scene.ActiveAreas.Add(a); a.Id = aa.Attribute("id").Value; a.Description = CreateDescription(aa.Element("description")); a.Transform = CreateTransform(aa); var actionsEle = aa.Element("actions"); if (actionsEle != null) { foreach (var action in actionsEle.Elements()) { if (action.Name == "custom") { Custom custom = new Custom(); a.Actions.Add(custom); custom.Name = action.Attribute("name").Value; } else if (action.Name == "examine") { Examine examine = new Examine(); a.Actions.Add(examine); var eff = action.Element("effect"); if (eff != null) { examine.Effect = CreateEffect(eff); } } else if (action.Name == "use") { Use use = new Use(); a.Actions.Add(use); a.Use = use; Effect effect = new Effect(); var effectEle = action.Element("effect"); if (effectEle != null) { use.Effect = CreateEffect(effectEle); } } } } } } #endregion #region Resources foreach (XElement resourceEle in sceneEle.Elements("resources")) { ResourceList resList = new ResourceList(); scene.Resources.Add(resList); foreach (XElement assetEle in resourceEle.Elements("asset")) { Asset asset = new Asset(); resList.Assets.Add(asset); asset.Type = assetEle.Attribute("type").Value; asset.Uri = assetEle.Attribute("uri").Value; } XElement conditionEle = resourceEle.Element("condition"); if (conditionEle != null) { resList.Condition = CreateCondition(conditionEle); } } #endregion #region Characters var sceneCharacters = sceneEle.Element("characters"); if (sceneCharacters != null) { foreach (XElement item in sceneCharacters.Elements("character-ref")) { SceneCharacter sChar = new SceneCharacter(); scene.Characters.Add(sChar); sChar.CharacterId = item.Attribute("idTarget").Value; sChar.Scale = Convert.ToDecimal(item.Attribute("scale").Value); sChar.X = Convert.ToInt32(item.Attribute("x").Value); sChar.Y = Convert.ToInt32(item.Attribute("y").Value); sChar.Condition = CreateCondition(item.Element("condition")); } } #endregion #region Exits var exits = sceneEle.Element("exits"); if (exits != null) { foreach (XElement exitEle in exits.Elements("exit")) { Exit exit = new Exit(); scene.Exits.Add(exit); exit.Transform = CreateTransform(exitEle); exit.IsRectangular = exitEle.Attribute("rectangular").Value == "yes" ? true : false; exit.MouseOverDescription = exitEle.Element("exit-look").Attribute("text").Value; exit.TargetObjectId = exitEle.Attribute("idTarget").Value; XElement conditionEle = exitEle.Element("condition"); if (conditionEle != null) { exit.Condition = CreateCondition(conditionEle); } var effect = exitEle.Element("effect"); if (effect != null) { exit.Effect = CreateEffect(effect); } } } #endregion #region Objects if (sceneEle.Element("objects") != null) { foreach (var objectEle in sceneEle.Element("objects").Elements("object-ref")) { SceneObject obj = new SceneObject(); scene.Objects.Add(obj); obj.TargetId = objectEle.Attribute("idTarget").Value; obj.TargetObject = chapter.Objects.Single(x => x.Id == obj.TargetId); obj.X = Convert.ToInt32(objectEle.Attribute("x").Value); obj.Y = Convert.ToInt32(objectEle.Attribute("y").Value); obj.Layer = Convert.ToInt32(objectEle.Attribute("layer").Value); var cond = objectEle.Element("condition"); if (cond != null) { obj.Condition = CreateCondition(cond); } } } #endregion } #endregion #region Slidescenes foreach (XElement slideEle in xml.Elements("slidescene")) { SlideScene ss = new SlideScene(); chapter.SlideScenes.Add(ss); ss.Name = slideEle.Element("name").Value; ss.Id = slideEle.Attribute("id").Value; // ss.TargetScene = chapter.Scenes.First(x => x.SceneId == slideEle.Attribute("idTarget").Value); string slidesPath = slideEle.Element("resources").Element("asset").Attribute("uri").Value; int slideNumber = 1; while (true) { string uri = slidesPath + "_0" + slideNumber.ToString(); if (!File.Exists(Path + uri + ".jpg")) { break; } slideNumber++; Asset newSlide = new Asset(); ss.Slides.Add(newSlide); newSlide.Type = "slides"; newSlide.Uri = uri; } } #endregion #region Conversations foreach (var convEle in xml.Elements("graph-conversation")) { Conversation conv = new Conversation(); chapter.Conversations.Add(conv); conv.Id = convEle.Attribute("id").Value; foreach (var node in convEle.Elements()) { #region Dialogue Node if (node.Name == "dialogue-node") { DialogueNode dNode = new DialogueNode(); conv.Nodes.Add(dNode); dNode.NodeIndex = node.Attribute("nodeindex").Value; var end = node.Element("end-conversation"); if (end != null) { dNode.EndEffect = CreateEffect(end.Element("effect")); } foreach (var item in node.Elements()) { if (item.Name == "speak-char") { SpeakChar speak = new SpeakChar(); dNode.Dialogue.Add(speak); speak.TargetId = item.Attribute("idTarget").Value; speak.Text = item.Value; } else if (item.Name == "speak-player") { SpeakPlayer speak = new SpeakPlayer(); dNode.Dialogue.Add(speak); speak.Text = item.Value; } else if (item.Name == "child") { dNode.NextNodeId = item.Attribute("nodeindex").Value; } } } #endregion #region Option Node else if (node.Name == "option-node") { OptionNode oNode = new OptionNode(); conv.Nodes.Add(oNode); oNode.NodeIndex = node.Attribute("nodeindex").Value; foreach (var optionEle in node.Elements("speak-player")) { Option option = new Option(); oNode.Options.Add(option); SpeakPlayer speak = new SpeakPlayer(); option.SelectedOption = speak; speak.Text = optionEle.Value; option.NextNodeId = optionEle.ElementsAfterSelf("child").First().Attribute("nodeindex").Value; } } #endregion } } #endregion #region Characters foreach (var charEle in xml.Elements("character")) { Character character = new Character(); chapter.Characters.Add(character); character.Id = charEle.Attribute("id").Value; foreach (var item in charEle.Element("resources").Elements("asset")) { Asset asset = new Asset(); character.Assets.Add(asset); asset.Type = item.Attribute("type").Value; asset.Uri = item.Attribute("uri").Value; } character.Description = CreateDescription(charEle.Element("description")); character.TextColor = CreateTextColor(charEle.Element("textcolor")); } #endregion #region Macros var macros = xml.Elements("macro"); if (macros != null) { foreach (var macroEle in macros) { Macro m = new Macro(); chapter.Macros.Add(m); m.Id = macroEle.Attribute("id").Value; foreach (var item in macroEle.Elements()) { if (item.Name == "speak-player") { SpeakPlayerMacro sp = new SpeakPlayerMacro(item.Value); m.Actions.Add(sp); } else if (item.Name == "trigger-scene") { TriggerSceneMacro ts = new TriggerSceneMacro(item.Attribute("idTarget").Value); m.Actions.Add(ts); } else if (item.Name == "activate") { ActivateFlag af = new ActivateFlag(item.Attribute("flag").Value); m.Actions.Add(af); } } } } #endregion #region Second loop #region Scenes foreach (var scene in chapter.Scenes) { #region Exits foreach (var exit in scene.Exits) { exit.TargetObject = chapter.GetElementById(exit.TargetObjectId); } #endregion #region Active areas foreach (var area in scene.ActiveAreas) { if (area.Use != null) { if (area.Use.Effect != null) { var effect = area.Use.Effect; effect.TriggerSlideScene = (SlideScene)chapter.GetElementById(effect.TriggerSlideSceneId); effect.TriggerScene = (Scene)chapter.GetElementById(effect.TriggerSceneId); if (effect.TriggerConversationId != null) { effect.TriggerScene.Conversations.Add(chapter.Conversations.Single(x => x.Id == effect.TriggerConversationId)); } } } } #endregion #region Characters foreach (var item in scene.Characters) { item.Character = chapter.Characters.Single(x => x.Id == item.CharacterId); } #endregion } #endregion #region Objects foreach (var obj in chapter.Objects) { try { if (obj.Use.Effect.TriggerSlideSceneId != null) { obj.Use.Effect.TriggerSlideScene = chapter.SlideScenes.Single(x => x.Id == obj.Use.Effect.TriggerSlideSceneId); } if (obj.Use.Effect.TriggerSceneId != null) { obj.Use.Effect.TriggerScene = chapter.Scenes.Single(x => x.Id == obj.Use.Effect.TriggerSceneId); } } catch { } } #endregion #region Conversations foreach (var item in chapter.Conversations) { foreach (var node in item.Nodes) { var endEffect = node.EndEffect; if (endEffect != null) { if (endEffect.TriggerSlideSceneId != null) { endEffect.TriggerSlideScene = chapter.SlideScenes.Single(x => x.Id == endEffect.TriggerSlideSceneId); } if (endEffect.TriggerSceneId != null) { endEffect.TriggerScene = chapter.Scenes.Single(x => x.Id == endEffect.TriggerSceneId); } } if (node is DialogueNode) { var current = ((DialogueNode)node); if (current.NextNodeId != null) { current.NextNode = item.Nodes.Single(x => x.NodeIndex == current.NextNodeId); } } else { var current = ((OptionNode)node); foreach (var option in current.Options) { if (option.NextNodeId != null) { option.NextNode = item.Nodes.Single(x => x.NodeIndex == option.NextNodeId); } } } } } #endregion #endregion return(chapter); }
public override void ParseElement(XmlElement element) { XmlNodeList points = element.SelectNodes("point"), descriptionss = element.SelectNodes("description"), actionss = element.SelectNodes("actions"), conditions = element.SelectNodes("condition"); //, //effects = element.SelectNodes("effect"); string tmpArgVal; int x = 0, y = 0, width = 0, height = 0; string id = null; bool rectangular = true; int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0; bool hasInfluence = false; tmpArgVal = element.GetAttribute("rectangular"); if (!string.IsNullOrEmpty(tmpArgVal)) { rectangular = tmpArgVal.Equals("yes"); } tmpArgVal = element.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("width"); if (!string.IsNullOrEmpty(tmpArgVal)) { width = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("height"); if (!string.IsNullOrEmpty(tmpArgVal)) { height = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("id"); if (!string.IsNullOrEmpty(tmpArgVal)) { id = tmpArgVal; } tmpArgVal = element.GetAttribute("hasInfluenceArea"); if (!string.IsNullOrEmpty(tmpArgVal)) { hasInfluence = tmpArgVal.Equals("yes"); } tmpArgVal = element.GetAttribute("influenceX"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceX = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("influenceY"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceY = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("influenceWidth"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceWidth = int.Parse(tmpArgVal); } tmpArgVal = element.GetAttribute("influenceHeight"); if (!string.IsNullOrEmpty(tmpArgVal)) { influenceHeight = int.Parse(tmpArgVal); } activeArea = new ActiveArea((id == null ? generateId() : id), rectangular, x, y, width, height); if (hasInfluence) { InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); activeArea.setInfluenceArea(influenceArea); } if (element.SelectSingleNode("documentation") != null) activeArea.setDocumentation(element.SelectSingleNode("documentation").InnerText); descriptions = new List<Description>(); activeArea.setDescriptions(descriptions); foreach (XmlElement el in descriptionss) { description = new Description(); new DescriptionsSubParser_(description, chapter).ParseElement(el); this.descriptions.Add(description); } foreach (XmlElement el in points) { if (activeArea != null) { int x_ = 0, y_ = 0; tmpArgVal = el.GetAttribute("x"); if (!string.IsNullOrEmpty(tmpArgVal)) { x_ = int.Parse(tmpArgVal); } tmpArgVal = el.GetAttribute("y"); if (!string.IsNullOrEmpty(tmpArgVal)) { y_ = int.Parse(tmpArgVal); } Vector2 point = new Vector2(x_, y_); activeArea.addVector2(point); } } foreach (XmlElement el in actionss) { new ActionsSubParser_(chapter, activeArea).ParseElement(el); } foreach (XmlElement el in conditions) { currentConditions = new Conditions(); new ConditionSubParser_(currentConditions, chapter).ParseElement(el); this.activeArea.setConditions(currentConditions); } scene.addActiveArea(activeArea); }
private void InfestArea(string areaTag, ActiveArea area, int initialLevel, CLRScriptBase s) { if (area == null) { area = GetAreaByTag(areaTag); } if (!InfestedAreas.Contains(area)) { InfestedAreas.Add(area); } if (!InfestedAreaLevels.ContainsKey(areaTag)) { InfestedAreaLevels.Add(areaTag, initialLevel); } else { InfestedAreaLevels[areaTag] = initialLevel; } s.SetLocalString(area.Id, InfestNameVar, this.InfestationName); int count = 0; uint wp = s.GetLocalObject(area.Id, WayPointArrayName + count.ToString()); while (s.GetIsObjectValid(wp) != CLRScriptBase.FALSE) { int groupNum = 1; string oldGroup = s.GetLocalString(wp, GroupVarName + groupNum.ToString()); while (oldGroup != "") { s.SetLocalString(wp, InfestPrefix + GroupVarName + groupNum.ToString(), oldGroup); s.SetLocalString(wp, GroupVarName + groupNum.ToString(), InfestGroupScript); groupNum++; oldGroup = s.GetLocalString(wp, GroupVarName + groupNum.ToString()); } if (s.GetLocalInt(wp, "ACR_SPAWN_TYPE") != CLRScriptBase.OBJECT_TYPE_CREATURE) { count++; wp = s.GetLocalObject(area.Id, WayPointArrayName + count.ToString()); continue; } int var = 1; string oldVar = s.GetLocalString(wp, SingleVarName + var.ToString()); while (oldVar != "") { s.SetLocalString(wp, InfestPrefix + SingleVarName + var.ToString(), oldVar); s.SetLocalString(wp, SingleVarName + var.ToString(), GetRandomSpawnAtTier(initialLevel)); var++; oldVar = s.GetLocalString(wp, SingleVarName + var.ToString()); } var = 1; oldVar = s.GetLocalString(wp, RandomVarName + var.ToString()); while (oldVar != "") { s.SetLocalString(wp, InfestPrefix + RandomVarName + var.ToString(), oldVar); s.SetLocalString(wp, RandomVarName + var.ToString(), GetRandomSpawnAtTier(initialLevel)); var++; oldVar = s.GetLocalString(wp, RandomVarName + var.ToString()); } count++; wp = s.GetLocalObject(area.Id, WayPointArrayName + count.ToString()); } }
/* * (non-Javadoc) * * @see es.eucm.eadventure.engine.cargador.subparsers.SubParser#startElement(java.lang.string, java.lang.string, * java.lang.string, org.xml.sax.Attributes) */ public override void startElement(string namespaceURI, string sName, string qName, Dictionary<string, string> attrs) { // If no element is being subparsed if (subParsing == SUBPARSING_NONE) { // If it is a object tag, create the new object (with its id) if (qName.Equals("active-area")) { int x = 0, y = 0, width = 0, height = 0; string id = null; bool rectangular = true; int influenceX = 0, influenceY = 0, influenceWidth = 0, influenceHeight = 0; bool hasInfluence = false; foreach (KeyValuePair<string, string> entry in attrs) { if (entry.Key.Equals("rectangular")) rectangular = entry.Value.ToString().Equals("yes"); if (entry.Key.Equals("x")) x = int.Parse(entry.Value.ToString()); if (entry.Key.Equals("y")) y = int.Parse(entry.Value.ToString()); if (entry.Key.Equals("width")) width = int.Parse(entry.Value.ToString()); if (entry.Key.Equals("height")) height = int.Parse(entry.Value.ToString()); if (entry.Key.Equals("id")) id = entry.Value.ToString(); if (entry.Key.Equals("hasInfluenceArea")) hasInfluence = entry.Value.ToString().Equals("yes"); if (entry.Key.Equals("influenceX")) influenceX = int.Parse(entry.Value.ToString()); if (entry.Key.Equals("influenceY")) influenceY = int.Parse(entry.Value.ToString()); if (entry.Key.Equals("influenceWidth")) influenceWidth = int.Parse(entry.Value.ToString()); if (entry.Key.Equals("influenceHeight")) influenceHeight = int.Parse(entry.Value.ToString()); } activeArea = new ActiveArea((id == null ? generateId() : id), rectangular, x, y, width, height); if (hasInfluence) { InfluenceArea influenceArea = new InfluenceArea(influenceX, influenceY, influenceWidth, influenceHeight); activeArea.setInfluenceArea(influenceArea); } descriptions = new List<Description>(); activeArea.setDescriptions(descriptions); } else if (qName.Equals("point")) { if (activeArea != null) { int x = 0, y = 0; foreach (KeyValuePair<string, string> entry in attrs) { if (entry.Key.Equals("x")) x = int.Parse(entry.Value.ToString()); if (entry.Key.Equals("y")) y = int.Parse(entry.Value.ToString()); } Vector2 point = new Vector2(x, y); activeArea.addVector2(point); } } // If it is a description tag, create the new description (with its id) else if (qName.Equals("description")) { description = new Description(); subParser = new DescriptionsSubParser(description, chapter); subParsing = SUBPARSING_DESCRIPTION; } else if (qName.Equals("actions")) { subParser = new ActionsSubParser(chapter, activeArea); subParsing = SUBPARSING_ACTIONS; } // If it is a condition tag, create new conditions and switch the state else if (qName.Equals("condition")) { currentConditions = new Conditions(); subParser = new ConditionSubParser(currentConditions, chapter); subParsing = SUBPARSING_CONDITION; } // If it is a effect tag, create new effects and switch the state else if (qName.Equals("effect")) { subParser = new EffectSubParser(currentEffects, chapter); subParsing = SUBPARSING_EFFECT; } } // If it is reading an effect or a condition, spread the call if (subParsing != SUBPARSING_NONE) { subParser.startElement(namespaceURI, sName, qName, attrs); } }