|
| 1 | +using BTD_Mod_Helper.Api.Components; |
| 2 | +using BTD_Mod_Helper.Api.Enums; |
| 3 | +using BTD_Mod_Helper.Api.Helpers; |
| 4 | +using FactoryCore.API.ModuleValues; |
| 5 | +using NfdSharp; |
| 6 | +using System; |
| 7 | +using System.Collections.Generic; |
| 8 | +using System.IO; |
| 9 | +using System.Linq; |
| 10 | +using System.Text; |
| 11 | +using System.Threading.Tasks; |
| 12 | +using UnityEngine; |
| 13 | +using static Il2CppNinjaKiwi.GUTS.Models.BossRushRandomizerSettings; |
| 14 | +using static Il2CppSystem.Linq.Expressions.Interpreter.CastInstruction.CastInstructionNoT; |
| 15 | +using static Il2CppSystem.Linq.Expressions.Interpreter.NullableMethodCallInstruction; |
| 16 | + |
| 17 | +namespace BloonFactory.ModuleProperties |
| 18 | +{ |
| 19 | + internal class FileModuleProperty : ModuleProperty |
| 20 | + { |
| 21 | + public byte[] DefaultValue; |
| 22 | + public string Filter; |
| 23 | + |
| 24 | + public FileModuleProperty(byte[] defaultValue, string name, string filter) |
| 25 | + { |
| 26 | + DefaultValue = defaultValue; |
| 27 | + Name = name; |
| 28 | + Filter = filter; |
| 29 | + } |
| 30 | + public override ModHelperPanel GetVisual(ModHelperPanel root) |
| 31 | + { |
| 32 | + var panel = root.AddPanel(new Info("FloatSliderModuleValue", 0, 0, 1000, 300)); |
| 33 | + var button = panel.AddButton(new Info("Button", 0, 0, 750, 250, new Vector2(0.5f, 0.5f)), VanillaSprites.GreenBtnLong, new Action(ButtonPressed)); |
| 34 | + button.AddText(new Info("Text", 0, 0, 700, 200, new Vector2(0.5f, 0.5f)), "Select File").EnableAutoSizing(100, 0); |
| 35 | + return panel; |
| 36 | + } |
| 37 | + public void ButtonPressed() |
| 38 | + { |
| 39 | + FileDialogHelper.PrepareNativeDlls(); |
| 40 | + |
| 41 | + if (Nfd.OpenDialog(Filter, "", out string path) == Nfd.NfdResult.NFD_OKAY) |
| 42 | + { |
| 43 | + byte[] bytes = File.ReadAllBytes(path); |
| 44 | + Module.SetValue(bytes, Name); |
| 45 | + } |
| 46 | + } |
| 47 | + public override void LoadData() |
| 48 | + { |
| 49 | + if (!Module.HasValue(Name)) |
| 50 | + Module.SetValue(DefaultValue, Name); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments