private void SetupWorkshopAssetRows()
        {
            var workshopAssetCount = WorkshopAssetMonitor.Instance.GetWorkshopAssetCount();

            ModLogger.Debug("{0} workshop assets found", workshopAssetCount);
            Enumerable.Range(0, workshopAssetCount).ForEach(i => _rows.Add(_scrollablePanel.AddUIComponent <UIWorkshopAssetRow>()));
        }
        private void PopulateWorkshopAssets()
        {
            var workshopAssetRowDatas = _workshopAssetListState.GetCurrentList();

            ModLogger.Debug("Populate " + workshopAssetRowDatas.Count());
            Enumerable.Range(0, workshopAssetRowDatas.Count).ForEach(i => _rows[i].Load(workshopAssetRowDatas[i], i % 2 == 0));
        }
        public void RemoveRow(IUIWorkshopAssetRowData workshopAssetRowData)
        {
            try
            {
                ModLogger.Debug("Trying to remove row");
                var row = _rows.FirstOrDefault(r => r.WorkshopId == workshopAssetRowData.WorkshopId);
                if (row != null)
                {
                    ModLogger.Debug("Removing row '{0}'", workshopAssetRowData.ReadableName);
                    _scrollablePanel.RemoveUIComponent(row);
                    _rows.Remove(row);
                }
                else
                {
                    ModLogger.Debug("Row '{0}' not found", workshopAssetRowData.ReadableName);
                }

                ClearWorkshopAssets();
                PopulateWorkshopAssets();
            }
            catch (Exception ex)
            {
                ModLogger.Exception(ex);
            }
        }
        protected override void InitializeMonitor()
        {
            ModLogger.Debug("Initializing prop monitor");

            try
            {
                // Clear any existing data from the overwatch container
                OverwatchPropContainer.Instance.ClearCache();

                // Process the list of existing props when initializing to make sure the list is up-to-date
                var capacity = Singleton <PropManager> .instance.m_props.m_buffer.Count();

                Enumerable.Range(0, capacity).DoAll(i => ProcessProp((ushort)i));

                // Store a reference to the current frame index so we know from which frame we need to process on the next update cycle
                MarkFrame();

                // Mark the monitor as initialized and spinning
                MarkInitialized();
                OverwatchControl.Instance.PropMonitorSpun = true;

                ModLogger.Debug("Prop monitor initialized");
            }
            catch (Exception ex)
            {
                ModLogger.Error("An error occured while initializing the prop monitor");
                ModLogger.Exception(ex);
                MarkTerminated();
            }
        }
예제 #5
0
        public sealed override void OnLevelLoaded(LoadMode mode)
        {
            _mode = mode;

            // Don't load in asset and map editor
            if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame)
            {
                return;
            }

            try
            {
                ModLogger.Debug("Creating main window");

                // Get a handle to the main game view
                UIView aView = UIView.GetAView();

                // Create the gameobject and attach a mainwindow instance
                GameObject goMainWindow = new GameObject(WorkshopMonitorMainWindowGameObjectName);
                _mainWindow = goMainWindow.AddComponent <UIMainWindow>();
                _mainWindow.transform.parent = aView.transform;

                ModLogger.Debug("Main window created");
            }
            catch (Exception ex)
            {
                ModLogger.Error("An error occured while creating the main window");
                ModLogger.Exception(ex);
            }
        }
예제 #6
0
        public override void OnLevelUnloading()
        {
            // Don't unload in asset and map editor
            if (_mode != LoadMode.LoadGame && _mode != LoadMode.NewGame)
            {
                return;
            }

            try
            {
                ModLogger.Debug("Destroying main window");

                // Destroy the mainwindow when unloading to make sure a fresh new window is used for the next game
                if (_mainWindow != null)
                {
                    GameObject.Destroy(_mainWindow.gameObject);
                }

                ModLogger.Debug("Main window destroyed");
            }
            catch (Exception ex)
            {
                ModLogger.Error("An error occured while destroying the main window");
                ModLogger.Exception(ex);
            }
        }
        public static bool InitAlbumDatas()
        {
            try
            {
                string activeOption = SingletonScriptableObject <LocalizationSettings> .instance.GetActiveOption("Language");

                string albums_lang   = $"albums_{activeOption}";
                var    configManager = Singleton <ConfigManager> .instance;
                var    m_Dictionary  = (Dictionary <string, JArray>)AccessTools.Field(typeof(ConfigManager), "m_Dictionary").GetValue(configManager);

                if (!m_Dictionary.ContainsKey(albums_lang))
                {
                    // Trigger the load
                    ModLogger.Debug($"Trigger the load{albums_lang}");
                    var notused = Singleton <ConfigManager> .instance["albums"];
                }
                if (!m_Dictionary.ContainsKey(albums_lang))
                {
                    // Trigger failed
                    ModLogger.Debug("Cannot Trigger load Albums title");
                    return(true);
                }
                ModLogger.Debug("Trigger load Albums success");

                var found = false;
                foreach (var obj in m_Dictionary[albums_lang])
                {
                    ModLogger.Debug($"{obj}");
                    if (obj.Value <string>("title") == language[activeOption])
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    // Not Found Custom
                    ModLogger.Debug($"Add {language[activeOption]}");
                    var @object = new JObject();
                    @object.Add("title", language[activeOption]);
                    m_Dictionary[albums_lang].Add(@object);
                }

                var jobj = new JObject();
                jobj.Add("uid", "custom");
                jobj.Add("title", "Custom Maps");
                jobj.Add("prefabsName", "AlbumCustom");
                jobj.Add("price", "Free");
                jobj.Add("jsonName", "custom");
                jobj.Add("needPurchase", false);
                jobj.Add("free", true);
                m_Dictionary["albums"].Add(jobj);
            }
            catch (Exception ex)
            {
                ModLogger.Debug(ex);
            }

            return(true);
        }
        public override void CacheAsset(ushort assetId, Building asset)
        {
            base.CacheAsset(assetId, asset);

            if (asset.Info == null)
            {
                ModLogger.Debug(string.Format("Asset with id {0} has no info", assetId));
                return;
            }

            if (asset.Info.m_props == null)
            {
                ModLogger.Debug(string.Format("Info of asset with id {0} has no props", assetId));
                return;
            }

            for (var i = 0; i < asset.Info.m_props.Length; i++)
            {
                var prop = asset.Info.m_props[i];
                if (prop == null)
                {
                    ModLogger.Debug(string.Format("Asset with id {0} has null-prop at index {1}", assetId, i));
                    return;
                }
                if (prop.m_prop != null)
                {
                    var wrapper = new OverwatchPropWrapper(assetId, i, prop.m_prop);
                    ModLogger.Debug("caching child prop " + wrapper.TechnicalName);
                    OverwatchPropContainer.Instance.CacheChildAsset(wrapper);
                }
            }
        }
        public List <IUIWorkshopAssetRowData> GetCurrentList()
        {
            try
            {
                ModLogger.Debug("Creating workshop item list with filter {0} and sortfield {1}", _currentFilter, _currentSortField);

                // Filter the current list and sort it
                var result = WorkshopAssetMonitor.Instance.GetWorkshopAssets()
                             .Where(a => (a.AssetType & _currentFilter) == a.AssetType)
                             .Cast <IUIWorkshopAssetRowData>()
                             .ToList();

                result.Sort(new WorkshopAssetComparer(_currentSortField, _descending));

                ModLogger.Debug("Created workshop item list with {0} items after filter", result.Count());

                return(result);
            }
            catch (Exception ex)
            {
                ModLogger.Debug("An unexpected error occured while creating a filtered and sorted list of workshop items");
                ModLogger.Exception(ex);
                return(new List <IUIWorkshopAssetRowData>());
            }
        }
예제 #10
0
 private void captionPanel_Sort(object sender, SortEventArgs e)
 {
     ModLogger.Debug("Sorting data on {0}", e.SortField);
     ClearWorkshopAssets();
     _workshopAssetListState.SetSortField(e.SortField);
     PopulateWorkshopAssets();
     ModLogger.Debug("Sorted data on {0}", e.SortField);
 }
예제 #11
0
 private void UICustomButton_eventClick(UIComponent component, UIMouseEventParameter eventParam)
 {
     ModLogger.Debug("Triggering command '{0}' from clickhandler", _command.GetType().Name);
     if (_command != null)
     {
         _command.Execute();
     }
 }
        public void Stop()
        {
            var workshopAssetCount = _workshopAssets.Count;

            _workshopAssets = new List <WorkshopAsset>();

            ModLogger.Debug("WorkshopAssetMonitor unloaded {0} workshop assets", workshopAssetCount);
        }
예제 #13
0
        public override void OnCreated(IThreading threading)
        {
            _initialized = false;
            _terminated  = false;

            base.OnCreated(threading);

            ModLogger.Debug(string.Format("{0} created", _monitorType));
        }
예제 #14
0
        public override void OnReleased()
        {
            _initialized = false;
            _terminated  = false;

            base.OnReleased();

            ModLogger.Debug(string.Format("{0} released", _monitorType));
        }
