Esempio n. 1
0
        void radioStationary_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioStationary.Checked)
            {
                return;
            }

            if (!(_gd is StationaryGrhData))
            {
                const string msg =
                    "Are you sure you wish to convert this GrhData to stationary? Most GrhData values will be lost.";
                const string cap = "Convert to stationary?";
                if (MessageBox.Show(msg, cap, MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }

                var newGD = GrhInfo.ReplaceExistingWithStationary(_gd.GrhIndex);
                if (newGD == null)
                {
                    MessageBox.Show("Conversion to stationary failed for some reason...");
                    return;
                }

                _gd = newGD;
            }

            radioAnimated.Checked = false;
            gbStationary.Visible  = true;
            gbAnimated.Visible    = false;
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the GrhToPlace from the hotkey.
        /// </summary>
        /// <param name="hotkeyIndex">The hotkey index.</param>
        public void SetGrhFromHotkey(int hotkeyIndex)
        {
            if (hotkeyIndex >= HotkeyedGrhs.Length || hotkeyIndex < 0)
            {
                return;
            }

            string categorization = HotkeyedGrhs[hotkeyIndex];

            if (string.IsNullOrEmpty(categorization))
            {
                return;
            }

            GrhData grhData = null;

            try
            {
                SpriteCategorization cat = new SpriteCategorization(categorization);
                grhData = GrhInfo.GetData(cat);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
            }

            if (grhData == null)
            {
                // No grh for categorization, so unset it
                HotkeyedGrhs[hotkeyIndex] = null;
                return;
            }

            Map.SetGrhToPlace(grhData.GrhIndex);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the currently selected <see cref="GrhData"/> using the <see cref="SelectedGrhDataHandler"/>.
        /// </summary>
        /// <returns>The currently selected <see cref="GrhData"/>.</returns>
        GrhData GetCurrentlySelectedGrhData()
        {
            GrhData selected = null;

            try
            {
                if (SelectedGrhDataHandler != null)
                {
                    selected = SelectedGrhDataHandler(this);
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to get selected GrhData for `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, this, ex);
                }
                Debug.Fail(string.Format(errmsg, this, ex));

                selected = null;
            }

            return(selected);
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditGrhForm"/> class.
        /// </summary>
        /// <param name="gd">The <see cref="GrhData"/> to edit.</param>
        /// <param name="mapGrhWalls">The <see cref="MapGrhWalls"/> instance.</param>
        /// <param name="createWall">Delegate describing how to create wall instances.</param>
        /// <param name="deleteOnCancel">If the <see cref="GrhData"/> will be deleted if the editing is canceled.</param>
        /// <exception cref="ArgumentNullException"><paramref name="gd" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="mapGrhWalls" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="createWall" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">Cannot edit an <see cref="AutomaticAnimatedGrhData"/>.</exception>
        public EditGrhForm(GrhData gd, MapGrhWalls mapGrhWalls, CreateWallEntityHandler createWall, bool deleteOnCancel)
        {
            if (gd == null)
            {
                throw new ArgumentNullException("gd");
            }
            if (mapGrhWalls == null)
            {
                throw new ArgumentNullException("mapGrhWalls");
            }
            if (createWall == null)
            {
                throw new ArgumentNullException("createWall");
            }
            if (gd is AutomaticAnimatedGrhData)
            {
                throw new ArgumentException("Cannot edit an AutomaticAnimatedGrhData.", "gd");
            }

            DeleteOnCancel = deleteOnCancel;
            WasCanceled    = false;

            // Set the local members
            _createWall  = createWall;
            _gd          = gd;
            _mapGrhWalls = mapGrhWalls;

            _grh = new Grh(gd, AnimType.Loop, TickCount.Now);

            InitializeComponent();

            ShowGrhInfo();
        }
Esempio n. 5
0
        void GrhInfo_Removed(GrhData sender, EventArgs e)
        {
            var node = FindGrhDataNode(sender);

            if (node != null)
            {
                node.Update();
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Attempts to begin the editing of a <see cref="GrhData"/>.
        /// </summary>
        /// <param name="gd">The <see cref="GrhData"/> to edit.</param>
        /// <returns>True if the editing started successfully; otherwise false.</returns>
        public bool BeginEditGrhData(GrhData gd)
        {
            if (_compactMode)
            {
                return(false);
            }

            return(BeginEditGrhData(gd, false));
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the <see cref="Image"/> for the given argument.
        /// </summary>
        /// <param name="gd">The <see cref="GrhData"/> to get the <see cref="Image"/> for.</param>
        /// <returns>The <see cref="Image"/> for the <paramref name="gd"/>.</returns>
        public Image GetImage(GrhData gd)
        {
            if (gd == null)
            {
                return(_errorImage);
            }

            return(GetImage(gd.GetFrame(0), false, null, null));
        }
Esempio n. 8
0
        /// <summary>
        /// Removes all the walls for a <see cref="GrhData"/>.
        /// </summary>
        /// <param name="grhData">The <see cref="GrhData"/> to remove the walls for.</param>
        public void RemoveWalls(GrhData grhData)
        {
            var index = (int)grhData.GrhIndex;

            if (!_walls.CanGet(index))
            {
                return;
            }

            _walls.RemoveAt(index);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates a new <see cref="GrhTreeViewNode"/>.
        /// </summary>
        /// <param name="grhTreeView">The <see cref="GrhTreeView"/> that will contain the node.</param>
        /// <param name="grhData">The <see cref="GrhData"/> that the node will contain.</param>
        /// <returns>The new <see cref="GrhTreeViewNode"/>.</returns>
        public static GrhTreeViewNode Create(GrhTreeView grhTreeView, GrhData grhData)
        {
            var existingNode = grhTreeView.FindGrhDataNode(grhData);

            if (existingNode != null)
            {
                existingNode.Update();
                return(existingNode);
            }

            return(new GrhTreeViewNode(grhTreeView, grhData));
        }
Esempio n. 10
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (DesignMode)
            {
                return;
            }

            // Load the default emitter sprite
            _defaultEmitterSprite = GrhInfo.GetData("Particle", "sparkle alpha");
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GrhTreeViewNode"/> class.
        /// </summary>
        /// <param name="treeView">The <see cref="GrhTreeView"/> this node belongs to.</param>
        /// <param name="grhData">The <see cref="GrhData"/> this node contains.</param>
        GrhTreeViewNode(GrhTreeView treeView, GrhData grhData)
        {
            _grhData = grhData;
            Update(treeView);

            // If this is a root node, load the image immediately since our lazy-loading of images only triggers when
            // nodes expand, but the root nodes are never shown by expanding
            if (Parent == null)
            {
                EnsureImageIsSet();
            }
        }
Esempio n. 12
0
        void RebuildMapGrhWalls(IEnumerable <KeyValuePair <GrhData, GrhData.FileTags> > grhDataFileTags)
        {
            MapGrhWalls.Clear();

            foreach (var kvp in grhDataFileTags)
            {
                if (kvp.Value.Walls == null || kvp.Value.Walls.Count == 0)
                {
                    continue;
                }

                List <WallEntityBase> wallList = new List <WallEntityBase>();
                GrhData gd = kvp.Key;

                // Create the wall entities
                foreach (var wallInfo in kvp.Value.Walls)
                {
                    GrhData.BoundWallType wallType = wallInfo.Item1;
                    Rectangle?            area     = wallInfo.Item2;

                    Vector2 position;
                    Vector2 size;

                    if (area.HasValue)
                    {
                        position = new Vector2(area.Value.X, area.Value.Y);
                        size     = new Vector2(area.Value.Width, area.Value.Height);
                    }
                    else
                    {
                        position = Vector2.Zero;
                        size     = Vector2.Zero;
                    }

                    if (wallType == GrhData.BoundWallType.Solid || wallType == GrhData.BoundWallType.Platform)
                    {
                        WallEntity wall = new WallEntity(position, size)
                        {
                            IsPlatform = wallType == GrhData.BoundWallType.Platform
                        };
                        wallList.Add(wall);
                    }
                }

                // If there are any walls, trim the list and set it
                if (wallList.Count > 0)
                {
                    wallList.TrimExcess();
                    MapGrhWalls[gd] = wallList;
                }
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Sets the icon for an animated <see cref="GrhData"/>.
        /// </summary>
        /// <param name="grhData">The <see cref="GrhData"/>.</param>
        void SetIconImageAnimated(GrhData grhData)
        {
            // If we have already created the Grh for animations, we just need to make sure we have the
            // correct GrhData set on it
            if (_animationGrh != null)
            {
                _animationGrh.SetGrh(grhData);
                return;
            }

            _animationGrh = new Grh(grhData, AnimType.Loop, TickCount.Now);

            _grhImageList.GetImageAsync(grhData.GetFrame(0), _asyncCallback, this);
        }
Esempio n. 14
0
 /// <summary>
 /// Asynchronously gets the <see cref="Image"/> for the given argument.
 /// </summary>
 /// <param name="gd">The <see cref="GrhData"/> to get the <see cref="Image"/> for.</param>
 /// <param name="callback">The <see cref="GrhImageListAsyncCallback"/> to invoke when the operation has finished.</param>
 /// <param name="userState">The optional user state object to pass to the <paramref name="callback"/>.</param>
 public void GetImageAsync(GrhData gd, GrhImageListAsyncCallback callback, object userState)
 {
     if (gd == null)
     {
         if (callback != null)
         {
             callback(this, null, ErrorImage, userState);
         }
     }
     else
     {
         GetImage(gd.GetFrame(0), true, callback, userState);
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Attempts to begin the editing of a <see cref="GrhData"/>.
        /// </summary>
        /// <param name="node">The <see cref="TreeNode"/> containing the <see cref="GrhData"/> to edit.</param>
        /// <param name="gd">The <see cref="GrhData"/> to edit.</param>
        /// <param name="deleteOnCancel">If true, the <paramref name="gd"/> will be deleted if the edit form is
        /// closed by pressing "Cancel".</param>
        /// <returns>True if the editing started successfully; otherwise false.</returns>
        bool BeginEditGrhData(TreeNode node, GrhData gd, bool deleteOnCancel)
        {
            if (node == null || gd == null)
            {
                return(false);
            }

            if (EditGrhDataRequested != null)
            {
                EditGrhDataRequested.Raise(this, new GrhTreeViewEditGrhDataEventArgs(node, gd, deleteOnCancel));
            }

            return(true);
        }
Esempio n. 16
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            if (DesignMode)
            {
                return;
            }

            cmbEmitterType.SelectedEmitterChanged -= cmbEmitterType_SelectedEmitterChanged;
            cmbEmitterType.SelectedEmitterChanged += cmbEmitterType_SelectedEmitterChanged;

            // Load the default emitter sprite
            _defaultEmitterSprite = GrhInfo.GetData("Particle", "sparkle");
        }
Esempio n. 17
0
        /// <summary>
        /// Gets the tool tip text for any animated <see cref="GrhData"/>.
        /// </summary>
        /// <param name="grhData">The <see cref="GrhData"/>.</param>
        /// <returns>The tool tip text for any animated <see cref="GrhData"/>.</returns>
        static string GetToolTipTextAnimated(GrhData grhData)
        {
            var sb = new StringBuilder();

            if (grhData is AutomaticAnimatedGrhData)
            {
                sb.AppendLine("*Automatic Animated GrhData*");
            }

            sb.AppendLine("Grh: " + grhData.GrhIndex);
            AppendFramesToolTipText(grhData.Frames, sb);
            sb.AppendLine();
            sb.Append("Speed: " + (1f / grhData.Speed));

            return(sb.ToString());
        }
Esempio n. 18
0
        void MenuClickNewGrh(object sender, EventArgs e)
        {
            if (_contentManager == null)
            {
                return;
            }

            // Create the new GrhData
            var     category = GetCategoryFromTreeNode(SelectedNode);
            GrhData gd       = GrhInfo.CreateGrhData(_contentManager, category);

            UpdateGrhData(gd);

            // Begin edit
            BeginEditGrhData(gd, true);
        }
Esempio n. 19
0
        /// <summary>
        /// Makes the <see cref="GrhData"/> handled by this <see cref="GrhTreeViewNode"/> synchronize
        /// to the information displayed by the node (in opposed to <see cref="Update"/>, which makes the node
        /// update to match the <see cref="GrhData"/>).
        /// </summary>
        public void SyncGrhData()
        {
            // Check that the GrhData still exists
            var gd = GrhInfo.GetData(GrhData.GrhIndex);

            if (gd != _grhData)
            {
                RemoveRecursive();
                return;
            }

            var category = ((GrhTreeViewFolderNode)Parent).FullCategory;
            var title    = Text;

            GrhData.SetCategorization(new SpriteCategorization(category, title));
        }
Esempio n. 20
0
        void ShowGrhInfoForAnimated(GrhData grhData)
        {
            radioStationary.Checked = false;
            radioAnimated.Checked   = true;
            txtFrames.Text          = string.Empty;

            for (var i = 0; i < grhData.FramesCount; i++)
            {
                var frame = grhData.GetFrame(i);
                if (frame != null)
                {
                    txtFrames.Text += frame.GrhIndex + Environment.NewLine;
                }
            }

            txtSpeed.Text = (1f / grhData.Speed).ToString();
        }
Esempio n. 21
0
        /// <summary>
        /// Finds the <see cref="GrhTreeViewNode"/> for the given <see cref="GrhData"/>.
        /// </summary>
        /// <param name="grhData">The <see cref="GrhData"/> to find the <see cref="GrhTreeViewNode"/> for.</param>
        /// <returns>The <see cref="GrhTreeViewNode"/> that is for the given <paramref name="grhData"/>, or null
        /// if invalid or not found.</returns>
        public GrhTreeViewNode FindGrhDataNode(GrhData grhData)
        {
            if (grhData == null)
            {
                return(null);
            }

            var folder = FindFolder(grhData.Categorization.Category.ToString());

            if (folder != null)
            {
                var existingNode = folder.Nodes.OfType <GrhTreeViewNode>().FirstOrDefault(x => x.GrhData == grhData);
                if (existingNode != null)
                {
                    return(existingNode);
                }
            }

            return(null);
        }
Esempio n. 22
0
        static int ExtractNumber(GrhData data)
        {
            var text = data.Categorization.Title.ToString();

            Match match = Regex.Match(text, @"(\d+)");

            if (match == null)
            {
                return(0);
            }

            int value;

            if (!int.TryParse(match.Value, out value))
            {
                return(0);
            }

            return(value);
        }
Esempio n. 23
0
        /// <summary>
        /// Decides the <see cref="ContentLevel"/> to use for <see cref="GrhData"/>s.
        /// </summary>
        /// <param name="grhData">The <see cref="GrhData"/> to get the <see cref="ContentLevel"/> for.</param>
        /// <returns>The <see cref="ContentLevel"/> for the <paramref name="grhData"/>.</returns>
        static ContentLevel ContentLevelDecider(GrhData grhData)
        {
            const StringComparison comp = StringComparison.OrdinalIgnoreCase;

            var cat = grhData.Categorization.Category.ToString();

            // For stuff that will be put into a global atlas, use the temporary level
            if (cat.StartsWith("gui", comp))
            {
                return(ContentLevel.Temporary);
            }

            // For stuff in the map category, use Map
            if (cat.StartsWith("map", comp))
            {
                return(ContentLevel.Map);
            }

            // Everything else, return global
            return(ContentLevel.Global);
        }
Esempio n. 24
0
 /// <summary>
 /// Adds a <see cref="GrhData"/> to the tree or updates it if it already exists.
 /// </summary>
 /// <param name="gd"><see cref="GrhData"/> to add or update.</param>
 void AddGrhToTree(GrhData gd)
 {
     GrhTreeViewNode.Create(this, gd);
 }
Esempio n. 25
0
        /// <summary>
        /// Completely rebuilds the <see cref="GrhTreeView"/>.
        /// </summary>
        public void RebuildTree()
        {
            if (DesignMode)
            {
                return;
            }

            // Suspend the layout and updating while we massively alter the collection
            BeginUpdate();
            SuspendLayout();

            try
            {
                // If there are any nodes already, keep track of which is selected
                GrhTreeViewNode selectedGrhNode = SelectedNode as GrhTreeViewNode;
                GrhData         selectedGrhData = selectedGrhNode != null ? selectedGrhNode.GrhData : null;

                // Clear any existing nodes (probably isn't any, but just in case...)
                Nodes.Clear();

                // Set up the filter
                string[] filterWords = (Filter ?? string.Empty).Split(',').Distinct(StringComparer.OrdinalIgnoreCase).Select(x => x.Trim()).Where(x => x.Length > 0).ToArray();
                if (filterWords.Length == 0)
                {
                    filterWords = null;
                }

                // Iterate through all the GrhDatas
                foreach (var grhData in GrhInfo.GrhDatas)
                {
                    if (filterWords != null)
                    {
                        // With filtering
                        string cat = grhData.Categorization.ToString();
                        if (filterWords.Any(x => cat.Contains(x, StringComparison.OrdinalIgnoreCase)))
                        {
                            AddGrhToTree(grhData);
                        }
                    }
                    else
                    {
                        // No filtering
                        AddGrhToTree(grhData);
                    }
                }

                // Perform the initial sort
                Sort();

                // If we used filtering, expand all nodes
                if (filterWords != null)
                {
                    ExpandAll();
                }

                // Restore selection
                if (selectedGrhData != null)
                {
                    SelectedNode = FindGrhDataNode(selectedGrhData);
                }
            }
            finally
            {
                // Resume the layout and updating
                ResumeLayout();
                EndUpdate();
            }
        }
Esempio n. 26
0
 /// <summary>
 /// Gets the GrhData.FileTags for the given GrhData.
 /// </summary>
 public GrhData.FileTags GetFileTags(GrhData gd)
 {
     return(GetFileTags(gd.GrhIndex));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GrhTreeViewEventArgs"/> class.
 /// </summary>
 /// <param name="grhData">The <see cref="GrhData"/>.</param>
 /// <param name="args">The <see cref="System.Windows.Forms.TreeViewEventArgs"/> instance containing the event data.</param>
 public GrhTreeViewEventArgs(GrhData grhData, TreeViewEventArgs args) : base(args.Node, args.Action)
 {
     _grhData = grhData;
 }
Esempio n. 28
0
        /// <summary>
        /// Places a <see cref="MapGrh"/> on the map.
        /// </summary>
        /// <param name="map">The map to place the <see cref="MapGrh"/> on.</param>
        /// <param name="camera">The <see cref="ICamera2D"/>.</param>
        /// <param name="screenPos">The screen position to place the <see cref="MapGrh"/>.</param>
        /// <param name="useTileMode">If TileMode should be used.</param>
        /// <param name="gd">The <see cref="GrhData"/> to place. Set to null to attempt to use the <see cref="GrhData"/> that is
        /// currently selected in the <see cref="GlobalState"/>.</param>
        /// <returns>The <see cref="MapGrh"/> instance that was added, or null if the the <see cref="MapGrh"/> could not be
        /// added for any reason.</returns>
        public static MapGrh PlaceMapGrh(Map map, ICamera2D camera, Vector2 screenPos, bool useTileMode, GrhData gd = null)
        {
            // Get the GrhData to place from the global state
            if (gd == null)
            {
                gd = GlobalState.Instance.Map.GrhToPlace.GrhData;
            }

            // Ensure we have a GrhData to place
            if (gd == null)
            {
                return(null);
            }

            // Get the world position to place it
            var drawPos = camera.ToWorld(screenPos);

            drawPos = GridAligner.Instance.Align(drawPos, useTileMode).Round();

            // Cache some other values
            var selGrhGrhIndex = gd.GrhIndex;
            var isForeground   = EditorSettings.Default.MapGrh_DefaultIsForeground;
            var depth          = EditorSettings.Default.MapGrh_DefaultDepth;
            var drawPosArea    = drawPos.ToRectangle(new Vector2(2), true);

            if (!useTileMode)
            {
                // Make sure the same MapGrh doesn't already exist at that position
                if (map.Spatial.Contains <MapGrh>(drawPosArea,
                                                  x =>
                                                  x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.IsForeground == isForeground &&
                                                  Math.Round(x.Position.QuickDistance(drawPos)) <= 1))
                {
                    return(null);
                }
            }
            else
            {
                // Make sure the same MapGrh doesn't already exist at that position on the same layer
                if (map.Spatial.Contains <MapGrh>(drawPosArea,
                                                  x =>
                                                  x.Grh.GrhData.GrhIndex == selGrhGrhIndex && x.IsForeground == isForeground &&
                                                  Math.Round(x.Position.QuickDistance(drawPos)) <= 1))
                {
                    return(null);
                }

                // In TileMode, do not allow ANY MapGrh at the same position and layer depth. And if it does exist, instead of aborting,
                // delete the existing one.
                var existingMapGrhs = map.Spatial.GetMany <MapGrh>(drawPosArea,
                                                                   x =>
                                                                   x.LayerDepth == depth && x.IsForeground == isForeground && Math.Round(x.Position.QuickDistance(drawPos)) <= 1);
                foreach (var toDelete in existingMapGrhs)
                {
                    Debug.Assert(toDelete != null);
                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("TileMode caused MapGrh `{0}` to be overwritten.", toDelete);
                    }

                    map.RemoveMapGrh(toDelete);
                }

                Debug.Assert(
                    !map.Spatial.Contains <MapGrh>(drawPosArea,
                                                   x =>
                                                   x.LayerDepth == depth && x.IsForeground == isForeground &&
                                                   Math.Round(x.Position.QuickDistance(drawPos)) <= 1));
            }

            // Create the new MapGrh and add it to the map
            var g  = new Grh(gd, AnimType.Loop, map.GetTime());
            var mg = new MapGrh(g, drawPos, isForeground)
            {
                LayerDepth = depth
            };

            map.AddMapGrh(mg);

            return(mg);
        }
Esempio n. 29
0
 public GrhTreeViewEditGrhDataEventArgs(TreeNode node, GrhData grhData, bool deleteOnCancel)
 {
     _node           = node;
     _grhData        = grhData;
     _deleteOnCancel = deleteOnCancel;
 }
Esempio n. 30
0
 public List <WallEntityBase> this[GrhData gd]
 {
     get { return(this[gd.GrhIndex]); }
     set { this[gd.GrhIndex] = value; }
 }