Add Activity Config Editor (CHS Only)

This commit is contained in:
2023-05-08 22:53:40 +08:00
parent f4ec2ee5fa
commit 226742776f
18 changed files with 1736 additions and 517 deletions

View File

@@ -0,0 +1,448 @@
namespace GrasscutterTools.Forms
{
partial class FormActivityEditor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.BtnSave = new System.Windows.Forms.Button();
this.BtnLoad = new System.Windows.Forms.Button();
this.ActivityConfigJsonPath = new System.Windows.Forms.TextBox();
this.LblActivityConfigJsonPath = new System.Windows.Forms.Label();
this.GrpAllActivity = new System.Windows.Forms.GroupBox();
this.ListAllActivity = new System.Windows.Forms.ListView();
this.GrpFileActivity = new System.Windows.Forms.GroupBox();
this.GrpActivityInfo = new System.Windows.Forms.GroupBox();
this.LblActivityTitle = new System.Windows.Forms.Label();
this.LblActivityParmEditTip = new System.Windows.Forms.Label();
this.BtnDelete = new System.Windows.Forms.Button();
this.BtnAddOrUpdate = new System.Windows.Forms.Button();
this.DTPEndTime = new System.Windows.Forms.DateTimePicker();
this.DTPBeginTime = new System.Windows.Forms.DateTimePicker();
this.TxtMeetCondList = new System.Windows.Forms.TextBox();
this.NUDScheduleId = new System.Windows.Forms.NumericUpDown();
this.NUDActivityType = new System.Windows.Forms.NumericUpDown();
this.NUDActivityId = new System.Windows.Forms.NumericUpDown();
this.LblEndTime = new System.Windows.Forms.Label();
this.LblBeginTime = new System.Windows.Forms.Label();
this.LblMeetCondList = new System.Windows.Forms.Label();
this.LblScheduleId = new System.Windows.Forms.Label();
this.LblActivityType = new System.Windows.Forms.Label();
this.LblActivityId = new System.Windows.Forms.Label();
this.ColumnActivityName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ColumnActivityId = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ListActivityConfigItems = new System.Windows.Forms.ListView();
this.ColActivityId = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ColActivityTitle = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ColActivityBeginTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ColActivityEndTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.GrpAllActivity.SuspendLayout();
this.GrpFileActivity.SuspendLayout();
this.GrpActivityInfo.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.NUDScheduleId)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NUDActivityType)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NUDActivityId)).BeginInit();
this.SuspendLayout();
//
// BtnSave
//
this.BtnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.BtnSave.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.BtnSave.Location = new System.Drawing.Point(776, 12);
this.BtnSave.Name = "BtnSave";
this.BtnSave.Size = new System.Drawing.Size(100, 23);
this.BtnSave.TabIndex = 3;
this.BtnSave.Text = "保存";
this.BtnSave.UseVisualStyleBackColor = true;
this.BtnSave.Click += new System.EventHandler(this.BtnSave_Click);
//
// BtnLoad
//
this.BtnLoad.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.BtnLoad.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.BtnLoad.Location = new System.Drawing.Point(671, 12);
this.BtnLoad.Name = "BtnLoad";
this.BtnLoad.Size = new System.Drawing.Size(100, 23);
this.BtnLoad.TabIndex = 2;
this.BtnLoad.Text = "加载";
this.BtnLoad.UseVisualStyleBackColor = true;
this.BtnLoad.Click += new System.EventHandler(this.BtnLoad_Click);
//
// ActivityConfigJsonPath
//
this.ActivityConfigJsonPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ActivityConfigJsonPath.Location = new System.Drawing.Point(176, 12);
this.ActivityConfigJsonPath.Name = "ActivityConfigJsonPath";
this.ActivityConfigJsonPath.Size = new System.Drawing.Size(489, 23);
this.ActivityConfigJsonPath.TabIndex = 1;
//
// LblActivityConfigJsonPath
//
this.LblActivityConfigJsonPath.AutoSize = true;
this.LblActivityConfigJsonPath.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.LblActivityConfigJsonPath.Location = new System.Drawing.Point(17, 15);
this.LblActivityConfigJsonPath.Name = "LblActivityConfigJsonPath";
this.LblActivityConfigJsonPath.Size = new System.Drawing.Size(153, 17);
this.LblActivityConfigJsonPath.TabIndex = 0;
this.LblActivityConfigJsonPath.Text = "ActivityConfig.json 路径:";
//
// GrpAllActivity
//
this.GrpAllActivity.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.GrpAllActivity.Controls.Add(this.ListAllActivity);
this.GrpAllActivity.Location = new System.Drawing.Point(612, 41);
this.GrpAllActivity.Name = "GrpAllActivity";
this.GrpAllActivity.Size = new System.Drawing.Size(260, 328);
this.GrpAllActivity.TabIndex = 6;
this.GrpAllActivity.TabStop = false;
this.GrpAllActivity.Text = "已知活动 by dplek";
//
// ListAllActivity
//
this.ListAllActivity.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.ColumnActivityId,
this.ColumnActivityName});
this.ListAllActivity.Dock = System.Windows.Forms.DockStyle.Fill;
this.ListAllActivity.FullRowSelect = true;
this.ListAllActivity.HideSelection = false;
this.ListAllActivity.Location = new System.Drawing.Point(3, 19);
this.ListAllActivity.MultiSelect = false;
this.ListAllActivity.Name = "ListAllActivity";
this.ListAllActivity.Size = new System.Drawing.Size(254, 306);
this.ListAllActivity.TabIndex = 0;
this.ListAllActivity.UseCompatibleStateImageBehavior = false;
this.ListAllActivity.View = System.Windows.Forms.View.Details;
this.ListAllActivity.SelectedIndexChanged += new System.EventHandler(this.ListAllActivity_SelectedIndexChanged);
//
// GrpFileActivity
//
this.GrpFileActivity.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.GrpFileActivity.Controls.Add(this.ListActivityConfigItems);
this.GrpFileActivity.Location = new System.Drawing.Point(12, 41);
this.GrpFileActivity.Name = "GrpFileActivity";
this.GrpFileActivity.Size = new System.Drawing.Size(260, 328);
this.GrpFileActivity.TabIndex = 4;
this.GrpFileActivity.TabStop = false;
this.GrpFileActivity.Text = "当前文件";
//
// GrpActivityInfo
//
this.GrpActivityInfo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.GrpActivityInfo.Controls.Add(this.LblActivityTitle);
this.GrpActivityInfo.Controls.Add(this.LblActivityParmEditTip);
this.GrpActivityInfo.Controls.Add(this.BtnDelete);
this.GrpActivityInfo.Controls.Add(this.BtnAddOrUpdate);
this.GrpActivityInfo.Controls.Add(this.DTPEndTime);
this.GrpActivityInfo.Controls.Add(this.DTPBeginTime);
this.GrpActivityInfo.Controls.Add(this.TxtMeetCondList);
this.GrpActivityInfo.Controls.Add(this.NUDScheduleId);
this.GrpActivityInfo.Controls.Add(this.NUDActivityType);
this.GrpActivityInfo.Controls.Add(this.NUDActivityId);
this.GrpActivityInfo.Controls.Add(this.LblEndTime);
this.GrpActivityInfo.Controls.Add(this.LblBeginTime);
this.GrpActivityInfo.Controls.Add(this.LblMeetCondList);
this.GrpActivityInfo.Controls.Add(this.LblScheduleId);
this.GrpActivityInfo.Controls.Add(this.LblActivityType);
this.GrpActivityInfo.Controls.Add(this.LblActivityId);
this.GrpActivityInfo.Location = new System.Drawing.Point(278, 41);
this.GrpActivityInfo.Name = "GrpActivityInfo";
this.GrpActivityInfo.Size = new System.Drawing.Size(328, 328);
this.GrpActivityInfo.TabIndex = 5;
this.GrpActivityInfo.TabStop = false;
this.GrpActivityInfo.Text = "活动信息";
//
// LblActivityTitle
//
this.LblActivityTitle.AutoEllipsis = true;
this.LblActivityTitle.ForeColor = System.Drawing.SystemColors.GrayText;
this.LblActivityTitle.Location = new System.Drawing.Point(173, 45);
this.LblActivityTitle.Name = "LblActivityTitle";
this.LblActivityTitle.Size = new System.Drawing.Size(134, 17);
this.LblActivityTitle.TabIndex = 2;
this.LblActivityTitle.Text = "活动名称";
//
// LblActivityParmEditTip
//
this.LblActivityParmEditTip.AutoSize = true;
this.LblActivityParmEditTip.ForeColor = System.Drawing.SystemColors.GrayText;
this.LblActivityParmEditTip.Location = new System.Drawing.Point(40, 251);
this.LblActivityParmEditTip.Name = "LblActivityParmEditTip";
this.LblActivityParmEditTip.Size = new System.Drawing.Size(248, 17);
this.LblActivityParmEditTip.TabIndex = 13;
this.LblActivityParmEditTip.Text = "提示:通常情况下你只需要修改活动进行时间";
//
// BtnDelete
//
this.BtnDelete.Enabled = false;
this.BtnDelete.Location = new System.Drawing.Point(199, 271);
this.BtnDelete.Name = "BtnDelete";
this.BtnDelete.Size = new System.Drawing.Size(89, 30);
this.BtnDelete.TabIndex = 15;
this.BtnDelete.Text = "- 删除";
this.BtnDelete.UseVisualStyleBackColor = true;
this.BtnDelete.Click += new System.EventHandler(this.BtnDelete_Click);
//
// BtnAddOrUpdate
//
this.BtnAddOrUpdate.Location = new System.Drawing.Point(43, 271);
this.BtnAddOrUpdate.Name = "BtnAddOrUpdate";
this.BtnAddOrUpdate.Size = new System.Drawing.Size(150, 30);
this.BtnAddOrUpdate.TabIndex = 14;
this.BtnAddOrUpdate.Text = "√ 添加或更新";
this.BtnAddOrUpdate.UseVisualStyleBackColor = true;
this.BtnAddOrUpdate.Click += new System.EventHandler(this.BtnAddOrUpdate_Click);
//
// DTPEndTime
//
this.DTPEndTime.Location = new System.Drawing.Point(107, 188);
this.DTPEndTime.Name = "DTPEndTime";
this.DTPEndTime.Size = new System.Drawing.Size(200, 23);
this.DTPEndTime.TabIndex = 12;
//
// DTPBeginTime
//
this.DTPBeginTime.Location = new System.Drawing.Point(107, 159);
this.DTPBeginTime.Name = "DTPBeginTime";
this.DTPBeginTime.Size = new System.Drawing.Size(200, 23);
this.DTPBeginTime.TabIndex = 10;
//
// TxtMeetCondList
//
this.TxtMeetCondList.Location = new System.Drawing.Point(107, 130);
this.TxtMeetCondList.Name = "TxtMeetCondList";
this.TxtMeetCondList.Size = new System.Drawing.Size(200, 23);
this.TxtMeetCondList.TabIndex = 8;
//
// NUDScheduleId
//
this.NUDScheduleId.Location = new System.Drawing.Point(107, 101);
this.NUDScheduleId.Maximum = new decimal(new int[] {
2147483647,
0,
0,
0});
this.NUDScheduleId.Name = "NUDScheduleId";
this.NUDScheduleId.Size = new System.Drawing.Size(80, 23);
this.NUDScheduleId.TabIndex = 6;
//
// NUDActivityType
//
this.NUDActivityType.Location = new System.Drawing.Point(107, 72);
this.NUDActivityType.Maximum = new decimal(new int[] {
2147483647,
0,
0,
0});
this.NUDActivityType.Name = "NUDActivityType";
this.NUDActivityType.Size = new System.Drawing.Size(60, 23);
this.NUDActivityType.TabIndex = 4;
//
// NUDActivityId
//
this.NUDActivityId.Location = new System.Drawing.Point(107, 43);
this.NUDActivityId.Maximum = new decimal(new int[] {
2147483647,
0,
0,
0});
this.NUDActivityId.Name = "NUDActivityId";
this.NUDActivityId.Size = new System.Drawing.Size(60, 23);
this.NUDActivityId.TabIndex = 1;
this.NUDActivityId.ValueChanged += new System.EventHandler(this.NUDActivityId_ValueChanged);
//
// LblEndTime
//
this.LblEndTime.AutoSize = true;
this.LblEndTime.Location = new System.Drawing.Point(21, 193);
this.LblEndTime.Name = "LblEndTime";
this.LblEndTime.Size = new System.Drawing.Size(80, 17);
this.LblEndTime.TabIndex = 11;
this.LblEndTime.Text = "活动结束时间";
//
// LblBeginTime
//
this.LblBeginTime.AutoSize = true;
this.LblBeginTime.Location = new System.Drawing.Point(21, 164);
this.LblBeginTime.Name = "LblBeginTime";
this.LblBeginTime.Size = new System.Drawing.Size(80, 17);
this.LblBeginTime.TabIndex = 9;
this.LblBeginTime.Text = "活动开始时间";
//
// LblMeetCondList
//
this.LblMeetCondList.AutoSize = true;
this.LblMeetCondList.Location = new System.Drawing.Point(21, 133);
this.LblMeetCondList.Name = "LblMeetCondList";
this.LblMeetCondList.Size = new System.Drawing.Size(80, 17);
this.LblMeetCondList.TabIndex = 7;
this.LblMeetCondList.Text = "满足条件列表";
//
// LblScheduleId
//
this.LblScheduleId.AutoSize = true;
this.LblScheduleId.Location = new System.Drawing.Point(21, 103);
this.LblScheduleId.Name = "LblScheduleId";
this.LblScheduleId.Size = new System.Drawing.Size(45, 17);
this.LblScheduleId.TabIndex = 5;
this.LblScheduleId.Text = "计划ID";
//
// LblActivityType
//
this.LblActivityType.AutoSize = true;
this.LblActivityType.Location = new System.Drawing.Point(21, 74);
this.LblActivityType.Name = "LblActivityType";
this.LblActivityType.Size = new System.Drawing.Size(56, 17);
this.LblActivityType.TabIndex = 3;
this.LblActivityType.Text = "活动类型";
//
// LblActivityId
//
this.LblActivityId.AutoSize = true;
this.LblActivityId.Location = new System.Drawing.Point(21, 45);
this.LblActivityId.Name = "LblActivityId";
this.LblActivityId.Size = new System.Drawing.Size(45, 17);
this.LblActivityId.TabIndex = 0;
this.LblActivityId.Text = "活动ID";
//
// ColumnActivityName
//
this.ColumnActivityName.Text = "活动名称";
this.ColumnActivityName.Width = 300;
//
// ColumnActivityId
//
this.ColumnActivityId.Text = "ID";
this.ColumnActivityId.Width = 50;
//
// ListActivityConfigItems
//
this.ListActivityConfigItems.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.ColActivityId,
this.ColActivityTitle,
this.ColActivityBeginTime,
this.ColActivityEndTime});
this.ListActivityConfigItems.Dock = System.Windows.Forms.DockStyle.Fill;
this.ListActivityConfigItems.FullRowSelect = true;
this.ListActivityConfigItems.HideSelection = false;
this.ListActivityConfigItems.Location = new System.Drawing.Point(3, 19);
this.ListActivityConfigItems.MultiSelect = false;
this.ListActivityConfigItems.Name = "ListActivityConfigItems";
this.ListActivityConfigItems.Size = new System.Drawing.Size(254, 306);
this.ListActivityConfigItems.TabIndex = 0;
this.ListActivityConfigItems.UseCompatibleStateImageBehavior = false;
this.ListActivityConfigItems.View = System.Windows.Forms.View.Details;
this.ListActivityConfigItems.SelectedIndexChanged += new System.EventHandler(this.ListActivityConfigItems_SelectedIndexChanged);
//
// ColActivityId
//
this.ColActivityId.Text = "ID";
this.ColActivityId.Width = 50;
//
// ColActivityTitle
//
this.ColActivityTitle.Text = "活动名称";
this.ColActivityTitle.Width = 150;
//
// ColActivityBeginTime
//
this.ColActivityBeginTime.Text = "开始时间";
this.ColActivityBeginTime.Width = 120;
//
// ColActivityEndTime
//
this.ColActivityEndTime.Text = "结束时间";
this.ColActivityEndTime.Width = 120;
//
// FormActivityEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(884, 381);
this.Controls.Add(this.GrpAllActivity);
this.Controls.Add(this.GrpActivityInfo);
this.Controls.Add(this.GrpFileActivity);
this.Controls.Add(this.BtnSave);
this.Controls.Add(this.BtnLoad);
this.Controls.Add(this.ActivityConfigJsonPath);
this.Controls.Add(this.LblActivityConfigJsonPath);
this.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F);
this.Margin = new System.Windows.Forms.Padding(4);
this.MinimumSize = new System.Drawing.Size(900, 420);
this.Name = "FormActivityEditor";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ActivityConfig.json Editor";
this.GrpAllActivity.ResumeLayout(false);
this.GrpFileActivity.ResumeLayout(false);
this.GrpActivityInfo.ResumeLayout(false);
this.GrpActivityInfo.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.NUDScheduleId)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.NUDActivityType)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.NUDActivityId)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button BtnSave;
private System.Windows.Forms.Button BtnLoad;
private System.Windows.Forms.TextBox ActivityConfigJsonPath;
private System.Windows.Forms.Label LblActivityConfigJsonPath;
private System.Windows.Forms.GroupBox GrpAllActivity;
private System.Windows.Forms.GroupBox GrpFileActivity;
private System.Windows.Forms.GroupBox GrpActivityInfo;
private System.Windows.Forms.ListView ListAllActivity;
private System.Windows.Forms.Label LblEndTime;
private System.Windows.Forms.Label LblBeginTime;
private System.Windows.Forms.Label LblMeetCondList;
private System.Windows.Forms.Label LblScheduleId;
private System.Windows.Forms.Label LblActivityType;
private System.Windows.Forms.Label LblActivityId;
private System.Windows.Forms.Button BtnDelete;
private System.Windows.Forms.Button BtnAddOrUpdate;
private System.Windows.Forms.DateTimePicker DTPEndTime;
private System.Windows.Forms.DateTimePicker DTPBeginTime;
private System.Windows.Forms.TextBox TxtMeetCondList;
private System.Windows.Forms.NumericUpDown NUDScheduleId;
private System.Windows.Forms.NumericUpDown NUDActivityType;
private System.Windows.Forms.NumericUpDown NUDActivityId;
private System.Windows.Forms.Label LblActivityParmEditTip;
private System.Windows.Forms.Label LblActivityTitle;
private System.Windows.Forms.ColumnHeader ColumnActivityId;
private System.Windows.Forms.ColumnHeader ColumnActivityName;
private System.Windows.Forms.ListView ListActivityConfigItems;
private System.Windows.Forms.ColumnHeader ColActivityId;
private System.Windows.Forms.ColumnHeader ColActivityTitle;
private System.Windows.Forms.ColumnHeader ColActivityBeginTime;
private System.Windows.Forms.ColumnHeader ColActivityEndTime;
}
}

View File

@@ -0,0 +1,301 @@
/**
* Grasscutter Tools
* Copyright (C) 2023 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 <https://www.gnu.org/licenses/>.
*
**/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using GrasscutterTools.Game;
using GrasscutterTools.Game.Activity;
using GrasscutterTools.Properties;
using GrasscutterTools.Utils;
using Newtonsoft.Json;
namespace GrasscutterTools.Forms
{
public partial class FormActivityEditor : Form
{
#region - -
private List<ActivityConfigItem> ActivityConfigItems;
#endregion - -
#region - -
public FormActivityEditor()
{
InitializeComponent();
Icon = Resources.IconGrasscutter;
DTPBeginTime.Value = DateTime.Today;
DTPEndTime.Value = DateTime.Today.AddMonths(1);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
LoadAllActivity();
try
{
// 加载文件路径
var path = Settings.Default.ActivityConfigJsonPath;
ActivityConfigJsonPath.Text = path;
if (!string.IsNullOrEmpty(path) && File.Exists(path))
LoadActivityConfig(path);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
Settings.Default.ActivityConfigJsonPath = ActivityConfigJsonPath.Text;
base.OnFormClosed(e);
}
#endregion - -
#region - ActivityConfig.json -
/// <summary>
/// 加载按钮点击时触发
/// </summary>
private void BtnLoad_Click(object sender, EventArgs e)
{
try
{
var path = ActivityConfigJsonPath.Text.Trim();
if (path == string.Empty)
{
var dialog = new OpenFileDialog
{
FileName = "ActivityConfig.json",
Filter = "ActivityConfig.Json (*.json)|*.json|All files (*.*)|*.*",
};
var result = dialog.ShowDialog();
if (result == DialogResult.OK)
path = ActivityConfigJsonPath.Text = dialog.FileName;
else
return;
}
// 反序列化
LoadActivityConfig(path);
MessageBox.Show("OK", Resources.Tips, MessageBoxButtons.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 加载活动配置
/// </summary>
/// <param name="path">ActivityConfig.json 文件路径</param>
private void LoadActivityConfig(string path)
{
ActivityConfigItems = JsonConvert.DeserializeObject<List<ActivityConfigItem>>(File.ReadAllText(path)) ?? new List<ActivityConfigItem>();
ListActivityConfigItems.BeginUpdate();
ListActivityConfigItems.Items.Clear();
ListActivityConfigItems.Items.AddRange(ActivityConfigItems.Select(Convert).ToArray());
ListActivityConfigItems.EndUpdate();
}
private ListViewItem Convert(ActivityConfigItem item)
{
return new ListViewItem(new[]
{
item.ActivityId.ToString(),
GameData.Activity[item.ActivityId],
item.BeginTime.ToShortDateString(),
item.EndTime.ToShortDateString(),
});
}
/// <summary>
/// 保存按钮点击时触发
/// </summary>
private void BtnSave_Click(object sender, EventArgs e)
{
try
{
var path = ActivityConfigJsonPath.Text.Trim();
if (path == string.Empty)
{
var dialog = new SaveFileDialog
{
FileName = "ActivityConfig.json",
Filter = "ActivityConfig.json (*.json)|*.json|All files (*.*)|*.*",
};
var result = dialog.ShowDialog();
if (result == DialogResult.OK)
path = ActivityConfigJsonPath.Text = dialog.FileName;
else
return;
}
// 序列化
File.WriteAllText(path, JsonConvert.SerializeObject(ActivityConfigItems, Formatting.Indented));
MessageBox.Show("OK", Resources.Tips, MessageBoxButtons.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#endregion - ActivityConfig.json -
#region - -
/// <summary>
/// 加载所有活动
/// </summary>
private void LoadAllActivity()
{
ListAllActivity.BeginUpdate();
foreach (var grp in GameData.Activity)
{
var grpControl = ListAllActivity.Groups.Add(grp.Key, grp.Key);
for (var i = 0; i < grp.Value.Count; i++)
{
ListAllActivity.Items.Add(new ListViewItem(new[]
{
grp.Value.Ids[i].ToString(), grp.Value.Names[i]
}, grpControl));
}
}
ListAllActivity.EndUpdate();
}
/// <summary>
/// 所有活动列表选中项改变时触发
/// </summary>
private void ListAllActivity_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
if (ListAllActivity.SelectedItems.Count == 0)
return;
NUDActivityId.Text = ListAllActivity.SelectedItems[0].Text;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 活动ID改变时触发
/// </summary>
private void NUDActivityId_ValueChanged(object sender, EventArgs e)
{
// 更新活动名称到提示文本
var activityId = (int)NUDActivityId.Value;
LblActivityTitle.Text = GameData.Activity[activityId];
// 检查是否在列表中,允许删除
var item = ActivityConfigItems.Find(it => it.ActivityId == activityId);
BtnDelete.Enabled = item != null;
}
/// <summary>
/// 点击添加或更新按钮时触发
/// </summary>
private async void BtnAddOrUpdate_Click(object sender, EventArgs e)
{
var activityId = (int)NUDActivityId.Value;
var item = ActivityConfigItems.Find(it => it.ActivityId == activityId);
if (item == null)
{
item = new ActivityConfigItem();
ActivityConfigItems.Add(item);
ListActivityConfigItems.Items.Add(Convert(item));
}
item.ActivityType = (int)NUDActivityType.Value;
item.ScheduleId = (int)NUDScheduleId.Value;
try
{
item.MeetCondList = TxtMeetCondList.Text.Split(',').Select(it => int.Parse(it.Trim())).ToList();
}
catch (Exception ex)
{
item.MeetCondList = new List<int>();
}
if (DTPBeginTime.Value > DTPEndTime.Value)
{
// ?
}
item.BeginTime = DTPBeginTime.Value.Date;
item.EndTime = DTPEndTime.Value.Date.AddDays(1).AddSeconds(-1);
BtnDelete.Enabled = true;
await UIUtil.ButtonComplete(BtnAddOrUpdate);
}
/// <summary>
/// 点击删除按钮时触发
/// </summary>
private void BtnDelete_Click(object sender, EventArgs e)
{
var activityId = (int)NUDActivityId.Value;
var index = ActivityConfigItems.FindIndex(it => it.ActivityId == activityId);
if (index != -1)
{
ListActivityConfigItems.Items.RemoveAt(index);
ActivityConfigItems.RemoveAt(index);
}
BtnDelete.Enabled = false;
}
/// <summary>
/// 当前文件活动配置列表选中项改变时触发
/// </summary>
private void ListActivityConfigItems_SelectedIndexChanged(object sender, EventArgs e)
{
if (ListActivityConfigItems.SelectedItems.Count == 0)
return;
var index = ListActivityConfigItems.SelectedIndices[0];
var configItem = ActivityConfigItems[index];
NUDActivityId.Value = configItem.ActivityId;
NUDActivityType.Value = configItem.ActivityType;
NUDScheduleId.Value = configItem.ScheduleId;
TxtMeetCondList.Text = configItem.MeetCondList?.Count > 0
? string.Join(",", configItem.MeetCondList)
: string.Empty;
DTPBeginTime.Value = configItem.BeginTime;
DTPEndTime.Value = configItem.EndTime;
}
#endregion - -
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>