public CarryMore() { // Add keybinds _pickUpKey = new Keybind("PickUp", "Pick up targeted item", KeyCode.E); _dropAllKey = new Keybind("DropAll", "Drop all items", KeyCode.Y, KeyCode.LeftControl); _dropSelectedKey = new Keybind("DropSelected", "Drop selected item (or last item if the list is hidden)", KeyCode.Y); _toggleGuiKey = new Keybind("ToggleGUI", "Toggle inventory list", KeyCode.X); _toggleSettingsKey = new Keybind("ToggleSettingsGUI", "Toggle settings", KeyCode.X, KeyCode.LeftControl); // Load settings MySettings.Load(SavePath); //_alertVisible = false; // Initialize the item list Items = new ItemList(MySettings.Settings.MaxItems, this); // Initialize list UI _listVisible = false; _listStyle = new GUIStyle(); _listStyle.alignment = TextAnchor.MiddleLeft; _listStyle.fontSize = 12; _listStyle.normal.textColor = Color.white; }
public override void OnSave() { Items.DropAll(); MySettings.Save(SavePath); }
public override void OnGUI() { if (_listVisible) { GUI.Label(new Rect(_listPosLeft - 20.0f, Screen.height - _listPosBottom - _listLineHeight, Screen.width, _listLineHeight), $"Backpack ({Items.Count} / {Items.Capacity})", _listStyle); for (int i = 0; i < Items.Count; ++i) { float top = Screen.height - _listPosBottom - (_listLineHeight * ((Items.Count - i) + 1)); string name = Items[i].name.Replace("(Clone)", "").Replace("(itemx)", "").Replace("(xxxxx)", ""); if (i == Items.SelectedIndex) { GUI.Label(new Rect(_listPosLeft - 20.0f, top, 20.0f, _listLineHeight), ">", _listStyle); } GUI.Label(new Rect(_listPosLeft, top, Screen.width, _listLineHeight), name, _listStyle); } } if (MySettings.GuiVisible) { _playerInMenu.Value = true; GUI.Box(MySettings.GuiBackground, "Settings"); GUILayout.BeginArea(MySettings.GuiArea); GUILayout.BeginVertical(); MySettings.Temporary.LogAll = GUILayout.Toggle(MySettings.Temporary.LogAll, "Log everything"); MySettings.Temporary.LogSome = GUILayout.Toggle(MySettings.Temporary.LogSome, "Log pick-up and drop events"); MySettings.Temporary.AddIfOpen = GUILayout.Toggle(MySettings.Temporary.AddIfOpen, "Pick up only if the list is visible"); MySettings.Temporary.DropIfOpen = GUILayout.Toggle(MySettings.Temporary.DropIfOpen, "Drop only if the list is visible"); GUILayout.Label(string.Format("\nCapacity: {0}", MySettings.Temporary.MaxItems)); MySettings.Temporary.MaxItems = Mathf.RoundToInt(GUILayout.HorizontalSlider(MySettings.Temporary.MaxItems, 1.0f, 50.0f)); GUILayout.Label("WARNING:\nBackpack must be emptied in order to apply the settings."); GUILayout.EndVertical(); GUILayout.BeginHorizontal(); if (GUILayout.Button("OK")) { if (Items.Count > 0) { ModConsole.Error($"[Backpack] Can't apply settings - backpack is not empty ({Items.Count})"); } else { MySettings.Settings.AddIfOpen = MySettings.Temporary.AddIfOpen; MySettings.Settings.DropIfOpen = MySettings.Temporary.DropIfOpen; MySettings.Settings.LogAll = MySettings.Temporary.LogAll; MySettings.Settings.LogSome = MySettings.Temporary.LogSome; MySettings.Settings.MaxItems = MySettings.Temporary.MaxItems; Items.Realloc(); MySettings.Save(SavePath); MySettings.GuiVisible = false; if (!_pauseMenu.activeInHierarchy) { _playerInMenu.Value = false; } } } if (GUILayout.Button("Cancel")) { MySettings.GuiVisible = false; if (!_pauseMenu.activeInHierarchy) { _playerInMenu.Value = false; } } GUILayout.EndHorizontal(); GUILayout.EndArea(); } }