protected override TreeViewItem BuildRoot() { var root = new TreeViewItem { id = 0, depth = -1, displayName = "TABLE" }; PhxLuaRuntime runtime = PhxGameRuntime.GetLuaRuntime(); if (!Application.isPlaying || runtime == null) { return(root); } Lua L = runtime.GetLua(); // BuildRoot is called every time Reload is called to ensure that TreeViewItems // are created from data. Here we create a fixed set of items. In a real world example, // a data model should be passed into the TreeView and the items created from the model. // This section illustrates that IDs should be unique. The root item is required to // have a depth of -1, and the rest of the items increment from that. PhxLuaRuntime.Table table = runtime.ToValue(TableIdx) as PhxLuaRuntime.Table; if (table != null) { var allItems = new List <TreeViewItem>(); int id = 0; void AddTable(PhxLuaRuntime.Table t, int depth) { foreach (KeyValuePair <object, object> entry in table) { if (entry.Value is PhxLuaRuntime.Table) { AddTable((PhxLuaRuntime.Table)entry.Value, depth + 1); } else { allItems.Add(new TreeViewItem { id = id++, depth = depth, displayName = string.Format($"{entry.Key.ToString()} = {entry.Value.ToString()}") }); } } } AddTable(table, 0); // Utility method that initializes the TreeViewItem.children and .parent for all items. SetupParentsAndChildrenFromDepths(root, allItems); } // Return root of the tree return(root); }
void Start() { Debug.Assert(LstMaps != null); Debug.Assert(LstModes != null); Debug.Assert(LstEras != null); Debug.Assert(LstRotation != null); Debug.Assert(BtnAdd != null); Debug.Assert(BtnRemove != null); Debug.Assert(BtnRemoveAll != null); Debug.Assert(BtnStart != null); Debug.Assert(BtnQuit != null); LstMaps.OnSelect += OnMapSelectionChanged; BtnAdd.onClick.AddListener(AddMap); BtnRemove.onClick.AddListener(RemoveSelectionFromRotation); BtnRemoveAll.onClick.AddListener(ClearRotation); BtnStart.onClick.AddListener(StartRotation); BtnQuit.onClick.AddListener(Quit); bool bForMP = false; RT.CallLuaFunction("missionlist_ExpandMaplist", 0, bForMP); PhxLuaRuntime.Table spMissions = RT.GetTable("missionselect_listbox_contents"); foreach (KeyValuePair <object, object> entry in spMissions) { PhxLuaRuntime.Table map = entry.Value as PhxLuaRuntime.Table; string mapluafile = map.Get <string>("mapluafile"); bool bIsModLevel = map.Get <bool>("isModLevel"); string mapName = ENV.GetLocalizedMapName(mapluafile); LstMaps.AddItem(mapName, bIsModLevel); MapLuaFiles.Add(mapluafile); } }
void OnMapSelectionChanged(int newIdx) { string mapluafile = MapLuaFiles[newIdx]; LstModes.Clear(); LstEras.Clear(); ModeSubs.Clear(); EraSubs.Clear(); object[] res = RT.CallLuaFunction("missionlist_ExpandModelist", 1, mapluafile); PhxLuaRuntime.Table modes = res[0] as PhxLuaRuntime.Table; foreach (KeyValuePair <object, object> entry in modes) { PhxLuaRuntime.Table mode = entry.Value as PhxLuaRuntime.Table; string modeNamePath = mode.Get <string>("showstr"); if (mode.Get("bIsWildcard") == null) { PhxListBoxItem item = LstModes.AddItem(ENV.GetLocalized(modeNamePath)); Texture2D icon = TextureLoader.Instance.ImportUITexture(mode.Get <string>("icon")); item.SetIcon(icon); string key = mode.Get <string>("key"); item.SetChecked(LastCheckedModes.Contains(key)); item.OnCheckChanged += (bool check) => { if (check) { LastCheckedModes.Add(key); } else { LastCheckedModes.Remove(key); } }; ModeSubs.Add(new SubIcon { Sub = mode.Get <string>("subst"), Icon = icon }); } } res = RT.CallLuaFunction("missionlist_ExpandEralist", 1, mapluafile); PhxLuaRuntime.Table eras = res[0] as PhxLuaRuntime.Table; foreach (KeyValuePair <object, object> entry in eras) { PhxLuaRuntime.Table era = entry.Value as PhxLuaRuntime.Table; string eraNamePath = era.Get <string>("showstr"); if (era.Get("bIsWildcard") == null) { PhxListBoxItem item = LstEras.AddItem(ENV.GetLocalized(eraNamePath)); Texture2D icon = TextureLoader.Instance.ImportUITexture(era.Get <string>("icon2")); item.SetIcon(icon); string key = era.Get <string>("key"); item.SetChecked(LastCheckedEras.Contains(key)); item.OnCheckChanged += (bool check) => { if (check) { LastCheckedEras.Add(key); } else { LastCheckedEras.Remove(key); } }; EraSubs.Add(new SubIcon { Sub = era.Get <string>("subst"), Icon = icon }); } } }