public static void LoadFromXML(XML source) { strings = new Dictionary <string, Dictionary <string, string> >(); XMLList.Enumerator et = source.GetEnumerator("string"); while (et.MoveNext()) { XML cxml = et.Current; string key = cxml.GetAttribute("name"); string text = cxml.text; int i = key.IndexOf("-"); if (i == -1) { continue; } string key2 = key.Substring(0, i); string key3 = key.Substring(i + 1); Dictionary <string, string> col; if (!strings.TryGetValue(key2, out col)) { col = new Dictionary <string, string>(); strings[key2] = col; } col[key3] = text; } }
public void Setup(XML xml) { XMLList.Enumerator et = xml.GetEnumerator("relation"); string targetId; GObject target; while (et.MoveNext()) { XML cxml = et.Current; targetId = cxml.GetAttribute("target"); if (_owner.parent != null) { if (targetId != null && targetId != "") { target = _owner.parent.GetChildById(targetId); } else { target = _owner.parent; } } else { //call from component construction target = ((GComponent)_owner).GetChildById(targetId); } if (target != null) { AddItems(target, cxml.GetAttribute("sidePair")); } } }
void LoadMovieClip(PackageItem item) { string str = _descPack[item.id + ".xml"]; XML xml = new XML(str); string[] arr = null; str = xml.GetAttribute("interval"); if (str != null) item.interval = float.Parse(str) / 1000f; item.swing = xml.GetAttributeBool("swing", false); str = xml.GetAttribute("repeatDelay"); if (str != null) item.repeatDelay = float.Parse(str) / 1000f; int frameCount = xml.GetAttributeInt("frameCount"); item.frames = new MovieClip.Frame[frameCount]; int i = 0; string spriteId; XML frameNode; MovieClip.Frame frame; AtlasSprite sprite; XMLList.Enumerator et = xml.GetNode("frames").GetEnumerator(); while (et.MoveNext()) { frameNode = et.Current; frame = new MovieClip.Frame(); arr = frameNode.GetAttributeArray("rect"); frame.rect = new Rect(int.Parse(arr[0]), int.Parse(arr[1]), int.Parse(arr[2]), int.Parse(arr[3])); str = frameNode.GetAttribute("addDelay"); if (str != null) frame.addDelay = float.Parse(str) / 1000f; str = frameNode.GetAttribute("sprite"); if (str != null) spriteId = item.id + "_" + str; else if (frame.rect.width != 0) spriteId = item.id + "_" + i; else spriteId = null; if (spriteId != null && _sprites.TryGetValue(spriteId, out sprite)) { PackageItem atlasItem = _itemsById[sprite.atlas]; if (atlasItem != null) { if (item.texture == null) item.texture = (NTexture)GetItemAsset(atlasItem); frame.uvRect = new Rect(sprite.rect.x / item.texture.width * item.texture.uvRect.width, 1 - sprite.rect.yMax * item.texture.uvRect.height / item.texture.height, sprite.rect.width * item.texture.uvRect.width / item.texture.width, sprite.rect.height * item.texture.uvRect.height / item.texture.height); } } item.frames[i] = frame; i++; } }
/// <summary> /// 收集创建目标对象所需的所有类型信息 /// </summary> /// <param name="item"></param> /// <param name="list"></param> void CollectComponentChildren(PackageItem item, List<DisplayListItem> list) { if (!item.decoded) LoadComponent(item); if (item.displayList == null) LoadComponentChildren(item); int cnt = item.displayList.Length; for (int i = 0; i < cnt; i++) { DisplayListItem di = item.displayList[i]; if (di.packageItem != null && di.packageItem.type == PackageItemType.Component) CollectComponentChildren(di.packageItem, list); else if (di.type == "list") //也要收集列表的item { XMLList.Enumerator et = di.desc.GetEnumerator("item"); string defaultItem = null; di.listItemCount = 0; while (et.MoveNext()) { XML ix = et.Current; string url = ix.GetAttribute("url"); if (string.IsNullOrEmpty(url)) { if (defaultItem == null) defaultItem = di.desc.GetAttribute("defaultItem"); url = defaultItem; if (string.IsNullOrEmpty(url)) continue; } PackageItem pi = UIPackage.GetItemByURL(url); if (pi != null) { if (pi.type == PackageItemType.Component) CollectComponentChildren(pi, list); list.Add(new DisplayListItem(pi, null)); di.listItemCount++; } } } list.Add(di); } }
public void Setup(XML xml) { string[] arr; name = xml.GetAttribute("name"); autoRadioGroupDepth = xml.GetAttributeBool("autoRadioGroupDepth"); arr = xml.GetAttributeArray("pages"); if (arr != null) { int cnt = arr.Length; for (int i = 0; i < cnt; i += 2) { _pageIds.Add(arr[i]); _pageNames.Add(arr[i + 1]); } } XMLList.Enumerator et = xml.GetEnumerator("action"); while (et.MoveNext()) { if (_actions == null) { _actions = new List <ControllerAction>(); } XML cxml = et.Current; ControllerAction action = ControllerAction.CreateAction(cxml.GetAttribute("type")); action.Setup(cxml); _actions.Add(action); } arr = xml.GetAttributeArray("transitions"); if (arr != null) { if (_actions == null) { _actions = new List <ControllerAction>(); } int cnt = arr.Length; for (int i = 0; i < cnt; i++) { string str = arr[i]; PlayTransitionAction taction = new PlayTransitionAction(); int k = str.IndexOf("="); taction.transitionName = str.Substring(k + 1); str = str.Substring(0, k); k = str.IndexOf("-"); int ii = int.Parse(str.Substring(k + 1)); if (ii < _pageIds.Count) { taction.toPage = new string[] { _pageIds[ii] } } ; str = str.Substring(0, k); if (str != "*") { ii = int.Parse(str); if (ii < _pageIds.Count) { taction.fromPage = new string[] { _pageIds[ii] } } ; } taction.stopOnExit = true; _actions.Add(taction); } } if (parent != null && _pageIds.Count > 0) { _selectedIndex = 0; } else { _selectedIndex = -1; } } } }
internal void ConstructFromResource(List <GObject> objectPool, int poolIndex) { XML xml = packageItem.componentData; string str; string[] arr; underConstruct = true; arr = xml.GetAttributeArray("size"); sourceWidth = int.Parse(arr[0]); sourceHeight = int.Parse(arr[1]); initWidth = sourceWidth; initHeight = sourceHeight; SetSize(sourceWidth, sourceHeight); arr = xml.GetAttributeArray("pivot"); if (arr != null) { float f1 = float.Parse(arr[0]); float f2 = float.Parse(arr[1]); this.SetPivot(f1, f2, xml.GetAttributeBool("anchor")); } this.opaque = xml.GetAttributeBool("opaque", true); arr = xml.GetAttributeArray("hitTest"); if (arr != null) { PixelHitTestData hitTestData = packageItem.owner.GetPixelHitTestData(arr[0]); if (hitTestData != null) { this.rootContainer.hitArea = new PixelHitTest(hitTestData, int.Parse(arr[1]), int.Parse(arr[2])); } } OverflowType overflow; str = xml.GetAttribute("overflow"); if (str != null) { overflow = FieldTypes.ParseOverflowType(str); } else { overflow = OverflowType.Visible; } str = xml.GetAttribute("margin"); if (str != null) { _margin.Parse(str); } if (overflow == OverflowType.Scroll) { ScrollType scroll; str = xml.GetAttribute("scroll"); if (str != null) { scroll = FieldTypes.ParseScrollType(str); } else { scroll = ScrollType.Vertical; } ScrollBarDisplayType scrollBarDisplay; str = xml.GetAttribute("scrollBar"); if (str != null) { scrollBarDisplay = FieldTypes.ParseScrollBarDisplayType(str); } else { scrollBarDisplay = ScrollBarDisplayType.Default; } int scrollBarFlags = xml.GetAttributeInt("scrollBarFlags"); Margin scrollBarMargin = new Margin(); str = xml.GetAttribute("scrollBarMargin"); if (str != null) { scrollBarMargin.Parse(str); } string vtScrollBarRes = null; string hzScrollBarRes = null; arr = xml.GetAttributeArray("scrollBarRes"); if (arr != null) { vtScrollBarRes = arr[0]; hzScrollBarRes = arr[1]; } SetupScroll(scrollBarMargin, scroll, scrollBarDisplay, scrollBarFlags, vtScrollBarRes, hzScrollBarRes); } else { SetupOverflow(overflow); } arr = xml.GetAttributeArray("clipSoftness"); if (arr != null) { this.clipSoftness = new Vector2(int.Parse(arr[0]), int.Parse(arr[1])); } _buildingDisplayList = true; XMLList.Enumerator et = xml.GetEnumerator("controller"); Controller controller; while (et.MoveNext()) { controller = new Controller(); _controllers.Add(controller); controller.parent = this; controller.Setup(et.Current); } GObject child; DisplayListItem[] displayList = packageItem.displayList; int childCount = displayList.Length; for (int i = 0; i < childCount; i++) { DisplayListItem di = displayList[i]; if (objectPool != null) { child = objectPool[poolIndex + i]; } else { if (di.packageItem != null) { di.packageItem.Load(); child = UIObjectFactory.NewObject(di.packageItem); child.packageItem = di.packageItem; child.ConstructFromResource(); } else { child = UIObjectFactory.NewObject(di.type); } } child.underConstruct = true; child.Setup_BeforeAdd(di.desc); child.parent = this; _children.Add(child); } this.relations.Setup(xml); for (int i = 0; i < childCount; i++) { _children[i].relations.Setup(displayList[i].desc); } for (int i = 0; i < childCount; i++) { child = _children[i]; child.Setup_AfterAdd(displayList[i].desc); child.underConstruct = false; } str = xml.GetAttribute("mask"); if (str != null) { this.mask = GetChildById(str).displayObject; } et = xml.GetEnumerator("transition"); while (et.MoveNext()) { Transition trans = new Transition(this); trans.Setup(et.Current); _transitions.Add(trans); } if (_transitions.Count > 0) { this.onAddedToStage.Add(__addedToStage); this.onRemovedFromStage.Add(__removedFromStage); } ApplyAllControllers(); _buildingDisplayList = false; underConstruct = false; BuildNativeDisplayList(); SetBoundsChangedFlag(); ConstructFromXML(xml); }
public void Setup(XML xml) { this.name = xml.GetAttribute("name"); _options = xml.GetAttributeInt("options"); this.autoPlay = xml.GetAttributeBool("autoPlay"); if (this.autoPlay) { this.autoPlayRepeat = xml.GetAttributeInt("autoPlayRepeat", 1); this.autoPlayDelay = xml.GetAttributeFloat("autoPlayDelay"); } XMLList.Enumerator et = xml.GetEnumerator("item"); while (et.MoveNext()) { XML cxml = et.Current; TransitionItem item = new TransitionItem(); _items.Add(item); item.time = (float)cxml.GetAttributeInt("time") / (float)FRAME_RATE; item.targetId = cxml.GetAttribute("target", string.Empty); item.type = FieldTypes.ParseTransitionActionType(cxml.GetAttribute("type")); item.tween = cxml.GetAttributeBool("tween"); item.label = cxml.GetAttribute("label"); if (item.tween) { item.duration = (float)cxml.GetAttributeInt("duration") / FRAME_RATE; if (item.time + item.duration > _maxTime) { _maxTime = item.time + item.duration; } string ease = cxml.GetAttribute("ease"); if (ease != null) { item.easeType = FieldTypes.ParseEaseType(ease); } item.repeat = cxml.GetAttributeInt("repeat"); item.yoyo = cxml.GetAttributeBool("yoyo"); item.label2 = cxml.GetAttribute("label2"); string v = cxml.GetAttribute("endValue"); if (v != null) { DecodeValue(item.type, cxml.GetAttribute("startValue", string.Empty), item.startValue); DecodeValue(item.type, v, item.endValue); } else { item.tween = false; DecodeValue(item.type, cxml.GetAttribute("startValue", string.Empty), item.value); } } else { if (item.time > _maxTime) { _maxTime = item.time; } DecodeValue(item.type, cxml.GetAttribute("value", string.Empty), item.value); } } }
void TranslateComponent(XML xml, Dictionary<string, string> strings) { XML listNode = xml.GetNode("displayList"); if (listNode == null) return; string ename, elementId, value; XMLList.Enumerator nodes = listNode.GetEnumerator(); while (nodes.MoveNext()) { XML cxml = nodes.Current; ename = cxml.name; elementId = cxml.GetAttribute("id"); if (cxml.HasAttribute("tooltips")) { if (strings.TryGetValue(elementId + "-tips", out value)) cxml.SetAttribute("tooltips", value); } if (ename == "text" || ename == "richtext") { if (strings.TryGetValue(elementId, out value)) cxml.SetAttribute("text", value); if (strings.TryGetValue(elementId + "-prompt", out value)) cxml.SetAttribute("prompt", value); } else if (ename == "list") { XMLList.Enumerator et = cxml.GetEnumerator("item"); int j = 0; while (et.MoveNext()) { if (strings.TryGetValue(elementId + "-" + j, out value)) et.Current.SetAttribute("title", value); j++; } } else if (ename == "component") { XML dxml = cxml.GetNode("Button"); if (dxml != null) { if (strings.TryGetValue(elementId, out value)) dxml.SetAttribute("title", value); if (strings.TryGetValue(elementId + "-0", out value)) dxml.SetAttribute("selectedTitle", value); } else { dxml = cxml.GetNode("Label"); if (dxml != null) { if (strings.TryGetValue(elementId, out value)) dxml.SetAttribute("title", value); } else { dxml = cxml.GetNode("ComboBox"); if (dxml != null) { if (strings.TryGetValue(elementId, out value)) dxml.SetAttribute("title", value); XMLList.Enumerator et = dxml.GetEnumerator("item"); int j = 0; while (et.MoveNext()) { if (strings.TryGetValue(elementId + "-" + j, out value)) et.Current.SetAttribute("title", value); j++; } } } } } } }