From 004a65c92edc11bab723fa996ef1a2e65eb78540 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 6 Sep 2015 17:39:11 -0400 Subject: [PATCH] Basic Bot - UI and code reorg --- .../tools/BasicBot/BasicBot.Designer.cs | 193 ++++++++------ .../tools/BasicBot/BasicBot.cs | 244 +++++++++--------- 2 files changed, 237 insertions(+), 200 deletions(-) diff --git a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.Designer.cs b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.Designer.cs index 820b72a53f..4943344866 100644 --- a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.Designer.cs @@ -46,6 +46,8 @@ this.ControlsBox = new System.Windows.Forms.GroupBox(); this.ControlProbabilityPanel = new System.Windows.Forms.Panel(); this.BestGroupBox = new System.Windows.Forms.GroupBox(); + this.PlayBestButton = new System.Windows.Forms.Button(); + this.ClearBestButton = new System.Windows.Forms.Button(); this.BestAttemptNumberLabel = new System.Windows.Forms.Label(); this.label17 = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); @@ -81,8 +83,7 @@ this.StopBtn = new System.Windows.Forms.Button(); this.label8 = new System.Windows.Forms.Label(); this.StartFromSlotBox = new System.Windows.Forms.ComboBox(); - this.ClearBestButton = new System.Windows.Forms.Button(); - this.PlayBestButton = new System.Windows.Forms.Button(); + this.ControlGroupBox = new System.Windows.Forms.GroupBox(); this.BotMenu.SuspendLayout(); this.BotStatusStrip.SuspendLayout(); this.ControlsBox.SuspendLayout(); @@ -90,6 +91,7 @@ this.panel1.SuspendLayout(); this.GoalGroupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.FrameLengthNumeric)).BeginInit(); + this.ControlGroupBox.SuspendLayout(); this.SuspendLayout(); // // BotMenu @@ -100,7 +102,7 @@ this.optionsToolStripMenuItem}); this.BotMenu.Location = new System.Drawing.Point(0, 0); this.BotMenu.Name = "BotMenu"; - this.BotMenu.Size = new System.Drawing.Size(574, 24); + this.BotMenu.Size = new System.Drawing.Size(587, 24); this.BotMenu.TabIndex = 0; this.BotMenu.Text = "menuStrip1"; // @@ -168,7 +170,7 @@ // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; - this.toolStripSeparator2.Size = new System.Drawing.Size(149, 6); + this.toolStripSeparator2.Size = new System.Drawing.Size(57, 6); // // toolStripSeparator1 // @@ -200,8 +202,7 @@ // // RunBtn // - this.RunBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.RunBtn.Location = new System.Drawing.Point(487, 495); + this.RunBtn.Location = new System.Drawing.Point(6, 56); this.RunBtn.Name = "RunBtn"; this.RunBtn.Size = new System.Drawing.Size(75, 23); this.RunBtn.TabIndex = 2001; @@ -213,9 +214,9 @@ // this.BotStatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.MessageLabel}); - this.BotStatusStrip.Location = new System.Drawing.Point(0, 530); + this.BotStatusStrip.Location = new System.Drawing.Point(0, 565); this.BotStatusStrip.Name = "BotStatusStrip"; - this.BotStatusStrip.Size = new System.Drawing.Size(574, 22); + this.BotStatusStrip.Size = new System.Drawing.Size(587, 22); this.BotStatusStrip.TabIndex = 2; this.BotStatusStrip.Text = "statusStrip1"; // @@ -231,27 +232,30 @@ | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.ControlsBox.Controls.Add(this.ControlProbabilityPanel); - this.ControlsBox.Location = new System.Drawing.Point(12, 27); + this.ControlsBox.Location = new System.Drawing.Point(12, 183); this.ControlsBox.Name = "ControlsBox"; - this.ControlsBox.Size = new System.Drawing.Size(311, 344); + this.ControlsBox.Size = new System.Drawing.Size(312, 369); this.ControlsBox.TabIndex = 3; this.ControlsBox.TabStop = false; this.ControlsBox.Text = "Controls"; // // ControlProbabilityPanel // - this.ControlProbabilityPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); + this.ControlProbabilityPanel.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.ControlProbabilityPanel.AutoScroll = true; this.ControlProbabilityPanel.Location = new System.Drawing.Point(6, 19); this.ControlProbabilityPanel.Name = "ControlProbabilityPanel"; - this.ControlProbabilityPanel.Size = new System.Drawing.Size(299, 319); + this.ControlProbabilityPanel.Size = new System.Drawing.Size(299, 344); this.ControlProbabilityPanel.TabIndex = 0; // // BestGroupBox // this.BestGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); + this.BestGroupBox.Controls.Add(this.PlayBestButton); + this.BestGroupBox.Controls.Add(this.ClearBestButton); this.BestGroupBox.Controls.Add(this.BestAttemptNumberLabel); this.BestGroupBox.Controls.Add(this.label17); this.BestGroupBox.Controls.Add(this.panel1); @@ -263,17 +267,39 @@ this.BestGroupBox.Controls.Add(this.label15); this.BestGroupBox.Controls.Add(this.label14); this.BestGroupBox.Controls.Add(this.label13); - this.BestGroupBox.Location = new System.Drawing.Point(329, 86); + this.BestGroupBox.Location = new System.Drawing.Point(330, 183); this.BestGroupBox.Name = "BestGroupBox"; - this.BestGroupBox.Size = new System.Drawing.Size(245, 285); + this.BestGroupBox.Size = new System.Drawing.Size(245, 369); this.BestGroupBox.TabIndex = 4; this.BestGroupBox.TabStop = false; this.BestGroupBox.Text = "Best"; // + // PlayBestButton + // + this.PlayBestButton.Enabled = false; + this.PlayBestButton.Location = new System.Drawing.Point(12, 46); + this.PlayBestButton.Name = "PlayBestButton"; + this.PlayBestButton.Size = new System.Drawing.Size(75, 23); + this.PlayBestButton.TabIndex = 2004; + this.PlayBestButton.Text = "&Play"; + this.PlayBestButton.UseVisualStyleBackColor = true; + this.PlayBestButton.Click += new System.EventHandler(this.PlayBestButton_Click); + // + // ClearBestButton + // + this.ClearBestButton.Enabled = false; + this.ClearBestButton.Location = new System.Drawing.Point(12, 70); + this.ClearBestButton.Name = "ClearBestButton"; + this.ClearBestButton.Size = new System.Drawing.Size(75, 23); + this.ClearBestButton.TabIndex = 2003; + this.ClearBestButton.Text = "&Clear"; + this.ClearBestButton.UseVisualStyleBackColor = true; + this.ClearBestButton.Click += new System.EventHandler(this.ClearBestButton_Click); + // // BestAttemptNumberLabel // this.BestAttemptNumberLabel.AutoSize = true; - this.BestAttemptNumberLabel.Location = new System.Drawing.Point(17, 40); + this.BestAttemptNumberLabel.Location = new System.Drawing.Point(59, 20); this.BestAttemptNumberLabel.Name = "BestAttemptNumberLabel"; this.BestAttemptNumberLabel.Size = new System.Drawing.Size(13, 13); this.BestAttemptNumberLabel.TabIndex = 23; @@ -290,12 +316,15 @@ // // panel1 // + this.panel1.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.panel1.AutoScroll = true; this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.panel1.Controls.Add(this.BestAttemptLogLabel); - this.panel1.Location = new System.Drawing.Point(12, 99); + this.panel1.Location = new System.Drawing.Point(12, 112); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(227, 180); + this.panel1.Size = new System.Drawing.Size(227, 251); this.panel1.TabIndex = 21; // // BestAttemptLogLabel @@ -309,6 +338,7 @@ // // BestTieBreak3Box // + this.BestTieBreak3Box.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.BestTieBreak3Box.Location = new System.Drawing.Point(178, 73); this.BestTieBreak3Box.Name = "BestTieBreak3Box"; this.BestTieBreak3Box.ReadOnly = true; @@ -318,6 +348,7 @@ // // BestTieBreak2Box // + this.BestTieBreak2Box.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.BestTieBreak2Box.Location = new System.Drawing.Point(178, 53); this.BestTieBreak2Box.Name = "BestTieBreak2Box"; this.BestTieBreak2Box.ReadOnly = true; @@ -327,6 +358,7 @@ // // BestTieBreak1Box // + this.BestTieBreak1Box.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.BestTieBreak1Box.Location = new System.Drawing.Point(178, 33); this.BestTieBreak1Box.Name = "BestTieBreak1Box"; this.BestTieBreak1Box.ReadOnly = true; @@ -336,6 +368,7 @@ // // BestMaximizeBox // + this.BestMaximizeBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.BestMaximizeBox.Location = new System.Drawing.Point(178, 13); this.BestMaximizeBox.Name = "BestMaximizeBox"; this.BestMaximizeBox.ReadOnly = true; @@ -345,6 +378,7 @@ // // label16 // + this.label16.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label16.AutoSize = true; this.label16.Location = new System.Drawing.Point(111, 76); this.label16.Name = "label16"; @@ -354,6 +388,7 @@ // // label15 // + this.label15.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label15.AutoSize = true; this.label15.Location = new System.Drawing.Point(111, 56); this.label15.Name = "label15"; @@ -363,6 +398,7 @@ // // label14 // + this.label14.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label14.AutoSize = true; this.label14.Location = new System.Drawing.Point(111, 36); this.label14.Name = "label14"; @@ -372,6 +408,7 @@ // // label13 // + this.label13.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label13.AutoSize = true; this.label13.Location = new System.Drawing.Point(119, 16); this.label13.Name = "label13"; @@ -381,9 +418,8 @@ // // label1 // - this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(339, 46); + this.label1.Location = new System.Drawing.Point(7, 98); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(51, 13); this.label1.TabIndex = 5; @@ -391,9 +427,8 @@ // // label2 // - this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(346, 63); + this.label2.Location = new System.Drawing.Point(14, 115); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(44, 13); this.label2.TabIndex = 6; @@ -401,9 +436,8 @@ // // AttemptsLabel // - this.AttemptsLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.AttemptsLabel.AutoSize = true; - this.AttemptsLabel.Location = new System.Drawing.Point(397, 46); + this.AttemptsLabel.Location = new System.Drawing.Point(65, 98); this.AttemptsLabel.Name = "AttemptsLabel"; this.AttemptsLabel.Size = new System.Drawing.Size(13, 13); this.AttemptsLabel.TabIndex = 7; @@ -411,9 +445,8 @@ // // FramesLabel // - this.FramesLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.FramesLabel.AutoSize = true; - this.FramesLabel.Location = new System.Drawing.Point(397, 63); + this.FramesLabel.Location = new System.Drawing.Point(65, 115); this.FramesLabel.Name = "FramesLabel"; this.FramesLabel.Size = new System.Drawing.Size(13, 13); this.FramesLabel.TabIndex = 8; @@ -421,8 +454,7 @@ // // GoalGroupBox // - this.GoalGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) + this.GoalGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.GoalGroupBox.Controls.Add(this.label12); this.GoalGroupBox.Controls.Add(this.label11); @@ -439,9 +471,9 @@ this.GoalGroupBox.Controls.Add(this.label4); this.GoalGroupBox.Controls.Add(this.FrameLengthNumeric); this.GoalGroupBox.Controls.Add(this.label3); - this.GoalGroupBox.Location = new System.Drawing.Point(12, 377); + this.GoalGroupBox.Location = new System.Drawing.Point(12, 27); this.GoalGroupBox.Name = "GoalGroupBox"; - this.GoalGroupBox.Size = new System.Drawing.Size(311, 150); + this.GoalGroupBox.Size = new System.Drawing.Size(312, 150); this.GoalGroupBox.TabIndex = 9; this.GoalGroupBox.TabStop = false; this.GoalGroupBox.Text = "Goal"; @@ -451,36 +483,36 @@ this.label12.AutoSize = true; this.label12.Location = new System.Drawing.Point(108, 124); this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(18, 13); + this.label12.Size = new System.Drawing.Size(59, 13); this.label12.TabIndex = 14; - this.label12.Text = "0x"; + this.label12.Text = "Address 0x"; // // label11 // this.label11.AutoSize = true; this.label11.Location = new System.Drawing.Point(108, 102); this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(18, 13); + this.label11.Size = new System.Drawing.Size(59, 13); this.label11.TabIndex = 13; - this.label11.Text = "0x"; + this.label11.Text = "Address 0x"; // // label10 // this.label10.AutoSize = true; this.label10.Location = new System.Drawing.Point(108, 79); this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(18, 13); + this.label10.Size = new System.Drawing.Size(59, 13); this.label10.TabIndex = 12; - this.label10.Text = "0x"; + this.label10.Text = "Address 0x"; // // label9 // this.label9.AutoSize = true; this.label9.Location = new System.Drawing.Point(108, 56); this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(18, 13); + this.label9.Size = new System.Drawing.Size(59, 13); this.label9.TabIndex = 11; - this.label9.Text = "0x"; + this.label9.Text = "Address 0x"; // // label7 // @@ -502,8 +534,10 @@ // // TieBreaker1Box // + this.TieBreaker1Box.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.TieBreaker1Box.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; - this.TieBreaker1Box.Location = new System.Drawing.Point(128, 75); + this.TieBreaker1Box.Location = new System.Drawing.Point(167, 75); this.TieBreaker1Box.Name = "TieBreaker1Box"; this.TieBreaker1Box.Nullable = true; this.TieBreaker1Box.Size = new System.Drawing.Size(95, 20); @@ -511,8 +545,10 @@ // // TieBreaker2Box // + this.TieBreaker2Box.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.TieBreaker2Box.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; - this.TieBreaker2Box.Location = new System.Drawing.Point(128, 98); + this.TieBreaker2Box.Location = new System.Drawing.Point(167, 98); this.TieBreaker2Box.Name = "TieBreaker2Box"; this.TieBreaker2Box.Nullable = true; this.TieBreaker2Box.Size = new System.Drawing.Size(95, 20); @@ -520,8 +556,10 @@ // // TieBreaker3Box // + this.TieBreaker3Box.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.TieBreaker3Box.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; - this.TieBreaker3Box.Location = new System.Drawing.Point(128, 120); + this.TieBreaker3Box.Location = new System.Drawing.Point(167, 120); this.TieBreaker3Box.Name = "TieBreaker3Box"; this.TieBreaker3Box.Nullable = true; this.TieBreaker3Box.Size = new System.Drawing.Size(95, 20); @@ -538,8 +576,10 @@ // // MaximizeAddressBox // + this.MaximizeAddressBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.MaximizeAddressBox.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper; - this.MaximizeAddressBox.Location = new System.Drawing.Point(128, 52); + this.MaximizeAddressBox.Location = new System.Drawing.Point(167, 52); this.MaximizeAddressBox.Name = "MaximizeAddressBox"; this.MaximizeAddressBox.Nullable = true; this.MaximizeAddressBox.Size = new System.Drawing.Size(95, 20); @@ -548,11 +588,11 @@ // maximizeLabeltext // this.maximizeLabeltext.AutoSize = true; - this.maximizeLabeltext.Location = new System.Drawing.Point(9, 56); + this.maximizeLabeltext.Location = new System.Drawing.Point(50, 56); this.maximizeLabeltext.Name = "maximizeLabeltext"; - this.maximizeLabeltext.Size = new System.Drawing.Size(94, 13); + this.maximizeLabeltext.Size = new System.Drawing.Size(53, 13); this.maximizeLabeltext.TabIndex = 3; - this.maximizeLabeltext.Text = "Maximize Address:"; + this.maximizeLabeltext.Text = "Maximize:"; // // label4 // @@ -591,8 +631,7 @@ // // StopBtn // - this.StopBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.StopBtn.Location = new System.Drawing.Point(487, 495); + this.StopBtn.Location = new System.Drawing.Point(6, 56); this.StopBtn.Name = "StopBtn"; this.StopBtn.Size = new System.Drawing.Size(75, 23); this.StopBtn.TabIndex = 2002; @@ -603,9 +642,8 @@ // // label8 // - this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(423, 456); + this.label8.Location = new System.Drawing.Point(7, 29); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(58, 13); this.label8.TabIndex = 11; @@ -613,7 +651,6 @@ // // StartFromSlotBox // - this.StartFromSlotBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.StartFromSlotBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.StartFromSlotBox.FormattingEnabled = true; this.StartFromSlotBox.Items.AddRange(new object[] { @@ -627,54 +664,39 @@ "Slot 7", "Slot 8", "Slot 9"}); - this.StartFromSlotBox.Location = new System.Drawing.Point(487, 456); + this.StartFromSlotBox.Location = new System.Drawing.Point(71, 25); this.StartFromSlotBox.Name = "StartFromSlotBox"; this.StartFromSlotBox.Size = new System.Drawing.Size(75, 21); this.StartFromSlotBox.TabIndex = 2000; // - // ClearBestButton + // ControlGroupBox // - this.ClearBestButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.ClearBestButton.Enabled = false; - this.ClearBestButton.Location = new System.Drawing.Point(490, 38); - this.ClearBestButton.Name = "ClearBestButton"; - this.ClearBestButton.Size = new System.Drawing.Size(75, 23); - this.ClearBestButton.TabIndex = 2003; - this.ClearBestButton.Text = "&Clear"; - this.ClearBestButton.UseVisualStyleBackColor = true; - this.ClearBestButton.Click += new System.EventHandler(this.ClearBestButton_Click); - // - // PlayBestButton - // - this.PlayBestButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.PlayBestButton.Enabled = false; - this.PlayBestButton.Location = new System.Drawing.Point(490, 66); - this.PlayBestButton.Name = "PlayBestButton"; - this.PlayBestButton.Size = new System.Drawing.Size(75, 23); - this.PlayBestButton.TabIndex = 2004; - this.PlayBestButton.Text = "&Play"; - this.PlayBestButton.UseVisualStyleBackColor = true; - this.PlayBestButton.Click += new System.EventHandler(this.PlayBestButton_Click); + this.ControlGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.ControlGroupBox.Controls.Add(this.StopBtn); + this.ControlGroupBox.Controls.Add(this.FramesLabel); + this.ControlGroupBox.Controls.Add(this.RunBtn); + this.ControlGroupBox.Controls.Add(this.AttemptsLabel); + this.ControlGroupBox.Controls.Add(this.StartFromSlotBox); + this.ControlGroupBox.Controls.Add(this.label2); + this.ControlGroupBox.Controls.Add(this.label8); + this.ControlGroupBox.Controls.Add(this.label1); + this.ControlGroupBox.Location = new System.Drawing.Point(329, 27); + this.ControlGroupBox.Name = "ControlGroupBox"; + this.ControlGroupBox.Size = new System.Drawing.Size(245, 150); + this.ControlGroupBox.TabIndex = 2004; + this.ControlGroupBox.TabStop = false; + this.ControlGroupBox.Text = "Control"; // // BasicBot // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(574, 552); - this.Controls.Add(this.PlayBestButton); - this.Controls.Add(this.ClearBestButton); - this.Controls.Add(this.StartFromSlotBox); - this.Controls.Add(this.label8); - this.Controls.Add(this.StopBtn); + this.ClientSize = new System.Drawing.Size(587, 587); + this.Controls.Add(this.ControlGroupBox); this.Controls.Add(this.GoalGroupBox); - this.Controls.Add(this.FramesLabel); - this.Controls.Add(this.AttemptsLabel); - this.Controls.Add(this.label2); - this.Controls.Add(this.label1); this.Controls.Add(this.BestGroupBox); this.Controls.Add(this.ControlsBox); this.Controls.Add(this.BotStatusStrip); - this.Controls.Add(this.RunBtn); this.Controls.Add(this.BotMenu); this.MainMenuStrip = this.BotMenu; this.Name = "BasicBot"; @@ -693,6 +715,8 @@ this.GoalGroupBox.ResumeLayout(false); this.GoalGroupBox.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.FrameLengthNumeric)).EndInit(); + this.ControlGroupBox.ResumeLayout(false); + this.ControlGroupBox.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -755,5 +779,6 @@ private System.Windows.Forms.ToolStripMenuItem NewMenuItem; private System.Windows.Forms.Button PlayBestButton; private System.Windows.Forms.ToolStripStatusLabel MessageLabel; + private System.Windows.Forms.GroupBox ControlGroupBox; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 18e8da12c5..d7fea0af54 100644 --- a/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -340,6 +340,20 @@ namespace BizHawk.Client.EmuHawk #region Control Events + #region FileMenu + + private void FileSubMenu_DropDownOpened(object sender, EventArgs e) + { + SaveMenuItem.Enabled = !string.IsNullOrWhiteSpace(_currentFileName); + } + + private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) + { + RecentSubMenu.DropDownItems.Clear(); + RecentSubMenu.DropDownItems.AddRange( + Settings.RecentBotFiles.RecentMenu(LoadFileFromRecent, true)); + } + private void NewMenuItem_Click(object sender, EventArgs e) { _currentFileName = string.Empty; @@ -360,49 +374,6 @@ namespace BizHawk.Client.EmuHawk UpdateBestAttempt(); } - private void ExitMenuItem_Click(object sender, EventArgs e) - { - Close(); - } - - private void RunBtn_Click(object sender, EventArgs e) - { - StartBot(); - } - - private void StopBtn_Click(object sender, EventArgs e) - { - StopBot(); - } - - private void ClearBestButton_Click(object sender, EventArgs e) - { - _bestBotAttempt = null; - UpdateBestAttempt(); - } - - private void PlayBestButton_Click(object sender, EventArgs e) - { - _replayMode = true; - _dontUpdateValues = true; - GlobalWin.MainForm.LoadQuickSave(SelectedSlot); // Triggers an UpdateValues call - _dontUpdateValues = false; - _startFrame = Emulator.Frame; - GlobalWin.MainForm.UnpauseEmulator(); - } - - private void FileSubMenu_DropDownOpened(object sender, EventArgs e) - { - SaveMenuItem.Enabled = !string.IsNullOrWhiteSpace(_currentFileName); - } - - private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) - { - RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange( - Settings.RecentBotFiles.RecentMenu(LoadFileFromRecent, true)); - } - private void OpenMenuItem_Click(object sender, EventArgs e) { var file = ToolHelpers.OpenFileDialog( @@ -442,8 +413,43 @@ namespace BizHawk.Client.EmuHawk } } + private void ExitMenuItem_Click(object sender, EventArgs e) + { + Close(); + } + #endregion + private void RunBtn_Click(object sender, EventArgs e) + { + StartBot(); + } + + private void StopBtn_Click(object sender, EventArgs e) + { + StopBot(); + } + + private void ClearBestButton_Click(object sender, EventArgs e) + { + _bestBotAttempt = null; + UpdateBestAttempt(); + } + + private void PlayBestButton_Click(object sender, EventArgs e) + { + _replayMode = true; + _dontUpdateValues = true; + GlobalWin.MainForm.LoadQuickSave(SelectedSlot); // Triggers an UpdateValues call + _dontUpdateValues = false; + _startFrame = Emulator.Frame; + GlobalWin.MainForm.UnpauseEmulator(); + } + + #endregion + + #region Classes + private class BotAttempt { public BotAttempt() @@ -471,6 +477,85 @@ namespace BizHawk.Client.EmuHawk public string FromSlot { get; set; } } + #endregion + + #region File Handling + + private void LoadFileFromRecent(string path) + { + var result = LoadBotFile(path); + if (!result) + { + Settings.RecentBotFiles.HandleLoadError(path); + } + } + + private bool LoadBotFile(string path) + { + var file = new FileInfo(path); + if (!file.Exists) + { + return false; + } + + var json = File.ReadAllText(path); + var botData = (BotData)ConfigService.LoadWithType(json); + + _bestBotAttempt = botData.Best; + + + var probabilityControls = ControlProbabilityPanel.Controls + .OfType() + .ToList(); + + foreach (var kvp in botData.ControlProbabilities) + { + var control = probabilityControls.Single(c => c.ButtonName == kvp.Key); + control.Probability = kvp.Value; + } + + MaximizeAddress = botData.Maximize; + TieBreaker1Address = botData.TieBreaker1; + TieBreaker2Address = botData.TieBreaker2; + TieBreaker3Address = botData.TieBreaker3; + FrameLength = botData.FrameLength; + FromSlot = botData.FromSlot; + UpdateBestAttempt(); + + if (_bestBotAttempt != null) + { + PlayBestButton.Enabled = true; + } + + _currentFileName = path; + Settings.RecentBotFiles.Add(_currentFileName); + + return true; + } + + private void SaveBotFile(string path) + { + var data = new BotData + { + Best = _bestBotAttempt, + ControlProbabilities = ControlProbabilities, + Maximize = MaximizeAddress, + TieBreaker1 = TieBreaker1Address, + TieBreaker2 = TieBreaker2Address, + TieBreaker3 = TieBreaker3Address, + FromSlot = FromSlot + }; + + var json = ConfigService.SaveWithType(data); + + File.WriteAllText(path, json); + _currentFileName = path; + Settings.RecentBotFiles.Add(_currentFileName); + MessageLabel.Text = Path.GetFileName(_currentFileName) + " saved"; + } + + #endregion + private int GetRamvalue(int addr) { // TODO: ability to pick memory domain @@ -697,78 +782,5 @@ namespace BizHawk.Client.EmuHawk GlobalWin.MainForm.PauseEmulator(); } - - private void SaveBotFile(string path) - { - var data = new BotData - { - Best = _bestBotAttempt, - ControlProbabilities = ControlProbabilities, - Maximize = MaximizeAddress, - TieBreaker1 = TieBreaker1Address, - TieBreaker2 = TieBreaker2Address, - TieBreaker3 = TieBreaker3Address, - FromSlot = FromSlot - }; - - var json = ConfigService.SaveWithType(data); - - File.WriteAllText(path, json); - _currentFileName = path; - Settings.RecentBotFiles.Add(_currentFileName); - MessageLabel.Text = Path.GetFileName(_currentFileName) + " saved"; - } - - private void LoadFileFromRecent(string path) - { - var result = LoadBotFile(path); - if (!result) - { - Settings.RecentBotFiles.HandleLoadError(path); - } - } - - private bool LoadBotFile(string path) - { - var file = new FileInfo(path); - if (!file.Exists) - { - return false; - } - - var json = File.ReadAllText(path); - var botData = (BotData)ConfigService.LoadWithType(json); - - _bestBotAttempt = botData.Best; - - - var probabilityControls = ControlProbabilityPanel.Controls - .OfType() - .ToList(); - - foreach (var kvp in botData.ControlProbabilities) - { - var control = probabilityControls.Single(c => c.ButtonName == kvp.Key); - control.Probability = kvp.Value; - } - - MaximizeAddress = botData.Maximize; - TieBreaker1Address = botData.TieBreaker1; - TieBreaker2Address = botData.TieBreaker2; - TieBreaker3Address = botData.TieBreaker3; - FrameLength = botData.FrameLength; - FromSlot = botData.FromSlot; - UpdateBestAttempt(); - - if (_bestBotAttempt != null) - { - PlayBestButton.Enabled = true; - } - - _currentFileName = path; - Settings.RecentBotFiles.Add(_currentFileName); - - return true; - } } }