public void LoadProperties(xTile.ObjectModel.Component component)
        {
            m_dataGridView.Rows.Clear();

            m_newProperties.Clear();
            foreach (KeyValuePair <string, PropertyValue> keyValuePair
                     in component.Properties)
            {
                m_newProperties.Add(keyValuePair.Key, keyValuePair.Value);

                DataGridViewRow         row      = new DataGridViewRow();
                DataGridViewTextBoxCell nameCell = new DataGridViewTextBoxCell();
                nameCell.Value = keyValuePair.Key;
                DataGridViewTextBoxCell valueCell = new DataGridViewTextBoxCell();
                valueCell.Value = keyValuePair.Value.ToString();

                if (keyValuePair.Value.Type == typeof(float) ||
                    keyValuePair.Value.Type == typeof(int))
                {
                    valueCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
                }

                row.Cells.Add(nameCell);
                row.Cells.Add(valueCell);
                m_dataGridView.Rows.Add(row);
            }
        }
        private void DisplayCustomProperties(xTile.ObjectModel.Component component)
        {
            int oldIndent = m_textBoxStatistics.SelectionIndent;

            m_textBoxStatistics.SelectionFont = m_propertyNameFont;
            m_textBoxStatistics.AppendText("Custom Properties\t");

            m_textBoxStatistics.SelectionFont = m_propertyValueFont;
            m_textBoxStatistics.AppendLine(component.Properties.Count.ToString());

            m_textBoxStatistics.SelectionIndent += 25;
            foreach (KeyValuePair <string, PropertyValue> keyValuePair in component.Properties)
            {
                m_textBoxStatistics.SelectionBullet = true;

                m_textBoxStatistics.SelectionFont = m_propertyNameFont;
                m_textBoxStatistics.AppendText(keyValuePair.Key);
                m_textBoxStatistics.AppendText(" = ");

                m_textBoxStatistics.SelectionFont = m_propertyValueFont;
                m_textBoxStatistics.AppendLine(keyValuePair.Value);
            }
            m_textBoxStatistics.SelectionBullet = false;
            m_textBoxStatistics.SelectionIndent = oldIndent;
        }
        public CustomPropertiesCommand(Component component, PropertyCollection newProperties)
        {
            m_component = component;

            m_oldProperties = new PropertyCollection(component.Properties);

            m_newProperties = newProperties;

            m_description = "Change custom properties";
        }
Exemple #4
0
        private TreeNode SearchComponent(TreeNode rootNode, xTile.ObjectModel.Component component)
        {
            if (rootNode.Tag == component)
            {
                return(rootNode);
            }

            foreach (TreeNode childNode in rootNode.Nodes)
            {
                TreeNode resultNode = SearchComponent(childNode, component);
                if (resultNode != null)
                {
                    return(resultNode);
                }
            }

            return(null);
        }
Exemple #5
0
        private void OnAfterSelect(object sender, TreeViewEventArgs treeViewEventArgs)
        {
            TreeNode treeNode = m_treeView.SelectedNode;

            if (treeNode.Tag is Layer)
            {
                treeNode.NodeFont = new Font(m_treeView.Font, FontStyle.Bold);
                treeNode.Text     = treeNode.Text;
            }

            if (ComponentChanged != null)
            {
                object tag = treeNode.Tag;
                xTile.ObjectModel.Component component = tag is xTile.ObjectModel.Component
                    ? (xTile.ObjectModel.Component)tag : null;

                ComponentChanged(this,
                                 new MapTreeViewEventArgs(treeNode, component));
            }
        }
Exemple #6
0
 private void StoreProperties(Stream stream, Component component)
 {
     StoreInt32(stream, component.Properties.Count);
     foreach (string key in component.Properties.Keys)
     {
         StoreString(stream, key);
         PropertyValue propertyValue = component.Properties[key];
         if (propertyValue.Type == typeof(bool))
         {
             stream.WriteByte(PROPERTY_BOOL);
             StoreBool(stream, (bool)propertyValue);
         }
         else if (propertyValue.Type == typeof(int))
         {
             stream.WriteByte(PROPERTY_INT);
             StoreInt32(stream, (int)propertyValue);
         }
         else if (propertyValue.Type == typeof(float))
         {
             stream.WriteByte(PROPERTY_FLOAT);
             StoreFloat(stream, (float)propertyValue);
         }
         else if (propertyValue.Type == typeof(string))
         {
             stream.WriteByte(PROPERTY_STRING);
             StoreString(stream, (string)propertyValue);
         }
         else
             throw new Exception("Unsupported property type: " + propertyValue.Type);
     }
 }
Exemple #7
0
 private void LoadProperties(Stream stream, Component component)
 {
     int propertyCount = LoadInt32(stream);
     while (propertyCount-- > 0)
     {
         string key = LoadString(stream);
         byte propertyType = (byte)stream.ReadByte();
         switch (propertyType)
         {
             case PROPERTY_BOOL:
                 component.Properties[key] = LoadBool(stream);
                 break;
             case PROPERTY_INT:
                 component.Properties[key] = LoadInt32(stream);
                 break;
             case PROPERTY_FLOAT:
                 component.Properties[key] = LoadFloat(stream);
                 break;
             case PROPERTY_STRING:
                 component.Properties[key] = LoadString(stream);
                 break;
         }
     }
 }
Exemple #8
0
 public MapTreeViewEventArgs(TreeNode treeNode, xTile.ObjectModel.Component component)
 {
     m_treeNode = treeNode;
     m_component = component;
 }
Exemple #9
0
        private void OnTileSheetDelete(object sender, EventArgs eventArgs)
        {
            if (m_selectedComponent == null
                || !(m_selectedComponent is TileSheet))
                return;

            TileSheet tileSheet = (TileSheet)m_selectedComponent;

            if (m_map.DependsOnTileSheet(tileSheet))
            {
                m_hasDependencyMessageBox.Show();
                return;
            }

            Command command = new TileSheetDeleteCommand(m_map, tileSheet, m_mapTreeView);
            m_commandHistory.Do(command);

            m_tileSheetPropertiesMenuItem.Enabled
                = m_tileSheetPropertiesButton.Enabled
                = m_tileSheetDeleteMenuItem.Enabled
                = m_tileSheetDeleteButton.Enabled = false;

            m_tilePicker.UpdatePicker();

            m_mapPanel.DisposeTileSheet(tileSheet);

            m_needsSaving = true;
            UpdateFileControls();
            UpdateEditControls();
            UpdateTileSheetControls();
            m_selectedComponent = m_mapTreeView.SelectedComponent;
        }
Exemple #10
0
        private void OnMainFormLoad(object sender, EventArgs eventArgs)
        {
            xTile.Format.FormatManager fm = xTile.Format.FormatManager.Instance;

            m_windowMode = WindowMode.Windowed;
            m_windowBounds = this.Bounds;

            // register supported formats for xTile
            RegisterFileFormats();

            m_map = new Map("Untitled");
            m_needsFilename = true;
            m_needsSaving = false;
            m_filename = "Untitled.tide";
            this.Text = "Untitled - tIDE";

            m_mapTreeView.Map = m_map;
            m_tilePicker.Map = m_map;
            m_mapPanel.Map = m_map;
            m_mapPanel.TileBrushCollection = m_tileBrushCollection;

            m_selectedComponent = m_map;

            m_viewZoomComboBox.SelectedIndex = m_mapPanel.ZoomIndex;

            ArrangeToolStripLayout();

            m_pluginManager = new PluginManager(m_menuStrip, m_toolStripContainer, m_mapPanel);
            OnPluginsReload(this, EventArgs.Empty);

            UpdateRecentFilesMenu();
            ArrangeToolStripLayout();

            // handle opening by file association or command line
            if (m_arguments.Length == 1)
            {
                string filename = m_arguments[0];
                string extension = Path.GetExtension(filename).ToLower();
                if (extension == ".tide" || extension == ".tbin")
                    OpenFile(filename);
            }
        }
Exemple #11
0
        private void StoreProperties(Component component, XmlWriter xmlWriter)
        {
            // properties are an optional element in TMX
            if (component.Properties.Count == 0)
                return;

            xmlWriter.WriteStartElement("properties");

            foreach (KeyValuePair<string, PropertyValue> keyValuePair in component.Properties)
            {
                xmlWriter.WriteStartElement("property");
                xmlWriter.WriteAttributeString("name", keyValuePair.Key);
                xmlWriter.WriteAttributeString("value", keyValuePair.Value.ToString());
                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
        }
Exemple #12
0
        private void OnTreeComponentChanged(object sender, MapTreeViewEventArgs mapTreeViewEventArgs)
        {
            xTile.ObjectModel.Component component = mapTreeViewEventArgs.Component;

            // enable/disable layer menu items as applicable
            bool layerSelected = component != null && component is Layer;

            m_mapPanel.Enabled = layerSelected;

            m_layerPropertiesMenuItem.Enabled
                = m_layerPropertiesButton.Enabled
                = m_layerOffsetMenuItem.Enabled
                = m_layerOffsetButton.Enabled
                = m_layerMakeInvisibleMenuItem.Enabled
                = m_layerMakeInvisibileButton.Enabled
                = m_layerDeleteMenuItem.Enabled
                = m_layerDeleteButton.Enabled
                = layerSelected;

            // print commands
            m_filePageSetupMenuItem.Enabled
                = m_filePageSetupButton.Enabled
                = m_filePrintPreviewMenuItem.Enabled
                = m_filePrintPreviewButton.Enabled
                = m_filePrintMenuItem.Enabled
                = m_filePrintButton.Enabled
                = layerSelected;

            if (layerSelected)
            {
                Layer layer = (Layer)component;

                m_mapPanel.SelectedLayer = layer;
            }
            else
            {
                m_mapPanel.SelectedLayer = null;
            }

            m_selectedComponent = component;

            UpdateEditControls();
            UpdateLayerOrderingControls();

            // enable/disable tile sheet menu items as applicable
            UpdateTileSheetControls();
        }
Exemple #13
0
 public MapTreeViewEventArgs(TreeNode treeNode, xTile.ObjectModel.Component component)
 {
     m_treeNode  = treeNode;
     m_component = component;
 }
Exemple #14
0
        public void UpdateTree()
        {
            /*
             * if (m_map == null)
             * {
             *  m_treeView.Nodes.Clear();
             *  return;
             * }*/

            xTile.ObjectModel.Component selectedComponent = SelectedComponent;

            TreeNode mapNode        = m_treeView.Nodes[0];
            TreeNode layersNode     = mapNode.Nodes[0];
            TreeNode tileSheetsNode = mapNode.Nodes[1];

            if (m_map == null)
            {
                mapNode.Tag = layersNode.Tag = tileSheetsNode.Tag = null;
                layersNode.Nodes.Clear();
                tileSheetsNode.Nodes.Clear();
                return;
            }

            mapNode.Tag = m_map;
            mapNode.ContextMenuStrip = m_mapContextMenuStrip;

            layersNode.Tag = m_map.Layers;
            layersNode.ContextMenuStrip = m_layersContextMenuStrip;

            tileSheetsNode.Tag = m_map.TileSheets;
            tileSheetsNode.ContextMenuStrip = m_tileSheetsContextMenuStrip;

            // layers
            UpdateLayersSubTree(layersNode);

            // tile sheets
            UpdateTileSheetsSubTree(tileSheetsNode);


            // map root node

            /*
             * TreeNode mapNode = null;
             * TreeNode layersNode = null;
             * TreeNode tileSheetsNode = null;
             * if (m_treeView.Nodes.Count == 0)
             * {
             *  // create root map node
             *  int mapImageIndex = m_imageList.Images.IndexOfKey("Map.png");
             *  mapNode = new TreeNode(m_map.Id, mapImageIndex, mapImageIndex);
             *  mapNode.ContextMenuStrip = m_mapContextMenuStrip;
             *  mapNode.Tag = m_map;
             *
             *  // create layer collection node
             *  string layersLabel = LanguageManager.GetText(typeof(MapTreeView), "Generic.Layers");
             *  int layerFolderImageIndex = m_imageList.Images.IndexOfKey("LayerFolder.png");
             *  layersNode = new TreeNode(layersLabel, layerFolderImageIndex, layerFolderImageIndex);
             *  layersNode.Name = "Generic.Layers";
             *  layersNode.ContextMenuStrip = m_layersContextMenuStrip;
             *  layersNode.Tag = m_map.Layers;
             *  mapNode.Nodes.Add(layersNode);
             *
             *  // create tilesheet collection node
             *  string tileSheetsLabel = LanguageManager.GetText(typeof(MapTreeView), "Generic.TileSheets");
             *  int tileSheetFolderImageIndex = m_imageList.Images.IndexOfKey("TileSheetFolder.png");
             *  tileSheetsNode = new TreeNode(tileSheetsLabel, tileSheetFolderImageIndex, tileSheetFolderImageIndex);
             *  tileSheetsNode.Name = "Generic.TileSheets";
             *  tileSheetsNode.ContextMenuStrip = m_tileSheetsContextMenuStrip;
             *  tileSheetsNode.Tag = m_map.TileSheets;
             *  mapNode.Nodes.Add(tileSheetsNode);
             *
             *  m_treeView.Nodes.Add(mapNode);
             *
             *  m_treeView.SelectedNode = mapNode;
             * }
             * else
             * {
             *  if (m_map != null)
             *  {
             *      // determine update map node
             *      TreeNode mapNode = m_treeView.Nodes[0];
             *      //mapNode.Text = m_map.Id;
             *      mapNode.Tag = m_map;
             *
             *      TreeNode layersNode = mapNode.Nodes[0];
             *      layersNode.Tag = m_map.Layers;
             *
             *      TreeNode tileSheetsNode = mapNode.Nodes[1];
             *      tileSheetsNode.Tag = m_map.TileSheets;
             *
             *      // layers
             *      UpdateLayersSubTree(layersNode);
             *
             *      // tile sheets
             *      UpdateTileSheetsSubTree(tileSheetsNode);
             *  }
             * }*/


            if (selectedComponent != null &&
                SearchComponent(m_treeView.Nodes[0], selectedComponent) != null)
            {
                SelectedComponent = selectedComponent;
            }
        }
Exemple #15
0
        private void StoreProperties(Component component, XmlWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("Properties");

            foreach (KeyValuePair<string, PropertyValue> keyValuePair in component.Properties)
            {
                xmlWriter.WriteStartElement("Property");
                xmlWriter.WriteAttributeString("Key", keyValuePair.Key);
                xmlWriter.WriteAttributeString("Type", keyValuePair.Value.Type.Name);
                xmlWriter.WriteCData(keyValuePair.Value);
                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteEndElement();
        }
Exemple #16
0
        private void LoadProperties(XmlHelper xmlHelper, Component component)
        {
            xmlHelper.AdvanceStartElement("Properties");

            while (xmlHelper.AdvanceStartRepeatedElement("Property", "Properties"))
            {
                string propertyKey = xmlHelper.GetAttribute("Key");
                string propertyType = xmlHelper.GetAttribute("Type");
                string propertyValue = xmlHelper.GetCData();

                if (propertyType == typeof(bool).Name)
                    component.Properties[propertyKey] = bool.Parse(propertyValue);
                else if (propertyType == typeof(int).Name)
                    component.Properties[propertyKey] = int.Parse(propertyValue);
                else if (propertyType == typeof(float).Name)
                    component.Properties[propertyKey] = float.Parse(propertyValue);
                else
                    component.Properties[propertyKey] = propertyValue;

                xmlHelper.AdvanceEndElement("Property");
            }
        }
Exemple #17
0
        private void OpenFile(string filename)
        {
            FormatManager formatManager = FormatManager.Instance;

            StartWaitCursor();

            string basePath = Path.GetDirectoryName(filename);
            string oldCurrentDirectory = Directory.GetCurrentDirectory();
            Directory.SetCurrentDirectory(basePath);

            Map newMap = null;
            try
            {
                newMap = formatManager.LoadMap(filename);

                RecentFilesManager.StoreFilename(filename);

                // convert relative image source paths to absolute paths
                foreach (TileSheet tileSheet in newMap.TileSheets)
                    tileSheet.ImageSource = PathHelper.GetAbsolutePath(basePath, tileSheet.ImageSource);

                ClipBoardManager.Instance.StoreTileBrush(null);
                m_tileBrushCollection.TileBrushes.Clear();

                m_map = newMap;

                foreach (TileSheet tileSheet in m_map.TileSheets)
                    TileImageCache.Instance.Refresh(tileSheet);

                m_mapTreeView.Map = m_map;
                m_tilePicker.Map = m_map;
                m_mapPanel.Map = m_map;

                m_mapTreeView.UpdateTree();
                m_tilePicker.UpdatePicker();

                if (m_map.Layers.Count == 0)
                {
                    m_selectedComponent = null;
                    m_mapTreeView.SelectedComponent = null;
                }
                else
                {
                    m_selectedComponent = m_mapTreeView.SelectedComponent = m_map.Layers[m_map.Layers.Count - 1];
                }

                m_mapPanel.Enabled = true;
                m_mapPanel.Invalidate(true);

                m_needsFilename = false;
                m_needsSaving = false;

                m_filename = filename;
                m_commandHistory.Clear();

                // refresh tile brush definitions
                m_tileBrushCollection.LoadFromMap(m_map);

                // refresh auto tile definitions
                AutoTileManager.Instance.Refresh(m_map);

                // push to top of recent file list
                RecentFilesManager.StoreFilename(filename);

                UpdateAllControls();
            }
            catch (Exception exception)
            {
                string message = exception.Message;
                if (exception.InnerException != null)
                    message += " Inner Message: " + exception.InnerException.Message;
                m_loadErrorMessageBox.VariableDictionary["message"] = message;
                m_loadErrorMessageBox.Show();
            }

            Directory.SetCurrentDirectory(oldCurrentDirectory);

            StopWaitCursor();
        }
Exemple #18
0
        private void OnFileNew(object sender, EventArgs eventArgs)
        {
            if (!HandleUnsavedChanges(sender, eventArgs))
                return;

            Map map = new Map("Untitled Map");

            MapPropertiesDialog mapPropertiesDialog = new MapPropertiesDialog(map, true);

            if (mapPropertiesDialog.ShowDialog(this) == DialogResult.OK)
            {
                m_map = map;
                m_mapTreeView.Map = m_map;
                m_mapTreeView.UpdateTree();
                m_tilePicker.Map = map;
                m_mapPanel.Map = map;

                m_needsFilename = true;
                m_needsSaving = true;

                m_commandHistory.Clear();
                m_selectedComponent = null;

                // refresh tile brush definitions
                m_tileBrushCollection.LoadFromMap(m_map);

                // refresh auto tile definitions
                AutoTileManager.Instance.Refresh(m_map);

                UpdateAllControls();
            }
        }
 public void StoreProperties(xTile.ObjectModel.Component component)
 {
     component.Properties.Clear();
     component.Properties.CopyFrom(m_newProperties);
 }
Exemple #20
0
        private void LoadProperties(XmlHelper xmlHelper, Component component)
        {
            while (xmlHelper.AdvanceStartRepeatedElement("property", "properties"))
            {
                string propertyKey = xmlHelper.GetAttribute("name");
                string propertyValue = xmlHelper.GetAttribute("value");

                component.Properties[propertyKey] = propertyValue;

                xmlHelper.AdvanceEndElement("property");
            }
        }