/// <summary> /// Sets the Grh to a new index. /// </summary> /// <param name="grhData">New GrhData to use for the Grh.</param> /// <param name="anim">Type of animation.</param> /// <param name="currentTime">Current time.</param> public void SetGrh(GrhData grhData, AnimType anim, TickCount currentTime) { _grhData = grhData; _frame = 0; _anim = anim; _lastUpdated = currentTime; }
public UnsupportedGrhDataTypeException(GrhData grhData) : base( grhData, string.Format("GrhData `{0}` is of derived type `{1}`, which is not supported by this operation.", grhData, grhData.GetType())) { }
static string GetStr(GrhData grhData, string msg) { var s = string.Format("Exception caused by GrhData `{0}`.", grhData != null ? grhData.ToString() : "[NULL]"); if (!string.IsNullOrEmpty(s)) s += " " + msg; return s; }
/// <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(); }
public UnsupportedGrhDataTypeException(GrhData grhData) : base( grhData, string.Format("GrhData `{0}` is of derived type `{1}`, which is not supported by this operation.", grhData, grhData.GetType())) { }
/// <summary> /// Removes a <see cref="GrhData"/> from the dictionary. /// </summary> /// <param name="gd"><see cref="GrhData"/> to remove.</param> static void RemoveFromDictionary(GrhData gd) { Dictionary <SpriteTitle, GrhData> titleDic; if (!_catDic.TryGetValue(gd.Categorization.Category, out titleDic)) { const string errmsg = "Tried to remove GrhData `{0}` from the categorization dictionary with the" + " categorization of `{1}`, but the whole category does not exist!" + " This likely means some bad issue in the GrhInfo class..."; var err = string.Format(errmsg, gd, gd.Categorization); log.Fatal(err); Debug.Fail(err); return; } if (!titleDic.Remove(gd.Categorization.Title)) { const string errmsg = "Tried to remove GrhData `{0}` from the categorization dictionary with the" + " categorization of `{1}`, but the GrhData did not exist in the title dictionary!" + " This likely means some bad issue in the GrhInfo class..."; var err = string.Format(errmsg, gd, gd.Categorization); log.Fatal(err); Debug.Fail(err); } }
/// <summary> /// Performs a detailed check to ensure the Grh can be drawn without problem. This should be called before /// any drawing is done! /// </summary> /// <param name="spriteBatch"><see cref="ISpriteBatch"/> to draw to.</param> /// <returns>True if it is safe for the Grh to draw to the <paramref name="spriteBatch"/>, else false.</returns> bool CanDrawGrh(ISpriteBatch spriteBatch) { // Invalid GrhData if (GrhData == null) { const string errmsg = "Failed to render Grh - GrhData is null!"; if (log.IsWarnEnabled) { log.Warn(errmsg); } return(false); } // Invalid texture if (Texture == null) { if (log.IsWarnEnabled) { var sgd = GrhData as StationaryGrhData; if (sgd == null) { const string errmsg = "Failed to render Grh `{0}` - GrhData `{1}` is of type `{2}` instead of the expected type `{3}`!"; log.ErrorFormat(errmsg, this, GrhData, GrhData.GetType(), typeof(StationaryGrhData)); } else { const string errmsg = "Failed to render Grh `{0}` - GrhData returning null texture for `{1}`!"; log.WarnFormat(errmsg, this, sgd.TextureName); } } return(false); } // Invalid SpriteBatch if (spriteBatch == null) { const string errmsg = "Failed to render Grh `{0}` - SpriteBatch is null!"; if (log.IsWarnEnabled) { log.WarnFormat(errmsg, this); } return(false); } if (spriteBatch.IsDisposed) { const string errmsg = "Failed to render Grh `{0}` - SpriteBatch is disposed!"; if (log.IsWarnEnabled) { log.WarnFormat(errmsg, this); } return(false); } // All is good return(true); }
/// <summary> /// Sets the Grh to a new index. /// </summary> /// <param name="grhData">New GrhData to use for the stationary Grh.</param> public void SetGrh(GrhData grhData) { if (GrhData == grhData) { return; } SetGrh(grhData, AnimType, LastUpdated); }
static string GetStr(GrhData grhData, string msg) { var s = string.Format("Exception caused by GrhData `{0}`.", grhData != null ? grhData.ToString() : "[NULL]"); if (!string.IsNullOrEmpty(s)) { s += " " + msg; } return(s); }
/// <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(); }
/// <summary> /// Handles when the category of a <see cref="GrhData"/> in the DArray changes. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="NetGore.EventArgs{SpriteCategorization}"/> instance containing the event data.</param> static void ChangeCategorizationHandler(GrhData sender, EventArgs <SpriteCategorization> e) { var gd = sender; if (gd == null) { Debug.Fail("gd is null."); return; } RemoveFromDictionary(gd); AddToDictionary(gd); }
static GrhData TryGetGrhData(string categoryAndTitle) { GrhData grhData = null; try { grhData = GrhInfo.GetData(new SpriteCategorization(categoryAndTitle)); } catch (ArgumentNullException) { // Ignore invalid argument error } return(grhData); }
/// <summary> /// Adds a <see cref="GrhData"/> to the dictionary. /// </summary> /// <param name="gd"><see cref="GrhData"/> to add to the dictionary.</param> static void AddToDictionary(GrhData gd) { Dictionary <SpriteTitle, GrhData> titleDic; // Check if the category exists if (!_catDic.TryGetValue(gd.Categorization.Category, out titleDic)) { // Category does not exist, so create and add it titleDic = new Dictionary <SpriteTitle, GrhData>(); _catDic.Add(gd.Categorization.Category, titleDic); } // Add the GrhData to the sub-dictionary by its title titleDic.Add(gd.Categorization.Title, gd); }
static void AssertGrhIndexIsFree(GrhIndex index, GrhData ignoreWhen) { // Make sure we can even get the index if (!_grhDatas.CanGet((int)index)) { return; } // Get the current GrhData var currentGD = GetData(index); // Check if occupied if (currentGD != null && (ignoreWhen == null || currentGD != ignoreWhen)) { Debug.Fail("Existing GrhData is going to be overwritten. This is likely not what was intended."); } }
/// <summary> /// Adds a <see cref="GrhData"/> to the list of <see cref="GrhData"/>s at the index assigned to it. /// </summary> /// <param name="gd"><see cref="GrhData"/> to add.</param> /// <exception cref="ArgumentNullException"><paramref name="gd" /> is <c>null</c>.</exception> internal static void AddGrhData(GrhData gd) { if (gd == null) { throw new ArgumentNullException("gd"); } var index = gd.GrhIndex; AssertGrhIndexIsFree(index, gd); _grhDatas[(int)index] = gd; // Make sure the GrhData is only in the list once Debug.Assert(GrhDatas.Count(x => x == gd) == 1, "The GrhData should be in the list only once. Somehow, its in there either more times, or not at all."); }
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; }
/// <summary> /// Gets the GrhData.FileTags for the given GrhData. /// </summary> public GrhData.FileTags GetFileTags(GrhData gd) { return GetFileTags(gd.GrhIndex); }
/// <summary> /// Draws the <see cref="ICharacterSprite"/>. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw with.</param> /// <param name="position">The position to draw the sprite.</param> /// <param name="heading">The character's heading.</param> /// <param name="color">The color of the sprite.</param> public void Draw(ISpriteBatch spriteBatch, Vector2 position, Direction heading, Color color) { // If we have a body modifier being used, invalidate it if: // 1. The heading has changed. // 2. The animation has ended. // // If we don't have a body modifier being used, just ensure we have the correct Set being used. // // If we are moving, always use the walking animation. _currentHeading = heading; // If the body modifier is set, check if it needs to be unset if (_currentBodyModifier != null) { if (_bodyGrh.AnimType == AnimType.None || _bodyModifierDirection != heading) { _currentBodyModifier = null; } } // If we are moving, the body modifier is not set, or the sprite is invalid, use the non-modifier set if (Character.Velocity != Vector2.Zero || _currentBodyModifier == null || _bodyGrh.GrhData == null) { var prefix = (Character.Velocity == Vector2.Zero ? string.Empty : "Walk "); var directionSuffix = GetDirectionSetName(heading); _currentBodyModifier = null; InternalSetSet(prefix + directionSuffix); } // Ensure the sprite is valid before trying to update and draw it if (_bodyGrh.GrhData == null) { return; } // Update _bodyGrh.Update(_currentTime); position += new Vector2(Character.Size.X / 2f, Character.Size.Y - _bodyGrh.Size.Y); // Get the GrhDatas to draw, along with their draw order List <Tuple <int, GrhData, PaperDollLayerType> > grhDatas = new List <Tuple <int, GrhData, PaperDollLayerType> >(); grhDatas.Add(new Tuple <int, GrhData, PaperDollLayerType>(GetLayerOrder(PaperDollLayerType.Body, heading), _bodyGrh.GrhData, PaperDollLayerType.Body)); if (Paperdoll) { string setSuffix = !string.IsNullOrEmpty(_currentSet) ? "." + _currentSet : ""; if (_layers != null) { foreach (var layerName in _layers) { GrhData gd = GrhInfo.GetData(new SpriteCategorization("Character." + layerName + setSuffix)); if (gd == null) { continue; } PaperDollLayerType layerType = GetPaperDollLayerType(layerName); int layerOrder = GetLayerOrder(layerType, heading); grhDatas.Add(new Tuple <int, GrhData, PaperDollLayerType>(layerOrder, gd, layerType)); } } } // Sort by layer order grhDatas = grhDatas.OrderBy(x => x.Item1).ToList(); // Draw in order var drawingGrh = _bodyGrh.DeepCopy(); for (int i = 0; i < grhDatas.Count; i++) { GrhData gd = grhDatas[i].Item2; // Set frame GrhData gdFrame = gd.GetFrame((int)Math.Floor(_bodyGrh.Frame)) ?? gd.Frames.LastOrDefault(); if (gdFrame == null) { continue; } drawingGrh.SetGrh(gdFrame); // Get offset Vector2 sizeXOffset = new Vector2(drawingGrh.Size.X / -2f, 0); Vector2 layerOffset = GetPaperDollLayerOffset(grhDatas[i].Item3); // Draw drawingGrh.Draw(spriteBatch, position + layerOffset + sizeXOffset, color); } }
/// <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); }
/// <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; }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Exception"/> class with a specified error message. /// </summary> /// <param name="grhData">The <see cref="GrhData"/> related to the <see cref="Exception"/>.</param> /// <param name="message">The message that describes the error.</param> public GrhDataException(GrhData grhData, string message) : base(GetStr(grhData, message)) { }
/// <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); }
/// <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 PlaceMapGrhAtScreenPos(Map map, ICamera2D camera, Vector2 screenPos, bool useTileMode, GrhData gd = null) { // Get the world position to place it var worldPos = camera.ToWorld(screenPos); return PlaceMapGrhAtWorldPos(map, worldPos, useTileMode, gd); }
/// <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"); }
/// <summary> /// Creates a Grh. /// </summary> /// <param name="grhData">GrhData to create from.</param> /// <param name="anim">Animation type.</param> /// <param name="currentTime">Current time.</param> public Grh(GrhData grhData, AnimType anim, TickCount currentTime) { SetGrh(grhData, anim, currentTime); }
/// <summary> /// Initializes a new instance of the <see cref="Grh"/> class. /// </summary> /// <param name="grhData">GrhData to create from.</param> public Grh(GrhData grhData) { SetGrh(grhData); }
/// <summary> /// Returns a <see cref="System.String"/> that represents this instance. /// </summary> /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> public override string ToString() { return("Grh: " + (GrhData != null ? GrhData.ToString() : "(No GrhData loaded)")); }
/// <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; }
/// <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); }
/// <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(); }
/// <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); }
/// <summary> /// Initializes a new instance of the <see cref="GrhTreeNodeMouseClickEventArgs"/> class. /// </summary> /// <param name="grhData">The <see cref="GrhData"/>.</param> /// <param name="args">The <see cref="System.Windows.Forms.TreeNodeMouseClickEventArgs"/> instance containing the event data.</param> public GrhTreeNodeMouseClickEventArgs(GrhData grhData, TreeNodeMouseClickEventArgs args) : base(args.Node, args.Button, args.Clicks, args.X, args.Y) { _grhData = grhData; }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Exception"/> class. /// </summary> /// <param name="grhData">The <see cref="GrhData"/> related to the <see cref="Exception"/>.</param> public GrhDataException(GrhData grhData) : base(GetStr(grhData, null)) { }
/// <summary> /// Deletes a <see cref="GrhData"/>. /// </summary> /// <param name="grhData"><see cref="GrhData"/> to delete.</param> /// <exception cref="ArgumentNullException"><paramref name="grhData" /> is <c>null</c>.</exception> public static void Delete(GrhData grhData) { if (grhData == null) { throw new ArgumentNullException("grhData"); } var grhIndex = grhData.GrhIndex; if (grhIndex.IsInvalid) { return; } // Insure the index is valid if (!_grhDatas.CanGet((int)grhIndex)) { const string errmsg = "Attempted to delete GrhData `{0}`, but GrhIndex `{1}` could not be acquired."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, grhData, grhIndex); } Debug.Fail(string.Format(errmsg, grhData, grhIndex)); return; } // Make sure we are deleting the correct GrhData var i = (int)grhIndex; if (_grhDatas[i] != grhData) { const string errmsg = "Attempted to delete GrhData `{0}`, but GrhIndex `{1}` is already in use by" + " a different GrhData `{2}`. Most likely, the GrhData we tried to delete is already deleted, and" + " the GrhIndex has been recycled to a new GrhData. Stop trying to delete dead stuff, will ya!?"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, grhData, grhIndex, _grhDatas[i]); } Debug.Fail(string.Format(errmsg, grhData, grhIndex, _grhDatas[i])); return; } // Remove the GrhData from the collection _grhDatas.RemoveAt((int)grhIndex); // If a stationary GrhData and auto-size is set, delete the texture, too try { var sgd = grhData as StationaryGrhData; if (sgd != null && sgd.AutomaticSize) { // Make sure no other GrhData is using the texture var origTexture = sgd.GetOriginalTexture(); if (GrhDatas.OfType <StationaryGrhData>().All(x => origTexture != x.GetOriginalTexture())) { // Dispose of the texture then recycle the file origTexture.Dispose(); try { sgd.TextureName.RecycleFile(); } catch { } } } } catch (Exception ex) { const string errmsg = "Failed to recycle texture file for GrhData `{0}`. Exception: {1}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, grhData, ex); } Debug.Fail(string.Format(errmsg, grhData, ex)); } }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Exception"/> class with a specified error /// message and a reference to the inner exception that is the cause of this exception. /// </summary> /// <param name="grhData">The <see cref="GrhData"/> related to the <see cref="Exception"/>.</param> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception, /// or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> public GrhDataException(GrhData grhData, string message, Exception innerException) : base(GetStr(grhData, message), innerException) { }
public GrhTreeViewEditGrhDataEventArgs(TreeNode node, GrhData grhData, bool deleteOnCancel) { _node = node; _grhData = grhData; _deleteOnCancel = deleteOnCancel; }
/// <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"); }
/// <summary> /// Creates a Grh. /// </summary> /// <param name="grhData">GrhData to create from.</param> /// <param name="anim">Animation type.</param> /// <param name="currentTime">Current time.</param> public Grh(GrhData grhData, AnimType anim, TickCount currentTime) { SetGrh(grhData, anim, currentTime); }
/// <summary> /// Handles when a <see cref="GrhData"/> is removed or a new <see cref="GrhData"/> is added, and deletes /// the walls for it. /// </summary> /// <param name="sender">The <see cref="GrhData"/> that the event is related to.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void DeleteGrhDataWalls(GrhData sender, EventArgs e) { RemoveWalls(sender); }
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(); }
public List<WallEntityBase> this[GrhData gd] { get { return this[gd.GrhIndex]; } set { this[gd.GrhIndex] = value; } }
/// <summary> /// Updates all of the automaticly added GrhDatas. /// </summary> /// <param name="cm"><see cref="IContentManager"/> to use for new GrhDatas.</param> /// <param name="rootGrhDir">Root Grh texture directory.</param> /// <param name="added">The GrhDatas that were added (empty if none were added).</param> /// <param name="deleted">The GrhDatas that were deleted (empty if none were added).</param> /// <param name="grhDataFileTags">The file tags for the corresponding GrhDatas.</param> /// <returns> /// IEnumerable of all of the new GrhDatas created. /// </returns> public static void Update(IContentManager cm, string rootGrhDir, out GrhData[] added, out GrhData[] deleted, out Dictionary<GrhData, GrhData.FileTags> grhDataFileTags) { if (!rootGrhDir.EndsWith("\\") && !rootGrhDir.EndsWith("/")) rootGrhDir += "/"; // Clear the temporary content to make sure we have plenty of working memory cm.Unload(ContentLevel.Temporary, true); // Get the relative file path for all files up-front (only do this once since it doesn't scale well) var relFilePaths = Directory.GetFiles(rootGrhDir, "*", SearchOption.AllDirectories) .Select(x => x.Replace('\\', '/').Substring(rootGrhDir.Length)) .ToArray(); // Also grab the existing GrhDatas var existingGrhDatas = GrhInfo.GrhDatas.ToDictionary(x => x.Categorization.ToString(), x => x); // Go through each file and do the adds grhDataFileTags = new Dictionary<GrhData, GrhData.FileTags>(); HashSet<GrhData> addedGrhDatas = new HashSet<GrhData>(); HashSet<GrhData> deletedGrhDatas = new HashSet<GrhData>(); HashSet<GrhData> grhDatasToDelete = new HashSet<GrhData>(existingGrhDatas.Values); HashSet<string> checkedAnimationRelDirs = new HashSet<string>(StringComparer.OrdinalIgnoreCase); foreach (var relFilePath in relFilePaths) { // Before doing anything else, ensure it is a valid file type to handle string fileExtension = Path.GetExtension(relFilePath); if (!_graphicFileSuffixes.Contains(fileExtension, StringComparer.OrdinalIgnoreCase)) continue; string absFilePath = rootGrhDir + relFilePath; // Grab some stuff based on the file path string absDir = Path.GetDirectoryName(absFilePath); if (rootGrhDir.Length >= absDir.Length) continue; string relDir = absDir.Substring(rootGrhDir.Length); string parentDirName = absDir.Substring(Path.GetDirectoryName(absDir).Length + 1); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(relFilePath); bool isAnimationFrame = parentDirName.StartsWith("_"); if (!isAnimationFrame) { // ** Stationary ** var fileTags = GrhData.FileTags.Create(fileNameWithoutExtension); // Build the categorization info string category = relDir.Replace("/", SpriteCategorization.Delimiter).Replace("\\", SpriteCategorization.Delimiter); SpriteCategorization cat = new SpriteCategorization(category, fileTags.Title); // Get existing GrhIndex? grhIndex = null; GrhData grhData; if (existingGrhDatas.TryGetValue(cat.ToString(), out grhData)) { grhDatasToDelete.Remove(grhData); } // If already exists as animated, delete first if (grhData != null && (grhData is AnimatedGrhData || grhData is AutomaticAnimatedGrhData)) { grhIndex = grhData.GrhIndex; // We will re-use this GrhIndex GrhInfo.Delete(grhData); deletedGrhDatas.Add(grhData); grhData = null; } // Add new string texturePath = "/" + relFilePath.Substring(0, relFilePath.Length - Path.GetExtension(absFilePath).Length); if (grhData == null) { grhData = GrhInfo.CreateGrhData(cm, cat, texturePath, grhIndex); addedGrhDatas.Add(grhData); } else { // Make sure the texture is correct string currTextureName = "/" + ((StationaryGrhData)grhData).TextureName.ToString().TrimStart('/', '\\'); if (currTextureName != texturePath) { ((StationaryGrhData)grhData).ChangeTexture(texturePath); } } // Ensure set to auto-size StationaryGrhData stationaryGrhData = (StationaryGrhData)grhData; if (!stationaryGrhData.AutomaticSize) { stationaryGrhData.AutomaticSize = true; } // Add to GrhDataFileTags if (grhDataFileTags.ContainsKey(grhData)) { throw new GrhDataException(grhData, string.Format("Found more than one stationary GrhData with the categorization: `{0}`." + " Make sure that you do not have multiple image files in /DevContent/ in the same folder with the same name but different extensions (e.g. Sprite.png and Sprite.jpg).", grhData.Categorization)); } grhDataFileTags.Add(grhData, fileTags); } else { // ** Animated ** // Make sure we only handle each animation once (since this will get called for each frame since we're looping over the files) if (!checkedAnimationRelDirs.Add(relDir)) continue; var fileTags = GrhData.FileTags.Create(parentDirName.Substring(1)); // Remove the _ prefix from directory name // Build the categorization string category = Path.GetDirectoryName(absDir).Substring(rootGrhDir.Length) .Replace("/", SpriteCategorization.Delimiter).Replace("\\", SpriteCategorization.Delimiter); SpriteCategorization cat = new SpriteCategorization(category, fileTags.Title); // Get existing GrhIndex? grhIndex = null; GrhData grhData; if (existingGrhDatas.TryGetValue(cat.ToString(), out grhData)) { grhDatasToDelete.Remove(grhData); // If already exists as stationary, delete first if (grhData is StationaryGrhData) { grhIndex = grhData.GrhIndex; // We will re-use this GrhIndex GrhInfo.Delete(grhData); deletedGrhDatas.Add(grhData); grhData = null; } } // Add new if (grhData == null) { grhData = GrhInfo.CreateAutomaticAnimatedGrhData(cm, cat, grhIndex); addedGrhDatas.Add(grhData); } // Add to GrhDataFileTags if (grhDataFileTags.ContainsKey(grhData)) { throw new GrhDataException(grhData, string.Format("Found more than one animated GrhData with the categorization: `{0}`." + " Make sure that you do not have multiple sub-folders in /DevContent/ in the same folder with the same name but different folder tags (e.g. /_Sprite[s100]/ and /_Sprite[s200]/).", grhData.Categorization)); } grhDataFileTags.Add(grhData, fileTags); } } // Now check if there are any GrhDatas to be deleted by taking existing GrhDatas, getting their relative path, and // see if that exists in our relative path list we built earlier against the file system foreach (var toDelete in grhDatasToDelete) { GrhInfo.Delete(toDelete); deletedGrhDatas.Add(toDelete); } if (log.IsInfoEnabled) log.WarnFormat("Automatic GrhData creation update resulted in `{0}` new GrhData(s) and `{1}` deleted GrhData(s).", addedGrhDatas.Count, deletedGrhDatas.Count); added = addedGrhDatas.ToArray(); deleted = deletedGrhDatas.ToArray(); }
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; }
/// <summary> /// Initializes a new instance of the <see cref="GrhTreeViewCancelEventArgs"/> class. /// </summary> /// <param name="grhData">The <see cref="GrhData"/>.</param> /// <param name="args">The <see cref="System.Windows.Forms.TreeViewCancelEventArgs"/> instance containing the event data.</param> public GrhTreeViewCancelEventArgs(GrhData grhData, TreeViewCancelEventArgs args) : base(args.Node, args.Cancel, args.Action) { _grhData = grhData; }
/// <summary> /// Sets the Grh to a new index. /// </summary> /// <param name="grhData">New GrhData to use for the Grh.</param> /// <param name="anim">Type of animation.</param> /// <param name="currentTime">Current time.</param> public void SetGrh(GrhData grhData, AnimType anim, TickCount currentTime) { _grhData = grhData; _frame = 0; _anim = anim; _lastUpdated = currentTime; }
/// <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); }
/// <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 DefaultContentLevelDecider(GrhData grhData) { return(ContentLevel.Map); }
/// <summary> /// Sets the Grh to a new index. /// </summary> /// <param name="grhData">New GrhData to use for the stationary Grh.</param> public void SetGrh(GrhData grhData) { if (GrhData == grhData) return; SetGrh(grhData, AnimType, LastUpdated); }
/// <summary> /// Initializes a new instance of the <see cref="Grh"/> class. /// </summary> /// <param name="grhData">GrhData to create from.</param> public Grh(GrhData grhData) { SetGrh(grhData); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Exception"/> class with a specified error /// message and a reference to the inner exception that is the cause of this exception. /// </summary> /// <param name="grhData">The <see cref="GrhData"/> related to the <see cref="Exception"/>.</param> /// <param name="message">The error message that explains the reason for the exception.</param> /// <param name="innerException">The exception that is the cause of the current exception, /// or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param> public GrhDataException(GrhData grhData, string message, Exception innerException) : base(GetStr(grhData, message), innerException) { }