⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.cs

📁 一个通用的数据库访问层
💻 CS
📖 第 1 页 / 共 3 页
字号:
			if( node == null ){
				return;
			}

			DialogResult res = MessageBox.Show( "Are you sure you want to delete selected item?",  applicationName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question );
			if( res == DialogResult.Cancel ){
				return;
			}

			YariSoft.Utils.AgentPlayer.MovieTypeEnum movieType = ( YariSoft.Utils.AgentPlayer.MovieTypeEnum )node.Parent.Tag;
			ArrayList MovieCollection = ( ArrayList )this.workObject.Movies[ movieType ];
			for( int i = 0; i < MovieCollection.Count; i++ ){
				if( (( AgentMovie )MovieCollection[i]).Name == node.Text ){
					MovieCollection.RemoveAt(i);	
					node.Remove();
					this.workObject.HasChanges = true;
					break;
				}
			}
			if( ! ( this.tree.SelectedNode.Tag is AgentMovie ) ){
				this.grid.DataSource = null;
			}
		}

		private void playActionItem_Click(object sender, System.EventArgs e)
		{
			AgentMovie Movie = ( AgentMovie )this.grid.Tag;
			if( Movie == null ){
				return;
			}
			this.workObject.Play( Movie, this.agent.Character );
		}

		private void animationOperationItem_Click(object sender, System.EventArgs e)
		{
			AgentOperation operation = new AgentOperation( AgentOperation.OperationTypeEnum.Animation, "");
			if( this.EditOperation( ref operation ) ){
				AgentMovie Movie = ( AgentMovie )this.grid.Tag;
				Movie.AddOperation( operation );
				this.AddOperationRow( ( DataTable )this.grid.DataSource, operation );
			}
		}

		private void talkOperationItem_Click(object sender, System.EventArgs e)
		{
			AgentOperation operation = new AgentOperation( AgentOperation.OperationTypeEnum.Speak, "" );
			if( this.EditOperation( ref operation ) ){
				AgentMovie Movie = ( AgentMovie )this.grid.Tag;
				Movie.AddOperation( operation );
				this.AddOperationRow( ( DataTable )this.grid.DataSource, operation );
			}
		}

		private void positionOperationItem_Click(object sender, System.EventArgs e)
		{
			AgentOperation operation = new AgentOperation( AgentOperation.OperationTypeEnum.MoveTo, new Point( 150, 150 ));
			if( this.EditOperation( ref operation ) ){
				AgentMovie Movie = ( AgentMovie )this.grid.Tag;
				Movie.AddOperation( operation );
				this.AddOperationRow( ( DataTable )this.grid.DataSource, operation );
			}
		}

		private bool EditOperation( ref AgentOperation Operation )
		{
			bool result = false;
			AgentMovie Movie = ( AgentMovie )this.grid.Tag;
			if( Movie == null ){
				return result;
			}

			YariSoft.AgentMovieEditor.Modals.BaseEditForm editForm = null; 
			switch( Operation.OperationType ){
				case AgentOperation.OperationTypeEnum.Animation:
					editForm = new YariSoft.AgentMovieEditor.Modals.ComboWindow();
					break;
				case AgentOperation.OperationTypeEnum.Speak:
					editForm = new YariSoft.AgentMovieEditor.Modals.EditWindow();
					((Modals.EditWindow)editForm).Init ( "Please specify text to speech", "Text:", ( string )Operation.Action );
					break;
				case AgentOperation.OperationTypeEnum.MoveTo:
					editForm = new YariSoft.AgentMovieEditor.Modals.PositionForm();
					break;
			}

			editForm.Value = Operation.Action;
			if( DialogResult.OK == editForm.ShowDialog ( this ) ){
				Operation.Action = editForm.Value;
				this.workObject.HasChanges = true;
				result = true;
			}	
			editForm.Dispose();
			return result;
		}

		private void deleteOperationItem_Click(object sender, System.EventArgs e)
		{
			AgentMovie Movie = ( AgentMovie )this.grid.Tag;
			if( Movie == null ){
				return;
			}
			Movie.Operations.RemoveAt( this.grid.CurrentRowIndex );
			((DataTable)this.grid.DataSource).Rows.RemoveAt( this.grid.CurrentRowIndex );
			this.workObject.HasChanges = true;
		}

		private void editOperationItem_Click(object sender, System.EventArgs e)
		{
			if( this.grid.DataSource == null ){
				return;
			}
			AgentMovie Movie = ( AgentMovie )this.grid.Tag;
			if( Movie == null ){
				return;
			}
			AgentOperation operation = (AgentOperation)Movie.Operations[ this.grid.CurrentRowIndex ];
			if( this.EditOperation( ref operation ) ){
				Movie.Operations[ this.grid.CurrentRowIndex ] = operation;
				String TypeCaption = "";
				String Description = "";
				this.TranslateOperation( operation, ref TypeCaption, ref Description );
				(( DataTable )this.grid.DataSource).Rows[this.grid.CurrentRowIndex][1]=Description;
			}
		}

		private void upOperationItem_Click(object sender, System.EventArgs e)
		{
			this.SwapOperations( this.grid.CurrentRowIndex , this.grid.CurrentRowIndex - 1 );
		}

		private void downOperationItem_Click(object sender, System.EventArgs e)
		{
			this.SwapOperations( this.grid.CurrentRowIndex , this.grid.CurrentRowIndex + 1 );		
		}

		private void SwapOperations( int CurIndex, int NewIndex )
		{
			if( this.grid.DataSource == null || CurIndex == -1 ){
				return;
			}
			AgentMovie Movie = ( AgentMovie )this.grid.Tag;
			if( Movie == null ){
				return;
			}
			object operation = Movie.Operations[ CurIndex ];
			Movie.Operations.RemoveAt( CurIndex );
			Movie.Operations.Insert( NewIndex, operation );
			int prev = NewIndex;
			this.FillOperations( Movie );
			this.grid.CurrentRowIndex = prev;
			this.workObject.HasChanges = true;
		}

		private bool EditValue( string WindowCaption, string LabelText, ref string Value )
		{
			bool result = false;
			YariSoft.AgentMovieEditor.Modals.EditWindow editWindow = new YariSoft.AgentMovieEditor.Modals.EditWindow();
			if( editWindow.Init ( WindowCaption, LabelText, Value ) ){
				if( DialogResult.OK == editWindow.ShowDialog ( this ) ){
					Value = (string)editWindow.Value;
					result = true;
				}
			}
			return result;
		}

		private void RefreshMenuItems()
		{
			bool Enable = false;
			this.newActionItem.Enabled		= Enable;
			this.renameActionItem.Enabled	= Enable;
			this.deleteAcionItem.Enabled	= Enable;
			this.newPopupItem.Enabled		= Enable;
			this.renamePopupItem.Enabled	= Enable;
			this.deletePopupItem.Enabled	= Enable;
			Enable = true;

			TreeNode node = this.tree.SelectedNode;
			if( node != null ){
				if( node.Tag is YariSoft.Utils.AgentPlayer.MovieTypeEnum || node.Tag is AgentMovie ){
					this.newActionItem.Enabled		= Enable;
					this.newPopupItem.Enabled		= Enable;
				}
				if( node.Tag is AgentMovie ){
					this.renameActionItem.Enabled	= Enable;
					this.deleteAcionItem.Enabled	= Enable;
					this.renamePopupItem.Enabled	= Enable;
					this.deletePopupItem.Enabled	= Enable;
				}
			}
		}

		private void tree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			this.RefreshMenuItems();
			TreeNode node = this.tree.SelectedNode;
			if( node != null && node.Tag is AgentMovie ){
				AgentMovie agentMovie = (AgentMovie)node.Tag;
				this.FillOperations ( agentMovie );
			}
		}

		private void tree_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if(e.Button == MouseButtons.Right) { 
				this.tree.SelectedNode = this.tree.GetNodeAt (e.X ,e.Y); 
			} 
		}

		private bool CheckChanges(){
			if( this.workObject.HasChanges ){
				DialogResult res = MessageBox.Show( "Do you want to save changes to file '" + this.workObject.FileName + "'?",  applicationName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question );
				if( res == DialogResult.Cancel ){
					return false;
				} else if( res == DialogResult.Yes ){
					this.workObject.SaveToFile();
				}
			}
			return true;
		}

		private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			if( ! this.CheckChanges() ){
				e.Cancel = true;
				return;
			}	
		}

		private void SetFormCaption()
		{
			this.Text =  applicationName + " - " + this.workObject.FileName;
		}

		private void FillOperations( AgentMovie Movie )
		{
			DataTable table = new DataTable("Table");
			DataColumn typeName = new DataColumn("TypeName",System.Type.GetType("System.String"));
			DataColumn description = new DataColumn("Description",System.Type.GetType("System.String") );
			table.Columns.Add( typeName );
			table.Columns.Add( description );
			foreach( AgentOperation operation in Movie.Operations ){
				this.AddOperationRow( table, operation );
			}
			this.grid.DataSource = table;
			this.grid.Tag = Movie;
		}

		private void AddOperationRow( DataTable Table, AgentOperation Operation )
		{
			String TypeCaption = "";
			String Description = "";
			this.TranslateOperation( Operation, ref TypeCaption, ref Description );
			DataRow row = Table.NewRow();
			row[0] = TypeCaption;
			row[1] = Description;
			Table.Rows.Add( row );
		}

		private void TranslateOperation( AgentOperation Operation, ref string TypeCaption, ref string Description )
		{ 
			switch( Operation.OperationType ){
				case AgentOperation.OperationTypeEnum.Animation:
					TypeCaption = "Animation";
					Description = ( string )Operation.Action;
					break;
				case AgentOperation.OperationTypeEnum.Speak:
					TypeCaption = "Speak";
					Description = ( string )Operation.Action;
					break;
				case AgentOperation.OperationTypeEnum.MoveTo:
					TypeCaption = "MoveTo";
					Point curPoint = ( Point )Operation.Action;
					Description = "X: " + curPoint.X.ToString() + ", Y: "+ curPoint.Y.ToString();
					break;
			}
		}

		private void gridPopup_Popup(object sender, System.EventArgs e)
		{
			bool Enabled = false;

			this.newOperationItem.Enabled		= Enabled;
			this.editOperationItem.Enabled		= Enabled;
			this.deleteOperationItem.Enabled	= Enabled;
			this.upOperationItem.Enabled		= Enabled;
			this.downOperationItem.Enabled		= Enabled;

			Enabled = true;
			if( this.grid.DataSource == null ){
				return;
			} else {
				this.newOperationItem.Enabled = Enabled;
				DataTable table = ( DataTable )this.grid.DataSource;
				if( table.Rows.Count == 0 ){
					return;
				}
				this.editOperationItem.Enabled		= Enabled;
				this.deleteOperationItem.Enabled	= Enabled;

				if( this.grid.CurrentRowIndex != table.Rows.Count - 1 ){
					this.downOperationItem.Enabled	= Enabled;
				}
				if( this.grid.CurrentRowIndex != 0 ){
					this.upOperationItem.Enabled	= Enabled;
				}
			}
		}

		private void grid_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			System.Drawing.Point pt = new Point(e.X, e.Y); 
			DataGrid.HitTestInfo hti = this.grid.HitTest(pt); 
			if(hti.Type == DataGrid.HitTestType.Cell) { 
				for( int i = 0; i < (( DataTable )this.grid.DataSource).Rows.Count; i++  ){
					this.grid.UnSelect( i );
				}
				
				this.grid.CurrentCell = new DataGridCell(hti.Row, hti.Column); 
				this.grid.Select(hti.Row); 
			} 
		}

		private void grid_DoubleClick(object sender, System.EventArgs e)
		{
			this.editOperationItem_Click(sender, e);
		}

		private void aboutMenuItem_Click(object sender, System.EventArgs e)
		{
			AgentMovieEditor.Modals.AboutForm form = new AgentMovieEditor.Modals.AboutForm();
			form.ShowDialog(this);
			form.Dispose();
		}

		private void propActionItem_Click(object sender, System.EventArgs e)
		{
			agent.ShowProperties();
		}

		private void tree_DoubleClick(object sender, System.EventArgs e)
		{
			this.playActionItem_Click( this, null );		
		}
		#endregion

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -