Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
DataEditorX
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
聖園ミカ
DataEditorX
Commits
f014efd8
Commit
f014efd8
authored
Mar 27, 2016
by
DailyShana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rewrite undo
parent
e72065c5
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
459 additions
and
351 deletions
+459
-351
DataEditorX/Config/YgoPath.cs
DataEditorX/Config/YgoPath.cs
+24
-32
DataEditorX/Core/CardEdit.cs
DataEditorX/Core/CardEdit.cs
+290
-204
DataEditorX/Core/CommandManager.cs
DataEditorX/Core/CommandManager.cs
+94
-0
DataEditorX/Core/YGOUtil.cs
DataEditorX/Core/YGOUtil.cs
+30
-51
DataEditorX/DataEditForm.cs
DataEditorX/DataEditForm.cs
+20
-64
DataEditorX/DataEditorX.csproj
DataEditorX/DataEditorX.csproj
+1
-0
No files found.
DataEditorX/Config/YgoPath.cs
View file @
f014efd8
...
...
@@ -20,7 +20,7 @@ public void SetPath(string gamepath)
luapath
=
MyPath
.
Combine
(
gamepath
,
"script"
);
ydkpath
=
MyPath
.
Combine
(
gamepath
,
"deck"
);
replaypath
=
MyPath
.
Combine
(
gamepath
,
"replay"
);
}
}
/// <summary>游戏目录</summary>
public
string
gamepath
;
/// <summary>大图目录</summary>
...
...
@@ -36,71 +36,63 @@ public void SetPath(string gamepath)
/// <summary>录像目录</summary>
public
string
replaypath
;
public
string
GetImage
(
long
id
,
bool
bak
=
false
)
public
string
GetImage
(
long
id
)
{
return
GetImage
(
id
.
ToString
()
,
bak
);
return
GetImage
(
id
.
ToString
());
}
public
string
GetImageThum
(
long
id
,
bool
bak
=
false
)
public
string
GetImageThum
(
long
id
)
{
return
GetImageThum
(
id
.
ToString
()
,
bak
);
return
GetImageThum
(
id
.
ToString
());
}
public
string
GetImageField
(
long
id
,
bool
bak
=
false
)
public
string
GetImageField
(
long
id
)
{
return
GetImageField
(
id
.
ToString
()
,
bak
);
//场地图
return
GetImageField
(
id
.
ToString
());
//场地图
}
public
string
GetScript
(
long
id
,
bool
bak
=
false
)
public
string
GetScript
(
long
id
)
{
return
GetScript
(
id
.
ToString
()
,
bak
);
return
GetScript
(
id
.
ToString
());
}
public
string
GetYdk
(
string
name
)
{
return
MyPath
.
Combine
(
ydkpath
,
name
+
".ydk"
);
}
//字符串id
public
string
GetImage
(
string
id
,
bool
bak
=
false
)
public
string
GetImage
(
string
id
)
{
if
(
bak
)
return
MyPath
.
Combine
(
picpath
,
id
+
".jpg.bak"
);
return
MyPath
.
Combine
(
picpath
,
id
+
".jpg"
);
}
public
string
GetImageThum
(
string
id
,
bool
bak
=
false
)
public
string
GetImageThum
(
string
id
)
{
if
(
bak
)
return
MyPath
.
Combine
(
picpath2
,
id
+
".jpg.bak"
);
return
MyPath
.
Combine
(
picpath2
,
id
+
".jpg"
);
}
public
string
GetImageField
(
string
id
,
bool
bak
=
false
)
public
string
GetImageField
(
string
id
)
{
if
(
bak
)
return
MyPath
.
Combine
(
fieldpath
,
id
+
".png.bak"
);
return
MyPath
.
Combine
(
fieldpath
,
id
+
".png"
);
//场地图
}
public
string
GetScript
(
string
id
,
bool
bak
=
false
)
public
string
GetScript
(
string
id
)
{
if
(
bak
)
return
MyPath
.
Combine
(
luapath
,
"c"
+
id
+
".lua.bak"
);
return
MyPath
.
Combine
(
luapath
,
"c"
+
id
+
".lua"
);
}
public
string
[]
GetCardfiles
(
long
id
,
bool
bak
=
false
)
public
string
[]
GetCardfiles
(
long
id
)
{
string
[]
files
=
new
string
[]{
GetImage
(
id
,
bak
),
//大图
GetImageThum
(
id
,
bak
),
//小图
GetImageField
(
id
,
bak
),
//场地图
GetScript
(
id
,
bak
)
GetImage
(
id
),
//大图
GetImageThum
(
id
),
//小图
GetImageField
(
id
),
//场地图
GetScript
(
id
)
};
return
files
;
}
public
string
[]
GetCardfiles
(
string
id
,
bool
bak
=
false
)
public
string
[]
GetCardfiles
(
string
id
)
{
string
[]
files
=
new
string
[]{
GetImage
(
id
,
bak
),
//大图
GetImageThum
(
id
,
bak
),
//小图
GetImageField
(
id
,
bak
),
//场地图
GetScript
(
id
,
bak
)
GetImage
(
id
),
//大图
GetImageThum
(
id
),
//小图
GetImageField
(
id
),
//场地图
GetScript
(
id
)
};
return
files
;
}
}
}
}
DataEditorX/Core/CardEdit.cs
View file @
f014efd8
This diff is collapsed.
Click to expand it.
DataEditorX/Core/CommandManager.cs
0 → 100644
View file @
f014efd8
using
System
;
using
System.Collections.Generic
;
namespace
DataEditorX.Core
{
public
delegate
void
StatusBool
(
bool
val
);
public
interface
ICommand
:
ICloneable
{
bool
Excute
(
params
object
[]
args
);
}
public
interface
IBackableCommand
:
ICommand
{
void
Undo
();
}
public
interface
ICommandManager
{
void
ExcuteCommand
(
ICommand
command
,
params
object
[]
args
);
void
Undo
();
void
ReverseUndo
();
//反撤销
event
StatusBool
UndoStateChanged
;
}
public
class
CommandManager
:
ICommandManager
{
private
Stack
<
ICommand
>
undoStack
=
new
Stack
<
ICommand
>();
private
Stack
<
ICommand
>
reverseStack
=
new
Stack
<
ICommand
>();
public
event
StatusBool
UndoStateChanged
;
public
CommandManager
()
{
UndoStateChanged
+=
new
StatusBool
(
CommandManager_UndoStateChanged
);
UndoStateChanged
+=
new
StatusBool
(
CommandManager_ReverseUndoStateChanged
);
}
private
void
CommandManager_UndoStateChanged
(
bool
val
)
{
}
private
void
CommandManager_ReverseUndoStateChanged
(
bool
val
)
{
}
#
region
ICommandManager
成员
public
void
ExcuteCommand
(
ICommand
command
,
params
object
[]
args
)
{
if
(!
command
.
Excute
(
args
))
return
;
reverseStack
.
Clear
();
if
(
command
is
IBackableCommand
)
{
undoStack
.
Push
((
ICommand
)
command
.
Clone
());
}
else
{
undoStack
.
Clear
();
}
UndoStateChanged
(
undoStack
.
Count
>
0
);
}
public
void
Undo
()
{
IBackableCommand
command
=
(
IBackableCommand
)
undoStack
.
Pop
();
if
(
command
==
null
)
{
return
;
}
command
.
Undo
();
reverseStack
.
Push
((
ICommand
)
command
.
Clone
());
UndoStateChanged
(
undoStack
.
Count
>
0
);
//UndoStateChanged(reverseStack.Count > 0);
}
public
void
ReverseUndo
()
{
IBackableCommand
command
=
(
IBackableCommand
)
reverseStack
.
Pop
();
if
(
command
==
null
)
{
return
;
}
command
.
Excute
();
undoStack
.
Push
((
ICommand
)
command
.
Clone
());
UndoStateChanged
(
undoStack
.
Count
>
0
);
}
#
endregion
}
}
DataEditorX/Core/YGOUtil.cs
View file @
f014efd8
...
...
@@ -3,10 +3,9 @@
using
System.IO
;
using
System.Collections.Generic
;
using
System.Text.RegularExpressions
;
using
Microsoft.VisualBasic
;
using
Microsoft.VisualBasic
.FileIO
;
using
System.Configuration
;
using
DataEditorX.Config
;
using
System.Windows.Forms
;
using
DataEditorX.Core.Info
;
...
...
@@ -205,59 +204,20 @@ public static string[] ReadImage(string path)
#
region
删除资源
//删除资源
public
enum
DeleteOption
{
BACKUP
,
RESTORE
,
CLEAN
,
NONE
,
}
public
static
void
CardDelete
(
long
id
,
YgoPath
ygopath
,
DeleteOption
option
)
public
static
void
CardDelete
(
long
id
,
YgoPath
ygopath
)
{
string
[]
files
=
ygopath
.
GetCardfiles
(
id
);
string
[]
bakfiles
=
ygopath
.
GetCardfiles
(
id
,
true
);
switch
(
option
)
for
(
int
i
=
0
;
i
<
files
.
Length
;
i
++)
{
case
DeleteOption
.
BACKUP
:
for
(
int
i
=
0
;
i
<
files
.
Length
;
i
++)
{
if
(
File
.
Exists
(
bakfiles
[
i
]))
File
.
Delete
(
bakfiles
[
i
]);
if
(
File
.
Exists
(
files
[
i
]))
File
.
Move
(
files
[
i
],
files
[
i
]
+
".bak"
);
}
break
;
case
DeleteOption
.
RESTORE
:
for
(
int
i
=
0
;
i
<
bakfiles
.
Length
;
i
++)
{
if
(
File
.
Exists
(
files
[
i
]))
File
.
Delete
(
files
[
i
]);
if
(
File
.
Exists
(
bakfiles
[
i
]))
File
.
Move
(
bakfiles
[
i
],
bakfiles
[
i
].
Replace
(
"bak"
,
""
));
}
break
;
case
DeleteOption
.
CLEAN
:
for
(
int
i
=
0
;
i
<
bakfiles
.
Length
;
i
++)
{
if
(
File
.
Exists
(
bakfiles
[
i
]))
File
.
Delete
(
bakfiles
[
i
]);
}
break
;
case
DeleteOption
.
NONE
:
for
(
int
i
=
0
;
i
<
files
.
Length
;
i
++)
{
if
(
File
.
Exists
(
files
[
i
]))
File
.
Delete
(
files
[
i
]);
}
break
;
if
(
FileSystem
.
FileExists
(
files
[
i
]))
FileSystem
.
DeleteFile
(
files
[
i
],
UIOption
.
OnlyErrorDialogs
,
RecycleOption
.
SendToRecycleBin
);
}
}
#
endregion
#
region
资源改名
//资源改名
public
static
void
CardRename
(
long
newid
,
long
oldid
,
YgoPath
ygopath
,
bool
delold
)
public
static
void
CardRename
(
long
newid
,
long
oldid
,
YgoPath
ygopath
)
{
string
[]
newfiles
=
ygopath
.
GetCardfiles
(
newid
);
string
[]
oldfiles
=
ygopath
.
GetCardfiles
(
oldid
);
...
...
@@ -266,13 +226,32 @@ public static void CardRename(long newid, long oldid, YgoPath ygopath, bool delo
{
if
(
File
.
Exists
(
oldfiles
[
i
]))
{
if
(
delold
)
File
.
Move
(
oldfiles
[
i
],
newfiles
[
i
]);
else
File
.
Copy
(
oldfiles
[
i
],
newfiles
[
i
],
false
);
try
{
File
.
Move
(
oldfiles
[
i
],
newfiles
[
i
]);
}
catch
{
}
}
}
}
#
endregion
#
endregion
#
region
复制资源
public
static
void
CardCopy
(
long
newid
,
long
oldid
,
YgoPath
ygopath
)
{
string
[]
newfiles
=
ygopath
.
GetCardfiles
(
newid
);
string
[]
oldfiles
=
ygopath
.
GetCardfiles
(
oldid
);
for
(
int
i
=
0
;
i
<
oldfiles
.
Length
;
i
++)
{
if
(
File
.
Exists
(
oldfiles
[
i
]))
{
try
{
File
.
Copy
(
oldfiles
[
i
],
newfiles
[
i
],
false
);
}
catch
{
}
}
}
}
#
endregion
}
}
DataEditorX/DataEditForm.cs
View file @
f014efd8
...
...
@@ -55,6 +55,8 @@ public partial class DataEditForm : DockContent, IDataForm
//setcode正在输入
bool
[]
setcodeIsedit
=
new
bool
[
5
];
CommandManager
cmdManager
=
new
CommandManager
();
Image
m_cover
;
MSEConfig
msecfg
;
...
...
@@ -90,6 +92,13 @@ void Initialize(string datapath)
InitializeComponent
();
title
=
this
.
Text
;
nowCdbFile
=
""
;
cmdManager
.
UndoStateChanged
+=
delegate
(
bool
val
)
{
if
(
val
)
btn_undo
.
Enabled
=
true
;
else
btn_undo
.
Enabled
=
false
;
};
}
#
endregion
...
...
@@ -147,18 +156,6 @@ void DataEditFormLoad(object sender, EventArgs e)
//窗体关闭
void
DataEditFormFormClosing
(
object
sender
,
FormClosingEventArgs
e
)
{
//清理备份文件
List
<
long
>
delids
=
new
List
<
long
>();
foreach
(
CardEdit
.
FileDeleted
deleted
in
cardedit
.
undoDeleted
)
{
if
(
deleted
!=
null
&&
deleted
.
deleted
)
delids
.
AddRange
(
deleted
.
ids
);
}
if
(
delids
.
Count
!=
0
)
{
foreach
(
long
id
in
delids
)
YGOUtil
.
CardDelete
(
id
,
GetPath
(),
YGOUtil
.
DeleteOption
.
CLEAN
);
}
//当前有任务执行,是否结束
if
(
tasker
!=
null
&&
tasker
.
IsRuning
())
{
...
...
@@ -566,7 +563,7 @@ void Lv_cardlistKeyDown(object sender, KeyEventArgs e)
switch
(
e
.
KeyCode
)
{
case
Keys
.
Delete
:
c
ardedit
.
DelCards
(
menuitem_operacardsfile
.
Checked
);
c
mdManager
.
ExcuteCommand
(
cardedit
.
delCard
,
menuitem_operacardsfile
.
Checked
);
break
;
case
Keys
.
Right
:
Btn_PageDownClick
(
null
,
null
);
...
...
@@ -730,18 +727,14 @@ void Btn_resetClick(object sender, EventArgs e)
//添加
void
Btn_addClick
(
object
sender
,
EventArgs
e
)
{
if
(
cardedit
!=
null
)
cardedit
.
AddCard
();
if
(
cardedit
.
undoSQL
.
Count
!=
0
)
btn_undo
.
Enabled
=
true
;
if
(
cardedit
!=
null
)
cmdManager
.
ExcuteCommand
(
cardedit
.
addCard
);
}
//修改
void
Btn_modClick
(
object
sender
,
EventArgs
e
)
{
if
(
cardedit
!=
null
)
cardedit
.
ModCard
(
menuitem_operacardsfile
.
Checked
);
if
(
cardedit
.
undoSQL
.
Count
!=
0
)
btn_undo
.
Enabled
=
true
;
cmdManager
.
ExcuteCommand
(
cardedit
.
modCard
,
menuitem_operacardsfile
.
Checked
);
}
//打开脚本
void
Btn_luaClick
(
object
sender
,
EventArgs
e
)
...
...
@@ -753,16 +746,16 @@ void Btn_luaClick(object sender, EventArgs e)
void
Btn_delClick
(
object
sender
,
EventArgs
e
)
{
if
(
cardedit
!=
null
)
cardedit
.
DelCards
(
menuitem_operacardsfile
.
Checked
);
if
(
cardedit
.
undoSQL
.
Count
!=
0
)
btn_undo
.
Enabled
=
true
;
cmdManager
.
ExcuteCommand
(
cardedit
.
delCard
,
menuitem_operacardsfile
.
Checked
);
}
//撤销
void
Btn_undoClick
(
object
sender
,
EventArgs
e
)
{
if
(
cardedit
!=
null
)
cardedit
.
Undo
();
if
(
cardedit
.
undoSQL
.
Count
==
0
)
btn_undo
.
Enabled
=
false
;
{
cmdManager
.
Undo
();
Search
(
true
);
}
}
//导入卡图
void
Btn_imgClick
(
object
sender
,
EventArgs
e
)
...
...
@@ -1105,45 +1098,8 @@ void Menuitem_copyselecttoClick(object sender, EventArgs e)
//保存卡片到当前数据库
public
void
SaveCards
(
Card
[]
cards
)
{
if
(!
CheckOpen
())
return
;
if
(
cards
==
null
||
cards
.
Length
==
0
)
return
;
bool
replace
=
false
;
Card
[]
oldcards
=
DataBase
.
Read
(
nowCdbFile
,
true
,
""
);
if
(
oldcards
!=
null
&&
oldcards
.
Length
!=
0
)
{
int
i
=
0
;
foreach
(
Card
oc
in
oldcards
)
{
foreach
(
Card
c
in
cards
)
{
if
(
c
.
id
==
oc
.
id
)
{
i
+=
1
;
if
(
i
==
1
)
{
replace
=
MyMsg
.
Question
(
LMSG
.
IfReplaceExistingCard
);
break
;
}
}
}
if
(
i
>
0
)
break
;
}
}
cardedit
.
undoSQL
.
Add
(
""
);
cardedit
.
undoModified
.
Add
(
new
CardEdit
.
FileModified
());
cardedit
.
undoDeleted
.
Add
(
new
CardEdit
.
FileDeleted
());
DataBase
.
CopyDB
(
nowCdbFile
,
!
replace
,
cards
);
CardEdit
.
DBcopied
copied
=
new
CardEdit
.
DBcopied
();
copied
.
copied
=
true
;
copied
.
NewCards
=
cards
;
copied
.
replace
=
replace
;
copied
.
OldCards
=
oldcards
;
cardedit
.
undoCopied
.
Add
(
copied
);
cmdManager
.
ExcuteCommand
(
cardedit
.
copyCard
,
cards
);
Search
(
srcCard
,
true
);
btn_undo
.
Enabled
=
true
;
}
//卡片另存为
void
CopyTo
(
Card
[]
cards
)
...
...
DataEditorX/DataEditorX.csproj
View file @
f014efd8
...
...
@@ -87,6 +87,7 @@
</Compile>
<Compile
Include=
"Common\MyPath.cs"
/>
<Compile
Include=
"Controls\History.cs"
/>
<Compile
Include=
"Core\CommandManager.cs"
/>
<Compile
Include=
"Core\IDataForm.cs"
/>
<Compile
Include=
"Controls\IEditForm.cs"
/>
<Compile
Include=
"Controls\IMainForm.cs"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment