[Rpgworldmodel-commits] SF.net SVN: rpgworldmodel: [13] doc
Status: Inactive
Brought to you by:
deadwood_pl
From: <dea...@us...> - 2006-07-09 14:48:35
|
Revision: 13 Author: deadwood_pl Date: 2006-07-09 07:48:10 -0700 (Sun, 09 Jul 2006) ViewCVS: http://svn.sourceforge.net/rpgworldmodel/?rev=13&view=rev Log Message: ----------- Basic work on IEquip implementation. Needed: how to bind equipment location with equipment slot. Modified Paths: -------------- doc/RPGWorldModel_model.zuml src/RPGWorldModel.Abstracts/AnimatedEntity.cs src/RPGWorldModel.Abstracts/Golbin.cs src/RPGWorldModel.Abstracts/Human.cs src/RPGWorldModel.Abstracts/Humanoid.cs src/RPGWorldModel.Abstracts/IEquip.cs src/test_applications/tester/Form1.Designer.cs src/test_applications/tester/Form1.cs Modified: doc/RPGWorldModel_model.zuml =================================================================== (Binary files differ) Modified: src/RPGWorldModel.Abstracts/AnimatedEntity.cs =================================================================== --- src/RPGWorldModel.Abstracts/AnimatedEntity.cs 2006-07-06 16:26:23 UTC (rev 12) +++ src/RPGWorldModel.Abstracts/AnimatedEntity.cs 2006-07-09 14:48:10 UTC (rev 13) @@ -15,9 +15,9 @@ protected EquipmentSlotList equipmentSlots = new EquipmentSlotList(); - public virtual EquipmentSlotList.Enumerator AvailableEquipmentSlots + public virtual IEnumerable<EquipmentSlot> AvailableEquipmentSlots { - get { return equipmentSlots.GetEnumerator(); } + get { return equipmentSlots; } } public abstract EquipResponse Equip(EquipRequest request); Modified: src/RPGWorldModel.Abstracts/Golbin.cs =================================================================== --- src/RPGWorldModel.Abstracts/Golbin.cs 2006-07-06 16:26:23 UTC (rev 12) +++ src/RPGWorldModel.Abstracts/Golbin.cs 2006-07-09 14:48:10 UTC (rev 13) @@ -38,13 +38,6 @@ randomizeMaxHealthPoints(); } - public override EquipResponse Equip(EquipRequest request) - { - EquipResponse response = new EquipResponse(); - response.Status = EquipStatus.Undefined; - return response; - } - #endregion Modified: src/RPGWorldModel.Abstracts/Human.cs =================================================================== --- src/RPGWorldModel.Abstracts/Human.cs 2006-07-06 16:26:23 UTC (rev 12) +++ src/RPGWorldModel.Abstracts/Human.cs 2006-07-09 14:48:10 UTC (rev 13) @@ -38,13 +38,6 @@ randomizeMaxHealthPoints(); } - public override EquipResponse Equip(EquipRequest request) - { - EquipResponse response = new EquipResponse(); - response.Status = EquipStatus.Undefined; - return response; - } - #endregion } } Modified: src/RPGWorldModel.Abstracts/Humanoid.cs =================================================================== --- src/RPGWorldModel.Abstracts/Humanoid.cs 2006-07-06 16:26:23 UTC (rev 12) +++ src/RPGWorldModel.Abstracts/Humanoid.cs 2006-07-09 14:48:10 UTC (rev 13) @@ -40,6 +40,20 @@ } #endregion + + + public override EquipResponse Equip(EquipRequest request) + { + // Basic equip implementation for humanoids + + // TEMP!!!!! + equipmentSlots[8].AddEquipable(request.RequestedEquipable); + + EquipResponse response = new EquipResponse(); + response.Status = EquipStatus.Equipped; + return response; + } + } public abstract class HumanoidAdvanced : Humanoid Modified: src/RPGWorldModel.Abstracts/IEquip.cs =================================================================== --- src/RPGWorldModel.Abstracts/IEquip.cs 2006-07-06 16:26:23 UTC (rev 12) +++ src/RPGWorldModel.Abstracts/IEquip.cs 2006-07-09 14:48:10 UTC (rev 13) @@ -6,7 +6,7 @@ { public interface IEquip { - EquipmentSlotList.Enumerator AvailableEquipmentSlots + IEnumerable<EquipmentSlot> AvailableEquipmentSlots { get; } @@ -20,11 +20,11 @@ public class EquipRequest { - private IEquipable requestEntity = null; - public IEquipable RequestEntity + private IEquipable requestedEquipable = null; + public IEquipable RequestedEquipable { - get { return requestEntity; } - set { requestEntity = value; } + get { return requestedEquipable; } + set { requestedEquipable = value; } } } @@ -35,20 +35,25 @@ public abstract class EquipmentSlot { protected EquipableList equippedEntities = new EquipableList(); - EquipableList.Enumerator EquippedEntities + public IEnumerable<IEquipable> EquippedEntities { - get { return equippedEntities.GetEnumerator(); } + get { return equippedEntities; } } - public void Add(IEquipable equipable) + public void AddEquipable(IEquipable equipable) { equippedEntities.Add(equipable); } - public void Remove(IEquipable equipable) + public void RemoveEquipable(IEquipable equipable) { equippedEntities.Remove(equipable); } + + public abstract string SlotName + { + get; + } } public class EquipmentSlotList : List<EquipmentSlot> @@ -57,58 +62,114 @@ public class EquipmentSlotHead : EquipmentSlot { + public override string SlotName + { + get { return "Head"; } + } } public class EquipmentSlotFace : EquipmentSlot { + public override string SlotName + { + get { return "Face"; } + } } public class EquipmentSlotNeck : EquipmentSlot { + public override string SlotName + { + get { return "Neck"; } + } } public class EquipmentSlotTorso : EquipmentSlot { + public override string SlotName + { + get { return "Torso"; } + } } public class EquipmentSlotWaist : EquipmentSlot { + public override string SlotName + { + get { return "Waist"; } + } } public class EquipmentSlotBack : EquipmentSlot { + public override string SlotName + { + get { return "Back"; } + } } public class EquipmentSlotLeftArm : EquipmentSlot { + public override string SlotName + { + get { return "Left Arm"; } + } } public class EquipmentSlotRightArm : EquipmentSlot { + public override string SlotName + { + get { return "Right Arm"; } + } } public class EquipmentSlotLeftHand : EquipmentSlot { + public override string SlotName + { + get { return "Left Hand"; } + } } public class EquipmentSlotRightHand : EquipmentSlot { + public override string SlotName + { + get { return "Right Hand"; } + } } public class EquipmentSlotLeftLeg : EquipmentSlot { + public override string SlotName + { + get { return "Left Leg"; } + } } public class EquipmentSlotRightLeg : EquipmentSlot { + public override string SlotName + { + get { return "Right Leg"; } + } } public class EquipmentSlotLeftFoot : EquipmentSlot { + public override string SlotName + { + get { return "Left Foot"; } + } } public class EquipmentSlotRightFoot : EquipmentSlot { + public override string SlotName + { + get { return "Right Foot"; } + } } /* Modified: src/test_applications/tester/Form1.Designer.cs =================================================================== --- src/test_applications/tester/Form1.Designer.cs 2006-07-06 16:26:23 UTC (rev 12) +++ src/test_applications/tester/Form1.Designer.cs 2006-07-09 14:48:10 UTC (rev 13) @@ -47,6 +47,7 @@ this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage(); + this.tbInflictedPhysicalDamage = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.tbItemName = new System.Windows.Forms.TextBox(); this.tbItemMaxDurability = new System.Windows.Forms.TextBox(); @@ -58,11 +59,18 @@ this.btnItemRapair = new System.Windows.Forms.Button(); this.btnItemDamage = new System.Windows.Forms.Button(); this.tabPage3 = new System.Windows.Forms.TabPage(); + this.btnEquipaSelected = new System.Windows.Forms.Button(); + this.lvAvailableItems = new System.Windows.Forms.ListView(); + this.tvEquipmentSlots = new System.Windows.Forms.TreeView(); + this.btnHumanCreate = new System.Windows.Forms.Button(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); this.errorProvider1 = new System.Windows.Forms.ErrorProvider(this.components); - this.tbInflictedPhysicalDamage = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); this.tabControl1.SuspendLayout(); this.tabPage1.SuspendLayout(); this.tabPage2.SuspendLayout(); + this.tabPage3.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).BeginInit(); this.SuspendLayout(); // @@ -187,13 +195,16 @@ // // tabControl1 // + this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.tabControl1.Controls.Add(this.tabPage1); this.tabControl1.Controls.Add(this.tabPage2); this.tabControl1.Controls.Add(this.tabPage3); this.tabControl1.Location = new System.Drawing.Point(12, 12); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(457, 334); + this.tabControl1.Size = new System.Drawing.Size(652, 394); this.tabControl1.TabIndex = 15; // // tabPage1 @@ -216,7 +227,7 @@ this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); - this.tabPage1.Size = new System.Drawing.Size(449, 308); + this.tabPage1.Size = new System.Drawing.Size(644, 368); this.tabPage1.TabIndex = 0; this.tabPage1.Text = "AnimatedEntities"; this.tabPage1.UseVisualStyleBackColor = true; @@ -237,11 +248,18 @@ this.tabPage2.Location = new System.Drawing.Point(4, 22); this.tabPage2.Name = "tabPage2"; this.tabPage2.Padding = new System.Windows.Forms.Padding(3); - this.tabPage2.Size = new System.Drawing.Size(449, 308); + this.tabPage2.Size = new System.Drawing.Size(644, 368); this.tabPage2.TabIndex = 1; this.tabPage2.Text = "Items"; this.tabPage2.UseVisualStyleBackColor = true; // + // tbInflictedPhysicalDamage + // + this.tbInflictedPhysicalDamage.Location = new System.Drawing.Point(332, 74); + this.tbInflictedPhysicalDamage.Name = "tbInflictedPhysicalDamage"; + this.tbInflictedPhysicalDamage.Size = new System.Drawing.Size(100, 20); + this.tbInflictedPhysicalDamage.TabIndex = 25; + // // label3 // this.label3.AutoSize = true; @@ -325,29 +343,86 @@ // // tabPage3 // + this.tabPage3.Controls.Add(this.label4); + this.tabPage3.Controls.Add(this.btnEquipaSelected); + this.tabPage3.Controls.Add(this.lvAvailableItems); + this.tabPage3.Controls.Add(this.tvEquipmentSlots); + this.tabPage3.Controls.Add(this.btnHumanCreate); + this.tabPage3.Controls.Add(this.pictureBox1); this.tabPage3.Location = new System.Drawing.Point(4, 22); this.tabPage3.Name = "tabPage3"; - this.tabPage3.Size = new System.Drawing.Size(449, 308); + this.tabPage3.Size = new System.Drawing.Size(644, 368); this.tabPage3.TabIndex = 2; this.tabPage3.Text = "Equip"; this.tabPage3.UseVisualStyleBackColor = true; // + // btnEquipaSelected + // + this.btnEquipaSelected.Location = new System.Drawing.Point(319, 342); + this.btnEquipaSelected.Name = "btnEquipaSelected"; + this.btnEquipaSelected.Size = new System.Drawing.Size(75, 23); + this.btnEquipaSelected.TabIndex = 4; + this.btnEquipaSelected.Text = "Equip"; + this.btnEquipaSelected.UseVisualStyleBackColor = true; + this.btnEquipaSelected.Click += new System.EventHandler(this.btnEquipaSelected_Click); + // + // lvAvailableItems + // + this.lvAvailableItems.HideSelection = false; + this.lvAvailableItems.Location = new System.Drawing.Point(319, 176); + this.lvAvailableItems.Name = "lvAvailableItems"; + this.lvAvailableItems.Size = new System.Drawing.Size(322, 97); + this.lvAvailableItems.TabIndex = 3; + this.lvAvailableItems.UseCompatibleStateImageBehavior = false; + this.lvAvailableItems.View = System.Windows.Forms.View.List; + // + // tvEquipmentSlots + // + this.tvEquipmentSlots.HideSelection = false; + this.tvEquipmentSlots.Location = new System.Drawing.Point(319, 15); + this.tvEquipmentSlots.Name = "tvEquipmentSlots"; + this.tvEquipmentSlots.Size = new System.Drawing.Size(322, 155); + this.tvEquipmentSlots.TabIndex = 2; + this.tvEquipmentSlots.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvEquipmentSlots_AfterSelect); + // + // btnHumanCreate + // + this.btnHumanCreate.Location = new System.Drawing.Point(566, 342); + this.btnHumanCreate.Name = "btnHumanCreate"; + this.btnHumanCreate.Size = new System.Drawing.Size(75, 23); + this.btnHumanCreate.TabIndex = 1; + this.btnHumanCreate.Text = "Create"; + this.btnHumanCreate.UseVisualStyleBackColor = true; + this.btnHumanCreate.Click += new System.EventHandler(this.btnHumanCreate_Click); + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(13, 15); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(300, 300); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // // errorProvider1 // this.errorProvider1.ContainerControl = this; // - // tbInflictedPhysicalDamage + // label4 // - this.tbInflictedPhysicalDamage.Location = new System.Drawing.Point(332, 74); - this.tbInflictedPhysicalDamage.Name = "tbInflictedPhysicalDamage"; - this.tbInflictedPhysicalDamage.Size = new System.Drawing.Size(100, 20); - this.tbInflictedPhysicalDamage.TabIndex = 25; + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); + this.label4.Location = new System.Drawing.Point(320, 280); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(243, 13); + this.label4.TabIndex = 5; + this.label4.Text = "Select Left Hand, select item, click Equip"; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(481, 358); + this.ClientSize = new System.Drawing.Size(676, 418); this.Controls.Add(this.tabControl1); this.Name = "Form1"; this.Text = "Form1"; @@ -357,6 +432,9 @@ this.tabPage1.PerformLayout(); this.tabPage2.ResumeLayout(false); this.tabPage2.PerformLayout(); + this.tabPage3.ResumeLayout(false); + this.tabPage3.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).EndInit(); this.ResumeLayout(false); @@ -395,6 +473,12 @@ private System.Windows.Forms.Button btnItemRapair; private System.Windows.Forms.Button btnItemDamage; private System.Windows.Forms.TextBox tbInflictedPhysicalDamage; + private System.Windows.Forms.Button btnHumanCreate; + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.TreeView tvEquipmentSlots; + private System.Windows.Forms.ListView lvAvailableItems; + private System.Windows.Forms.Button btnEquipaSelected; + private System.Windows.Forms.Label label4; } } Modified: src/test_applications/tester/Form1.cs =================================================================== --- src/test_applications/tester/Form1.cs 2006-07-06 16:26:23 UTC (rev 12) +++ src/test_applications/tester/Form1.cs 2006-07-09 14:48:10 UTC (rev 13) @@ -25,10 +25,18 @@ { Random rand = new Random(); + // characters AnimatedEntity enemy = null; AnimatedEntity player = null; + + // item Item testItem = null; + // equip + Humanoid equipTest = null; + EquipmentSlot selectedSlot = null; + EquipableList availableEquipable = new EquipableList(); + public Form1() { InitializeComponent(); @@ -205,5 +213,278 @@ } } + + private void refreshEquipImage() + { + if (equipTest == null) + return; + + Bitmap bmp = new Bitmap(300, 300); + + Graphics g = Graphics.FromImage(bmp); + + g.DrawRectangle(Pens.Black, 0, 0, 299, 299); + + foreach (EquipmentSlot slot in equipTest.AvailableEquipmentSlots) + { + int x = 0, y = 0, w = 0, h = 0; + + if (slot is EquipmentSlotHead) + { + x = 80; y = 20; w = 40; h = 40; + } + + if (slot is EquipmentSlotFace) + { + x = 40; y = 25; w = 30; h = 30; + } + + if (slot is EquipmentSlotNeck) + { + x = 90; y = 65; w = 20; h = 20; + } + + if (slot is EquipmentSlotTorso) + { + x = 60; y = 90; w = 80; h = 80; + } + + if (slot is EquipmentSlotRightArm) + { + x = 35; y = 85; w = 20; h = 80; + } + + if (slot is EquipmentSlotLeftArm) + { + x = 145; y = 85; w = 20; h = 80; + } + + if (slot is EquipmentSlotRightHand) + { + x = 40; y = 170; w = 10; h = 30; + } + + if (slot is EquipmentSlotLeftHand) + { + x = 150; y = 170; w = 10; h = 30; + } + + + if (slot is EquipmentSlotWaist) + { + x = 60; y = 175; w = 80; h = 10; + } + + + if (slot is EquipmentSlotRightLeg) + { + x = 60; y = 190; w = 20; h = 80; + } + + if (slot is EquipmentSlotLeftLeg) + { + x = 120; y = 190; w = 20; h = 80; + } + + if (slot is EquipmentSlotRightFoot) + { + x = 60; y = 275; w = 20; h = 20; + } + + if (slot is EquipmentSlotLeftFoot) + { + x = 120; y = 275; w = 20; h = 20; + } + + if (slot is EquipmentSlotBack) + { + x = 190; y = 30; w = 60; h = 60; + } + + + if (slot == selectedSlot) + g.FillRectangle(Brushes.Black, x, y, w, h); + else + g.DrawRectangle(Pens.Black, x, y, w, h); + + foreach (IEquipable equipable in slot.EquippedEntities) + { + if (equipable is Sword) + { + g.FillRectangle(Brushes.Blue, x, y, 5, 100); + g.FillRectangle(Brushes.Blue, x - 10, y + 20, 25, 5); + + Point[] points = new Point[3]; + points[0].X = x; + points[0].Y = y + 100; + points[1].X = x + 2; + points[1].Y = y + 110; + points[2].X = x+5; + points[2].Y = y + 100; + g.FillPolygon(Brushes.Blue, points); + + } + } + } + + g.Dispose(); + + if (pictureBox1.Image != null) + pictureBox1.Image.Dispose(); + + pictureBox1.Image = bmp; + + } + + private void refreshEquipList() + { + if (equipTest == null) + return; + + tvEquipmentSlots.Nodes.Clear(); + TreeNode rootNode = tvEquipmentSlots.Nodes.Add("Slots"); + + foreach (EquipmentSlot slot in equipTest.AvailableEquipmentSlots) + { + rootNode.Nodes.Add(new EquipmentSlotTreeNode(slot)); + } + + tvEquipmentSlots.ExpandAll(); + } + + private void refreshAvailableItemsList() + { + lvAvailableItems.Clear(); + + foreach (IEquipable equipable in availableEquipable) + { + lvAvailableItems.Items.Add(new EquipableListViewItem(equipable)); + } + + } + + private void btnHumanCreate_Click(object sender, EventArgs e) + { + equipTest = new Human(); + equipTest.InitializeEntity(); + + IronShortSword sword = new IronShortSword(); + sword.InitializeEntity(); + + availableEquipable.Add(sword); + + refreshEquip(); + } + + private void refreshEquip() + { + // Drawing 'equipment slots' + refreshEquipImage(); + + refreshEquipList(); + + refreshAvailableItemsList(); + + } + + private void tvEquipmentSlots_AfterSelect(object sender, TreeViewEventArgs e) + { + EquipmentSlotTreeNode select = tvEquipmentSlots.SelectedNode as EquipmentSlotTreeNode; + + selectedSlot = null; + + if (select != null) + { + selectedSlot = select.Slot; + } + + refreshEquipImage(); + + } + + private void btnEquipaSelected_Click(object sender, EventArgs e) + { + if (lvAvailableItems.SelectedItems.Count != 1) + return; + + if (tvEquipmentSlots.SelectedNode == null) + return; + + if (equipTest == null) + return; + + IEquipable selectedEquipable = + (lvAvailableItems.SelectedItems[0] as EquipableListViewItem).Equipable; + + EquipmentSlot slot = + (tvEquipmentSlots.SelectedNode as EquipmentSlotTreeNode).Slot; + + EquipRequest request = new EquipRequest(); + request.RequestedEquipable = selectedEquipable; + + EquipResponse response = equipTest.Equip(request); + + if (response.Status == EquipStatus.Equipped) + availableEquipable.Remove(selectedEquipable); + + refreshEquip(); + } } + + public class EquipmentSlotTreeNode : TreeNode + { + private EquipmentSlot slot = null; + + public EquipmentSlot Slot + { + get { return slot; } + set { slot = value; } + } + + private EquipmentSlotTreeNode() + { + } + + public EquipmentSlotTreeNode(EquipmentSlot slot) + { + if (slot == null) + throw new ArgumentException("slot must not be null", "slot"); + + Slot = slot; + this.Text = slot.SlotName; + + foreach (IEquipable equipable in Slot.EquippedEntities) + this.Nodes.Add((equipable as INamedEntity).Name); + } + } + + public class EquipableListViewItem : ListViewItem + { + private IEquipable equipable = null; + + public IEquipable Equipable + { + get { return equipable; } + set { equipable = value; } + } + + private EquipableListViewItem() + { + } + + public EquipableListViewItem(IEquipable equipable) + { + if (equipable == null) + throw new ArgumentException("equipable must not be null", "equipable"); + + Equipable = equipable; + + if (Equipable is INamedEntity) + Text = (Equipable as INamedEntity).Name; + else + Text = "NOT NAMED"; + } + + } + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |