<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using Duality;
using Duality.Drawing;
using Duality.Components;
using Duality.Resources;
using Duality.Plugins.Tilemaps;
using Duality.Editor.Plugins.Tilemaps.Properties;
using Duality.Editor.Plugins.Tilemaps.UndoRedoActions;
using Duality.Editor.Plugins.CamView.CamViewStates;
using Duality.Editor.Plugins.CamView.CamViewLayers;


namespace Duality.Editor.Plugins.Tilemaps.CamViewStates
{
	public class TilemapEditorCamViewState : CamViewState
	{
		private enum TilemapTool
		{
			None,

			Select,
			Brush,
			Rect,
			Oval,
			Fill
		}
		private enum ContinuousAction
		{
			None,

			DrawTile,
			FillTileRect,
			FillTileOval
		}

		private static readonly Point2 InvalidTile = new Point2(-1, -1);

		private TilemapTool      selectedTool     = TilemapTool.Brush;
		private Tilemap          selectedTilemap  = null;
		private TilemapRenderer  hoveredRenderer  = null;
		private Point2           hoveredTile      = InvalidTile;
		private TilemapTool      activeTool       = TilemapTool.None;
		private Tilemap          activeTilemap    = null;
		private Point2           activeAreaOrigin = InvalidTile;
		private Grid<bool>       activeArea       = new Grid<bool>();
		private ContinuousAction action           = ContinuousAction.None;

		private ToolStrip        toolstrip        = null;
		private ToolStripButton  toolButtonSelect = null;
		private ToolStripButton  toolButtonBrush  = null;
		private ToolStripButton  toolButtonRect   = null;
		private ToolStripButton  toolButtonOval   = null;
		private ToolStripButton  toolButtonFill   = null;


		public override string StateName
		{
			get { return "Tilemap Editor"; }
		}


		public TilemapEditorCamViewState()
		{
			this.SetDefaultObjectVisibility(
				typeof(Tilemap),
				typeof(TilemapRenderer));
			this.SetDefaultActiveLayers(
				typeof(GridCamViewLayer));
		}
		
		private void SetActiveTool(TilemapTool tool)
		{
			this.selectedTool = tool;
			this.UpdateToolbar();
			this.OnMouseMove();
		}

		private Tilemap QuerySelectedTilemap()
		{
			// Detect whether the user has either selected a Tilemap directly, 
			// or a related Component that points to an external one
			return
				DualityEditorApp.Selection.Components.OfType<Tilemap>().FirstOrDefault() ?? 
				DualityEditorApp.Selection.GameObjects.GetComponents<Tilemap>().FirstOrDefault() ??
				DualityEditorApp.Selection.Components.OfType<TilemapRenderer>().Select(r => r.ExternalTilemap).FirstOrDefault() ?? 
				DualityEditorApp.Selection.GameObjects.GetComponents<TilemapRenderer>().Select(r => r.ExternalTilemap).FirstOrDefault();
		}
		private IEnumerable<TilemapRenderer> QueryVisibleTilemapRenderers()
		{
			var all = Scene.Current.FindComponents<TilemapRenderer>();
			return all.Where(r => 
				r.Active && 
				!DesignTimeObjectData.Get(r.GameObj).IsHidden && 
				this.IsCoordInView(r.GameObj.Transform.Pos, r.BoundRadius));
		}
		private bool GetTilemapDisplayedGreyedOut(Tilemap tilemap)
		{
			Tilemap hoveredTilemap = this.hoveredRenderer != null ? this.hoveredRenderer.ActiveTilemap : null;
			if (this.selectedTilemap != null)
				return tilemap != this.selectedTilemap && tilemap != hoveredTilemap;
			else
				return false;
		}
		
		private void UpdateToolbar()
		{
			this.toolButtonSelect.Checked = false;
			this.toolButtonBrush.Checked  = false;
			this.toolButtonRect.Checked   = false;
			this.toolButtonOval.Checked   = false;
			this.toolButtonFill.Checked   = false;

			switch (this.selectedTool)
			{
				case TilemapTool.Select: this.toolButtonSelect.Checked = true; break;
				case TilemapTool.Brush:  this.toolButtonBrush.Checked  = true; break;
				case TilemapTool.Rect:   this.toolButtonRect.Checked   = true; break;
				case TilemapTool.Oval:   this.toolButtonOval.Checked   = true; break;
				case TilemapTool.Fill:   this.toolButtonFill.Checked   = true; break;
			}
		}
		private void UpdateCursor()
		{
			switch (this.activeTool)
			{<commit_msg>Tilemap Editor Tweak #REMOVE: Removed old / unused tilemap editor code.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

using Duality;
using Duality.Drawing;
using Duality.Components;
using Duality.Resources;
using Duality.Plugins.Tilemaps;
using Duality.Editor.Plugins.Tilemaps.Properties;
using Duality.Editor.Plugins.Tilemaps.UndoRedoActions;
using Duality.Editor.Plugins.CamView.CamViewStates;
using Duality.Editor.Plugins.CamView.CamViewLayers;


namespace Duality.Editor.Plugins.Tilemaps.CamViewStates
{
	public class TilemapEditorCamViewState : CamViewState
	{
		private enum TilemapTool
		{
			None,

			Select,
			Brush,
			Rect,
			Oval,
			Fill
		}
		private enum ContinuousAction
		{
			None,

			DrawTile,
			FillTileRect,
			FillTileOval
		}

		private static readonly Point2 InvalidTile = new Point2(-1, -1);

		private TilemapTool      selectedTool     = TilemapTool.Brush;
		private Tilemap          selectedTilemap  = null;
		private TilemapRenderer  hoveredRenderer  = null;
		private Point2           hoveredTile      = InvalidTile;
		private TilemapTool      activeTool       = TilemapTool.None;
		private Tilemap          activeTilemap    = null;
		private Point2           activeAreaOrigin = InvalidTile;
		private Grid<bool>       activeArea       = new Grid<bool>();
		private ContinuousAction action           = ContinuousAction.None;

		private ToolStrip        toolstrip        = null;
		private ToolStripButton  toolButtonSelect = null;
		private ToolStripButton  toolButtonBrush  = null;
		private ToolStripButton  toolButtonRect   = null;
		private ToolStripButton  toolButtonOval   = null;
		private ToolStripButton  toolButtonFill   = null;


		public override string StateName
		{
			get { return "Tilemap Editor"; }
		}


		public TilemapEditorCamViewState()
		{
			this.SetDefaultObjectVisibility(
				typeof(Tilemap),
				typeof(TilemapRenderer));
			this.SetDefaultActiveLayers(
				typeof(GridCamViewLayer));
		}
		
		private void SetActiveTool(TilemapTool tool)
		{
			this.selectedTool = tool;
			this.UpdateToolbar();
			this.OnMouseMove();
		}

		private Tilemap QuerySelectedTilemap()
		{
			// Detect whether the user has either selected a Tilemap directly, 
			// or a related Component that points to an external one
			return
				DualityEditorApp.Selection.Components.OfType<Tilemap>().FirstOrDefault() ?? 
				DualityEditorApp.Selection.GameObjects.GetComponents<Tilemap>().FirstOrDefault() ??
				DualityEditorApp.Selection.Components.OfType<TilemapRenderer>().Select(r => r.ExternalTilemap).FirstOrDefault() ?? 
				DualityEditorApp.Selection.GameObjects.GetComponents<TilemapRenderer>().Select(r => r.ExternalTilemap).FirstOrDefault();
		}
		private IEnumerable<TilemapRenderer> QueryVisibleTilemapRenderers()
		{
			var all = Scene.Current.FindComponents<TilemapRenderer>();
			return all.Where(r => 
				r.Active && 
				!DesignTimeObjectData.Get(r.GameObj).IsHidden && 
				this.IsCoordInView(r.GameObj.Transform.Pos, r.BoundRadius));
		}
		
		private void UpdateToolbar()
		{
			this.toolButtonSelect.Checked = false;
			this.toolButtonBrush.Checked  = false;
			this.toolButtonRect.Checked   = false;
			this.toolButtonOval.Checked   = false;
			this.toolButtonFill.Checked   = false;

			switch (this.selectedTool)
			{
				case TilemapTool.Select: this.toolButtonSelect.Checked = true; break;
				case TilemapTool.Brush:  this.toolButtonBrush.Checked  = true; break;
				case TilemapTool.Rect:   this.toolButtonRect.Checked   = true; break;
				case TilemapTool.Oval:   this.toolButtonOval.Checked   = true; break;
				case TilemapTool.Fill:   this.toolButtonFill.Checked   = true; break;
			}
		}
		private void UpdateCursor()
		{
			switch (this.activeTool)
			{
{'fraction_non_alphanumeric': 0.08771041640298696, 'fraction_numerical': 0.0015187950892292116, 'mean_word_length': 3.7204301075268815, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1794443', 'n_tokens_mistral': 2767, 'n_tokens_neox': 2389, 'n_words': 492}