Click here to Skip to main content
15,887,421 members
Articles / Game Development

Learning XNA 2D Engine IceCream With 1945 Demo Project

Rate me:
Please Sign up or sign in to vote.
5.00/5 (13 votes)
8 Aug 2012CPOL16 min read 66.6K   2.3K   51  
IceCream1945 is a demonstration of XNA and the IceCream 2D library in a 2D top-down scrolling shooter similar to 1942 for the NES.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IceCream;
using IceCream.Drawing;
using Milkshake.Editors;

namespace Milkshake.SelectorDialogs
{
    public partial class MaterialSelectorDialog : Form
    {
        #region Fields

        private Material _selectedMaterial;
        private bool _showLocalTextures = false;

        #endregion

        public bool ShowLocalTextures
        {
            get { return _showLocalTextures; }
            set { _showLocalTextures = value;  }
        }

        public Material SelectedMaterial
        {
            get { return _selectedMaterial; }
            set { _selectedMaterial = value; }
        } 

        public MaterialSelectorDialog()
        {
            InitializeComponent();            
        }

        private void TextureSelectorDialog_Load(object sender, EventArgs e)
        {
            MaterialEditor.LoadItemsInTreeView(treeViewMaterials, true, _showLocalTextures);
            SelectTextureNode();
        }

        private void SelectTextureNode()
        {
            /*
            TreeNode selectedNode = null;
            if (_selectedMaterial.TextureScope == TextureScope.Default)
            {
                selectedNode = treeViewTextures.Nodes[0];
            }
            else if (_selectedMaterial.TextureScope == TextureScope.Global)
            {
                foreach (TreeNode node in treeViewTextures.Nodes[1].Nodes)
                {
                    // if it's an untagged texture
                    if (node.ImageIndex == 1)
                    {
                        if (node.Text == _selectedMaterial.UID)
                        {
                            selectedNode = node;
                            break;
                        }
                    }
                    // check the tagged textures
                    else
                    {
                        foreach (TreeNode subNode in node.Nodes)
                        {
                            if (subNode.Text == _selectedMaterial.UID)
                            {
                                selectedNode = subNode;
                                break;
                            }
                        }
                    }
                }
                if (selectedNode == null)
                {
                    IceMaker.DisplayErrorMessage("the global texture with UID \"" + _selectedMaterial.UID + "\" wasn't found in the tree");
                }
            }
            else if (_selectedMaterial.TextureScope == TextureScope.Local)
            {
                if (_showLocalTextures == true)
                {
                    IceMaker.DisplayErrorMessage("The texture reference's scope is set to Local but the showLocalTextures option is set to false");
                }
                else
                {
                    foreach (TreeNode node in treeViewTextures.Nodes[2].Nodes)
                    {
                        // if it's an untagged texture
                        if (node.ImageIndex == 1)
                        {
                            if (node.Text == _selectedMaterial.UID)
                            {
                                selectedNode = node;
                                break;
                            }
                        }
                        // check the tagged textures
                        else
                        {
                            foreach (TreeNode subNode in node.Nodes)
                            {
                                if (subNode.Text == _selectedMaterial.UID)
                                {
                                    selectedNode = subNode;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (selectedNode == null)
                {
                    IceMaker.DisplayErrorMessage("the local texture with UID \"" + _selectedMaterial.UID + "\" wasn't found in the tree");
                }
            }
            // select the node
            treeViewTextures.SelectedNode = selectedNode;
            */
        }
        
        private void SelectTexture(Material material)
        {
            _selectedMaterial = material;
            materialPreviewControl.Texture = material.Texture;          
        }

        private void treeViewTextures_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // if it's a material
            if (e.Node.Tag is Material)
            {                
                SelectTexture(e.Node.Tag as Material);
            }
        }

        private void treeViewMaterials_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            // if it's a material
            if (e.Node.Tag is Material)
            {
                // direct close
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
    } 
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions