Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrhData"/> class.
 /// </summary>
 /// <param name="cat">The <see cref="SpriteCategorization"/>.</param>
 /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception>
 protected GrhData(SpriteCategorization cat)
 {
     // This is the only way we allow GrhDatas with an invalid GrhIndex. It should only ever be called for
     // GrhDatas that will NOT persist, such as the AutomaticAnimatedGrhData's frames.
     _categorization = cat;
     _grhIndex = GrhIndex.Invalid;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// When overridden in the derived class, notifies the owner of this object instance
 /// that an equipment slot has changed.
 /// </summary>
 /// <param name="slot">The slot that changed.</param>
 /// <param name="graphicIndex">The new graphic index of the slot.</param>
 protected override void SendSlotUpdate(EquipmentSlot slot, GrhIndex? graphicIndex)
 {
     using (var msg = ServerPacket.UpdateEquipmentSlot(slot, graphicIndex))
     {
         User.Send(msg, ServerMessageType.GUIItems);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SkeletonBodyItemInfo"/> class.
 /// </summary>
 /// <param name="grhIndex">The <see cref="GrhIndex"/> for the sprite to draw for the body item.</param>
 /// <param name="sourceName">Name of the source node.</param>
 /// <param name="destName">Name of the destination node (String.Empty for no destination).</param>
 /// <param name="offset">Grh drawing offset.</param>
 /// <param name="origin">Grh drawing origin.</param>
 public SkeletonBodyItemInfo(GrhIndex grhIndex, string sourceName, string destName, Vector2 offset, Vector2 origin)
 {
     GrhIndex = grhIndex;
     _sourceName = sourceName;
     _destName = destName;
     Offset = offset;
     Origin = origin;
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AnimatedGrhData"/> class.
        /// </summary>
        /// <param name="r">The <see cref="IValueReader"/>.</param>
        /// <param name="grhIndex">The <see cref="GrhIndex"/>.</param>
        /// <param name="cat">The <see cref="SpriteCategorization"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="grhIndex"/> is equal to GrhIndex.Invalid.</exception>
        AnimatedGrhData(IValueReader r, GrhIndex grhIndex, SpriteCategorization cat) : base(grhIndex, cat)
        {
            var speed = r.ReadInt(_speedValueKey);
            var frames = r.ReadMany(_framesNodeName, (xreader, xname) => xreader.ReadGrhIndex(xname));

            _speed = 1f / speed;
            _frames = CreateFrames(frames);
            _size = GetMaxSize(_frames);
        }
Ejemplo n.º 6
0
 public List<WallEntityBase> this[GrhIndex index]
 {
     get
     {
         if (!_walls.CanGet((int)index))
             return null;
         return _walls[(int)index];
     }
     set { _walls[(int)index] = value; }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StationaryGrhData"/> class.
        /// </summary>
        /// <param name="cm">The <see cref="IContentManager"/>.</param>
        /// <param name="grhIndex">The <see cref="GrhIndex"/>.</param>
        /// <param name="cat">The <see cref="SpriteCategorization"/>.</param>
        /// <param name="textureName">Name of the texture.</param>
        /// <param name="textureSource">The area of the texture to use, or null for the whole texture.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="grhIndex"/> is equal to GrhIndex.Invalid.</exception>
        public StationaryGrhData(IContentManager cm, GrhIndex grhIndex, SpriteCategorization cat, TextureAssetName textureName,
                                 Rectangle? textureSource) : base(grhIndex, cat)
        {
            _cm = cm;
            _textureName = textureName;

            if (textureSource == null)
                AutomaticSize = true;
            else
                SetSourceRect(textureSource.Value);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AutomaticAnimatedGrhData"/> class.
        /// </summary>
        /// <param name="cm">The <see cref="IContentManager"/> used for creating the frames.</param>
        /// <param name="grhIndex">The <see cref="GrhIndex"/>.</param>
        /// <param name="cat">The <see cref="SpriteCategorization"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="grhIndex"/> is equal to GrhIndex.Invalid.</exception>
        internal AutomaticAnimatedGrhData(IContentManager cm, GrhIndex grhIndex, SpriteCategorization cat) : base(grhIndex, cat)
        {
            var framesDir = GetFramesDirectory();
            if (framesDir == null)
                return;

            var animInfo = GetAutomaticAnimationInfo(framesDir);
            _speed = 1f / animInfo.Speed;

            Debug.Assert(animInfo.Title == cat.Title);

            _cm = cm;
            _frames = CreateFrames(framesDir);
        }
Ejemplo n.º 9
0
 public List<WallEntityBase> this[GrhIndex index]
 {
     get
     {
         List<WallEntityBase> ret;
         if (!_walls.TryGetValue(index, out ret))
             return null;
         return ret;
     }
     set 
     {
         _walls[index] = value;
     }
 }
Ejemplo 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 we were given an invalid default value, just use whatever the first valid one we can find is
            if (_selected == GrhIndex.Invalid)
            {
                var gd = GrhInfo.GrhDatas.FirstOrDefault();
                if (gd != null)
                    _selected = gd.GrhIndex;
            }

            // Load the GrhTreeView
            gtv.InitializeCompact();
            gtv.CollapseAll();
            gtv.SelectedNode = gtv.FindGrhDataNode(GrhInfo.GetData(_selected));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GrhData"/> class.
        /// </summary>
        /// <param name="grhIndex">The <see cref="GrhIndex"/>.</param>
        /// <param name="cat">The <see cref="SpriteCategorization"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="grhIndex"/> is equal to GrhIndex.Invalid.</exception>
        protected GrhData(GrhIndex grhIndex, SpriteCategorization cat)
        {
            if (cat == null)
                throw new ArgumentNullException("cat");

            if (grhIndex.IsInvalid)
            {
                const string errmsg =
                    "Failed to create GrhData with category `{0}`." +
                    " No GrhData may be created with a GrhIndex equal to GrhIndex.Invalid";
                var err = string.Format(errmsg, cat);
                log.Error(err);
                throw new ArgumentOutOfRangeException("grhIndex", err);
            }

            _categorization = cat;
            _grhIndex = grhIndex;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AutomaticAnimatedGrhData"/> class.
        /// </summary>
        /// <param name="cm">The <see cref="IContentManager"/> used for creating the frames.</param>
        /// <param name="grhIndex">The <see cref="GrhIndex"/>.</param>
        /// <param name="cat">The <see cref="SpriteCategorization"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="grhIndex"/> is equal to GrhIndex.Invalid.</exception>
        internal AutomaticAnimatedGrhData(IContentManager cm, GrhIndex grhIndex, SpriteCategorization cat) : base(grhIndex, cat)
        {
            _cm = cm;

            try
            {
                var framesDir = GetFramesDirectory();
                var framesDirName = Path.GetFileName(framesDir).Substring(1); // Get dir name only, and skip the _ at the start

                var fileTags = FileTags.Create(framesDirName);
                _speed = 1f / fileTags.AnimationSpeed.Value;

                Debug.Assert(fileTags.Title == cat.Title);

                _frames = CreateFrames(framesDir);
            }
            catch
            {
                _speed = 1f;
                _frames = new StationaryGrhData[0];
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GrhUITypeEditorForm"/> class.
        /// </summary>
        /// <param name="selected">The <see cref="GrhData"/> to select by default. Multiple values are supported.
        /// Can be null.</param>
        public GrhUITypeEditorForm(object selected)
        {
            if (selected == null)
                return;

            if (selected is GrhIndex)
            {
                var s = (GrhIndex)selected;
                _selected = s;
            }
            else if (selected is Grh)
            {
                var s = (Grh)selected;
                if (s.GrhData != null)
                    _selected = s.GrhData.GrhIndex;
            }
            else if (selected is GrhData)
            {
                var s = (GrhData)selected;
                _selected = s.GrhIndex;
            }

            InitializeComponent();
        }
Ejemplo n.º 14
0
 /// <summary>
 /// When overridden in the derived class, creates a new <see cref="GrhData"/> equal to this <see cref="GrhData"/>
 /// except for the specified parameters.
 /// </summary>
 /// <param name="newCategorization">The <see cref="SpriteCategorization"/> to give to the new
 /// <see cref="GrhData"/>.</param>
 /// <param name="newGrhIndex">The <see cref="GrhIndex"/> to give to the new
 /// <see cref="GrhData"/>.</param>
 /// <returns>
 /// A deep copy of this <see cref="GrhData"/>.
 /// </returns>
 protected override GrhData DeepCopy(SpriteCategorization newCategorization, GrhIndex newGrhIndex)
 {
     var copy = new StationaryGrhData(ContentManager, newGrhIndex, newCategorization, TextureName,
         AutomaticSize ? (Rectangle?)null : SourceRect);
     return copy;
 }
Ejemplo n.º 15
0
 protected override GrhData DeepCopy(SpriteCategorization newCategorization, GrhIndex newGrhIndex)
 {
     throw new NotSupportedException("Cannot make a copy of an AutomaticAnimatedGrhData.");
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Updates a slot in the Inventory
        /// </summary>
        /// <param name="slot">Slot to update</param>
        /// <param name="graphic">New graphic index</param>
        /// <param name="amount">New item amount</param>
        /// <param name="time">Current time</param>
        public void Update(InventorySlot slot, GrhIndex graphic, byte amount, TickCount time)
        {
            // If we get an amount of 0, just use UpdateEmpty()
            if (amount == 0)
            {
                UpdateEmpty(slot);
                return;
            }

            if (this[slot] == null)
            {
                // Add a new item
                this[slot] = new ItemEntity(graphic, amount, time);
            }
            else
            {
                // Update an existing item
                var item = this[slot];
                item.GraphicIndex = graphic;
                item.Amount = amount;
            }
        }
Ejemplo n.º 17
0
Archivo: Grh.cs Proyecto: Furt/netgore
 /// <summary>
 /// Sets the Grh to a new index.
 /// </summary>
 /// <param name="grhIndex">New Grh index to use for the stationary Grh.</param>
 public void SetGrh(GrhIndex grhIndex)
 {
     SetGrh(grhIndex, AnimType, LastUpdated);
 }
Ejemplo n.º 18
0
        void btnAccept_Click(object sender, EventArgs e)
        {
            var gdStationary = _gd as StationaryGrhData;
            var gdAnimated = _gd as AnimatedGrhData;

            // Validate the category and title, making sure its unique
            if (!ValidateCategorization(true))
                return;

            if (radioAnimated.Checked)
            {
                // Generate the frames
                var framesText = txtFrames.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                var frames = new GrhIndex[framesText.Length];
                for (var i = 0; i < framesText.Length; i++)
                {
                    // First check if it was entered as by the index
                    if (!Parser.Current.TryParse(framesText[i], out frames[i]))
                    {
                        // Support it being entered by category
                        var lastPeriod = framesText[i].LastIndexOf('.');
                        var category = framesText[i].Substring(0, lastPeriod);
                        var title = framesText[i].Substring(lastPeriod + 1);
                        var tempGD = GrhInfo.GetData(category, title);
                        if (tempGD != null)
                            frames[i] = tempGD.GrhIndex;
                    }
                }

                // Check that all the frames are valid
                foreach (var frame in frames)
                {
                    if (GrhInfo.GetData(frame) == null)
                    {
                        MessageBox.Show("GrhIndex [" + frame + "] does not exist! Aborting save...");
                        return;
                    }
                }
            }

            // Validate the strings
            GrhIndex newIndex;
            if (Parser.Current.TryParse(txtIndex.Text, out newIndex))
            {
                if (newIndex != _gd.GrhIndex)
                {
                    if (
                        MessageBox.Show("Are you sure you wish to change the index? Changes will not be reflected on maps!",
                            "Change GrhIndex", MessageBoxButtons.YesNo) == DialogResult.No)
                        return;

                    if (GrhInfo.GetData(newIndex) != null)
                    {
                        MessageBox.Show("Index already in use");
                        return;
                    }
                }
            }
            else
            {
                MessageBox.Show("Invalid index specified");
                return;
            }

            // Get the categorization
            var categorization = new SpriteCategorization(txtCategory.GetSanitizedText(), txtTitle.Text);

            // Set the information
            if (radioStationary.Checked)
            {
                if (gdStationary == null)
                {
                    MessageBox.Show("For some reason, could not cast the GrhData to StationaryGrhData...");
                    return;
                }

                // Stationary
                var cm = gdStationary.ContentManager;
                var x = Parser.Current.ParseInt(txtX.Text);
                var y = Parser.Current.ParseInt(txtY.Text);
                var w = Parser.Current.ParseInt(txtW.Text);
                var h = Parser.Current.ParseInt(txtH.Text);
                var textureName = txtTexture.GetSanitizedText();
                var autoSize = chkAutoSize.Checked;

                // Validate the texture
                try
                {
                    cm.LoadImage("Grh" + DirSep + textureName, ContentLevel.Map);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to load texture [" + textureName + "]! Aborting save..." + Environment.NewLine + ex);
                    return;
                }

                gdStationary.ChangeTexture(textureName, new Rectangle(x, y, w, h));
                _gd.SetCategorization(categorization);
                gdStationary.AutomaticSize = autoSize;
            }
            else
            {
                // Animated
                if (gdAnimated == null)
                {
                    MessageBox.Show("For some reason, could not cast the GrhData to AnimatedGrhData...");
                    return;
                }

                var speed = Parser.Current.ParseFloat(txtSpeed.Text);
                gdAnimated.SetSpeed(speed);
            }

            // Set the MapGrhWalls
            _mapGrhWalls[_gd] = BoundWalls.ToList();

            // Write
            Enabled = false;
            GrhInfo.Save(ContentPaths.Dev);
            Enabled = true;

            WasCanceled = false;

            DialogResult = DialogResult.OK;
        }
Ejemplo n.º 19
0
        public ItemEntity(GrhIndex graphicIndex, byte amount, TickCount currentTime) : base(Vector2.Zero, Vector2.Zero)
        {
            Amount = amount;

            _grh = new Grh(GrhInfo.GetData(graphicIndex), AnimType.Loop, currentTime);
        }
Ejemplo n.º 20
0
        public static void SetInventorySlot(PacketWriter pw, InventorySlot slot, GrhIndex graphic, byte amount)
        {
            pw.Write(ServerPacketID.SetInventorySlot);
            pw.Write(slot);

            if (graphic.IsInvalid)
                pw.Write(false);
            else
            {
                pw.Write(true);
                pw.Write(graphic);
            }

            pw.Write(amount);
        }
Ejemplo n.º 21
0
Archivo: Grh.cs Proyecto: Furt/netgore
        /// <summary>
        /// Sets the Grh to a new index.
        /// </summary>
        /// <param name="grhIndex">New Grh index to use.</param>
        /// <param name="anim">Type of animation.</param>
        /// <param name="currentTime">Current time.</param>
        public void SetGrh(GrhIndex grhIndex, AnimType anim, TickCount currentTime)
        {
            var grhData = GrhInfo.GetData(grhIndex);
            if (grhData == null && grhIndex != 0)
            {
                const string errmsg = "Failed to set Grh - GrhIndex `{0}` does not exist.";
                if (log.IsErrorEnabled)
                    log.ErrorFormat(errmsg, grhIndex);
                return;
            }

            SetGrh(grhData, anim, currentTime);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Gets the <see cref="Image"/> for the given argument.
 /// </summary>
 /// <param name="grhIndex">The <see cref="GrhIndex"/> to get the <see cref="Image"/> for.</param>
 /// <returns>The <see cref="Image"/> for the <paramref name="grhIndex"/>.</returns>
 public Image GetImage(GrhIndex grhIndex)
 {
     var gd = GrhInfo.GetData(grhIndex);
     return GetImage(gd);
 }
Ejemplo n.º 23
0
Archivo: Grh.cs Proyecto: Furt/netgore
 /// <summary>
 /// Initializes a new instance of the <see cref="Grh"/> class.
 /// </summary>
 /// <param name="grhIndex">Index of the stationary Grh.</param>
 public Grh(GrhIndex grhIndex)
 {
     SetGrh(grhIndex);
 }
Ejemplo n.º 24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ItemEntity"/> class.
        /// </summary>
        /// <param name="pos">The pos.</param>
        /// <param name="size">The size.</param>
        /// <param name="templateID">The template ID.</param>
        /// <param name="name">The name.</param>
        /// <param name="desc">The desc.</param>
        /// <param name="type">The type.</param>
        /// <param name="weaponType">Type of the weapon.</param>
        /// <param name="range">The range.</param>
        /// <param name="graphic">The graphic.</param>
        /// <param name="value">The value.</param>
        /// <param name="amount">The amount.</param>
        /// <param name="hp">The hp.</param>
        /// <param name="mp">The mp.</param>
        /// <param name="equippedBody">The equipped body.</param>
        /// <param name="actionDisplayID">The action display ID.</param>
        /// <param name="baseStats">The base stats.</param>
        /// <param name="reqStats">The req stats.</param>
        ItemEntity(Vector2 pos, Vector2 size, ItemTemplateID? templateID, string name, string desc, ItemType type,
                   WeaponType weaponType, ushort range, GrhIndex graphic, int value, byte amount, SPValueType hp, SPValueType mp,
                   string equippedBody, ActionDisplayID? actionDisplayID, IEnumerable<Stat<StatType>> baseStats,
                   IEnumerable<Stat<StatType>> reqStats) : base(pos, size)
        {
            _templateID = templateID;
            _name = name;
            _description = desc;
            _graphicIndex = graphic;
            _value = value;
            _amount = amount;
            _type = type;
            _weaponType = weaponType;
            _range = range;
            _hp = hp;
            _mp = mp;
            _equippedBody = equippedBody;
            _actionDisplayID = actionDisplayID;

            _baseStats = NewItemStats(baseStats, StatCollectionType.Base);
            _reqStats = NewItemStats(reqStats, StatCollectionType.Requirement);

            Resized += ItemEntity_Resized;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ItemEntity"/> class.
        /// </summary>
        /// <param name="iv">The item values.</param>
        public ItemEntity(IItemTable iv) : base(Vector2.Zero, new Vector2(iv.Width, iv.Height))
        {
            _id = iv.ID;
            _templateID = iv.ItemTemplateID;

            _name = iv.Name;
            _description = iv.Description;
            _graphicIndex = iv.Graphic;
            _value = iv.Value;
            _amount = iv.Amount;
            _type = iv.Type;
            _weaponType = iv.WeaponType;
            _range = iv.Range;
            _equippedBody = iv.EquippedBody;

            _baseStats = NewItemStats(iv.Stats.Select(x => (Stat<StatType>)x), StatCollectionType.Base);
            _reqStats = NewItemStats(iv.ReqStats.Select(x => (Stat<StatType>)x), StatCollectionType.Requirement);

            Resized += ItemEntity_Resized;
        }
Ejemplo n.º 26
0
 public static PacketWriter SetInventorySlot(InventorySlot slot, GrhIndex graphic, byte amount)
 {
     var pw = GetWriter();
     SetInventorySlot(pw, slot, graphic, amount);
     return pw;
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StationaryGrhData"/> class.
        /// </summary>
        /// <param name="r">The <see cref="IValueReader"/>.</param>
        /// <param name="cm">The <see cref="IContentManager"/>.</param>
        /// <param name="grhIndex">The <see cref="GrhIndex"/>.</param>
        /// <param name="cat">The <see cref="SpriteCategorization"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="cat"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="grhIndex"/> is equal to GrhIndex.Invalid.</exception>
        StationaryGrhData(IValueReader r, IContentManager cm, GrhIndex grhIndex, SpriteCategorization cat) : base(grhIndex, cat)
        {
            _cm = cm;

            var automaticSize = r.ReadBool(_automaticSizeValueKey);
            var textureReader = r.ReadNode(_textureNodeName);
            var textureName = textureReader.ReadTextureAssetName(_textureNameValueKey);
            var textureSource = textureReader.ReadRectangle(_textureSourceValueKey);

            _textureName = textureName;
            SetSourceRect(textureSource);
            _automaticSize = automaticSize;
        }
Ejemplo n.º 28
0
        public static PacketWriter UpdateEquipmentSlot(EquipmentSlot slot, GrhIndex? graphic)
        {
            var pw = GetWriter(ServerPacketID.UpdateEquipmentSlot);
            pw.WriteEnum(slot);
            pw.Write(graphic.HasValue);

            if (graphic.HasValue)
                pw.Write(graphic.Value);

            return pw;
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Asynchronously gets the <see cref="Image"/> for the given argument.
 /// </summary>
 /// <param name="grhIndex">The <see cref="GrhIndex"/> 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(GrhIndex grhIndex, GrhImageListAsyncCallback callback, object userState)
 {
     var gd = GrhInfo.GetData(grhIndex);
     GetImageAsync(gd, callback, userState);
 }
Ejemplo n.º 30
0
Archivo: Grh.cs Proyecto: Furt/netgore
 /// <summary>
 /// Initializes a new instance of the <see cref="Grh"/> class.
 /// </summary>
 /// <param name="grhIndex">Index of the Grh.</param>
 /// <param name="anim">Animation type.</param>
 /// <param name="currentTime">Current time.</param>
 public Grh(GrhIndex grhIndex, AnimType anim, TickCount currentTime)
 {
     SetGrh(grhIndex, anim, currentTime);
 }