示例#1
0
 private void Save_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     if (SaveClicked != null)
     {
         SaveClicked.Invoke();
     }
 }
示例#2
0
        public UIElement GetControls(object objectToEdit)
        {
            var editableMembers = _memberResolver.GetMembers(objectToEdit);

            var stackPanel = new StackPanel {
                Margin = _settings.Margin
            };

            foreach (var member in editableMembers)
            {
                var control = _controlResolver.GetControl(objectToEdit, member);
                stackPanel.Children.Add(control);
            }

            var saveButton = new Button {
                Content = "Save"
            };

            saveButton.Click += SaveButton_Click;
            stackPanel.Children.Add(saveButton);

            // register enter keydown as save
            stackPanel.KeyDown += (sender, args) =>
            {
                if (args.Key == Key.Enter)
                {
                    args.Handled = true;
                    SaveClicked?.Invoke(this, EventArgs.Empty);
                }
            };
            return(stackPanel);
        }
示例#3
0
        public ControlForm()
        {
            Form = new Form
            {
                FormBorderStyle = FormBorderStyle.Sizable
            };

            _editControl = new PropertyGrid {
                Dock = DockStyle.Fill
            };
            _toolStrip  = new ToolStrip();
            _saveButton = new ToolStripButton {
                Text = "Save"
            };
            _saveButton.Click += (sender, e) => SaveClicked?.Invoke(sender, e);
            _toolStrip.Items.Add(_saveButton);

            Form.Controls.Add(_toolStrip);
            Form.Controls.Add(_editControl);
            Form.TopMost = true;

            Form.Closed += (sender, args) => Application.Exit();
        }
示例#4
0
 private void ButtonPress_Save(object sender, EventArgs e)
 {
     SaveClicked?.Invoke(sender, e);
 }
示例#5
0
        //--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
        #region --Set-, Get- Methods--


        #endregion
        //--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
        #region --Misc Methods (Public)--


        #endregion

        #region --Misc Methods (Private)--


        #endregion

        #region --Misc Methods (Protected)--


        #endregion
        //--------------------------------------------------------Events:---------------------------------------------------------------------\\
        #region --Events--
        private void save_btn_Click(object sender, RoutedEventArgs e)
        {
            SaveClicked?.Invoke(this, e);
        }
示例#6
0
 private void SaveButton_OnClick(object sender, RoutedEventArgs e)
 {
     SaveClicked?.Invoke(this, EventArgs.Empty);
     IsDirty = false;
 }
示例#7
0
        void AddToTree(string location, FullXldInfo xld)
        {
            var      parts = location.Split('\\');
            TreeNode node  = _rootNode;

            foreach (var dir in parts.Take(parts.Length - 1)) // Ensure parent nodes exist
            {
                if (!node.Nodes.ContainsKey(dir))
                {
                    node.Nodes.Add(dir, dir);
                }
                node = node.Nodes[dir];
            }

            string key = parts.Last();

            if (!key.EndsWith(".bin"))
            {
                return;
            }
            key = key.Substring(0, key.Length - 4);
            int number = int.Parse(key);

            if (!xld.Assets.ContainsKey(number))
            {
                xld.Assets[number] = new FullAssetInfo {
                    Width = 32
                }
            }
            ;

            FullAssetInfo asset = xld.Assets[number];

            string name = string.IsNullOrEmpty(asset.Name)
                ? key
                : $"{asset.Name} ({number})";

            if (!node.Nodes.ContainsKey(key))
            {
                var newNode = node.Nodes.Add(key, name);
                newNode.Tag      = asset;
                newNode.NodeFont = (asset.PaletteHints?.Count == 0) ? _boldFont : _defaultFont;
                _nodes[asset]    = newNode;
            }
        }

        (string, FullXldInfo) CurrentXld
        {
            get
            {
                if (fileTree.SelectedNode == null)
                {
                    return(null, null);
                }

                var node = fileTree.SelectedNode;
                if (int.TryParse(fileTree.SelectedNode.Name, out _))
                {
                    node = fileTree.SelectedNode.Parent;
                }

                string filename = "";
                while (node != _rootNode)
                {
                    filename = node.Name + "\\" + filename;
                    node     = node.Parent;
                }

                filename = filename.TrimEnd('\\');
                var fullXldPath = Path.GetFullPath(Path.Combine(Path.Combine(_generalConfig.BasePath, _generalConfig.ExportedXldPath), filename));
                return(_config.Xlds.ContainsKey(filename)
                    ? (fullXldPath, _config.Xlds[filename])
                    : (null, null));
            }
        }

        (string, FullAssetInfo) CurrentObject
        {
            get
            {
                if (!int.TryParse(fileTree.SelectedNode?.Name, out int number))
                {
                    return(null, null);
                }

                var(xldFilename, xld) = CurrentXld;
                if (xld == null || !xld.Assets.ContainsKey(number))
                {
                    return(null, null);
                }

                var filename = $"{xldFilename}\\{number:00}.bin";
                return(filename, xld.Assets[number]);
            }
        }

        void SyncSelectedPalettes()
        {
            var(filename, asset) = CurrentObject;
            if (asset == null)
            {
                return;
            }

            if (asset.PaletteHints == null)
            {
                asset.PaletteHints = new List <int>();
            }

            for (int index = 0; index < chkListPalettes.Items.Count; index++)
            {
                var item = (AlbionPalette)chkListPalettes.Items[index];
                chkListPalettes.SetItemChecked(index, asset.PaletteHints.Contains(item.Id));
            }

            if (!chkListPalettes.GetItemChecked(chkListPalettes.SelectedIndex) && chkListPalettes.CheckedIndices.Count > 0)
            {
                chkListPalettes.SelectedIndex = chkListPalettes.CheckedIndices[0];
            }
        }

        void FileTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            var(filename, asset) = CurrentObject;
            if (asset == null)
            {
                return;
            }
            SyncSelectedPalettes();

            trackWidth.Value = asset.EffectiveWidth == 0 ? 1 : asset.EffectiveWidth;
            trackFrame.Value = 0;
            textName.Text    = asset.Name;
            Render();

            if (_logicalSprite != null)
            {
                trackFrameCount.Value = _logicalSprite.Frames.Count;
                if (asset.Parent.Format == FileFormat.FixedSizeSprite &&
                    asset.Height != null &&
                    _logicalSprite.Frames[0].Height != asset.Height)
                {
                    asset.Height = _logicalSprite.Frames[0].Height;
                }
            }
        }

        #region Width
        void TrackWidth_ValueChanged(object sender, EventArgs e)
        {
            var(filename, asset) = CurrentObject;
            if (asset == null)
            {
                return;
            }

            if (!asset.Parent.Width.HasValue &&
                asset.Parent.Format == FileFormat.FixedSizeSprite &&
                asset.Width != trackWidth.Value)
            {
                asset.Width    = trackWidth.Value;
                _logicalSprite = null; // Force sprite reload
                _visualSprite  = null;
                Render();
            }

            if (sender != numWidth && (int)numWidth.Value != trackWidth.Value)
            {
                numWidth.Value = trackWidth.Value;
            }
        }

        void TrackWidth_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.Left && trackWidth.Value != 0)
            {
                trackWidth.Value = (int)(trackWidth.Value / (e.Shift ? 1.5 : 2.0));
                e.Handled        = true;
            }

            if (e.Control && e.KeyCode == Keys.Right)
            {
                var newValue = (int)(trackWidth.Value * (e.Shift ? 1.5 : 2.0));
                if (newValue > trackWidth.Maximum)
                {
                    newValue = trackWidth.Maximum;
                }
                trackWidth.Value = newValue;
                e.Handled        = true;
            }
        }

        void NumWidth_ValueChanged(object sender, EventArgs e)
        {
            if (sender != trackWidth && trackWidth.Value != (int)numWidth.Value)
            {
                trackWidth.Value = (int)numWidth.Value;
            }
        }

        void NumWidth_Enter(object sender, EventArgs e)
        {
            numWidth.Select(0, numWidth.Text.Length);
        }

        #endregion

        void TextName_TextChanged(object sender, EventArgs e)
        {
            var(filename, asset) = CurrentObject;
            if (asset != null)
            {
                asset.Name = textName.Text;
            }
        }

        void TrackFrameCount_ValueChanged(object sender, EventArgs e)
        {
            var(filename, asset) = CurrentObject;
            if (_logicalSprite != null && asset != null)
            {
                int?newHeight =
                    trackFrameCount.Value <= 1
                        ? (int?)null
                        : _logicalSprite.Height / trackFrameCount.Value;

                if (!asset.Parent.Height.HasValue &&
                    asset.Parent.Format == FileFormat.FixedSizeSprite &&
                    asset.Height != newHeight)
                {
                    asset.Height   = newHeight;
                    _logicalSprite = null; // Force sprite reload
                    _visualSprite  = null;
                    Render();
                }
            }

            if (sender != numFrameCount && (int)numFrameCount.Value != trackFrameCount.Value)
            {
                numFrameCount.Value = trackFrameCount.Value;
            }
        }

        void NumFrameCount_ValueChanged(object sender, EventArgs e)
        {
            if (sender != trackFrameCount && trackFrameCount.Value != (int)numFrameCount.Value)
            {
                trackFrameCount.Value = (int)numFrameCount.Value;
            }
        }

        void TrackFrame_ValueChanged(object sender, EventArgs e)
        {
            Render();
            if (sender != numFrame && (int)numFrame.Value != trackFrame.Value)
            {
                numFrame.Value = trackFrame.Value;
            }
        }

        void NumFrame_ValueChanged(object sender, EventArgs e)
        {
            if (sender != trackFrame && trackFrame.Value != (int)numFrame.Value)
            {
                trackFrame.Value = (int)numFrame.Value;
            }
        }

        void BtnSave_Click(object sender, EventArgs e)
        {
            SaveClicked?.Invoke(this, EventArgs.Empty);
        }

        void ChkListPalettes_SelectedIndexChanged(object sender, EventArgs e)
        {
            Render();
        }

        void ChkAnimate_CheckedChanged(object sender, EventArgs e)
        {
            if (chkAnimate.Checked)
            {
                _timer.Start();
            }
            else
            {
                _timer.Stop();
            }
        }

        void FileTree_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.X && _logicalSprite != null)
            {
                trackWidth.Value = _logicalSprite.Frames[0].Height;
            }

            var(_, asset) = CurrentObject;
            if (e.Control && e.KeyCode == Keys.C && asset != null)
            {
                _savedPalettes = asset.PaletteHints.ToList();
            }

            if (e.Control && e.KeyCode == Keys.V && asset != null && _savedPalettes != null)
            {
                asset.PaletteHints.Clear();
                foreach (var palette in _savedPalettes)
                {
                    asset.PaletteHints.Add(palette);
                }
                SyncSelectedPalettes();
            }
        }

        void ChkListPalettes_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            var(_, asset) = CurrentObject;
            if (asset == null)
            {
                return;
            }

            var palette = (AlbionPalette)chkListPalettes.Items[e.Index];

            if (e.NewValue == CheckState.Checked)
            {
                if (!asset.PaletteHints.Contains(palette.Id))
                {
                    asset.PaletteHints.Add(palette.Id);
                }
            }
            else
            {
                asset.PaletteHints.Remove(palette.Id);
            }

            _nodes[asset].NodeFont = asset.PaletteHints?.Count == 0 ? _boldFont : _defaultFont;
        }
    }
示例#8
0
 void BtnSave_Click(object sender, EventArgs e)
 {
     SaveClicked?.Invoke(this, EventArgs.Empty);
 }
示例#9
0
 private void SaveButton_Click(object sender, RoutedEventArgs e)
 {
     SaveClicked?.Invoke(this, EventArgs.Empty);
 }
 /// <summary>
 /// Invokes the SaveClicked EventHandler and closes the window
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Save_Clicked(object sender, RoutedEventArgs e)
 {
     SaveClicked?.Invoke(this, new HsvBounds(new Hsv(h_Lower, s_Lower, v_Lower), new Hsv(h_Upper, s_Upper, v_Upper), inverted));
     _parent.Close();
 }
示例#11
0
 private void OnSaveJobClicked(object sender, RoutedEventArgs e)
 {
     SaveClicked?.Invoke(this, e);
 }
 protected void btnSave_Click(object sender, EventArgs e)
 {
     SaveClicked?.Invoke(sender, e);
 }
示例#13
0
 protected virtual void OnSaveClicked(EventArgs e)
 {
     SaveClicked?.Invoke(this, e);
 }