| | |
| | | private Vector2 scrollPosition; |
| | | private Vector2 reportScrollPosition; |
| | | private Vector2 battleInfoScrollPosition; |
| | | private Vector2 gmMessageScrollPosition; // GM消息滚动位置 |
| | | private Vector2 gmHistoryScrollPosition; // GM历史命令滚动位置 |
| | | private List<ItemConfig> searchResults = new List<ItemConfig>(); |
| | | private int itemCount = 1; |
| | | private bool isBattlePaused = false; |
| | | private bool showBattleInfo = false; // 控制战场信息显示/隐藏 |
| | | private bool showBattleInfo = false; |
| | | private List<string> gmMessages = new List<string>(); // 存储GM消息 |
| | | private List<string> gmCommandHistory = new List<string>(); // 存储历史GM命令 |
| | | private const int maxGmMessages = 50; // 最多保存50条消息 |
| | | private const int maxGmHistory = 30; // 最多保存30条历史命令 |
| | | |
| | | // 战报相关 |
| | | private string reportFilePath = ""; |
| | |
| | | private void OnEnable() |
| | | { |
| | | RefreshReportList(); |
| | | LoadGmCommandHistory(); |
| | | // 订阅GM消息刷新事件 |
| | | if (Application.isPlaying) |
| | | { |
| | | ServerTipDetails.gmMessageRefresh += OnGmMessageReceived; |
| | | } |
| | | } |
| | | |
| | | private void OnDisable() |
| | | { |
| | | SaveGmCommandHistory(); |
| | | // 取消订阅 |
| | | if (Application.isPlaying) |
| | | { |
| | | ServerTipDetails.gmMessageRefresh -= OnGmMessageReceived; |
| | | } |
| | | } |
| | | |
| | | private void Update() |
| | |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(5); |
| | | |
| | | // 提示信息 |
| | | GUIStyle hintStyle = new GUIStyle(EditorStyles.helpBox); |
| | | hintStyle.normal.textColor = new Color(0.5f, 0.8f, 1f); |
| | | hintStyle.fontSize = 10; |
| | | EditorGUILayout.LabelField("💡 支持多行命令,每行一条指令", hintStyle); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | // ========== GM历史命令与消息输出区域(左右分栏)========== |
| | | GUILayout.BeginHorizontal(); |
| | | |
| | | // 左侧:历史命令 |
| | | GUILayout.BeginVertical(GUILayout.Width(leftWidth * 0.5f - 10)); |
| | | |
| | | GUILayout.BeginHorizontal(); |
| | | GUILayout.Label("历史命令", EditorStyles.boldLabel); |
| | | GUILayout.FlexibleSpace(); |
| | | if (GUILayout.Button("清空", GUILayout.Width(60))) |
| | | { |
| | | if (EditorUtility.DisplayDialog("确认清空", "确定要清空所有历史命令吗?", "确定", "取消")) |
| | | { |
| | | gmCommandHistory.Clear(); |
| | | SaveGmCommandHistory(); |
| | | } |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | gmHistoryScrollPosition = GUILayout.BeginScrollView(gmHistoryScrollPosition, "box", GUILayout.Height(150)); |
| | | |
| | | if (gmCommandHistory.Count > 0) |
| | | { |
| | | for (int i = gmCommandHistory.Count - 1; i >= 0; i--) |
| | | { |
| | | GUILayout.BeginHorizontal("box"); |
| | | |
| | | // 显示命令(截断长文本) |
| | | string displayCmd = gmCommandHistory[i]; |
| | | if (displayCmd.Length > 30) |
| | | { |
| | | displayCmd = displayCmd.Substring(0, 27) + "..."; |
| | | } |
| | | |
| | | if (GUILayout.Button(displayCmd, EditorStyles.label)) |
| | | { |
| | | OnClickHistoryCommand(gmCommandHistory[i]); |
| | | } |
| | | |
| | | // 删除按钮 |
| | | if (GUILayout.Button("×", GUILayout.Width(20))) |
| | | { |
| | | gmCommandHistory.RemoveAt(i); |
| | | SaveGmCommandHistory(); |
| | | } |
| | | |
| | | GUILayout.EndHorizontal(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | GUILayout.Label("历史命令将在这里显示...", EditorStyles.centeredGreyMiniLabel); |
| | | } |
| | | |
| | | GUILayout.EndScrollView(); |
| | | |
| | | GUILayout.EndVertical(); |
| | | |
| | | // 中间分割线 |
| | | GUILayout.Box("", GUILayout.Width(2), GUILayout.Height(150)); |
| | | |
| | | // 右侧:消息输出 |
| | | GUILayout.BeginVertical(GUILayout.ExpandWidth(true)); |
| | | |
| | | GUILayout.BeginHorizontal(); |
| | | GUILayout.Label("GM消息输出", EditorStyles.boldLabel); |
| | | GUILayout.FlexibleSpace(); |
| | | if (GUILayout.Button("清空", GUILayout.Width(60))) |
| | | { |
| | | gmMessages.Clear(); |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | gmMessageScrollPosition = GUILayout.BeginScrollView(gmMessageScrollPosition, "box", GUILayout.Height(150)); |
| | | |
| | | if (gmMessages.Count > 0) |
| | | { |
| | | for (int i = gmMessages.Count - 1; i >= 0; i--) |
| | | { |
| | | GUILayout.Label(gmMessages[i], EditorStyles.wordWrappedLabel); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | GUILayout.Label("GM消息将在这里显示...", EditorStyles.centeredGreyMiniLabel); |
| | | } |
| | | |
| | | GUILayout.EndScrollView(); |
| | | |
| | | GUILayout.EndVertical(); |
| | | |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | // 提示信息 |
| | |
| | | warningStyle.normal.textColor = new Color(1f, 0.6f, 0f); |
| | | warningStyle.fontSize = 11; |
| | | EditorGUILayout.LabelField("⚠ 添加物品最好跟服务器确认过物品的存在后再添加", warningStyle); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | // 战报浏览区域 |
| | | GUILayout.Label("战报浏览", EditorStyles.boldLabel); |
| | | GUILayout.BeginVertical("box"); |
| | | |
| | | GUILayout.BeginHorizontal(); |
| | | if (GUILayout.Button("刷新战报列表", GUILayout.Width(120))) |
| | | { |
| | | RefreshReportList(); |
| | | } |
| | | if (GUILayout.Button("打开战报文件夹", GUILayout.Width(120))) |
| | | { |
| | | OpenReportFolder(); |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(5); |
| | | |
| | | if (reportFiles.Length > 0) |
| | | { |
| | | reportScrollPosition = GUILayout.BeginScrollView(reportScrollPosition, GUILayout.Height(150)); |
| | | |
| | | for (int i = 0; i < reportFiles.Length; i++) |
| | | { |
| | | GUILayout.BeginHorizontal("box"); |
| | | string fileName = Path.GetFileName(reportFiles[i]); |
| | | GUILayout.Label(fileName, GUILayout.Width(300)); |
| | | |
| | | if (GUILayout.Button("加载", GUILayout.Width(60))) |
| | | { |
| | | LoadReport(reportFiles[i]); |
| | | } |
| | | |
| | | if (GUILayout.Button("删除", GUILayout.Width(60))) |
| | | { |
| | | DeleteReport(reportFiles[i]); |
| | | } |
| | | |
| | | GUILayout.EndHorizontal(); |
| | | } |
| | | |
| | | GUILayout.EndScrollView(); |
| | | } |
| | | else |
| | | { |
| | | GUILayout.Label("未找到战报文件(.bytes)"); |
| | | } |
| | | |
| | | GUILayout.EndVertical(); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | |
| | | GUILayout.FlexibleSpace(); |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(5); |
| | | // 添加跳过战斗按钮 |
| | | GUILayout.BeginHorizontal(); |
| | | GUILayout.FlexibleSpace(); |
| | | BattleField bf = GetActiveBattleField(); |
| | | bool canSkip = bf != null && !string.IsNullOrEmpty(bf.guid); |
| | | GUI.enabled = canSkip; |
| | | if (GUILayout.Button("跳过当前战斗", GUILayout.Width(120), GUILayout.Height(30))) |
| | | { |
| | | OnSkipBattle(); |
| | | } |
| | | GUI.enabled = true; |
| | | GUILayout.FlexibleSpace(); |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(10); |
| | | |
| | | battleInfoScrollPosition = GUILayout.BeginScrollView(battleInfoScrollPosition); |
| | | |
| | | DrawBattleFieldInfo(); |
| | | |
| | | GUILayout.Space(20); |
| | | |
| | | // 战报浏览区域 |
| | | GUILayout.Label("战报浏览", EditorStyles.boldLabel); |
| | | GUILayout.BeginVertical("box"); |
| | | |
| | | GUILayout.BeginHorizontal(); |
| | | if (GUILayout.Button("刷新战报列表", GUILayout.Width(120))) |
| | | { |
| | | RefreshReportList(); |
| | | } |
| | | if (GUILayout.Button("打开战报文件夹", GUILayout.Width(120))) |
| | | { |
| | | OpenReportFolder(); |
| | | } |
| | | GUILayout.EndHorizontal(); |
| | | |
| | | GUILayout.Space(5); |
| | | |
| | | if (reportFiles.Length > 0) |
| | | { |
| | | reportScrollPosition = GUILayout.BeginScrollView(reportScrollPosition, GUILayout.Height(200)); |
| | | |
| | | for (int i = 0; i < reportFiles.Length; i++) |
| | | { |
| | | GUILayout.BeginHorizontal("box"); |
| | | string fileName = Path.GetFileName(reportFiles[i]); |
| | | GUILayout.Label(fileName, GUILayout.ExpandWidth(true)); |
| | | |
| | | if (GUILayout.Button("加载", GUILayout.Width(60))) |
| | | { |
| | | LoadReport(reportFiles[i]); |
| | | } |
| | | |
| | | if (GUILayout.Button("删除", GUILayout.Width(60))) |
| | | { |
| | | DeleteReport(reportFiles[i]); |
| | | } |
| | | |
| | | GUILayout.EndHorizontal(); |
| | | } |
| | | |
| | | GUILayout.EndScrollView(); |
| | | } |
| | | else |
| | | { |
| | | GUILayout.Label("未找到战报文件(.tfr)", EditorStyles.centeredGreyMiniLabel); |
| | | } |
| | | |
| | | GUILayout.EndVertical(); |
| | | |
| | | GUILayout.EndScrollView(); |
| | | |
| | |
| | | string reportFolder = Application.dataPath + "/../BattleReport/"; |
| | | if (Directory.Exists(reportFolder)) |
| | | { |
| | | reportFiles = Directory.GetFiles(reportFolder, "*.bytes"); |
| | | reportFiles = Directory.GetFiles(reportFolder, "*.tfr"); |
| | | Debug.Log($"找到 {reportFiles.Length} 个战报文件"); |
| | | } |
| | | else |
| | |
| | | commandText = $"MakeItemCount {item.ID} {itemCount}"; |
| | | } |
| | | |
| | | private void OnGmMessageReceived(string message) |
| | | { |
| | | // 添加时间戳 |
| | | string timeStamp = System.DateTime.Now.ToString("HH:mm:ss"); |
| | | string formattedMessage = $"[{timeStamp}] {message}"; |
| | | |
| | | gmMessages.Add(formattedMessage); |
| | | |
| | | // 限制消息数量 |
| | | if (gmMessages.Count > maxGmMessages) |
| | | { |
| | | gmMessages.RemoveAt(0); |
| | | } |
| | | |
| | | // 自动滚动到底部 |
| | | gmMessageScrollPosition.y = float.MaxValue; |
| | | |
| | | Repaint(); |
| | | } |
| | | |
| | | private void OnClickHistoryCommand(string command) |
| | | { |
| | | // 智能换行:如果当前有内容且不是以换行结尾,就添加换行 |
| | | if (!string.IsNullOrEmpty(commandText) && !commandText.EndsWith("\n")) |
| | | { |
| | | commandText += "\n"; |
| | | } |
| | | |
| | | commandText += command; |
| | | |
| | | Debug.Log($"已添加历史命令: {command}"); |
| | | } |
| | | |
| | | private void OnSendCommand() |
| | | { |
| | | if (string.IsNullOrEmpty(commandText)) |
| | |
| | | return; |
| | | } |
| | | |
| | | Debug.Log("发送命令: " + commandText); |
| | | GMCmdManager.Instance.OnSendGMQuest(commandText); |
| | | GMCmdManager.Instance.SetRecordCmdlist(commandText); |
| | | // 按换行符分割命令 |
| | | string[] commands = commandText.Split(new[] { "\r\n", "\r", "\n" }, System.StringSplitOptions.RemoveEmptyEntries); |
| | | |
| | | if (commands.Length == 0) |
| | | { |
| | | Debug.LogWarning("没有有效的命令"); |
| | | return; |
| | | } |
| | | |
| | | // 发送每条命令并添加到历史记录 |
| | | foreach (string cmd in commands) |
| | | { |
| | | string trimmedCmd = cmd.Trim(); |
| | | if (!string.IsNullOrEmpty(trimmedCmd)) |
| | | { |
| | | Debug.Log("发送命令: " + trimmedCmd); |
| | | GMCmdManager.Instance.OnSendGMQuest(trimmedCmd); |
| | | GMCmdManager.Instance.SetRecordCmdlist(trimmedCmd); |
| | | |
| | | // 添加到历史记录(避免重复) |
| | | if (!gmCommandHistory.Contains(trimmedCmd)) |
| | | { |
| | | gmCommandHistory.Add(trimmedCmd); |
| | | |
| | | // 限制历史记录数量 |
| | | if (gmCommandHistory.Count > maxGmHistory) |
| | | { |
| | | gmCommandHistory.RemoveAt(0); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (commands.Length > 1) |
| | | { |
| | | Debug.Log($"已发送 {commands.Length} 条命令"); |
| | | } |
| | | |
| | | // 保存历史记录 |
| | | SaveGmCommandHistory(); |
| | | } |
| | | |
| | | private void LoadGmCommandHistory() |
| | | { |
| | | string historyFile = Application.dataPath + "/../GMCommandHistory.txt"; |
| | | if (File.Exists(historyFile)) |
| | | { |
| | | try |
| | | { |
| | | string[] lines = File.ReadAllLines(historyFile); |
| | | gmCommandHistory = new List<string>(lines); |
| | | Debug.Log($"加载了 {gmCommandHistory.Count} 条历史GM命令"); |
| | | } |
| | | catch (System.Exception e) |
| | | { |
| | | Debug.LogError("加载GM命令历史失败: " + e.Message); |
| | | gmCommandHistory = new List<string>(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void SaveGmCommandHistory() |
| | | { |
| | | string historyFile = Application.dataPath + "/../GMCommandHistory.txt"; |
| | | try |
| | | { |
| | | File.WriteAllLines(historyFile, gmCommandHistory.ToArray()); |
| | | } |
| | | catch (System.Exception e) |
| | | { |
| | | Debug.LogError("保存GM命令历史失败: " + e.Message); |
| | | } |
| | | } |
| | | |
| | | private void OnPauseBattle() |
| | |
| | | |
| | | Debug.LogWarning("未找到激活的战斗窗口或 battleField 为空"); |
| | | } |
| | | |
| | | private void OnSkipBattle() |
| | | { |
| | | BattleField battleField = GetActiveBattleField(); |
| | | if (battleField == null) |
| | | { |
| | | Debug.LogWarning("未找到激活的战场"); |
| | | return; |
| | | } |
| | | |
| | | if (battleField.guid == string.Empty) |
| | | { |
| | | Debug.LogWarning("主线关卡无法跳过"); |
| | | return; |
| | | } |
| | | |
| | | battleField.ForceFinish(); |
| | | |
| | | } |
| | | } |