/** * Grasscutter Tools * Copyright (C) 2022 jie65535 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * **/ using System; using System.Drawing; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using GrasscutterTools.Game; using GrasscutterTools.Utils; namespace GrasscutterTools.Pages { internal class BasePage : UserControl { public BasePage() { Font = new Font("Microsoft YaHei UI", 9, GraphicsUnit.Point); //Size = new Size(652, 245); Size = new Size(646, 239); BackColor = Color.FromArgb(0xF9, 0xF9, 0xF9); Margin = new Padding(0); } #region - 命令相关 - protected static CommandVersion CommandVersion => Common.CommandVersion; public delegate void SetCommandHandler(string command, string args = ""); /// /// 设置命令 /// /// 命令 /// 参数 public SetCommandHandler SetCommand { get; set; } public delegate Task RunCommandsHandler(params string[] commands); /// /// 运行命令 /// public RunCommandsHandler RunCommands { get; set; } /// /// 获取当前输入框命令 /// public Func GetCommand { get; set; } /// /// 运行原始命令(未处理的竖线分割命令文本) /// /// 未处理的竖线分割命令文本 /// 是否运行成功 protected async Task RunRawCommands(string commands) { if (commands.IndexOf('|') == -1) return await RunCommands(FormatCommand(commands)); else return await RunCommands(commands.Split('|').Select(FormatCommand).ToArray()); } /// /// 格式化命令 /// (去除收尾空白,替换换行) /// /// 原始输入 /// 格式化后可执行命令 private static string FormatCommand(string raw) { return raw.Trim().Replace("\\r", "\r").Replace("\\n", "\n"); } #endregion - 命令相关 - #region - 生命周期事件 - /// /// 加载时触发(修改语言时会再次触发) /// public virtual void OnLoad() { } /// /// 进入页面时触发(可触发多次) /// public virtual void OnEnter() { } /// /// 关闭时触发(用于保存页面数据) /// public virtual void OnClosed() { } #endregion - 生命周期事件 - } }