private void AddRuleButton_Click(object sender, EventArgs e) { DeselectAllRules(); var newRule = new SmartTile.Rule(); WorkingSmartTile.Assignments[CurrentSmartTileID].Rules.Add(newRule); AddRule(newRule); }
void UpdateRuleGrid(PictureBox grid) { Image newGrid = Properties.Resources.RuleGrid; SmartTile.Rule rule = grid.Parent.Tag as SmartTile.Rule; using (Graphics g = Graphics.FromImage(newGrid)) g.FillRectangle(GridBrush, 16 + rule.X * 8, 16 + rule.Y * 8, 8, 8); grid.Image = newGrid; }
private void tilesetPicture_MouseClick(object sender, MouseEventArgs e) { if (CurrentSmartTileID >= 0 && CurrentSmartTileID < WorkingSmartTile.Assignments.Length) { ushort newTileID = (ushort)GetMouseTileIDFromTileset(e); var tiles = WorkingSmartTile.Assignments[CurrentSmartTileID].Tiles; if (e.Button == MouseButtons.Left) { if ((GetKeyState((int)Keys.F) & 0x8000) != 0) { newTileID |= (ushort)(AndValue + 1); } if ((GetKeyState((int)Keys.I) & 0x8000) != 0) { newTileID |= 0x2000; } if (CurrentRuleID < 0) { tiles.Add(newTileID); } else { Panel rulePanel = (panel4.Controls[panel4.Controls.Count - 1 - CurrentRuleID] as Panel); SmartTile.Rule rule = WorkingSmartTile.Assignments[CurrentSmartTileID].Rules[CurrentRuleID]; if (rule.Result.Count < 8) { rule.Result.Add(newTileID); UpdateRuleResultImages(rulePanel); } return; } } else if (e.Button == MouseButtons.Right) { if (tiles.RemoveAll(potentialTileIDToRemove => (potentialTileIDToRemove & AndValue) == (newTileID & AndValue)) == 0) { return; } } else { return; } elapsed = tiles.Count - 1; RedrawTiles(null); UpdateFramesPreview(); } }
Panel AddRule(SmartTile.Rule rule) { Panel panel = new Panel(); panel.Tag = rule; panel.Size = new Size(panel4.ClientSize.Width, 40); panel.Dock = DockStyle.Top; Label ifLabel = new Label(); ifLabel.Text = "if"; ifLabel.Location = new Point(14, 12); ifLabel.AutoSize = true; PictureBox grid = new PictureBox(); grid.Size = new Size(40, 40); grid.Location = new Point(32, 0); grid.MouseClick += (s, e) => { rule.X = e.X / 8 - 2; rule.Y = e.Y / 8 - 2; UpdateRuleGrid(grid); }; CheckBox notIn = new CheckBox(); notIn.Text = "not in"; notIn.Location = new Point(90, 12); notIn.AutoSize = true; notIn.Checked = rule.Not; notIn.CheckedChanged += (s, e) => { rule.Not = notIn.Checked; }; TextBox specificTileCriteria = new TextBox(); specificTileCriteria.Location = new Point(265, 10); specificTileCriteria.Text = string.Join(",", rule.SpecificTiles.Select(number => number.ToString())); specificTileCriteria.Visible = rule.OtherSmartTileID < 0; specificTileCriteria.LostFocus += (s, e) => { bool valid = SpecificTilesValidationPattern.Match(specificTileCriteria.Text).Success; specificTileCriteria.BackColor = valid ? Color.White : Color.Pink; if (valid) { rule.SpecificTiles = specificTileCriteria.Text.Split(',').Select(numbers => ushort.Parse(numbers.Trim())).ToList(); } }; ComboBox criteriaSource = new ComboBox(); criteriaSource.Items.AddRange(AllSmartTileNames.ToArray()); criteriaSource.Items.Add("specific tiles:"); criteriaSource.Location = new Point(150, 10); criteriaSource.Width = 105; criteriaSource.DropDownStyle = ComboBoxStyle.DropDownList; criteriaSource.SelectedIndex = rule.OtherSmartTileID >= 0 ? rule.OtherSmartTileID : criteriaSource.Items.Count - 1; criteriaSource.SelectedIndexChanged += (s, e) => { int newIndex = criteriaSource.SelectedIndex; if (newIndex == criteriaSource.Items.Count - 1) { rule.OtherSmartTileID = -1; specificTileCriteria.Show(); } else { rule.OtherSmartTileID = newIndex; specificTileCriteria.Hide(); } }; Label andOrThen = new Label(); andOrThen.Location = new Point(385, 12); andOrThen.AutoSize = true; andOrThen.Text = "and..."; PictureBox results = new PictureBox(); results.Location = new Point(420, 4); results.Size = new Size(256, 32); Button deleteRuleButton = new Button(); deleteRuleButton.Text = "X"; deleteRuleButton.Location = new Point(684, 4); deleteRuleButton.Size = new Size(32, 32); deleteRuleButton.Click += (s, e) => { WorkingSmartTile.Assignments[CurrentSmartTileID].Rules.Remove(panel.Tag as SmartTile.Rule); panel4.Controls.Remove(panel); DeselectAllRules(); }; Action RefreshRulesFromPanelOrder = () => { var rules = WorkingSmartTile.Assignments[CurrentSmartTileID].Rules; rules.Clear(); foreach (Control potentialPanel in panel4.Controls) { if (potentialPanel is Panel) { rules.Insert(0, potentialPanel.Tag as SmartTile.Rule); } } }; Button duplicateRuleButton = new Button(); duplicateRuleButton.Text = "D"; duplicateRuleButton.Location = new Point(732, 4); duplicateRuleButton.Size = new Size(16, 32); duplicateRuleButton.Click += (s, e) => { var newRule = new SmartTile.Rule(rule); var newPanel = AddRule(new SmartTile.Rule(rule)); panel4.Controls.SetChildIndex(newPanel, panel4.Controls.GetChildIndex(panel)); RefreshRulesFromPanelOrder(); UpdateRuleResultImages(newPanel); }; panel.Controls.AddRange(new Control[] { ifLabel, grid, notIn, criteriaSource, specificTileCriteria, andOrThen, results, deleteRuleButton, duplicateRuleButton }); for (int vDelta = -1; vDelta <= 1; vDelta += 2) { Button adjustOrderButton = new Button(); adjustOrderButton.Text = (vDelta == -1) ? "^" : "v"; adjustOrderButton.Location = new Point(716, 12 + vDelta * 8); adjustOrderButton.Size = new Size(16, 16); int localVDelta = vDelta; adjustOrderButton.Click += (s, e) => { var rules = WorkingSmartTile.Assignments[CurrentSmartTileID].Rules; var index = rules.FindIndex(r => r == rule); if (localVDelta == -1) { if (index == 0) { return; } } else { if (index == rules.Count - 1) { return; } } panel4.Controls.SetChildIndex(panel, panel4.Controls.GetChildIndex(panel) - localVDelta); RefreshRulesFromPanelOrder(); }; panel.Controls.Add(adjustOrderButton); } foreach (Control control in panel.Controls) { control.Left -= 5; control.MouseClick += (s, e) => { DeselectAllRules(); (s as Control).Parent.BackColor = Color.White; CurrentRuleID = WorkingSmartTile.Assignments[CurrentSmartTileID].Rules.FindIndex(r => r == rule); if (s is PictureBox && e.Button == MouseButtons.Right) { var X = e.X / 32; if (X < rule.Result.Count) { rule.Result.RemoveAt(X); UpdateRuleResultImages(panel); } } }; } UpdateRuleGrid(grid); panel4.Controls.Add(panel); panel4.Controls.SetChildIndex(panel, 1); return(panel); }