예제 #15
0
 public void Execute()
 {
     ModLogger.Debug("Executing ShowWorkshopAssetInfo command for workshopid '{0}'", _workshopAssetRowData.WorkshopId);
     if (Steam.IsOverlayEnabled() && _workshopAssetRowData.WorkshopId > 0)
     {
         Steam.ActivateGameOverlayToWorkshopItem(new PublishedFileId(_workshopAssetRowData.WorkshopId));
     }
     else
     {
         ConfirmPanel.ShowModal(UITexts.WorkshopAssetInfoOpenInBrowserTitle, UITexts.WorkshopAssetInfoOpenInBrowserMessage, AskInfoModalCallback);
     }
 }
예제 #16
0
        public static void GetJsonPrefix(string name, bool localization, ref Dictionary <string, JArray> ___m_Dictionary)
        {
            try
            {
                string activeOption = SingletonScriptableObject <LocalizationSettings> .instance.GetActiveOption("Language");

                if (name.StartsWith("ALBUMCUSTOM"))
                {
                    string albums_lang = $"ALBUMCUSTOM_{activeOption}";
                    // Load localization custom album songs, title and another
                    if (!___m_Dictionary.ContainsKey(albums_lang))
                    {
                        ModLogger.Debug($"Load custom album tab: {albums_lang}");
                        var obj = new JObject();
                        obj.Add("name", "测试");
                        obj.Add("author", "某10");

                        var arr = new JArray();
                        arr.Add(obj);

                        ___m_Dictionary.Add(albums_lang, arr);
                    }
                    // Load songs
                    if (!___m_Dictionary.ContainsKey(name))
                    {
                        ModLogger.Debug($"Load custom songs list: {name}");
                        var obj = new JObject();
                        obj.Add("uid", "custom-0");
                        obj.Add("name", "Test");
                        obj.Add("author", "某10");
                        obj.Add("bpm", "128");
                        obj.Add("music", "iyaiya_music");
                        obj.Add("demo", "iyaiya_demo");
                        obj.Add("cover", "iyaiya_cover");
                        obj.Add("noteJson", "iyaiya_map");
                        obj.Add("scene", "scene_05");
                        obj.Add("levelDesigner", "Lyt99");
                        obj.Add("difficulty1", "1");
                        obj.Add("difficulty2", "20");
                        obj.Add("difficulty3", "0");
                        obj.Add("unlockLevel", "1");

                        var arr = new JArray();
                        arr.Add(obj);

                        ___m_Dictionary.Add(name, arr);
                    }
                }
            }catch (Exception ex)
            {
                ModLogger.Debug(ex);
            }
        }
예제 #17
0
 public static void CompTrack(GameObject gameObject, int layer = 0)
 {
     foreach (var comps in gameObject.GetComponents(typeof(object)))
     {
         ModLogger.Debug($"{layer} Name:{gameObject.name} Component:{comps.GetType()}");
     }
     if (gameObject.transform.childCount > 0)
     {
         ++layer;
         for (var i = 0; i < gameObject.transform.childCount; i++)
         {
             CompTrack(gameObject.transform.GetChild(i).gameObject, layer);
         }
     }
 }
예제 #18
0
 protected override void OnKeyDown(UIKeyEventParameter p)
 {
     if (!p.used && p.keycode == KeyCode.Escape)
     {
         ModLogger.Debug("Hiding WorkshopMonitor window");
         this.Hide();
         if (this.parent != null)
         {
             this.parent.Focus();
         }
         p.Use();
         ModLogger.Debug("WorkshopMonitor window hidden");
     }
     base.OnKeyDown(p);
 }
예제 #19
0
        public override void Start()
        {
            ModLogger.Debug("Starting WorkshopMonitor window");

            base.Start();

            // Register this window instance with the commandfactory
            CommandFactory.Instance.SetMainWindow(this);

            _rows = new List <UIWorkshopAssetRow>();
            _workshopAssetListState = new WorkshopAssetListState(AssetType.All);

            // Make the window invisible by default
            Hide();

            // Set the fixed window size
            width  = UIConstants.MainWindowWidth;
            height = UIConstants.MainWindowHeight;

            // Define the window look
            backgroundSprite = UIConstants.MainWindowBackgroundSprite;
            UITextureAtlas atlas = Resources.FindObjectsOfTypeAll <UITextureAtlas>().FirstOrDefault(a => a.name == "Ingame");

            if (atlas != null)
            {
                this.atlas = atlas;
            }

            // Make the window interactive
            canFocus      = true;
            isInteractive = true;

            // Set the layout settings
            autoLayout          = true;
            autoLayoutDirection = LayoutDirection.Vertical;
            autoLayoutPadding   = UIConstants.AutoLayoutPadding;
            autoLayoutStart     = LayoutStart.TopLeft;

            // Create the window panels, scrollpanel and workshopassetrows
            SetupPanels();
            SetupScrollPanel();
            SetupWorkshopAssetRows();

            // Populate the workshopasset with workshopasset data
            PopulateWorkshopAssets();

            ModLogger.Debug("WorkshopMonitor window started");
        }
예제 #20
0
 private void filterPanel_FilterChanged(object sender, FilterChangedEventArgs e)
 {
     try
     {
         ModLogger.Debug("Changing filter to {0}", e.NewFilter);
         ClearWorkshopAssets();
         _workshopAssetListState.SetFilter(e.NewFilter);
         PopulateWorkshopAssets();
         ModLogger.Debug("Changed filter to {0}", e.NewFilter);
     }
     catch (Exception ex)
     {
         ModLogger.Exception(ex);
         throw;
     }
 }
예제 #21
0
        public override void Update()
        {
            base.Update();

            if (isActivationKeyUsed())
            {
                ModLogger.Debug("Displaying WorkshopMonitor window");

                // Always update the workshop monitor before showing the main window to ensure that the latest statistics are loaded
                WorkshopAssetMonitor.Instance.Update();

                showWindow();

                ModLogger.Debug("WorkshopMonitor window displayed");
            }
        }
 private void AskUnsubscribeModalCallback(UIComponent component, int result)
 {
     if (result == 1)
     {
         if (Steam.workshop.Unsubscribe(new PublishedFileId(_workshopAssetRowData.WorkshopId)))
         {
             ModLogger.Debug("Successfully unsubscribed '{0}'", _workshopAssetRowData.ReadableName);
             WorkshopAssetMonitor.Instance.Remove(_workshopAssetRowData.WorkshopAssetId);
             _mainWindow.RemoveRow(_workshopAssetRowData);
         }
         else
         {
             ModLogger.Debug("Failed to unsbuscribe '{0}'", _workshopAssetRowData.ReadableName);
         }
     }
 }
예제 #23
0
        public void SaveConfiguration()
        {
            ModLogger.Debug("Saving configuration to '{0}'", _filename);

            // Make sure the directory exists
            string dirname = Path.GetDirectoryName(_filename);

            if (!string.IsNullOrEmpty(dirname) && !Directory.Exists(dirname))
            {
                Directory.CreateDirectory(dirname);
            }

            // Serialize the configuration to the xml file
            using (StreamWriter sw = new StreamWriter(_filename))
            {
                new XmlSerializer(this.GetType()).Serialize(sw, this);
            }
        }
예제 #24
0
        private void SetupPanels()
        {
            ModLogger.Debug("Setting up panels");

            // Create and add the title panel
            _titlePanel        = AddUIComponent <UITitlePanel>();
            _titlePanel.Parent = this;

            // Create and add the filter panel
            _filterPanel = AddUIComponent <UIAssetTypeFilterPanel>();
            _filterPanel.FilterChanged += filterPanel_FilterChanged;

            // Create and add the caption panel
            _captionPanel       = AddUIComponent <UICaptionPanel>();
            _captionPanel.Sort += captionPanel_Sort;

            ModLogger.Debug("Panels set up");
        }
예제 #25
0
 public static void LoadFromName(string name)
 {
     //if(type != typeof(TextAsset))
     //{
     //    ModLogger.Debug($"type {type} {name}");
     //    return;
     //}
     ModLogger.Debug($"json {name}");
     //string activeOption = SingletonScriptableObject<LocalizationSettings>.instance.GetActiveOption("Language");
     //string albums_lang = $"albums_{activeOption}";
     //if (name.StartsWith(albums_lang))
     //{
     //    ModLogger.Debug($"language {name}");
     //}else if (name.StartsWith("albums"))
     //{
     //    ModLogger.Debug($"json {name}");
     //}
 }
        public void Update()
        {
            try
            {
                int workshopAssetCount = _workshopAssets.Count();

                ModLogger.Debug("WorkshopAssetMonitor is updating {0} workshop assets", workshopAssetCount);
                foreach (var item in _workshopAssets)
                {
                    item.UpdateInstanceCount();
                }
                ModLogger.Debug("WorkshopMonitor updated {0} workshop assets", workshopAssetCount);
            }
            catch (Exception ex)
            {
                ModLogger.Error("An error occured while updating the workshop item list, the numbers displayed could be incorrect");
                ModLogger.Exception(ex);
            }
        }
예제 #27
0
        public override void OnLevelUnloading()
        {
            // Don't stop in asset and map editor
            if (_mode != LoadMode.LoadGame && _mode != LoadMode.NewGame)
            {
                return;
            }

            try
            {
                ModLogger.Debug("Stopping WorkshopAssetMonitor");
                WorkshopAssetMonitor.Instance.Stop();
                ModLogger.Debug("WorkshopAssetMonitor stopped");
            }
            catch (Exception ex)
            {
                ModLogger.Error("An error occured while stopping the WorkshopAssetMonitor");
                ModLogger.Exception(ex);
            }
        }
예제 #28
0
        public static bool OnEnable()
        {
            try
            {
                int   num             = Singleton <ConfigManager> .instance["albums"].Count - 2;
                int[] freeAlbumIndexs = Singleton <WeekFreeManager> .instance.freeAlbumIndexs;
                Dictionary <int, Transform> dictionary = new Dictionary <int, Transform>();
                for (int i = 1; i < num; i++)
                {
                    Transform value = GameObject.Find(string.Format("ImgAlbum{0}", i)).transform;
                    int       key   = num - i + 2;
                    dictionary.Add(key, value);
                }
                dictionary = (from d in dictionary
                              orderby d.Key descending
                              select d).ToDictionary((KeyValuePair <int, Transform> d) => d.Key, (KeyValuePair <int, Transform> d) => d.Value);
                foreach (KeyValuePair <int, Transform> keyValuePair in dictionary)
                {
                    keyValuePair.Value.SetSiblingIndex(keyValuePair.Key);
                }
                if (freeAlbumIndexs != null && freeAlbumIndexs.Length > 0)
                {
                    for (int j = 0; j < freeAlbumIndexs.Length; j++)
                    {
                        int       num2      = freeAlbumIndexs[j];
                        Transform transform = GameObject.Find(string.Format("ImgAlbum{0}", num2)).transform;
                        transform.SetSiblingIndex(j + 3);
                    }
                }
            }
            catch (Exception ex)
            {
                ModLogger.Debug(ex);
            }

            return(false);
        }
예제 #29
0
        public static ConfigurationContainer LoadConfiguration(string filename)
        {
            ModLogger.Debug("Loading configuration from '{0}'", filename);

            ConfigurationContainer result = null;

            // Check if the file exists. If so, deserialize it to a new instance. If not so, create a new empty instance
            if (File.Exists(filename))
            {
                using (StreamReader sr = new StreamReader(filename))
                    result = (ConfigurationContainer) new XmlSerializer(typeof(ConfigurationContainer)).Deserialize(sr);
            }
            else
            {
                result = new ConfigurationContainer();
            }

            // Assign the filename to the result. This is used later on when saving the configuration.
            result._filename = filename;

            ModLogger.Debug("Configuration loaded from '{0}'", filename);

            return(result);
        }
예제 #30
0
        public static void RebuildChildren(FancyScrollView __instance)
        {
            if (__instance.name == "FancyScrollAlbum")
            {
                string activeOption = SingletonScriptableObject <LocalizationSettings> .instance.GetActiveOption("Language");

                if (GameObject.Find($"ImgAlbumCustom") == null)
                {
                    // Add new tab gameobject
                    var        gameobject = GameObject.Find("ImgAlbumCollection");
                    GameObject customTab  = GameObject.Instantiate(gameobject, gameobject.transform.parent);
                    customTab.name = $"ImgAlbumCustom";

                    customTab.transform.SetSiblingIndex(2);
                    // CompTrack(gameobject.transform.parent.gameObject);
                    CompTrack(customTab);
                    var a = customTab.GetComponent <VariableBehaviour>();
                    if (a != null)
                    {
                        ModLogger.Debug($"{a.result}:{a.variable.result}  {a.variable}");
                    }
                    var b = customTab.transform.Find("TxtAlbumTitle");
                    if (b != null)
                    {
                        b.GetComponent <UnityEngine.UI.Text>().text = language[activeOption];
                        var l18n = b.GetComponent <Localization>();
                        foreach (var opt in l18n.optionPairs)
                        {
                            ((TextOption)opt.option).value = language[opt.optionEntry.name];
                            ModLogger.Debug($" opt:{opt.optionEntry.name}  val:{((TextOption)opt.option).value.ToString()}");
                        }
                    }
                    ModLogger.Debug("Add custom map tab");
                }
            }
        }