diff --git a/.gitignore b/.gitignore index a0c1ddc..2bac753 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ bld/ [Oo]ut/ [Ll]og/ [Ll]ogs/ +Library/ # Visual Studio 2015/2017 cache/options directory .vs/ @@ -345,3 +346,4 @@ MigrationBackup/ # Fody - auto-generated XML schema FodyWeavers.xsd libs +/Divinity Chronicles/ScriptTrainer/Scripts.cs diff --git a/.gitmodules b/.gitmodules index 8691e72..529feaf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "Dyson Sphere Program/ScriptTrainer/UnityGameUI"] path = Dyson Sphere Program/ScriptTrainer/UnityGameUI url = https://github.com/GlossMod/UnityGameUI.git +[submodule "Potion Craft/ScriptTrainer/UnityGameUI"] + path = Potion Craft/ScriptTrainer/UnityGameUI + url = https://github.com/jim972329667/UnityGameUI.git \ No newline at end of file diff --git a/Against the Storm/ScriptTrainer.sln b/Against the Storm/ScriptTrainer.sln new file mode 100644 index 0000000..a370877 --- /dev/null +++ b/Against the Storm/ScriptTrainer.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32602.215 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptTrainer", "ScriptTrainer\ScriptTrainer.csproj", "{56B71F4D-F911-4369-87C0-F13AD81535C2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {56B71F4D-F911-4369-87C0-F13AD81535C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {56B71F4D-F911-4369-87C0-F13AD81535C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {56B71F4D-F911-4369-87C0-F13AD81535C2}.Debug|x86.ActiveCfg = Debug|x86 + {56B71F4D-F911-4369-87C0-F13AD81535C2}.Debug|x86.Build.0 = Debug|x86 + {56B71F4D-F911-4369-87C0-F13AD81535C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {56B71F4D-F911-4369-87C0-F13AD81535C2}.Release|Any CPU.Build.0 = Release|Any CPU + {56B71F4D-F911-4369-87C0-F13AD81535C2}.Release|x86.ActiveCfg = Release|x86 + {56B71F4D-F911-4369-87C0-F13AD81535C2}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DF11F9A6-5955-4B29-8D1A-BD80EF1C6103} + EndGlobalSection +EndGlobal diff --git a/Against the Storm/ScriptTrainer/BuildingWindows.cs b/Against the Storm/ScriptTrainer/BuildingWindows.cs new file mode 100644 index 0000000..c6e8a77 --- /dev/null +++ b/Against the Storm/ScriptTrainer/BuildingWindows.cs @@ -0,0 +1,486 @@ +using Eremite.Controller; +using Eremite.Model.Effects; +using Eremite.Model; +using Eremite.Tools.Runtime; +using Eremite.View.HUD.Construction; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine.Events; +using UnityEngine.UI; +using UnityEngine; +using UnityGameUI; +using Object = UnityEngine.Object; +using Eremite.Buildings; + +namespace ScriptTrainer +{ + internal class BuildingWindows : MonoBehaviour + { + public static BuildingWindows Instance { get; private set; } + public static GameObject Panel; + private static int initialX; + private static int initialY; + private static int elementX; + private static int elementY; + + #region[数据分页相关] + private static GameObject ItemPanel; + private static List ItemButtons = new List(); + private static int page = 1; + private static int maxPage = 1; + private static int conunt = 15; + private static string searchText = ""; + private static GameObject uiText; + public static bool Initialized = false; + + public static int SelectIndex = 0; + public static Dropdown EffectDropdown; + + + private static string uiText_text + { + get + { + return $"{page} / {maxPage}"; + } + } + #endregion + + public BuildingWindows(GameObject panel, int x, int y) + { + Instance = this; + Panel = panel; + initialX = elementX = x + 50; + initialY = elementY = y; + } + + public GameObject AddDropdown(string Text, int width, List options, GameObject panel, UnityAction action) + { + // 计算x轴偏移 + elementX += width / 2 - 30; + + // label + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(panel, txtBgSprite, "#FFFFFFFF"); + uiText.GetComponent().text = Text; + uiText.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + //uiText.GetComponent().sizeDelta = new Vector2(60, 30); + uiText.GetComponent().alignment = TextAnchor.MiddleLeft; + + // 坐标偏移 + elementX += 40; + + // 创建下拉框 + Sprite dropdownBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); // 背景颜色 + Sprite dropdownScrollbarSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#8C9EFFFF")); // 滚动条颜色 (如果有的话 + Sprite dropdownDropDownSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); // 框右侧小点的颜色 + Sprite dropdownCheckmarkSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#8C9EFFFF")); // 选中时的颜色 + Sprite dropdownMaskSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#E65100FF")); // 不知道是哪的颜色 + Color LabelColor = UIControls.HTMLString2Color("#EFEBE9FF"); + GameObject uiDropDown = UIControls.createUIDropDown(panel, dropdownBgSprite, dropdownScrollbarSprite, dropdownDropDownSprite, dropdownCheckmarkSprite, dropdownMaskSprite, options, LabelColor); + Object.DontDestroyOnLoad(uiDropDown); + uiDropDown.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + // 下拉框选中时触发方法 + uiDropDown.GetComponent().onValueChanged.AddListener(action); + + elementX += width / 2 + 60; + return uiDropDown; + } + public void Initialize() + { + //创建搜索框 + SearchBar(Panel); + elementX += 200; + //MainWindow.AddButton(ref elementX, ref elementY, "保存效果", Panel, () => + //{ + // if (GameController.Instance != null) + // Scripts.SaveEffects(ScriptPatch.AddEffects); + //}); + //MainWindow.AddButton(ref elementX, ref elementY, "载入效果", Panel, () => + //{ + // if (GameController.Instance != null) + // SpawnItemNames(Scripts.LoadEffects()); + //}); + //elementX -= 60; + var DropDown = AddDropdown("类型", 250, ZGGameObject.BuildingModels.Keys.ToList(), Panel, (int count) => + { + if (SelectIndex != count) + page = 1; + SelectIndex = count; + container(count); + }); + EffectDropdown = DropDown.GetComponent(); + elementY += 10; + + hr(); + + //创建物品列表 + //elementX += 200; + + //创建分页 + container(SelectIndex); + + elementY = 125 - 60 * 5; + PageBar(Panel); + + Initialized = true; + } + + #region[创建详细] + //搜索框 + private void SearchBar(GameObject panel) + { + elementY += 10; + elementX = -MainWindow.width / 2 + 120; + //label + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject suiText = UIControls.createUIText(panel, txtBgSprite, "#FFFFFFFF"); + suiText.GetComponent().text = "搜索"; + suiText.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + suiText.GetComponent().sizeDelta = new Vector2(60, 30); + suiText.GetComponent().alignment = TextAnchor.MiddleLeft; + + //坐标偏移 + elementX += -20; + + //输入框 + int w = 150; + Sprite inputFieldSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); + GameObject uiInputField = UIControls.createUIInputField(panel, inputFieldSprite, "#FFFFFFFF"); + uiInputField.GetComponent().text = searchText; + uiInputField.GetComponent().localPosition = new Vector3(elementX + 100, elementY, 0); + uiInputField.GetComponent().sizeDelta = new Vector2(w, 30); + + + //文本框失去焦点时触发方法 + uiInputField.GetComponent().onEndEdit.AddListener((string text) => + { + //Debug.Log(text); + page = 1; + searchText = text; + container(SelectIndex); + uiText.GetComponent().text = uiText_text; + //Destroy(ItemPanel); + }); + } + //分页 + private void PageBar(GameObject panel) + { + //背景 + GameObject pageObj = UIControls.createUIPanel(panel, "40", "500"); + pageObj.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + pageObj.GetComponent().localPosition = new Vector3(0, elementY, 0); + + //当前页数 / 总页数 + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + + if (uiText == null) + { + uiText = UIControls.createUIText(pageObj, txtBgSprite, "#ffFFFFFF"); + uiText.GetComponent().text = uiText_text; + uiText.GetComponent().localPosition = new Vector3(0, 0, 0); + //设置字体 + uiText.GetComponent().fontSize = 20; + uiText.GetComponent().alignment = TextAnchor.MiddleCenter; + } + + + //上一页 + string backgroundColor = "#8C9EFFFF"; + GameObject prevBtn = UIControls.createUIButton(pageObj, backgroundColor, "上一页", () => + { + + page--; + if (page <= 0) page = 1; + container(SelectIndex); + uiText.GetComponent().text = uiText_text; + }, new Vector3()); + prevBtn.GetComponent().sizeDelta = new Vector2(60, 20); + prevBtn.GetComponent().localPosition = new Vector3(-100, 0, 0); + + //下一页 + GameObject nextBtn = UIControls.createUIButton(pageObj, backgroundColor, "下一页", () => + { + page++; + if (page >= maxPage) page = maxPage; + container(SelectIndex); + uiText.GetComponent().text = uiText_text; + }); + nextBtn.GetComponent().sizeDelta = new Vector2(60, 20); + nextBtn.GetComponent().localPosition = new Vector3(100, 0, 0); + } + private static void container(int index = 0) + { + elementX = -200; + elementY = 125; + + //先清空旧的 ItemPanel + foreach (var item in ItemButtons) + { + UnityEngine.Object.Destroy(item); + } + ItemButtons.Clear(); + + ItemPanel = UIControls.createUIPanel(Panel, "300", "600"); + ItemPanel.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + ItemPanel.GetComponent().anchoredPosition = new Vector2(10, 0); + + int num = 0; + foreach (BuildingModel item in GetItemData(index)) + { + var btn = CreateItemButton("获得", item, ItemPanel, () => + { + SpawnItem(item); + }); + ItemButtons.Add(btn); + num++; + if (num % 3 == 0) + { + hr(); + } + } + } + + public static void SpawnDescriptionInputDialog(string ButtonText, string Description, UnityAction onFinish) + { + //创建画布 + GameObject canvas = UIControls.createUICanvas(); + Object.DontDestroyOnLoad(canvas); + //设置置顶显示 + canvas.GetComponent().overrideSorting = true; + canvas.GetComponent().sortingOrder = 100; + //分割物品介绍,设置界面大小 + List outlines = Description.GetSeparateSubString(18); + int size = outlines.Count * 20 + 20 + 40; + // 创建面板 + GameObject uiPanel = UIControls.createUIPanel(canvas, size.ToString(), "300", null); + uiPanel.GetComponent().color = UIControls.HTMLString2Color("#37474FFF"); + //创建物品介绍 + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + string DefaultColor = "#FFFFFFFF"; + for (int i = 0; i < outlines.Count; i++) + { + GameObject uiText = UIControls.createUIText(uiPanel, txtBgSprite, DefaultColor); + uiText.GetComponent().text = outlines[i]; + uiText.GetComponent().localPosition = new Vector2(0, size / 2 - 20 - 20 * i); + uiText.GetComponent().sizeDelta = new Vector2(280, 20); + uiText.GetComponent().fontSize = 14; + } + //创建确定按钮 + GameObject uiButton = UIControls.createUIButton(uiPanel, "#8C9EFFFF", ButtonText, () => + { + onFinish(); + Object.Destroy(canvas); + }, new Vector3(100, -size / 2 + 30, 0)); + + //创建关闭按钮 + GameObject closeButton = UIControls.createUIButton(uiPanel, "#B71C1CFF", "X", () => + { + Object.Destroy(canvas); + }, new Vector3(350 / 2 - 10, size / 2 - 10, 0)); + //设置closeButton宽高 + closeButton.GetComponent().sizeDelta = new Vector2(20, 20); + //字体颜色为白色 + closeButton.GetComponentInChildren().color = UIControls.HTMLString2Color("#FFFFFFFF"); + } + private static GameObject CreateItemButton(string ButtonText, BuildingModel item, GameObject panel, UnityAction action) + { + //按钮宽 200 高 50 + int buttonWidth = 190; + int buttonHeight = 50; + + //根据品质设置背景颜色 + string qualityColor = "#FFFFFFFF"; + + //创建一个背景 + GameObject background = UIControls.createUIPanel(panel, buttonHeight.ToString(), buttonWidth.ToString(), null); + background.GetComponent().color = UIControls.HTMLString2Color("#455A64FF"); + background.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + var tool = background.AddComponent(); + tool.SetBuilding(item); + + GameObject background_icon = UIControls.createUIPanel(background, buttonHeight.ToString(), "50", null); + background_icon.GetComponent().color = UIControls.HTMLString2Color(qualityColor); + background_icon.GetComponent().anchoredPosition = new Vector2(70, 0); + + GameObject icon = UIControls.createUIImage(background_icon, GetItemIcon(item)); + icon.GetComponent().sizeDelta = new Vector2(60, 60); + icon.GetComponent().localPosition = new Vector2(0, 0); + + //创建文字 + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(background, txtBgSprite, ColorUtility.ToHtmlStringRGBA(Color.white)); + uiText.GetComponent().text = GetItemName(item); + uiText.GetComponent().localPosition = new Vector3(0, 5, 0); + + //创建按钮 + string backgroundColor_btn = "#8C9EFFFF"; + GameObject button = UIControls.createUIButton(background, backgroundColor_btn, ButtonText, action, new Vector3()); + button.GetComponent().sizeDelta = new Vector2(60, 20); + button.GetComponent().localPosition = new Vector3(-50, -10, 0); + + elementX += 200; + + return background; + } + public static GameObject AddToggle(string Text, int width, GameObject panel, UnityAction action) + { + //计算x轴偏移 + elementX += width / 2 - 30; + + Sprite toggleBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture(ColorUtility.ToHtmlStringRGBA(Color.white))); + Sprite toggleSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#18FFFFFF")); + GameObject uiToggle = UIControls.createUIToggle(panel, toggleBgSprite, toggleSprite); + uiToggle.GetComponentInChildren().color = Color.white; + uiToggle.GetComponentInChildren().isOn = false; + uiToggle.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + uiToggle.GetComponentInChildren().text = Text; + uiToggle.GetComponentInChildren().onValueChanged.AddListener(action); + + + elementX += width / 2 + 10; + + return uiToggle; + } + private static void hr() + { + elementX = initialX; + elementY -= 60; + } + + #endregion + + public static void SpawnItem(BuildingModel item) + { + if (GameController.Instance != null) + { + try + { + var bpanel = Resources.FindObjectsOfTypeAll(); + if (bpanel == null || bpanel.Length == 0) + { + ScriptTrainer.WriteLog($"未找到Panel : {item.Name} {item.GetType()}"); + return; + } + bpanel[0].OnBuildingClicked(item); + MainWindow.OptionToggle = false; + ScriptTrainer.WriteLog($"添加建筑 {item.Name} {item.GetType()}"); + } + catch (Exception ex) + { + ScriptTrainer.WriteLog($"添加建筑 {item.Name} {item.GetType()} 错误:{ex.Message}"); + //Debug.LogException(ex); + } + } + else + { + ScriptTrainer.WriteLog("ZG:没有打开游戏!"); + } + + } + + #region[获取数据相关函数] + private static List GetItemData(int index) + { + List ItemData = ZGGameObject.BuildingModels[EffectDropdown.options[index].text]; + //ScriptTrainer.WriteLog($"ZG:全物品数量:{ItemData.Count}"); + string Lines = string.Empty; + //foreach( var item in ItemData) + //{ + // Lines += $"{item.DisplayName};{item.GetType()};{item.Name}\n"; + // //ScriptTrainer.WriteLog($"ZG:物品类型:{item.GetType()};名称:{item.Name}"); + //} + //File.WriteAllText("F:\\AllItems.txt", Lines); + if (searchText != "") + { + ItemData = FilterItemData(ItemData); + } + //Curse诅咒 Magazine + //对 DataList 进行分页 + List list = new List(); + int start = (page - 1) * conunt; + int end = start + conunt; + for (int i = start; i < end; i++) + { + if (i < ItemData.Count) + { + list.Add(ItemData[i]); + } + } + if (ItemData.Count % conunt != 0) + maxPage = ItemData.Count / conunt + 1; + else + maxPage = ItemData.Count / conunt; + if (uiText?.GetComponent()) + { + uiText.GetComponent().text = uiText_text; + } + + return list; + } + //搜索过滤 + private static List FilterItemData(List dataList) + { + if (searchText == "") + { + return dataList; + } + List list = new List(); + + foreach (var item in dataList) + { + string text = GetItemName(item); + string text2 = GetItemDescription(item); + if (text.Contains(searchText.Replace(" ", "")) || text2.Contains(searchText.Replace(" ", ""))) + { + list.Add(item); + } + } + + return list; + } + private static string GetItemName(BuildingModel item) + { + if (item.displayName.Text == ">Missing key<") + return item.Name; + string dis; + try + { + dis = item.displayName.Text; + } + catch + { + dis = item.Name; + } + return dis; + } + private static string GetItemDescription(BuildingModel item) + { + if (item.Description == ">Missing key<") + return item.Name; + string dis; + try + { + dis = item.Description; + } + catch + { + dis = item.Name; + } + return dis; + } + private static Sprite GetItemIcon(BuildingModel item) + { + return item.icon; + } + #endregion + + + } +} diff --git a/Against the Storm/ScriptTrainer/EffectWindows.cs b/Against the Storm/ScriptTrainer/EffectWindows.cs new file mode 100644 index 0000000..ae5971e --- /dev/null +++ b/Against the Storm/ScriptTrainer/EffectWindows.cs @@ -0,0 +1,519 @@ +using Eremite.Buildings.UI; +using Eremite.Controller; +using Eremite.Model; +using Eremite.Model.Effects; +using Eremite.Model.State; +using Eremite.Tools.Runtime; +using Eremite.View.HUD.Construction; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Xml.Linq; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.UI; +using UnityGameUI; +using Object = UnityEngine.Object; + +namespace ScriptTrainer +{ + internal class EffectWindows : MonoBehaviour + { + public static EffectWindows Instance { get; private set; } + public static GameObject Panel; + private static int initialX; + private static int initialY; + private static int elementX; + private static int elementY; + + #region[数据分页相关] + private static GameObject ItemPanel; + private static List ItemButtons = new List(); + private static int page = 1; + private static int maxPage = 1; + private static int conunt = 15; + private static string searchText = ""; + private static GameObject uiText; + public static bool Initialized = false; + + public static int SelectIndex = 0; + public static Dropdown EffectDropdown; + + + private static string uiText_text + { + get + { + return $"{page} / {maxPage}"; + } + } + #endregion + + public EffectWindows(GameObject panel, int x, int y) + { + Instance = this; + Panel = panel; + initialX = elementX = x + 50; + initialY = elementY = y; + } + + public GameObject AddDropdown(string Text, int width, List options, GameObject panel, UnityAction action) + { + // 计算x轴偏移 + elementX += width / 2 - 30; + + // label + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(panel, txtBgSprite, "#FFFFFFFF"); + uiText.GetComponent().text = Text; + uiText.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + //uiText.GetComponent().sizeDelta = new Vector2(60, 30); + uiText.GetComponent().alignment = TextAnchor.MiddleLeft; + + // 坐标偏移 + elementX += 40; + + // 创建下拉框 + Sprite dropdownBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); // 背景颜色 + Sprite dropdownScrollbarSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#8C9EFFFF")); // 滚动条颜色 (如果有的话 + Sprite dropdownDropDownSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); // 框右侧小点的颜色 + Sprite dropdownCheckmarkSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#8C9EFFFF")); // 选中时的颜色 + Sprite dropdownMaskSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#E65100FF")); // 不知道是哪的颜色 + Color LabelColor = UIControls.HTMLString2Color("#EFEBE9FF"); + GameObject uiDropDown = UIControls.createUIDropDown(panel, dropdownBgSprite, dropdownScrollbarSprite, dropdownDropDownSprite, dropdownCheckmarkSprite, dropdownMaskSprite, options, LabelColor); + Object.DontDestroyOnLoad(uiDropDown); + uiDropDown.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + // 下拉框选中时触发方法 + uiDropDown.GetComponent().onValueChanged.AddListener(action); + + elementX += width / 2 + 60; + return uiDropDown; + } + public void Initialize() + { + //创建搜索框 + SearchBar(Panel); + elementX += 200; + MainWindow.AddButton(ref elementX, ref elementY, "保存效果", Panel, () => + { + if (GameController.Instance != null) + Scripts.SaveEffects(ScriptPatch.AddEffects); + }); + MainWindow.AddButton(ref elementX, ref elementY, "载入效果", Panel, () => + { + if (GameController.Instance != null) + SpawnItemNames(Scripts.LoadEffects()); + }); + elementX -= 60; + var DropDown = AddDropdown("类型", 250, ZGGameObject.EffectModels.Keys.ToList(), Panel, (int count) => + { + if (SelectIndex != count) + page = 1; + SelectIndex = count; + container(count); + }); + EffectDropdown = DropDown.GetComponent(); + elementY += 10; + + hr(); + + //创建物品列表 + //elementX += 200; + + //创建分页 + container(SelectIndex); + + elementY = 125 - 60 * 5; + PageBar(Panel); + + Initialized = true; + } + + #region[创建详细] + //搜索框 + private void SearchBar(GameObject panel) + { + elementY += 10; + elementX = -MainWindow.width / 2 + 120; + //label + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(panel, txtBgSprite, "#FFFFFFFF"); + uiText.GetComponent().text = "搜索"; + uiText.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + uiText.GetComponent().sizeDelta = new Vector2(60, 30); + uiText.GetComponent().alignment = TextAnchor.MiddleLeft; + + //坐标偏移 + elementX += -20; + + //输入框 + int w = 150; + Sprite inputFieldSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); + GameObject uiInputField = UIControls.createUIInputField(panel, inputFieldSprite, "#FFFFFFFF"); + uiInputField.GetComponent().text = searchText; + uiInputField.GetComponent().localPosition = new Vector3(elementX + 100, elementY, 0); + uiInputField.GetComponent().sizeDelta = new Vector2(w, 30); + + + //文本框失去焦点时触发方法 + uiInputField.GetComponent().onEndEdit.AddListener((string text) => + { + //Debug.Log(text); + page = 1; + searchText = text; + container(SelectIndex); + EffectWindows.uiText.GetComponent().text = uiText_text; + //Destroy(ItemPanel); + }); + } + //分页 + private void PageBar(GameObject panel) + { + //背景 + GameObject pageObj = UIControls.createUIPanel(panel, "40", "500"); + pageObj.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + pageObj.GetComponent().localPosition = new Vector3(0, elementY, 0); + + //当前页数 / 总页数 + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + + if (uiText == null) + { + uiText = UIControls.createUIText(pageObj, txtBgSprite, "#ffFFFFFF"); + uiText.GetComponent().text = uiText_text; + uiText.GetComponent().localPosition = new Vector3(0, 0, 0); + //设置字体 + uiText.GetComponent().fontSize = 20; + uiText.GetComponent().alignment = TextAnchor.MiddleCenter; + } + + + //上一页 + string backgroundColor = "#8C9EFFFF"; + GameObject prevBtn = UIControls.createUIButton(pageObj, backgroundColor, "上一页", () => + { + + page--; + if (page <= 0) page = 1; + container(SelectIndex); + uiText.GetComponent().text = uiText_text; + }, new Vector3()); + prevBtn.GetComponent().sizeDelta = new Vector2(60, 20); + prevBtn.GetComponent().localPosition = new Vector3(-100, 0, 0); + + //下一页 + GameObject nextBtn = UIControls.createUIButton(pageObj, backgroundColor, "下一页", () => + { + page++; + if (page >= maxPage) page = maxPage; + container(SelectIndex); + uiText.GetComponent().text = uiText_text; + }); + nextBtn.GetComponent().sizeDelta = new Vector2(60, 20); + nextBtn.GetComponent().localPosition = new Vector3(100, 0, 0); + } + private static void container(int index = 0) + { + elementX = -200; + elementY = 125; + + //先清空旧的 ItemPanel + foreach (var item in ItemButtons) + { + UnityEngine.Object.Destroy(item); + } + ItemButtons.Clear(); + + ItemPanel = UIControls.createUIPanel(Panel, "300", "600"); + ItemPanel.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + ItemPanel.GetComponent().anchoredPosition = new Vector2(10, 0); + + int num = 0; + foreach (EffectModel item in GetItemData(index)) + { + var btn = CreateItemButton("获得", item, ItemPanel, () => + { + ScriptPatch.AddEffects.Add(item.Name); + SpawnItem(item); + }); + ItemButtons.Add(btn); + num++; + if (num % 3 == 0) + { + hr(); + } + } + } + + public static void SpawnDescriptionInputDialog(string ButtonText, string Description, UnityAction onFinish) + { + //创建画布 + GameObject canvas = UIControls.createUICanvas(); + Object.DontDestroyOnLoad(canvas); + //设置置顶显示 + canvas.GetComponent().overrideSorting = true; + canvas.GetComponent().sortingOrder = 100; + //分割物品介绍,设置界面大小 + List outlines = Description.GetSeparateSubString(18); + int size = outlines.Count * 20 + 20 + 40; + // 创建面板 + GameObject uiPanel = UIControls.createUIPanel(canvas, size.ToString(), "300", null); + uiPanel.GetComponent().color = UIControls.HTMLString2Color("#37474FFF"); + //创建物品介绍 + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + string DefaultColor = "#FFFFFFFF"; + for (int i = 0; i < outlines.Count; i++) + { + GameObject uiText = UIControls.createUIText(uiPanel, txtBgSprite, DefaultColor); + uiText.GetComponent().text = outlines[i]; + uiText.GetComponent().localPosition = new Vector2(0, size / 2 - 20 - 20 * i); + uiText.GetComponent().sizeDelta = new Vector2(280, 20); + uiText.GetComponent().fontSize = 14; + } + //创建确定按钮 + GameObject uiButton = UIControls.createUIButton(uiPanel, "#8C9EFFFF", ButtonText, () => + { + onFinish(); + Object.Destroy(canvas); + }, new Vector3(100, -size / 2 + 30, 0)); + + //创建关闭按钮 + GameObject closeButton = UIControls.createUIButton(uiPanel, "#B71C1CFF", "X", () => + { + Object.Destroy(canvas); + }, new Vector3(350 / 2 - 10, size / 2 - 10, 0)); + //设置closeButton宽高 + closeButton.GetComponent().sizeDelta = new Vector2(20, 20); + //字体颜色为白色 + closeButton.GetComponentInChildren().color = UIControls.HTMLString2Color("#FFFFFFFF"); + } + private static GameObject CreateItemButton(string ButtonText, EffectModel item, GameObject panel, UnityAction action) + { + //按钮宽 200 高 50 + int buttonWidth = 190; + int buttonHeight = 50; + + //根据品质设置背景颜色 + string qualityColor = "#FFFFFFFF"; + + //创建一个背景 + GameObject background = UIControls.createUIPanel(panel, buttonHeight.ToString(), buttonWidth.ToString(), null); + background.GetComponent().color = UIControls.HTMLString2Color("#455A64FF"); + background.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + var tool = background.AddComponent(); + tool.SetModel(item); + + GameObject background_icon = UIControls.createUIPanel(background, buttonHeight.ToString(), "50", null); + background_icon.GetComponent().color = UIControls.HTMLString2Color(qualityColor); + background_icon.GetComponent().anchoredPosition = new Vector2(70, 0); + + GameObject icon = UIControls.createUIImage(background_icon, GetItemIcon(item)); + icon.GetComponent().sizeDelta = new Vector2(60, 60); + icon.GetComponent().localPosition = new Vector2(0, 0); + + //创建文字 + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(background, txtBgSprite, ColorUtility.ToHtmlStringRGBA(Color.white)); + uiText.GetComponent().text = GetItemName(item); + uiText.GetComponent().localPosition = new Vector3(0, 5, 0); + + //创建按钮 + string backgroundColor_btn = "#8C9EFFFF"; + GameObject button = UIControls.createUIButton(background, backgroundColor_btn, ButtonText, action, new Vector3()); + button.GetComponent().sizeDelta = new Vector2(60, 20); + button.GetComponent().localPosition = new Vector3(-50, -10, 0); + + elementX += 200; + + return background; + } + public static GameObject AddToggle(string Text, int width, GameObject panel, UnityAction action) + { + //计算x轴偏移 + elementX += width / 2 - 30; + + Sprite toggleBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture(ColorUtility.ToHtmlStringRGBA(Color.white))); + Sprite toggleSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#18FFFFFF")); + GameObject uiToggle = UIControls.createUIToggle(panel, toggleBgSprite, toggleSprite); + uiToggle.GetComponentInChildren().color = Color.white; + uiToggle.GetComponentInChildren().isOn = false; + uiToggle.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + uiToggle.GetComponentInChildren().text = Text; + uiToggle.GetComponentInChildren().onValueChanged.AddListener(action); + + + elementX += width / 2 + 10; + + return uiToggle; + } + private static void hr() + { + elementX = initialX; + elementY -= 60; + } + + #endregion + + public static void SpawnItem(EffectModel item) + { + if (GameController.Instance != null) + { + try + { + ScriptTrainer.WriteLog($"{item.Name}:{item.DisplayName.Trim().ToLower()}:{item.Description.Trim().ToLower()}"); + if(item is ReplaceBuildingEffectModel replace) + { + if(replace.building == null) + { + ScriptTrainer.WriteLog($"无建筑 : {item.Name} {item.GetType()}"); + return; + } + var bpanel = Resources.FindObjectsOfTypeAll(); + if(bpanel == null || bpanel.Length == 0) + { + ScriptTrainer.WriteLog($"未找到Panel : {item.Name} {item.GetType()}"); + return; + } + bpanel[0].OnBuildingClicked(replace.building); + MainWindow.OptionToggle = false; + } + else + { + item.Apply(EffectContextType.None, null, 0); + } + ScriptTrainer.WriteLog($"添加物品 {item.Name} {item.GetType()}"); + } + catch(Exception ex) + { + ScriptTrainer.WriteLog($"添加物品 {item.Name} {item.GetType()} 错误:{ex.Message}"); + //Debug.LogException(ex); + } + } + else + { + ScriptTrainer.WriteLog("ZG:没有打开游戏!"); + } + + } + public static void SpawnItemNames(List items) + { + if (GameController.Instance != null) + { + foreach(var item in items) + { + try + { + EffectsRuntimeTools.AddEffect(item); + ScriptPatch.AddEffects.Add(item); + } + catch(Exception ex) + { + Debug.LogException(ex); + } + } + } + else + { + ScriptTrainer.WriteLog("ZG:没有打开游戏!"); + } + + } + + #region[获取数据相关函数] + private static List GetItemData(int index) + { + List ItemData = ZGGameObject.EffectModels[EffectDropdown.options[index].text]; + //ScriptTrainer.WriteLog($"ZG:全物品数量:{ItemData.Count}"); + string Lines = string.Empty; + //foreach( var item in ItemData) + //{ + // Lines += $"{item.DisplayName};{item.GetType()};{item.Name}\n"; + // //ScriptTrainer.WriteLog($"ZG:物品类型:{item.GetType()};名称:{item.Name}"); + //} + //File.WriteAllText("F:\\AllItems.txt", Lines); + if (searchText != "") + { + ItemData = FilterItemData(ItemData); + } + //Curse诅咒 Magazine + //对 DataList 进行分页 + List list = new List(); + int start = (page - 1) * conunt; + int end = start + conunt; + for (int i = start; i < end; i++) + { + if (i < ItemData.Count) + { + list.Add(ItemData[i]); + } + } + if (ItemData.Count % conunt != 0) + maxPage = ItemData.Count / conunt + 1; + else + maxPage = ItemData.Count / conunt; + if (uiText?.GetComponent()) + { + uiText.GetComponent().text = uiText_text; + } + + return list; + } + //搜索过滤 + private static List FilterItemData(List dataList) + { + if (searchText == "") + { + return dataList; + } + List list = new List(); + + foreach (var item in dataList) + { + string text = GetItemName(item); + string text2 = GetItemDescription(item); + if (text.Contains(searchText.Replace(" ", "")) || text2.Contains(searchText.Replace(" ", ""))) + { + list.Add(item); + } + } + + return list; + } + private static string GetItemName(EffectModel item) + { + try + { + var description = new Func(() => item.DisplayName)(); + return description == ">Missing key<" ? item.Name : description; + } + catch + { + return item.Name; + } + } + private static string GetItemDescription(EffectModel item) + { + try + { + var description = new Func(() => item.Description)(); + return description == ">Missing key<" ? item.Name : description; + } + catch + { + return item.Name; + } + } + private static Sprite GetItemIcon(EffectModel item) + { + return item.GetIcon(); + } + #endregion + + + } + +} diff --git a/Against the Storm/ScriptTrainer/ItemWindows.cs b/Against the Storm/ScriptTrainer/ItemWindows.cs new file mode 100644 index 0000000..46859cc --- /dev/null +++ b/Against the Storm/ScriptTrainer/ItemWindows.cs @@ -0,0 +1,461 @@ +using Eremite.Characters.Villagers; +using Eremite.Controller; +using Eremite.Model; +using Eremite.Model.State; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.UI; +using UnityGameUI; +using Object = UnityEngine.Object; + +namespace ScriptTrainer +{ + internal class ItemWindow : MonoBehaviour + { + private static GameObject Panel; + private static int initialX; + private static int initialY; + private static int elementX; + private static int elementY; + + #region[数据分页相关] + private static GameObject ItemPanel; + private static List ItemButtons = new List(); + private static int page = 1; + private static int maxPage = 1; + private static int conunt = 15; + private static string searchText = ""; + private static GameObject uiText; + private static string uiText_text + { + get + { + return $"{page} / {maxPage}"; + } + } + #endregion + + public ItemWindow(GameObject panel, int x, int y) + { + Panel = panel; + initialX = elementX = x + 50; + initialY = elementY = y; + Initialize(); + } + public void Initialize() + { + //创建搜索框 + SearchBar(Panel); + elementX += 300; + MainWindow.AddButton(ref elementX, ref elementY, "保存起步奖励", Panel, () => + { + if (GameController.Instance == null && MetaController.Instance != null) + Scripts.SaveStartBonuses(MetaController.Instance.MetaServices.MetaStateService.EmbarkBonuses.goodsPicked); + }); + MainWindow.AddButton(ref elementX, ref elementY, "载入起步奖励", Panel, () => + { + if (GameController.Instance == null && MetaController.Instance != null) + MetaController.Instance.MetaServices.MetaStateService.EmbarkBonuses.goodsPicked = Scripts.LoadStartBonuses(); + }); + elementY += 10; + hr(); + + //创建物品列表 + //elementX += 200; + elementY = 125 - 60 * 5; + //创建分页 + + PageBar(Panel); + } + + #region[创建详细] + //搜索框 + private void SearchBar(GameObject panel) + { + elementY += 10; + elementX = -MainWindow.width / 2 + 120; + //label + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(panel, txtBgSprite, "#FFFFFFFF"); + uiText.GetComponent().text = "搜索"; + uiText.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + uiText.GetComponent().sizeDelta = new Vector2(60, 30); + uiText.GetComponent().alignment = TextAnchor.MiddleLeft; + + //坐标偏移 + elementX += 60; + + //输入框 + int w = 260; + Sprite inputFieldSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); + GameObject uiInputField = UIControls.createUIInputField(panel, inputFieldSprite, "#FFFFFFFF"); + uiInputField.GetComponent().text = searchText; + uiInputField.GetComponent().localPosition = new Vector3(elementX + 100, elementY, 0); + uiInputField.GetComponent().sizeDelta = new Vector2(w, 30); + + + //文本框失去焦点时触发方法 + uiInputField.GetComponent().onEndEdit.AddListener((string text) => + { + //Debug.Log(text); + page = 1; + searchText = text; + container(); + ItemWindow.uiText.GetComponent().text = uiText_text; + //Destroy(ItemPanel); + }); + } + //分页 + private void PageBar(GameObject panel) + { + //背景 + GameObject pageObj = UIControls.createUIPanel(panel, "40", "500"); + pageObj.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + pageObj.GetComponent().localPosition = new Vector3(0, elementY, 0); + + //当前页数 / 总页数 + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + + if (uiText == null) + { + uiText = UIControls.createUIText(pageObj, txtBgSprite, "#ffFFFFFF"); + uiText.GetComponent().text = uiText_text; + uiText.GetComponent().localPosition = new Vector3(0, 0, 0); + //设置字体 + uiText.GetComponent().fontSize = 20; + uiText.GetComponent().alignment = TextAnchor.MiddleCenter; + } + + + //上一页 + string backgroundColor = "#8C9EFFFF"; + GameObject prevBtn = UIControls.createUIButton(pageObj, backgroundColor, "上一页", () => + { + + page--; + if (page <= 0) page = 1; + container(); + uiText.GetComponent().text = uiText_text; + }, new Vector3()); + prevBtn.GetComponent().sizeDelta = new Vector2(60, 20); + prevBtn.GetComponent().localPosition = new Vector3(-100, 0, 0); + + //下一页 + GameObject nextBtn = UIControls.createUIButton(pageObj, backgroundColor, "下一页", () => + { + page++; + if (page >= maxPage) page = maxPage; + container(); + uiText.GetComponent().text = uiText_text; + }); + nextBtn.GetComponent().sizeDelta = new Vector2(60, 20); + nextBtn.GetComponent().localPosition = new Vector3(100, 0, 0); + } + private static void container() + { + elementX = -200; + elementY = 125; + + //先清空旧的 ItemPanel + foreach (var item in ItemButtons) + { + UnityEngine.Object.Destroy(item); + } + ItemButtons.Clear(); + + ItemPanel = UIControls.createUIPanel(Panel, "300", "600"); + ItemPanel.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + ItemPanel.GetComponent().anchoredPosition = new Vector2(10, 0); + + int num = 0; + foreach (GoodModel item in GetItemData()) + { + var btn = CreateItemButton("获得", GetItemName(item), GetItemIcon(item), ItemPanel, () => + { + UIWindows.SpawnInputDialog($"您想获得多少个{GetItemName(item)}?", "获得", "100", (string count) => + { + ScriptTrainer.WriteLog($"已获得{count}个{GetItemName(item)}到背包。{item.Name}"); + + SpawnItem(item, count.ConvertToIntDef(100)); + }); + }); + ItemButtons.Add(btn); + num++; + if (num % 3 == 0) + { + hr(); + } + } + } + + public static void SpawnEquipmentInputDialog(string ButtonText, string Description, UnityAction onFinish) + { + //创建画布 + GameObject canvas = UIControls.createUICanvas(); + Object.DontDestroyOnLoad(canvas); + //设置置顶显示 + canvas.GetComponent().overrideSorting = true; + canvas.GetComponent().sortingOrder = 100; + //分割物品介绍,设置界面大小 + List outlines = Description.GetSeparateSubString(18); + int size = outlines.Count * 20 + 20 + 40; + // 创建面板 + GameObject uiPanel = UIControls.createUIPanel(canvas, size.ToString(), "300", null); + uiPanel.GetComponent().color = UIControls.HTMLString2Color("#37474FFF"); + //创建物品介绍 + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + string DefaultColor = "#FFFFFFFF"; + for (int i = 0; i < outlines.Count; i++) + { + GameObject uiText = UIControls.createUIText(uiPanel, txtBgSprite, DefaultColor); + uiText.GetComponent().text = outlines[i]; + uiText.GetComponent().localPosition = new Vector2(0, size / 2 - 20 - 20 * i); + uiText.GetComponent().sizeDelta = new Vector2(280, 20); + uiText.GetComponent().fontSize = 14; + } + //创建确定按钮 + GameObject uiButton = UIControls.createUIButton(uiPanel, "#8C9EFFFF", ButtonText, () => + { + onFinish(); + Object.Destroy(canvas); + }, new Vector3(100, -size / 2 + 30, 0)); + + //创建关闭按钮 + GameObject closeButton = UIControls.createUIButton(uiPanel, "#B71C1CFF", "X", () => + { + Object.Destroy(canvas); + }, new Vector3(350 / 2 - 10, size / 2 - 10, 0)); + //设置closeButton宽高 + closeButton.GetComponent().sizeDelta = new Vector2(20, 20); + //字体颜色为白色 + closeButton.GetComponentInChildren().color = UIControls.HTMLString2Color("#FFFFFFFF"); + } + private static GameObject CreateItemButton(string ButtonText, string ItemName, Sprite ItemIcon, GameObject panel, UnityAction action) + { + //按钮宽 200 高 50 + int buttonWidth = 190; + int buttonHeight = 50; + + //根据品质设置背景颜色 + string qualityColor = "#FFFFFFFF"; + + //创建一个背景 + GameObject background = UIControls.createUIPanel(panel, buttonHeight.ToString(), buttonWidth.ToString(), null); + background.GetComponent().color = UIControls.HTMLString2Color("#455A64FF"); + background.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + + GameObject background_icon = UIControls.createUIPanel(background, buttonHeight.ToString(), "50", null); + background_icon.GetComponent().color = UIControls.HTMLString2Color(qualityColor); + background_icon.GetComponent().anchoredPosition = new Vector2(70, 0); + + GameObject icon = UIControls.createUIImage(background_icon, ItemIcon); + icon.GetComponent().sizeDelta = new Vector2(60, 60); + icon.GetComponent().localPosition = new Vector2(0, 0); + + //创建文字 + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(background, txtBgSprite, ColorUtility.ToHtmlStringRGBA(Color.white)); + uiText.GetComponent().text = ItemName; + uiText.GetComponent().localPosition = new Vector3(0, 5, 0); + + //创建按钮 + string backgroundColor_btn = "#8C9EFFFF"; + GameObject button = UIControls.createUIButton(background, backgroundColor_btn, ButtonText, action, new Vector3()); + button.GetComponent().sizeDelta = new Vector2(60, 20); + button.GetComponent().localPosition = new Vector3(-50, -10, 0); + + elementX += 200; + + return background; + } + public static GameObject AddToggle(string Text, int width, GameObject panel, UnityAction action) + { + //计算x轴偏移 + elementX += width / 2 - 30; + + Sprite toggleBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture(ColorUtility.ToHtmlStringRGBA(Color.white))); + Sprite toggleSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#18FFFFFF")); + GameObject uiToggle = UIControls.createUIToggle(panel, toggleBgSprite, toggleSprite); + uiToggle.GetComponentInChildren().color = Color.white; + uiToggle.GetComponentInChildren().isOn = false; + uiToggle.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + uiToggle.GetComponentInChildren().text = Text; + uiToggle.GetComponentInChildren().onValueChanged.AddListener(action); + + + elementX += width / 2 + 10; + + return uiToggle; + } + private static void hr() + { + elementX = initialX; + elementY -= 60; + } + + #endregion + + public static void SpawnItem(GoodModel item, int count) + { + Good good = new Good(item.Name, count); + + //foreach (var x in MainController.Instance.Settings.Buildings) + //{ + // ScriptTrainer.WriteLog($"ZG Buildings:{x.displayName.Text}"); + //} + //foreach (var x in MainController.Instance.Settings.Relics) + //{ + // ScriptTrainer.WriteLog($"ZG Relics:{x.displayName.Text}"); + //} + //foreach (var x in MainController.Instance.Settings.workshops) + //{ + // ScriptTrainer.WriteLog($"ZG Workshops:{x.displayName.Text}"); + //} + //foreach (var x in MainController.Instance.Settings.mines) + //{ + // ScriptTrainer.WriteLog($"ZG Mines:{x.displayName.Text}"); + //} + //foreach (var x in MainController.Instance.Settings.Institutions) + //{ + // ScriptTrainer.WriteLog($"ZG Institutions:{x.displayName.Text}"); + //} + //foreach (var x in MainController.Instance.Settings.BuildingCategories) + //{ + // ScriptTrainer.WriteLog($"ZG BuildingCategories:{x.displayName.Text}"); + //} + + + //foreach (var x in MainController.Instance.Settings.cycleEffects) + //{ + // ScriptTrainer.WriteLog($"ZG CycleEffect:{x.DisplayName}"); + //} + //foreach (var x in MainController.Instance.Settings.altarEffects) + //{ + // ScriptTrainer.WriteLog($"ZG AltarEffects:{x.Name}"); + //} + //foreach (var x in MainController.Instance.Settings.conditionalSeasonalEffects) + //{ + // ScriptTrainer.WriteLog($"ZG ConditionalSeasonalEffects:{x.DisplayName}"); + //} + //foreach (var x in MainController.Instance.Settings.simpleSeasonalEffects) + //{ + // ScriptTrainer.WriteLog($"ZG SimpleSeasonalEffects:{x.DisplayName}"); + //} + + + + if(GameController.Instance != null) + { + var storage = GameController.Instance.GameServices.StorageService.GetStorage(); + storage.Store(good); + } + else if (MetaController.Instance != null) + { + var storage = MetaController.Instance.MetaServices.MetaEconomyService; + var storage2 = MetaController.Instance.MetaServices.MetaStateService.EmbarkBonuses; + + if (item.Name == "_Meta Food Stockpiles" || item.Name == "_Meta Machinery" || item.Name == "_Meta Artifacts") + { + MetaCurrencyModel metaCurrency = storage.GetMetaCurrency(item); + storage.Add(new MetaCurrency(metaCurrency.Name, count)); + ScriptTrainer.WriteLog(metaCurrency.Name); + } + else + { + //var x = MetaController.Instance.MetaServices.MetaStateService.Content.embarkGoods; + //string name = GetEmbarkName(item); + if (/*!x.Contains(name)*/storage2.goodsOptions.Count < 27) + { + storage2.goodsOptions.Add(new GoodPickState() { name = item.Name, amount = count, cost = 0 }); + } + } + } + } + + private static string GetEmbarkName(GoodModel item) + { + string[] strings = item.Name.Split(']'); + if (strings.Length > 1) + { + return "Meta Reward Embark Goods " + strings[1].Trim(); + } + else + return "Meta Reward Embark Goods " + strings[0].Trim(); + + + } + + #region[获取数据相关函数] + private static List GetItemData() + { + List ItemData = ZGGameObject.GoodModels; + //var xx = MainController.Instance.Settings.effects.ToList(); + //foreach (EffectModel item in xx) + //{ + // Debug.Log($"ZG;{item.regularEffect.Name};{item.Name};{item.upgradedEffect.Name}"); + //} + //ScriptTrainer.WriteLog($"ZG:全物品数量:{ItemData.Count}"); + if (searchText != "") + { + ItemData = FilterItemData(ItemData); + } + //Curse诅咒 Magazine + //对 DataList 进行分页 + List list = new List(); + int start = (page - 1) * conunt; + int end = start + conunt; + for (int i = start; i < end; i++) + { + if (i < ItemData.Count) + { + list.Add(ItemData[i]); + } + } + if (ItemData.Count % conunt != 0) + maxPage = ItemData.Count / conunt + 1; + else + maxPage = ItemData.Count / conunt; + + return list; + } + //搜索过滤 + private static List FilterItemData(List dataList) + { + if (searchText == "") + { + return dataList; + } + List list = new List(); + + foreach (var item in dataList) + { + string text = GetItemName(item); + string text2 = GetItemDescription(item); + if (text.Contains(searchText.Replace(" ", "")) || text2.Contains(searchText.Replace(" ", ""))) + { + list.Add(item); + } + } + + return list; + } + private static string GetItemName(GoodModel item) + { + return item.displayName.GetText(); + } + private static string GetItemDescription(GoodModel item) + { + return item.Description; + } + private static Sprite GetItemIcon(GoodModel item) + { + return item.icon; + } + #endregion + } + +} diff --git a/Against the Storm/ScriptTrainer/MainWindow.cs b/Against the Storm/ScriptTrainer/MainWindow.cs new file mode 100644 index 0000000..36dc875 --- /dev/null +++ b/Against the Storm/ScriptTrainer/MainWindow.cs @@ -0,0 +1,411 @@ + +using BepInEx; +using Eremite.Controller; +using System; +using System.Collections.Generic; +using System.IO; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.EventSystems; +using UnityEngine.UI; +using UnityGameUI; +using Navigation = UnityGameUI.Navigation; +using Object = UnityEngine.Object; + +namespace ScriptTrainer +{ + public class MainWindow : MonoBehaviour + { + #region[声明] + // Trainer Base + public static GameObject obj = null; + public static MainWindow instance; + public static bool initialized = false; + public static bool _optionToggle = false; + private static TooltipGUI toolTipComp = null; + + // UI + public static AssetBundle testAssetBundle = null; + public static GameObject canvas = null; + private static GameObject uiPanel = null; + public static readonly int width = Mathf.Min(Screen.width, 740); + private static readonly int height = (Screen.height < 400) ? Screen.height : (450); + + // 按钮位置 + private static int elementX = initialX; + private static int elementY = initialY; + private static int initialX + { + get + { + return -width / 2 + 120; + } + } + private static int initialY + { + get + { + return height / 2 - 60; + } + } + public static bool OptionToggle + { + get => _optionToggle; + set + { + _optionToggle = value; + if (_optionToggle) + { + MainController.Instance.AppServices.InputService.Config.Disable(); + } + else + { + MainController.Instance.AppServices.InputService.Config.Enable(); + } + if (!initialized) + { + instance.CreateUI(); + } + + canvas.SetActive(OptionToggle); + Event.current.Use(); + } + } + + #endregion + + internal static GameObject Create(string name) + { + obj = new GameObject(name); + DontDestroyOnLoad(obj); + + var component = new MainWindow(); + + toolTipComp = new TooltipGUI(); + toolTipComp.enabled = false; + + return obj; + } + + public MainWindow() + { + instance = this; + } + + public static void Initialize() + { + #region[初始化资源] + + #endregion + + instance.CreateUI(); + + initialized = true; + } + + #region[创建UI] + private void CreateUI() + { + if (canvas == null) + { + canvas = UIControls.createUICanvas(); + Object.DontDestroyOnLoad(canvas); + // 设置背景 + GameObject background = UIControls.createUIPanel(canvas, (height + 40).ToString(), (width + 40).ToString(), null); + background.GetComponent().color = UIControls.HTMLString2Color("#2D2D30FF"); + + // 将面板添加到画布, 请参阅 createUIPanel 了解我们将高度/宽度作为字符串传递的原因 + uiPanel = UIControls.createUIPanel(background, height.ToString(), width.ToString(), null); + // 设置背景颜色 + uiPanel.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + + #region[面板元素] + + + #region[创建标题 和 关闭按钮] + AddTitle(background, background); + + GameObject closeButton = UIControls.createUIButton(uiPanel, "#B71C1CFF", "X", () => + { + OptionToggle = false; + canvas.SetActive(OptionToggle); + }, new Vector3(width / 2 + 10, height / 2 + 10, 0)); + closeButton.GetComponent().sizeDelta = new Vector2(20, 20); + // 字体颜色为白色 + closeButton.GetComponentInChildren().color = UIControls.HTMLString2Color("#FFFFFFFF"); + + #endregion + + GameObject BasicScripts = UIControls.createUIPanel(uiPanel, "410", "600", null); + BasicScripts.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + BasicScripts.GetComponent().anchoredPosition = new Vector2(-70, -20); + + #region[添加功能按钮] + AddH3("常用功能:", BasicScripts); + { + AddButton("添加经验值", BasicScripts, () => + { + UIWindows.SpawnInputDialog($"您想添加多少经验值?", "添加", "100", (string count) => + { + Scripts.AddExp(count.ConvertToIntDef(100)); + }); + }); + AddToggle("无限起步点数",150, BasicScripts, (bool state) => + { + Scripts.InfinitePreparationPoints(state); + }); + hr(); + + hr(10); + } + + #endregion + + #region[获取物品] + ResetCoordinates(true, true); + GameObject ItemScripts = UIControls.createUIPanel(uiPanel, "410", "600", null); + ItemScripts.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + ItemScripts.GetComponent().anchoredPosition = new Vector2(-70, -20); + + ItemWindow itemWindow = new ItemWindow(ItemScripts, elementX, elementY); + + + #endregion + + #region[获取效果] + ResetCoordinates(true, true); + GameObject EffectScripts = UIControls.createUIPanel(uiPanel, "410", "600", null); + EffectScripts.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + EffectScripts.GetComponent().anchoredPosition = new Vector2(-70, -20); + + EffectWindows effectWindow = new EffectWindows(EffectScripts, elementX, elementY); + + + #endregion + + #region[获取效果] + ResetCoordinates(true, true); + GameObject BuildingScripts = UIControls.createUIPanel(uiPanel, "410", "600", null); + BuildingScripts.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + BuildingScripts.GetComponent().anchoredPosition = new Vector2(-70, -20); + + BuildingWindows buildingWindow = new BuildingWindows(BuildingScripts, elementX, elementY); + #endregion + + #endregion + + + #region[创建导航栏] + // 分割线 + GameObject DividingLine = UIControls.createUIPanel(uiPanel, (height - 40).ToString(), "10", null); + DividingLine.GetComponent().color = UIControls.HTMLString2Color("#2D2D30FF"); + DividingLine.GetComponent().anchoredPosition = new Vector3(width / 2 - 200 + 80, -20, 0); + + //// 按钮 + GameObject NavPanel = UIControls.createUIPanel(uiPanel, (height - 40).ToString(), "40", null); + NavPanel.GetComponent().color = UIControls.HTMLString2Color("#424242FF"); + NavPanel.GetComponent().anchoredPosition = new Vector3(width / 2 - 100, -20, 0); + + Navigation[] nav = new Navigation[] + { + new Navigation("BasicScripts","基础功能", BasicScripts, true), + new Navigation("ItemScripts", "物品添加", ItemScripts, false), + new Navigation("EffectScripts", "效果添加", EffectScripts, false), + new Navigation("BuildingScripts", "建筑添加", BuildingScripts, false), + }; + + UINavigation.Initialize(nav, NavPanel); + + #endregion + + canvas.SetActive(OptionToggle); + ScriptTrainer.WriteLog("初始化完成!"); + } + } + + #region[添加组件] + //添加按钮 + public static GameObject AddButton(string Text, GameObject panel, UnityAction action) + { + string backgroundColor = "#8C9EFFFF"; + Vector3 localPosition = new Vector3(elementX, elementY, 0); + elementX += 110; + + GameObject button = UIControls.createUIButton(panel, backgroundColor, Text, action, localPosition); + + // 按钮样式 + button.AddComponent().effectColor = UIControls.HTMLString2Color("#000000FF"); // 添加阴影 + button.GetComponent().effectDistance = new Vector2(2, -2); // 设置阴影偏移 + button.GetComponentInChildren().fontSize = 14; // 设置字体大小 + button.GetComponent().sizeDelta = new Vector2(100, 30); // 设置按钮大小 + + + return button; + } + public static GameObject AddButton(ref int elementX, ref int elementY, string Text, GameObject panel, UnityAction action) + { + string backgroundColor = "#8C9EFFFF"; + Vector3 localPosition = new Vector3(elementX, elementY, 0); + elementX += 110; + + GameObject button = UIControls.createUIButton(panel, backgroundColor, Text, action, localPosition); + + // 按钮样式 + button.AddComponent().effectColor = UIControls.HTMLString2Color("#000000FF"); // 添加阴影 + button.GetComponent().effectDistance = new Vector2(2, -2); // 设置阴影偏移 + button.GetComponentInChildren().fontSize = 14; // 设置字体大小 + button.GetComponent().sizeDelta = new Vector2(100, 30); // 设置按钮大小 + + + return button; + } + // 添加复选框 + public static GameObject AddToggle(string Text, int width, GameObject panel, UnityAction action) + { + // 计算x轴偏移 + elementX += width / 2 - 30; + + Sprite toggleBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture(ColorUtility.ToHtmlStringRGBA(Color.white))); + Sprite toggleSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#18FFFFFF")); + GameObject uiToggle = UIControls.createUIToggle(panel, toggleBgSprite, toggleSprite); + uiToggle.GetComponentInChildren().color = Color.white; + uiToggle.GetComponentInChildren().isOn = false; + uiToggle.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + uiToggle.GetComponentInChildren().text = Text; + uiToggle.GetComponentInChildren().onValueChanged.AddListener(action); + + + elementX += width / 2 + 10; + + return uiToggle; + } + // 添加输入框 + public static GameObject AddInputField(string Text, int width, string defaultText, GameObject panel, UnityAction action) + { + // 计算x轴偏移 + elementX += width / 2 - 30; + + // label + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(panel, txtBgSprite, "#FFFFFFFF"); + uiText.GetComponent().text = Text; + uiText.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + //uiText.GetComponent().sizeDelta = new Vector2(60, 30); + uiText.GetComponent().alignment = TextAnchor.MiddleLeft; + + + // 坐标偏移 + elementX += 10; + + // 输入框 + Sprite inputFieldSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); + GameObject uiInputField = UIControls.createUIInputField(panel, inputFieldSprite, "#FFFFFFFF"); + uiInputField.GetComponent().text = defaultText; + uiInputField.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + uiInputField.GetComponent().sizeDelta = new Vector2(width - 60, 30); + + // 文本框失去焦点时触发方法 + uiInputField.GetComponent().onEndEdit.AddListener(action); + + elementX += width / 2 + 10; + return uiInputField; + } + // 添加下拉框 + public GameObject AddDropdown(string Text, int width, List options, GameObject panel, UnityAction action) + { + // 计算x轴偏移 + elementX += width / 2 - 30; + + // label + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(panel, txtBgSprite, "#FFFFFFFF"); + uiText.GetComponent().text = Text; + uiText.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + //uiText.GetComponent().sizeDelta = new Vector2(60, 30); + uiText.GetComponent().alignment = TextAnchor.MiddleLeft; + + // 坐标偏移 + elementX += 60; + + // 创建下拉框 + Sprite dropdownBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); // 背景颜色 + Sprite dropdownScrollbarSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#8C9EFFFF")); // 滚动条颜色 (如果有的话 + Sprite dropdownDropDownSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#212121FF")); // 框右侧小点的颜色 + Sprite dropdownCheckmarkSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#8C9EFFFF")); // 选中时的颜色 + Sprite dropdownMaskSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#E65100FF")); // 不知道是哪的颜色 + Color LabelColor = UIControls.HTMLString2Color("#EFEBE9FF"); + GameObject uiDropDown = UIControls.createUIDropDown(panel, dropdownBgSprite, dropdownScrollbarSprite, dropdownDropDownSprite, dropdownCheckmarkSprite, dropdownMaskSprite, options, LabelColor); + Object.DontDestroyOnLoad(uiDropDown); + uiDropDown.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + // 下拉框选中时触发方法 + uiDropDown.GetComponent().onValueChanged.AddListener(action); + + elementX += width / 2 + 60; + return uiDropDown; + } + // 添加小标题 + public GameObject AddH3(string text, GameObject panel) + { + elementX += 40; + + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(panel, txtBgSprite, "#FFFFFFFF"); + uiText.GetComponent().text = text; + uiText.GetComponent().localPosition = new Vector3(elementX, elementY, 0); + + // 设置字体样式为h3小标题 + uiText.GetComponent().fontSize = 14; + uiText.GetComponent().fontStyle = FontStyle.Bold; + hr(); + elementY += 20; + elementX += 10; + return uiText; + } + // 添加标题 + public static GameObject AddTitle(GameObject panel, GameObject target) + { + GameObject TitleBackground = UIControls.createUIPanel(panel, "30", (width - 20).ToString(), null); + TitleBackground.GetComponent().color = UIControls.HTMLString2Color("#2D2D30FF"); + TitleBackground.GetComponent().localPosition = new Vector3(0, height / 2 - 30, 0); + + Sprite txtBgSprite = UIControls.createSpriteFrmTexture(UIControls.createDefaultTexture("#7AB900FF")); + GameObject uiText = UIControls.createUIText(TitleBackground, txtBgSprite, "#FFFFFFFF"); + uiText.GetComponent().sizeDelta = new Vector2(width - 10, 30); + uiText.GetComponent().localPosition = new Vector3(0, 0, 0); + Text text = uiText.GetComponent(); + text.text = ScriptTrainer.Instance.GetTitle(); + text.alignment = TextAnchor.MiddleCenter; + text.fontSize = 16; + + var drag = TitleBackground.AddComponent(); + drag.SetTarget(target); + + return uiText; + } + // 换行 + public void hr(int offsetX = 0, int offsetY = 0) + { + ResetCoordinates(true); + elementX += offsetX; + elementY -= 50 + offsetY; + + } + // 重置坐标 + public void ResetCoordinates(bool x, bool y = false) + { + if (x) elementX = initialX; + if (y) elementY = initialY; + } + #endregion + + + + #endregion + + + + + } +} diff --git a/Against the Storm/ScriptTrainer/Properties/AssemblyInfo.cs b/Against the Storm/ScriptTrainer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2ab24be --- /dev/null +++ b/Against the Storm/ScriptTrainer/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("ScriptTrainer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ScriptTrainer")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("56b71f4d-f911-4369-87c0-f13ad81535c2")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Against the Storm/ScriptTrainer/ScriptPatch.cs b/Against the Storm/ScriptTrainer/ScriptPatch.cs new file mode 100644 index 0000000..935acbc --- /dev/null +++ b/Against the Storm/ScriptTrainer/ScriptPatch.cs @@ -0,0 +1,129 @@ +using Eremite.Controller; +using Eremite.Model; +using Eremite.Services; +using Eremite.Services.World; +using Eremite.View.Cameras; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using UnityEngine; +using static UnityEngine.UI.Image; +using Random = UnityEngine.Random; +using Type = System.Type; + +namespace ScriptTrainer +{ + public class ScriptPatch + { + #region[全局参数] + public static bool InfinitePreparationPoints = false; + public static List AddEffects { get; set; } = new List(); + #endregion + + #region 前补丁 + //Prefix 前补丁,在补丁的函数前执行 + + //示例 + //[HarmonyPatch(typeof(RecyclingWells), "OnNetworkSpawn")] RecyclingWells为类型名称,OnNetworkSpawn为函数名称 + //public class RecyclingWellsOverridePatch_OnNetworkSpawn + //{ + // [HarmonyPrefix] 前置补丁的补丁函数前的声明 + // public static void Prefix(RecyclingWells __instance) __instance为特殊名称,当前注入类型入口 + // { + // Debug.Log($"ZG:修改前{Traverse.Create(__instance).Field("initialNumberOfUses").GetValue()}"); + // Traverse.Create(__instance).Field("initialNumberOfUses").SetValue(99); + // Debug.Log($"ZG:修改后{99}"); + // } + //} + + + #endregion + + #region 后补丁 + //Postfix后补丁,在函数执行后执行 + //[HarmonyPatch(typeof(Test), "Updata")] Test为类型名称,Updata为函数名称 + //public class TestOverridePatch_Updata + //{ + // [HarmonyPostfix] 后置补丁的补丁函数前的声明 + // public static void Postfix(ref int __result) __result为特殊名称,当前函数的返回值 + // { + // __result \= 2; + // } + //} + #endregion + + #region 多个同名函数补丁制作 + //[HarmonyPatch(typeof(HexMapManager), "GenerateNewMap", new Type[] { typeof(Sector) })] + //在HexMapManager类里有多个名为GenerateNewMap的函数时,HarmonyPatch的第三个参数是函数输入变量的类型,第四个参数是函数out输出变量的类型 + #endregion + + #region 可读写属性补丁制作 + //[HarmonyPatch(typeof(MinigameChest), "Price", MethodType.Getter)] + //[HarmonyPatch(typeof(MinigameChest), "Price", MethodType.Setter)] + #endregion + + #region 成员修改 + //Traverse.Create(__instance).Field("initialNumberOfUses").GetValue(); + //Traverse.Create(__instance).Field("initialNumberOfUses").SetValue(99); + //initialNumberOfUses 是成员名称, T为该成员类型 + #endregion + + [HarmonyPatch] + public class MetaPerksServicePatch + { + public static IEnumerable TargetMethods() + { + var method1 = AccessTools.Method(typeof(MetaPerksService), "GetMaxPreparationPoints"); + if (method1 != null) + { + yield return method1; + yield break; + } + + var method2 = AccessTools.Method(typeof(MetaPerksService), "GetBasePreparationPoints"); + if (method2 != null) + { + yield return method2; + yield break; + } + + var method3 = AccessTools.Method(typeof(WorldEmbarkService), "GetBonusPreparationPoints"); + if (method3 != null) + { + yield return method3; + yield break; + } + } + [HarmonyPostfix] + public static void Postfix(ref int __result) + { + if (InfinitePreparationPoints) + __result = 99; + } + } + [HarmonyPatch(typeof(GameController), "OnDestroy")] + public class GameControllerOverridePatch_OnDestroy + { + [HarmonyPostfix] + public static void OnDestroy() + { + Debug.Log("GameController.OnDestroy"); + AddEffects.Clear(); + Debug.Log("移除添加过的效果信息"); + } + } + + [HarmonyPatch(typeof(MainController), "OnServicesReady")] + public class MainControllerOverridePatch_OnServicesReady + { + [HarmonyPostfix] + public static void Postfix() + { + MetaController.Instance.MetaServices.AddInitCallback(ZGGameObject.InitializeEffectModels); + } + } + } +} diff --git a/Against the Storm/ScriptTrainer/ScriptTrainer.cs b/Against the Storm/ScriptTrainer/ScriptTrainer.cs new file mode 100644 index 0000000..54ede70 --- /dev/null +++ b/Against the Storm/ScriptTrainer/ScriptTrainer.cs @@ -0,0 +1,316 @@ +using BepInEx; +using BepInEx.Configuration; +using Eremite; +using Eremite.Buildings; +using Eremite.Controller; +using Eremite.Model; +using Eremite.Model.Effects; +using Eremite.Model.State; +using Eremite.Services; +using Eremite.View.Cameras; +using Eremite.View.HUD.Construction; +using Eremite.View.HUD.Perks; +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using UnityEngine; +using UnityEngine.InputSystem; + +namespace ScriptTrainer +{ + [BepInPlugin("aoe.top.plugins.ScriptTrainer", "Against the Storm 内置修改器", "1.1.0")] + public class ScriptTrainer: BaseUnityPlugin + { + // 窗口相关 + + public GameObject YourTrainer; + public static ScriptTrainer Instance; + + // 启动按键 + public static ConfigEntry ShowTrainer { get; set; } + public static ConfigEntry StartBonuses { get; set; } + public static ConfigEntry SaveEffects { get; set; } + + public void Awake() + { + Instance = this; + + #region[注入游戏补丁] + var harmony = new Harmony("ScriptTrainer"); + harmony.PatchAll(); + #endregion + + #region 读取游戏配置 + ShowTrainer = Config.Bind("修改器快捷键", "ShowTrainer", Key.F9); + StartBonuses = Config.Bind("起始物品", "StartBonuses", string.Empty); + SaveEffects = Config.Bind("保存效果", "SaveEffects", string.Empty); + #endregion + + #region 注入游戏修改器UI + YourTrainer = GameObject.Find("ZG_Trainer"); + if (YourTrainer == null) + { + YourTrainer = new GameObject("ZG_Trainer"); + GameObject.DontDestroyOnLoad(YourTrainer); + YourTrainer.hideFlags = HideFlags.HideAndDontSave; + YourTrainer.AddComponent(); + } + else YourTrainer.AddComponent(); + #endregion + + + ScriptTrainer.WriteLog("脚本已启动"); + } + public static void WriteLog(object log) + { + ScriptTrainer.Instance?.Logger.LogInfo(log); + } + private void ILog(object mess,LogType type) + { + + } + public void Start() + { + + } + + public void Update() + { + + } + public void FixedUpdate() + { + } + + public void OnDestroy() + { + // 移除 MainWindow.testAssetBundle 加载时的资源 + //AssetBundle.UnloadAllAssetBundles(true); + + } + public string GetTitle() + { + return $"{Info.Metadata.Name} 版本:{Info.Metadata.Version} by:Jim97"; + } + } + + public class ZGGameObject : MonoBehaviour + { + public static ZGGameObject Instance; + + public MainWindow mw; + public static List GoodModels { get; set; } = new List(); + public static Dictionary> EffectModels { get; private set; } = new Dictionary>() + { + {"全部", new List() }, + {"雷铸基石", new List() }, + {"基石", new List() }, + {"辅助技能", new List() }, + {"森林空地事件", new List() }, + {"修正", new List() }, + {"建筑蓝图", new List() }, + {"信标之塔", new List() }, + //{"建筑", new List() }, + {"物品", new List() }, + {"村民", new List() }, + {"其他", new List() }, + {"未命名", new List() } + }; + + public static Dictionary> BuildingModels { get; private set; } = new Dictionary>() + { + {"全部", new List() } + }; + + static bool initializedEffectModels = false; + + public static void InitializeEffectModels() + { + if (!initializedEffectModels) + { + GoodModels = MainController.Instance.Settings.Goods.ToList(); + ScriptTrainer.WriteLog("加载物品资源成功!"); + + foreach (EffectModel model in MainController.Instance.Settings.effects) + { + //var label = $"{model.label?.displayName?.key}:{model.label?.displayName}:{model.GetType()}:{model.DisplayName}:{model.DisplayNameKey}:{model.IsPositive}"; + //ScriptTrainer.WriteLog(label); + + string key = model.label?.displayName?.key; + + if (model.GetType() == typeof(ReplaceBuildingEffectModel)) + { + //EffectModels["建筑"].Add(model); + continue; + } + + if(model.DisplayName.Trim().ToLower() == ">missing key<" && model.Description.Trim().ToLower() == ">missing key<") + { + EffectModels["未命名"].Add(model); + } + + if (model.IsPositive) + { + switch (key) + { + case "Label_Reward_StormforgedCornerstone": + EffectModels["雷铸基石"].Add(model); + break; + case "Label_Reward_Cornerstone": + case "Label_Reward_ArchaeologistEffect": + case "Label_TimedBonus_Cornerstone": + case "Label_MetaReward_RevealEffect": + case "Label_Reward_TradeRoute": + case "Label_CycleBlessing": + case "Label_Reward_DecorationEffect": + case "Label_Reward_Hub": + case "Label_ResolveEffect_HouseUpgrade": + EffectModels["基石"].Add(model); + break; + case "Label_Reward_Perk": + EffectModels["辅助技能"].Add(model); + break; + case "Label_SeasonalEffect_Generic": + case "Label_DailyModifier": + case "Label_BiomeEffect": + case "Label_WorldEvent": + case "Label_ResolveEffect_Glade": + EffectModels["森林空地事件"].Add(model); + break; + case "Label_ModifierPrestige": + case "Label_Modifier": + case "Label_ModifierDifficulty": + case "Label_Reward_Resolve": + EffectModels["修正"].Add(model); + break; + case "Label_Reward_Building": + EffectModels["建筑蓝图"].Add(model); + break; + case "Label_Beacon_Miracels": + case "Label_Beacon_Bells": + case "Label_Beacon_Supplies": + EffectModels["信标之塔"].Add(model); + break; + case "Label_Reward_MetaGoods": + case "Label_Reward_Goods": + EffectModels["物品"].Add(model); + break; + case "Label_Reward_Villagers": + EffectModels["村民"].Add(model); + break; + default: + EffectModels["其他"].Add(model); + break; + } + } + else + { + EffectModels["其他"].Add(model); + } + + EffectModels["全部"].Add(model); + } + ScriptTrainer.WriteLog("加载效果资源成功!"); + + foreach (var building in MainController.Instance.Settings.Buildings) + { + BuildingModels["全部"].Add(building); + string bkey = building.category.displayName.Text; + if (BuildingModels.ContainsKey(bkey)) + { + BuildingModels[bkey].Add(building); + } + else + { + BuildingModels[bkey] = new List { building }; + } + } + ScriptTrainer.WriteLog("加载建筑资源成功!"); + + initializedEffectModels = true; + } + } + + public PerkTooltip PerkTooltip { get; set; } + public BuildButtonTooltip BuildingSlotTooltip { get; set; } + + public void Start() + { + mw = new MainWindow(); + + Instance = this; + + TooltipSettings.targetAllign = AnchorPresets.MiddleLeft; + TooltipSettings.tooltipPivot = AnchorPresets.MiddleRight; + } + public void Update() + { + if (!MainWindow.initialized) + { + MainWindow.Initialize(); + } + if (initializedEffectModels && !EffectWindows.Initialized) + { + EffectWindows.Instance.Initialize(); + } + if (initializedEffectModels && !BuildingWindows.Initialized) + { + BuildingWindows.Instance.Initialize(); + } + + if (GameController.Instance?.CameraController != null) + { + //Traverse.Create(GameController.Instance.CameraController).Field("zoomSeed").SetValue(400f); + GameController.Instance.CameraController.ZoomLimit = new Vector2(-100f, -8f); + } + if (GetKeyDown(ScriptTrainer.ShowTrainer.Value)) + { + if (!MainWindow.initialized) + { + return; + } + + MainWindow.OptionToggle = !MainWindow.OptionToggle; + } + } + + public void ShowPerk(EffectModel model) + { + if(PerkTooltip == null) + { + var tool = MainController.Instance?.AppServices?.TooltipsService?.Get(); + + if(tool != null) + { + var xx = GameObject.Instantiate(tool.gameObject, MainWindow.canvas.transform); + PerkTooltip = xx.GetComponent(); + } + } + + PerkTooltip?.Show(EffectWindows.Panel.GetComponent(), TooltipSettings, model, new PerkState() { hidden = false, name = model.Name, stacks = 1 }); + } + public void ShowBuilding(BuildingModel building) + { + if (BuildingSlotTooltip == null) + { + var tool = MainController.Instance?.AppServices?.TooltipsService?.Get(); + + if (tool != null) + { + var xx = GameObject.Instantiate(tool.gameObject, MainWindow.canvas.transform); + BuildingSlotTooltip = xx.GetComponent(); + } + } + + BuildingSlotTooltip?.Show(BuildingWindows.Panel.GetComponent(), building, true, false, TooltipSettings); + } + + public TooltipSettings TooltipSettings = new TooltipSettings(); + public bool GetKeyDown(Key keyboardKey) + { + return Keyboard.current != null && Keyboard.current[keyboardKey].wasPressedThisFrame; + } + } +} diff --git a/Against the Storm/ScriptTrainer/ScriptTrainer.csproj b/Against the Storm/ScriptTrainer/ScriptTrainer.csproj new file mode 100644 index 0000000..a216cbb --- /dev/null +++ b/Against the Storm/ScriptTrainer/ScriptTrainer.csproj @@ -0,0 +1,141 @@ + + + + + Debug + AnyCPU + {56B71F4D-F911-4369-87C0-F13AD81535C2} + Library + Properties + ScriptTrainer + ScriptTrainer + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + 7.3 + prompt + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + 7.3 + prompt + + + + False + ..\Library\BepInEx_86\0Harmony20.dll + + + False + E:\Program Files (x86)\Steam\steamapps\common\Against the Storm\Against the Storm_Data\Managed\Assembly-CSharp.dll + + + False + ..\Library\BepInEx_86\BepInEx.dll + + + False + ..\Library\BepInEx_86\BepInEx.Harmony.dll + + + ..\Library\Game\Sirenix.Serialization.dll + + + + + + + + + + ..\Library\Unity\Unity.InputSystem.dll + + + False + ..\Library\Unity\UnityEngine.dll + + + False + ..\Library\Unity\UnityEngine.AssetBundleModule.dll + + + False + ..\Library\Unity\UnityEngine.CoreModule.dll + + + False + ..\Library\Unity\UnityEngine.IMGUIModule.dll + + + False + ..\Library\Unity\UnityEngine.InputLegacyModule.dll + + + False + ..\Library\Unity\UnityEngine.TextRenderingModule.dll + + + False + ..\Library\Unity\UnityEngine.UI.dll + + + False + ..\Library\Unity\UnityEngine.UIModule.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + xcopy "$(TargetPath)" "E:\program files (x86)\steam\steamapps\common\Against the Storm\BepInEx\Plugins\" /s /i /y + + \ No newline at end of file diff --git a/Against the Storm/ScriptTrainer/ScriptTrainer.csproj.user b/Against the Storm/ScriptTrainer/ScriptTrainer.csproj.user new file mode 100644 index 0000000..a37778c --- /dev/null +++ b/Against the Storm/ScriptTrainer/ScriptTrainer.csproj.user @@ -0,0 +1,6 @@ + + + + Project + + \ No newline at end of file diff --git a/Against the Storm/ScriptTrainer/Scripts.cs b/Against the Storm/ScriptTrainer/Scripts.cs new file mode 100644 index 0000000..40ba648 --- /dev/null +++ b/Against the Storm/ScriptTrainer/Scripts.cs @@ -0,0 +1,110 @@ +using Eremite; +using Eremite.Controller; +using Eremite.Model; +using Eremite.Model.Meta; +using Eremite.Model.State; +using Eremite.Services; +using Eremite.View; +using System; +using System.Collections.Generic; +using UnityEngine; + + +namespace ScriptTrainer +{ + public class Scripts : MonoBehaviour + { + public static void AddExp(int exp) + { + LevelState SavedState = MetaController.Instance.MetaServices.MetaStateService.Level; + + if (exp == 0 || MetaController.Instance.MetaServices.MetaEconomyService.IsLastLevel(SavedState)) + { + return; + } + int b = SavedState.targetExp - SavedState.exp; + int num = Mathf.Min(exp, b); + int exp2 = exp - num; + MetaController.Instance.MetaServices.MetaStateService.Economy.currentCycleExp += num; + SavedState.exp += num; + CheckForLevelUp(); + AddExp(exp2); + } + public static void CheckForLevelUp() + { + LevelState SavedState = MetaController.Instance.MetaServices.MetaStateService.Level; + if (SavedState.exp == SavedState.targetExp) + { + LevelModel nextLevel = MainController.Instance.Settings.metaConfig.levels[SavedState.level + 1]; + SavedState.level++; + SavedState.exp = 0; + SavedState.targetExp = nextLevel.expCeiling; + + LevelModel toGrant = MainController.Instance.Settings.metaConfig.levels[SavedState.level]; + MetaRewardModel[] rewards = toGrant.rewards; + for (int i = 0; i < rewards.Length; i++) + { + rewards[i].Consume(); + } + } + } + + public static void InfinitePreparationPoints(bool state) + { + ScriptPatch.InfinitePreparationPoints = state; + } + + public static void SaveStartBonuses(List goods) + { + string value = string.Empty; + foreach(GoodPickState good in goods) + { + if (value != string.Empty) + value += '\n'; + value += $"{good.name};{good.amount}"; + } + ScriptTrainer.StartBonuses.Value = value; + } + public static List LoadStartBonuses() + { + List goods = new List(); + string values = ScriptTrainer.StartBonuses.Value; + + foreach(string value in values.Split('\n')) + { + GoodPickState good = new GoodPickState() + { + name = value.Split(';')[0], + amount = int.Parse(value.Split(';')[1]), + cost = 0 + }; + goods.Add(good); + } + + return goods; + } + public static void SaveEffects(List effects) + { + string value = string.Empty; + foreach (string effect in effects) + { + if (value != string.Empty) + value += '\n'; + value += effect; + } + ScriptTrainer.SaveEffects.Value = value; + } + public static List LoadEffects() + { + List effects = new List(); + string values = ScriptTrainer.SaveEffects.Value; + + foreach (string value in values.Split('\n')) + { + effects.Add(value); + } + + return effects; + } + } +} diff --git a/Against the Storm/ScriptTrainer/UnityGameUI/DragAndDrog.cs b/Against the Storm/ScriptTrainer/UnityGameUI/DragAndDrog.cs new file mode 100644 index 0000000..403ee7f --- /dev/null +++ b/Against the Storm/ScriptTrainer/UnityGameUI/DragAndDrog.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.InputSystem; + +namespace ScriptTrainer +{ + public class DragAndDrog : MonoBehaviour + { + private Vector3 initialMousePosition; + private bool isDragging = false; + + public GameObject Target { get; private set; } + public void Start() + { + + } + + // Update is called once per frame + public void Update() + { + GameObjectDragAndDrog(); + } + + private void OnMouseDown() + { + // 记录鼠标按下时的位置 + initialMousePosition = Mouse.current.position.ReadValue(); + + if (RectTransformUtility.RectangleContainsScreenPoint(GetComponent(), initialMousePosition)) + isDragging = true; + } + + private void OnMouseDrag() + { + if (isDragging) + { + // 计算鼠标移动的偏移量 + Vector3 currentMousePosition = Mouse.current.position.ReadValue(); + Vector3 delta = currentMousePosition - initialMousePosition; + + // 更新游戏对象的位置 + Target.transform.position += delta; + + // 更新初始鼠标位置 + initialMousePosition = currentMousePosition; + } + } + + private void OnMouseUp() + { + // 鼠标释放时停止拖拽 + isDragging = false; + } + + public void SetTarget(GameObject game) + { + Target = game; + } + //拖拽Updata + private void GameObjectDragAndDrog() + { + // 在Update中检查鼠标事件 + if (Mouse.current.leftButton.wasPressedThisFrame) + { + OnMouseDown(); + } + if (Mouse.current.leftButton.isPressed) + { + OnMouseDrag(); + } + if (Mouse.current.leftButton.wasReleasedThisFrame) + { + OnMouseUp(); + } + } + + public void OnDisable() + { + isDragging = false; + } + } +} diff --git a/Against the Storm/ScriptTrainer/UnityGameUI/Extensions.cs b/Against the Storm/ScriptTrainer/UnityGameUI/Extensions.cs new file mode 100644 index 0000000..2a70b11 --- /dev/null +++ b/Against the Storm/ScriptTrainer/UnityGameUI/Extensions.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; +using Object = UnityEngine.Object; + +namespace UnityGameUI +{ + internal delegate bool d_LoadImage(IntPtr tex, IntPtr data, bool markNonReadable); + internal delegate bool parseHTMLString(IntPtr HTMLString, IntPtr result); + + public static class Extensions + { + // Load Image ICall + + // Convert Hex string to Color32 + public static Color32 HexToColor(this string hexString) + { + string tmp = hexString; + + if (tmp.IndexOf('#') != -1) + tmp = tmp.Replace("#", ""); + + byte r = 0, g = 0, b = 0, a = 0; + + r = Convert.ToByte(tmp.Substring(0, 2), 16); + g = Convert.ToByte(tmp.Substring(2, 2), 16); + b = Convert.ToByte(tmp.Substring(4, 2), 16); + if (tmp.Length == 8) + a = Convert.ToByte(tmp.Substring(6, 2), 16); + else + { + return new Color((float)r / 255f, (float)g / 255f, (float)b / 255f); + } + return new Color32(r, g, b, a); + } + public static int ConvertToIntDef(this string input, int defaultValue) + { + int result; + if (int.TryParse(input, out result)) + { + return result; + } + return defaultValue; + } + public static float ConvertToFloatDef(this string input, float defaultValue) + { + float result; + if (float.TryParse(input, out result)) + { + return result; + } + return defaultValue; + } + public static List GetSeparateSubString(this string input, int charNumber) + { + List arrlist = new List(); + string tempStr = input; + for (int i = 0; i < tempStr.Length; i += charNumber) + { + if ((tempStr.Length - i) > charNumber)//如果是,就截取 + { + arrlist.Add(tempStr.Substring(i, charNumber)); + } + else + { + arrlist.Add(tempStr.Substring(i));//如果不是,就截取最后剩下的那部分 + } + } + return arrlist; + } + } +} diff --git a/Against the Storm/ScriptTrainer/UnityGameUI/TooltipGUI.cs b/Against the Storm/ScriptTrainer/UnityGameUI/TooltipGUI.cs new file mode 100644 index 0000000..eeb7df9 --- /dev/null +++ b/Against the Storm/ScriptTrainer/UnityGameUI/TooltipGUI.cs @@ -0,0 +1,50 @@ + +using Eremite.Buildings; +using Eremite.Model; +using ScriptTrainer; +using System; +using UnityEngine; +using UnityEngine.EventSystems; + +namespace UnityGameUI +{ + internal class TooltipGUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler + { + EffectModel effectModel; + BuildingModel building; + + public void SetModel(EffectModel model) + { + effectModel = model; + } + public void SetBuilding(BuildingModel model) + { + building = model; + } + public void OnPointerEnter(PointerEventData eventData) + { + if(effectModel != null) + { + ZGGameObject.Instance?.ShowPerk(effectModel); + } + + if(building != null) + { + ZGGameObject.Instance?.ShowBuilding(building); + } + } + + public void OnPointerExit(PointerEventData eventData) + { + if (effectModel != null) + { + ZGGameObject.Instance.PerkTooltip?.ForceHide(); + } + + if(building != null) + { + ZGGameObject.Instance.BuildingSlotTooltip?.ForceHide(); + } + } + } +} diff --git a/Against the Storm/ScriptTrainer/UnityGameUI/UIControls.cs b/Against the Storm/ScriptTrainer/UnityGameUI/UIControls.cs new file mode 100644 index 0000000..7fead04 --- /dev/null +++ b/Against the Storm/ScriptTrainer/UnityGameUI/UIControls.cs @@ -0,0 +1,811 @@ + +using System; +using System.Collections.Generic; +using System.IO; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.UI; +using Object = UnityEngine.Object; + +namespace UnityGameUI +{ + // UI 控件 + internal class UIControls : MonoBehaviour + { + #region[声明] + private const float kWidth = 160f; + private const float kThickHeight = 30f; + private const float kThinHeight = 20f; + private static Vector2 s_ThickElementSize = new Vector2(160f, 30f); + private static Vector2 s_ThinElementSize = new Vector2(160f, 20f); + private static Vector2 s_ImageElementSize = new Vector2(100f, 100f); + private static Color s_DefaultSelectableColor = new Color(1f, 1f, 1f, 1f); + private static Color s_PanelColor = new Color(1f, 1f, 1f, 0.392f); + private static Color s_TextColor = new Color(0.19607843f, 0.19607843f, 0.19607843f, 1f); + + public struct Resources + { + public Sprite standard; + public Sprite background; + public Sprite inputField; + public Sprite knob; + public Sprite checkmark; + public Sprite dropdown; + public Sprite mask; + } + #endregion + + public UIControls() + { + + } + + #region[元素] + + // 创建根元素 + private static GameObject CreateUIElementRoot(string name, Vector2 size) + { + GameObject gameObject = new GameObject(name); + RectTransform rectTransform = gameObject.AddComponent(); + rectTransform.sizeDelta = size; + return gameObject; + } + + // 创建UI对象 + private static GameObject CreateUIObject(string name, GameObject parent) + { + GameObject gameObject = new GameObject(name); + gameObject.AddComponent(); + UIControls.SetParentAndAlign(gameObject, parent); + return gameObject; + } + + // 设置默认文本 + private static void SetDefaultTextValues(Text lbl) + { + lbl.color = UIControls.s_TextColor; + //lbl.AssignDefaultFont(); + //lbl.FontTextureChanged(); + lbl.font = (Font)UnityEngine.Resources.GetBuiltinResource("Arial.ttf"); + // 设置字体为宋体 + //lbl.font = (Font)UnityEngine.Resources.GetBuiltinResource("simkai.ttf"); + } + + // 设置默认颜色过度值 + private static void SetDefaultColorTransitionValues(Selectable slider) + { + ColorBlock colors = slider.colors; + colors.highlightedColor = new Color(0.882f, 0.882f, 0.882f); + colors.pressedColor = new Color(0.698f, 0.698f, 0.698f); + colors.disabledColor = new Color(0.521f, 0.521f, 0.521f); + } + + // 设置父级对其 + private static void SetParentAndAlign(GameObject child, GameObject parent) + { + if (!(parent == null)) + { + child.transform.SetParent(parent.transform, false); + UIControls.SetLayerRecursively(child, parent.layer); + } + } + + // 递归设置层 + private static void SetLayerRecursively(GameObject go, int layer) + { + go.layer = layer; + Transform transform = go.transform; + for (int i = 0; i < transform.childCount; i++) + { + UIControls.SetLayerRecursively(transform.GetChild(i).gameObject, layer); + } + } + + // 创建面板 + public static GameObject CreatePanel(UIControls.Resources resources) + { + GameObject gameObject = UIControls.CreateUIElementRoot("Panel", UIControls.s_ThickElementSize); + RectTransform component = gameObject.GetComponent(); + component.anchorMin = Vector2.zero; + component.anchorMax = Vector2.one; + component.anchoredPosition = Vector2.zero; + component.sizeDelta = Vector2.zero; + Image image = gameObject.AddComponent(); + image.sprite = resources.background; + image.type = Image.Type.Sliced; + image.color = UIControls.s_PanelColor; + return gameObject; + } + + // 创建按钮 + public static GameObject CreateButton(UIControls.Resources resources, string Text) + { + GameObject gameObject = UIControls.CreateUIElementRoot("Button", UIControls.s_ThickElementSize); + GameObject gameObject2 = new GameObject("Text"); + gameObject2.AddComponent(); + UIControls.SetParentAndAlign(gameObject2, gameObject); + Image image = gameObject.AddComponent(); + image.sprite = resources.standard; + image.type = Image.Type.Sliced; + image.color = UIControls.s_DefaultSelectableColor; + Button defaultColorTransitionValues = gameObject.AddComponent