/// <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(); }
/// <summary> /// Draws the item in this slot. This method is always called, even when the slot is empty. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> /// <param name="itemSprite">The <see cref="Grh"/> to draw. Will never be null, but can contain /// an invalid or empty sprite.</param> protected virtual void DrawItem(ISpriteBatch spriteBatch, Grh itemSprite) { if (itemSprite.GrhData == null) { return; } // Grab the screen position and client size var sp = ScreenPosition; var cs = ClientSize; // Get the size to use for drawing (never exceeding the size of the control) var drawSize = Vector2.Min(cs, itemSprite.Size); // Get the draw position (centering on the control) var drawPos = sp + ((cs - drawSize) / 2f); // Draw var spriteDestRect = new Rectangle(drawPos.X, drawPos.Y, drawSize.X, drawSize.Y); _sprite.Draw(spriteBatch, spriteDestRect); // Draw the amount var itemInfo = GetSlotItemInfo(); if (itemInfo == null) { return; } var amount = ItemsCollection.PeerTradeForm.GetItemAmount(itemInfo); DrawItemAmount(spriteBatch, amount); }
/// <summary> /// Initializes a new instance of the <see cref="StatsForm"/> class. /// </summary> /// <param name="userInfo">The user info.</param> /// <param name="parent">The parent.</param> /// <exception cref="ArgumentNullException"><paramref name="userInfo" /> is <c>null</c>.</exception> public StatsForm(UserInfo userInfo, Control parent) : base(parent, Vector2.Zero, new Vector2(225, 275)) { if (userInfo == null) { throw new ArgumentNullException("userInfo"); } _addStatGrh = new Grh(GrhInfo.GetData("GUI", "AddStat")); _userInfo = userInfo; _yOffset = 2; NewUserInfoLabel("Level", x => x.Level.ToString()); NewUserInfoLabel("Exp", x => x.Exp.ToString()); NewUserInfoLabel("StatPoints", x => x.StatPoints.ToString()); AddLine(); NewUserInfoLabel("HP", x => x.HP + " / " + x.ModStats[StatType.MaxHP]); NewUserInfoLabel("MP", x => x.MP + " / " + x.ModStats[StatType.MaxMP]); AddLine(); NewStatLabel(StatType.MinHit); NewStatLabel(StatType.MaxHit); NewStatLabel(StatType.Defence); AddLine(); NewStatLabel(StatType.Str); NewStatLabel(StatType.Agi); NewStatLabel(StatType.Int); }
public ItemEntity(MapEntityIndex mapEntityIndex, Vector2 pos, Vector2 size, GrhIndex graphicIndex, TickCount currentTime) : base(pos, size) { Amount = 0; ((IDynamicEntitySetMapEntityIndex)this).SetMapEntityIndex(mapEntityIndex); _grh = new Grh(GrhInfo.GetData(graphicIndex), AnimType.Loop, currentTime); }
/// <summary> /// Initializes a new instance of the <see cref="MiniMapForm"/> class. /// </summary> /// <param name="parent">The parent.</param> /// <param name="screen">The game play screen.</param> public MiniMapForm(Control parent, GameplayScreen screen) : base(parent, new Vector2(50, 50), new Vector2(250, 250)) { _topLeftPos = new Vector2(this.Position.X + this.Border.LeftWidth, this.Position.Y + this.Border.TopHeight); _scaledMapGrh = new Grh(null); _entityCharGrh = new Grh(GrhInfo.GetData("GUI", "MiniMapCharacter")); _entityNPCGrh = new Grh(GrhInfo.GetData("GUI", "MiniMapNPC")); _gamePlayScreen = screen; }
/// <summary> /// Edits the specified object's value using the editor style indicated by the /// <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"/> method. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be /// used to gain additional context information.</param> /// <param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to /// obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the /// same object it was passed. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { var svc = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (svc != null) { using (var editorForm = new GrhUITypeEditorForm(value)) { var pt = context.PropertyDescriptor.PropertyType; if (svc.ShowDialog(editorForm) == DialogResult.OK) { var sel = editorForm.SelectedValue; // Handle setting the value based on the type we are working with if (pt == typeof(GrhIndex) || pt == typeof(GrhIndex?)) { value = sel; } else if (pt == typeof(Grh)) { var asGrh = value as Grh; if (asGrh != null) { asGrh.SetGrh(sel); } else { value = new Grh(sel, AnimType.Loop, 0); } } else if (pt == typeof(GrhData)) { value = GrhInfo.GetData(sel); } else { const string errmsg = "Don't know how to handle the source property type `{0}`. In value: {1}. Editor type: {2}"; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, pt, value, editorForm.GetType()); } Debug.Fail(string.Format(errmsg, pt, value, editorForm.GetType())); } } else { if (pt == typeof(GrhIndex?)) { value = null; } } } } return(value); }
/// <summary> /// Initializes a new instance of the <see cref="StatusEffectCollectionItem"/> class. /// </summary> /// <param name="statusEffectType">The <see cref="StatusEffectType"/> to use.</param> /// <param name="power">The power of the status effect.</param> /// <param name="disableTime">The game time at which this status effect will be disabled.</param> public StatusEffectCollectionItem(StatusEffectType statusEffectType, ushort power, int disableTime) { _statusEffectType = statusEffectType; _power = power; _disableTime = disableTime; _statusEffectInfo = StatusEffectInfoManager.Instance.GetAttribute(statusEffectType); _grh = new Grh(_statusEffectInfo.Icon); }
public SkillPictureBox(SkillsForm parent, SkillInfo <SkillType> skillInfo, Vector2 position) : base(parent, position, _iconSize) { _knownSkills = parent.KnownSkills; SkillInfo = skillInfo; Sprite = new Grh(GrhInfo.GetData(SkillInfo.Icon)); _cooldownManager = parent.CooldownManager; }
/// <summary> /// Gets the <see cref="Image"/> for the given argument. /// </summary> /// <param name="grh">The <see cref="Grh"/> to get the <see cref="Image"/> for.</param> /// <returns>The <see cref="Image"/> for the <paramref name="grh"/>.</returns> public Image GetImage(Grh grh) { if (grh == null) { return(_errorImage); } return(GetImage(grh.CurrentGrhData, false, null, null)); }
private void AddEntityGrh(ISpatial entity, Grh grh) { // Find the scaling value so we can position the entities correctly var scaleX = GamePlayScreen.Map.Size.X / ScaledMapGrh.Size.X; var scaleY = GamePlayScreen.Map.Size.Y / ScaledMapGrh.Size.Y; var scaledPos = new Vector2((entity.Position.X / scaleX) - grh.Size.X / 2, (entity.Position.Y / scaleY) - grh.Size.Y / 2); // Add the grh as well as the position _grhEntities.Add(new Tuple <Grh, Vector2>(new Grh(grh.GrhData), scaledPos)); }
/// <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> /// Asynchronously gets the <see cref="Image"/> for the given argument. /// </summary> /// <param name="grh">The <see cref="Grh"/> 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(Grh grh, GrhImageListAsyncCallback callback, object userState) { if (grh == null) { if (callback != null) { callback(this, null, ErrorImage, userState); } } else { GetImage(grh.CurrentGrhData, true, callback, userState); } }
/// <summary> /// When overridden in the derived class, initializes a <see cref="Grh"/> to display the information for an item. /// </summary> /// <param name="grh">The <see cref="Grh"/> to initialize (cannot be null).</param> /// <param name="itemInfo">The item information to be displayed. Can be null.</param> protected override void InitializeItemInfoSprite(Grh grh, IItemTable itemInfo) { if (itemInfo == null) { // Clear the sprite grh.SetGrh(null); } else { // Set the new sprite var newGD = GrhInfo.GetData(itemInfo.Graphic); grh.SetGrh(newGD); } }
public static void AD_Projectile(ActionDisplay actionDisplay, IMap map, Entity source, Entity target) { var drawableMap = map as IDrawableMap; var sourceAsCharacter = source as Character; // Play the sound PlaySoundSimple(actionDisplay, source); // Show the attack animation on the attacker if (sourceAsCharacter != null) { sourceAsCharacter.Attack(); } // Check if we can properly display the effect if (drawableMap != null && target != null && source != target) { // Show the graphic going from the attacker to attacked if (actionDisplay.GrhIndex != GrhIndex.Invalid) { var gd = GrhInfo.GetData(actionDisplay.GrhIndex); if (gd != null) { var grh = new Grh(gd, AnimType.Loop, TickCount.Now); var effect = new MapGrhEffectSeekPosition(grh, source.Center, target.Center, 750f) { MapRenderLayer = MapRenderLayer.SpriteForeground }; drawableMap.AddTemporaryMapEffect(effect); } } // Show the particle effect var pe = ParticleEffectManager.Instance.TryCreateEffect(actionDisplay.ParticleEffect); if (pe != null) { // Effect that just takes place on the target and dies very quickly pe.Position = target.Center; pe.Life = 100; var effect = new TemporaryMapParticleEffect(pe) { MapRenderLayer = MapRenderLayer.SpriteForeground }; drawableMap.AddTemporaryMapEffect(effect); } } }
void Map_GrhToPlaceChanged(object sender, EventArgs e) { try { Grh grh = GlobalState.Instance.Map.GrhToPlace; if (grh != null && grh.GrhData != null) { GrhTreeViewNode newNode = gtv.FindGrhDataNode(grh.GrhData); if (gtv.SelectedNode != newNode) { gtv.SelectedNode = newNode; } } } catch (Exception ex) { Debug.Fail(ex.ToString()); } }
/// <summary> /// Draws the <see cref="Control"/>. /// </summary> /// <param name="spriteBatch">The <see cref="ISpriteBatch"/> to draw to.</param> protected override void DrawControl(ISpriteBatch spriteBatch) { base.DrawControl(spriteBatch); var itemInfo = ItemInfo; if (itemInfo == null) { _grh = null; return; } if (_grh == null || _grh.GrhData.GrhIndex != itemInfo.Graphic) { try { _grh = new Grh(itemInfo.Graphic, AnimType.Loop, 0); } catch (Exception ex) { _grh = null; if (log.IsErrorEnabled) { log.ErrorFormat("Failed to load shop Grh with index `{0}`: `{1}`", itemInfo.Graphic, ex); } } } if (_grh == null) { return; } // Draw the item in the center of the slot var offset = (_itemSize - _grh.Size) / 2f; _grh.Draw(spriteBatch, ScreenPosition + offset); }
/// <summary> /// Handles initialization of the GameScreen. This will be invoked after the GameScreen has been /// completely and successfully added to the ScreenManager. It is highly recommended that you /// use this instead of the constructor. This is invoked only once. /// </summary> public override void Initialize() { base.Initialize(); PlayMusic = false; // Create the background sprite _background = new Grh(); var bgGrhData = GrhInfo.GetData("Background", "menu"); if (bgGrhData != null) { _background.SetGrh(bgGrhData); } else { const string errmsg = "Failed to find menu background image for screen `{0}` - background will not be drawn."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, this); } Debug.Fail(string.Format(errmsg, this)); } }
public static void AD_CastingSkill(ActionDisplay actionDisplay, IMap map, Entity source, Entity target) { // The maximum life the effects will have. This way, if the entity gets stuck with IsCastingSkill set to true, // the effects will at least go away eventually. Make sure that this is not greater than the longest possible // time to cast a skill. const int maxEffectLife = 1000 * 20; var drawableMap = map as IDrawableMap; var sourceAsCharacter = source as Character; var castingEffects = new List <ITemporaryMapEffect>(); // Make sure we have a valid source if (sourceAsCharacter == null) { const string errmsg = "AD_CastingSkill requires a Character as the source, but the source ({0}) is type `{1}`."; if (log.IsErrorEnabled) { log.ErrorFormat(errmsg, sourceAsCharacter, source.GetType()); } Debug.Fail(string.Format(errmsg, sourceAsCharacter, source.GetType())); return; } // Play the sound PlaySoundSimple(actionDisplay, source); // Check if we can properly display the effect if (drawableMap != null) { // Show the graphic going from the source to target if (actionDisplay.GrhIndex != GrhIndex.Invalid) { var gd = GrhInfo.GetData(actionDisplay.GrhIndex); if (gd != null) { // Make the effect loop indefinitely var grh = new Grh(gd, AnimType.Loop, TickCount.Now); var effect = new MapGrhEffectTimed(grh, source.Center, true, maxEffectLife); drawableMap.AddTemporaryMapEffect(effect); castingEffects.Add(effect); } } // Show the particle effect var pe = ParticleEffectManager.Instance.TryCreateEffect(actionDisplay.ParticleEffect); if (pe != null) { // Effect that just takes place on the caster pe.Position = source.Center; pe.Life = maxEffectLife; var effect = new TemporaryMapParticleEffect(pe, true); drawableMap.AddTemporaryMapEffect(effect); castingEffects.Add(effect); } } // Make sure we have at least one valid effect. If not, there is nothing more to do. if (castingEffects.Count <= 0) { return; } // Add the list of effects to our local dictionary lock (_activeCastingSkillEffectsSync) { // Make sure they don't already have effects in the dictionary RemoveFromActiveCastingSkillEffects(sourceAsCharacter); // Add to the dictionary _activeCastingSkillEffects.Add(sourceAsCharacter, castingEffects); } // Attach the listener for the IsCastingSkill sourceAsCharacter.IsCastingSkillChanged += AD_CastingSkill_Character_IsCastingSkillChanged; // If the source already finished casting the skill, destroy them now since we probably missed the event if (!sourceAsCharacter.IsCastingSkill) { RemoveFromActiveCastingSkillEffects(sourceAsCharacter); } }
/// <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> /// Gets the <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>. /// </summary> /// <param name="subCategory">The sprite sub-category under the skin.</param> /// <param name="spriteTitle">The title of the <see cref="ISprite"/> to get.</param> /// <returns>The <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>, /// or null if no <see cref="ISprite"/> could be created with the given categorization information.</returns> public ISprite GetSprite(SpriteCategory subCategory, SpriteTitle spriteTitle) { var key = string.Empty; if (subCategory != null && subCategory.ToString().Length > 0) { key += subCategory; } if (spriteTitle != null) { key += "." + spriteTitle; } // Check for the sprite in the cache ISprite sprite; if (_spriteCache.TryGetValue(key, out sprite)) { return(sprite); } // Check for the sprite in the current skin var fullSC = GetSpriteCategory(CurrentSkin, subCategory); var grhData = GrhInfo.GetData(fullSC, spriteTitle); // The sprite was not found in the current category, so check the default category only if the current category // is not the default category if (grhData == null && !IsCurrentSkinDefault) { fullSC = GetSpriteCategory(DefaultSkin, subCategory); grhData = GrhInfo.GetData(fullSC, spriteTitle); } // If the grhData is not null, create the sprite, otherwise have the sprite be null if (grhData == null) { sprite = null; } else { sprite = new Grh(grhData); } // Add the sprite to the cache, even if it is null try { if (sprite != null) { _spriteCache.Add(key, sprite); } } catch (ArgumentException ex) { const string errmsg = "Key `{0}` already exists. Multi-threading conflict? This should never happen, but its likely not critical. Exception: {1}"; if (log.IsWarnEnabled) { log.WarnFormat(errmsg, key, ex); } Debug.Fail(string.Format(errmsg, key, ex)); } // Return the sprite return(sprite); }
public static void AD_SkillCasted(ActionDisplay actionDisplay, IMap map, Entity source, Entity target) { var drawableMap = map as IDrawableMap; // Play the sound PlaySoundSimple(actionDisplay, source); // Check if we can properly display the effect if (drawableMap != null && source != null) { if (actionDisplay.GrhIndex != GrhIndex.Invalid) { if (target != null && target != source) { // Show the graphic going from the source to target var gd = GrhInfo.GetData(actionDisplay.GrhIndex); if (gd != null) { var grh = new Grh(gd, AnimType.Loop, TickCount.Now); var effect = new MapGrhEffectSeekPosition(grh, source.Center, true, target.Center, 750f); drawableMap.AddTemporaryMapEffect(effect); } } else { // Show the graphic at the source var gd = GrhInfo.GetData(actionDisplay.GrhIndex); if (gd != null) { var grh = new Grh(gd, AnimType.Loop, TickCount.Now); var effect = new MapGrhEffectLoopOnce(grh, source.Center, true); drawableMap.AddTemporaryMapEffect(effect); } } } // Show the particle effect var pe = ParticleEffectManager.Instance.TryCreateEffect(actionDisplay.ParticleEffect); if (pe != null) { pe.Position = source.Center; ITemporaryMapEffect effect; if (target != null && target != source) { // Effect that seeks out the position of the target effect = new TemporaryMapParticleEffectSeekPosition(pe, true, target.Center, 250f); } else { // Effect that takes place at the source effect = new TemporaryMapParticleEffect(pe, true); } // Add the effect to the map if (effect != null) { drawableMap.AddTemporaryMapEffect(effect); } } } }
/// <summary> /// When overridden in the derived class, initializes a <see cref="Grh"/> to display the information for an item. /// </summary> /// <param name="grh">The <see cref="Grh"/> to initialize (cannot be null).</param> /// <param name="itemInfo">The item information to be displayed. Can be null.</param> protected abstract void InitializeItemInfoSprite(Grh grh, TItemInfo itemInfo);
/// <summary> /// The default quest indicator drawer. /// </summary> /// <param name="grh">The <see cref="Grh"/> to draw.</param> /// <param name="c">The character the indicator is for.</param> /// <param name="sb">The <see cref="ISpriteBatch"/> to use to draw.</param> protected virtual void DefaultIndicatorDrawer(Grh grh, TCharacter c, ISpriteBatch sb) { var pos = new Vector2(c.Center.X, c.Position.Y) - new Vector2(grh.Size.X / 2f, grh.Size.Y + 12); grh.Draw(sb, pos); }
public ItemEntity() : base(Vector2.Zero, Vector2.Zero) { Amount = 1; _grh = new Grh(null); }
/// <summary> /// When overridden in the derived class, draws the graphics to the control. /// </summary> /// <param name="currentTime">The current time.</param> protected override void HandleDraw(TickCount currentTime) { base.HandleDraw(currentTime); if (DesignMode) { return; } if (_drawingManager.RenderWindow == null) { return; } if (Grh == null) { return; } Grh.Update(currentTime); m.Update(currentTime); _drawingManager.Update(currentTime); var sb = _drawingManager.BeginDrawWorld(_camera); if (sb == null) { return; } // Change the view var oldView = RenderWindow.GetView(); _drawView.Reset(new FloatRect(Camera.Min.X, Camera.Min.Y, Camera.Size.X, Camera.Size.Y)); RenderWindow.SetView(_drawView); try { try { Grh.Draw(sb, Vector2.Zero, Color.White); } catch (LoadingFailedException) { // A LoadingFailedException is generally fine here since it probably means the graphic file was invalid // or does not exist } // Draw the walls if (Walls != null) { foreach (var wall in Walls) { var rect = wall.ToRectangle(); RenderRectangle.Draw(sb, rect, _autoWallColor); } } m.Draw(sb, Camera); } finally { _drawingManager.EndDrawWorld(); // Restore the view RenderWindow.SetView(oldView); } }
public ItemEntity(GrhIndex graphicIndex, byte amount, TickCount currentTime) : base(Vector2.Zero, Vector2.Zero) { Amount = amount; _grh = new Grh(GrhInfo.GetData(graphicIndex), AnimType.Loop, currentTime); }
/// <summary> /// Gets the <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>. /// </summary> /// <param name="subCategory">The sprite sub-category under the skin.</param> /// <param name="spriteTitle">The title of the <see cref="ISprite"/> to get.</param> /// <returns>The <see cref="ISprite"/> for the skin with the given <see cref="SpriteTitle"/>, /// or null if no <see cref="ISprite"/> could be created with the given categorization information.</returns> public ISprite GetSprite(SpriteCategory subCategory, SpriteTitle spriteTitle) { var key = string.Empty; if (subCategory != null && subCategory.ToString().Length > 0) key += subCategory; if (spriteTitle != null) key += "." + spriteTitle; // Check for the sprite in the cache ISprite sprite; if (_spriteCache.TryGetValue(key, out sprite)) return sprite; // Check for the sprite in the current skin var fullSC = GetSpriteCategory(CurrentSkin, subCategory); var grhData = GrhInfo.GetData(fullSC, spriteTitle); // The sprite was not found in the current category, so check the default category only if the current category // is not the default category if (grhData == null && !IsCurrentSkinDefault) { fullSC = GetSpriteCategory(DefaultSkin, subCategory); grhData = GrhInfo.GetData(fullSC, spriteTitle); } // If the grhData is not null, create the sprite, otherwise have the sprite be null if (grhData == null) sprite = null; else sprite = new Grh(grhData); // Add the sprite to the cache, even if it is null try { if (sprite != null) _spriteCache.Add(key, sprite); } catch (ArgumentException ex) { const string errmsg = "Key `{0}` already exists. Multi-threading conflict? This should never happen, but its likely not critical. Exception: {1}"; if (log.IsWarnEnabled) log.WarnFormat(errmsg, key, ex); Debug.Fail(string.Format(errmsg, key, ex)); } // Return the sprite return sprite; }
/// <summary> /// When overridden in the derived class, draws the graphics to the control. /// </summary> /// <param name="currentTime">The current time.</param> protected override void HandleDraw(TickCount currentTime) { if (DesignMode) { base.HandleDraw(currentTime); return; } TransBoxManager.Update(currentTime); RenderWindow.Clear(Color.Black); // Update the cursor display for the transformation box. Only change the cursor if we are currently // under a transbox, or we have just stopped being under one. If we update it every frame, it screws with the // UI display for everything else (like when the cursor is over a textbox). var transBoxCursor = TransBoxManager.CurrentCursor; if (transBoxCursor == null) { if (_wasUnderTransBox) { Cursor = Cursors.Default; _wasUnderTransBox = false; } } else { Cursor = transBoxCursor; _wasUnderTransBox = true; } // TODO: Implement drawing logic // Do some actual work here _spriteBatch.Begin(BlendMode.Alpha, _camera); if (TilesetConfiguration != null) { int x = 0; int y = 0; for (int i = 0; i < TilesetConfiguration.GrhDatas.Count; i++) { var grh = TilesetConfiguration.GrhDatas[i]; Grh nGrh = new Grh(grh); nGrh.Draw(_spriteBatch, new Vector2(y * EditorSettings.Default.GridSize.X, x * EditorSettings.Default.GridSize.Y)); y++; if (y % TilesetConfiguration.Width == 0) { x++; y = 0; } } // Draw little selection box RenderRectangle.Draw(_spriteBatch, new Rectangle(grhX, grhY, EditorSettings.Default.GridSize.X, EditorSettings.Default.GridSize.Y), Color.TransparentWhite, Color.White, -3f); } _spriteBatch.End(); int deltaTime; if (_lastUpdateTime == TickCount.MinValue) { deltaTime = 30; } else { deltaTime = Math.Max(5, (int)(currentTime - _lastUpdateTime)); } _lastUpdateTime = currentTime; _camera.Min += _cameraVelocity * (deltaTime / 1000f); }