From 08b7dbd9a1a24b978afadd266da695503b832c8e Mon Sep 17 00:00:00 2001 From: Tim Young Date: Wed, 20 Sep 2017 12:39:34 -0500 Subject: [PATCH] done button working --- SpriteLibrary/SpriteEntryForm.Designer.cs | 1 + SpriteLibrary/SpriteEntryForm.cs | 39 ++++++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/SpriteLibrary/SpriteEntryForm.Designer.cs b/SpriteLibrary/SpriteEntryForm.Designer.cs index f7c7096..ba2819f 100644 --- a/SpriteLibrary/SpriteEntryForm.Designer.cs +++ b/SpriteLibrary/SpriteEntryForm.Designer.cs @@ -163,6 +163,7 @@ this.btnDone.TabIndex = 8; this.btnDone.Text = "Done"; this.btnDone.UseVisualStyleBackColor = true; + this.btnDone.Click += new System.EventHandler(this.btnDone_Click); // // btnCancel // diff --git a/SpriteLibrary/SpriteEntryForm.cs b/SpriteLibrary/SpriteEntryForm.cs index b287a60..ade5e40 100644 --- a/SpriteLibrary/SpriteEntryForm.cs +++ b/SpriteLibrary/SpriteEntryForm.cs @@ -476,13 +476,35 @@ namespace SpriteLibrary } - void ApplyChanges() + int IndexOfName(string spritname) + { + for(int i=0; i< SpriteInformation.Count; i++) + { + if (SpriteInformation[i].SpriteName == spritname) + return i; + } + return -1; + } + + bool VerifySpriteBeforeSaving() { if (tbSpriteName.Text == "") { MessageBox.Show("You cannot save a sprite that has no name."); - return; + return false; } + int index = IndexOfName(tbSpriteName.Text); + if(index != CurrentSIIndex && index != -1) + { + MessageBox.Show("You cannot have two sprites with the same name."); + return false; + } + return true; + } + + void ApplyChanges() + { + if (!VerifySpriteBeforeSaving()) return; FormToSpriteInformation(); if (CurrentSIIndex > 0 && CurrentSIIndex < SpriteInformation.Count) { @@ -503,10 +525,9 @@ namespace SpriteLibrary /// bool PromptToApplyChangesAndContinue() { - if (tbSpriteName.Text == "") + if (!VerifySpriteBeforeSaving()) { - MessageBox.Show("You cannot save a sprite that has no name."); - return true; + return true; //We could not verify, say we canceled out. } if (ValuesDifferFromData()) { @@ -712,5 +733,13 @@ namespace SpriteLibrary WeHaveNewItem(); } } + + private void btnDone_Click(object sender, EventArgs e) + { + if (PromptToApplyChangesAndContinue()) + { + Close(); + } + } } }