Пример #1
0
        private void AddToChildren(CControl control)
        {
            if (Util.OutermostParent == null)
            {
                Util.OutermostParent = Util.OriginalParent;
                //MessageBox.Show("Control Area's reference is not set. Cannot initialize toolbox.", "ControlArea Uninitialized");
                //return;
            }

            Canvas parent = Util.OutermostParent;

            //MessageBox.Show(parent.Name);

            //if (CControl.LastFocused == null)
            //    parent = CControlArea;
            //if (CControl.LastFocused is CFrame)
            //    parent = (CControl.LastFocused as CFrame).Content;

            control.fieldname = Util.GetFactoryName(control, parent);
            control.wide      = "64";
            control.tall      = "24";

            parent.Children.Add(control);
            control.OldParent = parent;

            Panel.SetZIndex(control, Util.MaxZ);

            control.xpos = (int)(parent.Width / 2 - control.ActualWidth / 2) + "";
            control.ypos = (int)(parent.Height / 2 - control.ActualHeight / 2) + "";

            //Canvas.SetLeft(control, parent.Width / 2 - control.Width / 2);
            //Canvas.SetTop(control, parent.Height / 2 - control.Height / 2);

            if (control.GetActualX < -32767)
            {
                control.xpos = "0";
            }
            if (control.GetActualY < -32767)
            {
                control.ypos = "0";
            }

            control.Focus();
        }
        public CProperties()
        {
            InitializeComponent();

            Loaded += (o, e) =>
            {
                CControl.CSControlChanged += (obj, ev) =>
                {
                    if (ctl != obj as CControl)
                    {
                        return;
                    }

                    ControlName.Content = Util.GetControlName(ctl.GetType());
                    SupplyValues();

                    IdentifyValues();
                };

                CControl.LastFocusedChanged += (obj, ev) =>
                {
                    ctl = CControl.LastFocused;

                    #region Image Property Visibility
                    imageURI.Visibility   = ctl != null && ctl is CBitmapImagePanel ? Visibility.Visible : Visibility.Collapsed;
                    imageCOLOR.Visibility = ctl != null && ctl.GetType().Name == "CBitmapImagePanel" ? imageURI.Visibility : Visibility.Collapsed;
                    #endregion

                    #region ImagePanel Property Visibility
                    imageSCALE.Visibility     = ctl != null && ctl is CImagePanel ? Visibility.Visible : Visibility.Collapsed;
                    imageFILLCOLOR.Visibility = imageSCALE.Visibility;
                    #endregion

                    #region Label/Button Property Visibility
                    labelALIGN.Visibility = ctl != null && (ctl is CLabel || ctl is CButton) ? Visibility.Visible : Visibility.Collapsed;
                    labelFONT.Visibility  = labelALIGN.Visibility;
                    labelTEXT.Visibility  = labelALIGN.Visibility;
                    #endregion

                    #region Button Property Visibility
                    buttonCOMMAND.Visibility = ctl != null && ctl is CButton ? Visibility.Visible : Visibility.Collapsed;
                    buttonPAINTBG.Visibility = buttonCOMMAND.Visibility;
                    #endregion

                    if (ctl == null)
                    {
                        ClearValues();
                        return;
                    }

                    ControlName.Content = Util.GetControlName(ctl.GetType());
                    SupplyValues();

                    IdentifyValues();
                };

                #region Generic Control Text Handlers
                header.KeyUp += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        header.Text = string.Empty;
                        return;
                    }

                    if (ev.Key == Key.Enter)
                    {
                        //if (header.Text == string.Empty)
                        //{
                        //    header.Text = ctl.headerName;
                        //    return;
                        //}

                        if (!Util.VerifyHeaderUniqueness(header.Text, ctl))
                        {
                            MessageBox.Show("Header <" + header.Text + "> is already assigned to other controls.", "Header Duplicate");
                            header.Text          = ctl.headerName;
                            CControl.LastFocused = null;
                            return;
                        }

                        ctl.headerName = header.Text;
                    }
                };

                header.LostFocus += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        header.Text = string.Empty;
                        return;
                    }

                    //if (header.Text == string.Empty)
                    //{
                    //    header.Text = ctl.headerName;
                    //    return;
                    //}

                    if (!Util.VerifyHeaderUniqueness(header.Text, ctl))
                    {
                        MessageBox.Show("Header <" + header.Text + "> is already assigned to other controls.", "Header Duplicate");
                        header.Text          = ctl.headerName;
                        CControl.LastFocused = null;
                        return;
                    }

                    ctl.headerName = header.Text;
                };

                //header.TextChanged += (obj, ev) =>
                //{
                //    if (ctl == null)
                //    {
                //        header.Text = string.Empty;
                //        return;
                //    }

                //    ctl.headerName = header.Text;
                //};

                fieldName.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        fieldName.Text = string.Empty;
                        return;
                    }

                    ctl.fieldname = fieldName.Text;
                };

                //fieldName.KeyUp += (obj, ev) =>
                //{
                //    if (ctl == null)
                //    {
                //        fieldName.Text = string.Empty;
                //        return;
                //    }

                //    if (ev.Key == Key.Enter)
                //    {
                //        if (fieldName.Text == string.Empty)
                //        {
                //            fieldName.Text = ctl.fieldname;
                //            return;
                //        }

                //        //if (!Util.VerifyNameuniqueness(fieldName.Text, ctl))
                //        //{
                //        //    MessageBox.Show("Name <" + fieldName.Text + "> is already used by other controls.", "Name Already Taken");
                //        //    fieldName.Text = ctl.fieldname;
                //        //    CControl.LastFocused = null;
                //        //    return;
                //        //}

                //        ctl.fieldname = fieldName.Text;
                //    }
                //};

                //fieldName.LostFocus += (obj, ev) =>
                //{
                //    if (ctl == null)
                //    {
                //        fieldName.Text = string.Empty;
                //        return;
                //    }

                //    if (fieldName.Text == string.Empty)
                //    {
                //        fieldName.Text = ctl.fieldname;
                //        return;
                //    }

                //    //if (!Util.VerifyNameuniqueness(fieldName.Text, ctl))
                //    //{
                //    //    MessageBox.Show("Name <" + fieldName.Text + "> is already used by other controls.", "Name Already Taken");
                //    //    fieldName.Text = ctl.fieldname;
                //    //    CControl.LastFocused = null;
                //    //    return;
                //    //}

                //    ctl.fieldname = fieldName.Text;
                //};

                xpos.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }

                    if (!ctl.LockX)
                    {
                        ctl.xpos = xpos.Text;
                    }

                    if (xpos.IsFocused)
                    {
                        foreach (var cc in Util.SelectedControls)
                        {
                            if (!cc.Locked && !cc.LockX && cc.IsEnabled)
                            {
                                cc.xpos = xpos.Text;
                            }
                        }
                    }
                };

                ypos.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }

                    if (!ctl.LockY)
                    {
                        ctl.ypos = ypos.Text;
                    }

                    if (ypos.IsFocused)
                    {
                        foreach (var cc in Util.SelectedControls)
                        {
                            if (!cc.Locked && !cc.LockY && cc.IsEnabled)
                            {
                                cc.ypos = ypos.Text;
                            }
                        }
                    }
                };

                Lock.LockChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    ctl.Locked = Lock.IsLocked;

                    if (LockToggler.IsFocused)
                    {
                        foreach (var cc in Util.SelectedControls)
                        {
                            cc.Locked = Lock.IsLocked;
                        }
                    }

                    PropertyStack.IsEnabled = !Lock.IsLocked;
                };

                xposLock.LockChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    ctl.LockX = xposLock.IsLocked;

                    xpos.IsEnabled = !xposLock.IsLocked;
                };

                yposLock.LockChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    ctl.LockY = yposLock.IsLocked;

                    ypos.IsEnabled = !yposLock.IsLocked;
                };

                wideLock.LockChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    ctl.LockWidth = wideLock.IsLocked;

                    wide.IsEnabled = !wideLock.IsLocked;
                };

                tallLock.LockChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    ctl.LockHeight = tallLock.IsLocked;

                    tall.IsEnabled = !tallLock.IsLocked;
                };

                //xpos.KeyUp += (obj, ev) =>
                //{
                //    if (ctl == null) return;

                //    if (ev.Key == Key.Enter)
                //        ctl.xpos = xpos.Text;
                //};

                //xpos.LostKeyboardFocus += (obj, ev) =>
                //{
                //    if (ctl == null) return;
                //    ctl.xpos = xpos.Text;
                //};

                //ypos.KeyUp += (obj, ev) =>
                //{
                //    if (ctl == null) return;

                //    if (ev.Key == Key.Enter)
                //        ctl.ypos = ypos.Text;
                //};

                //ypos.LostKeyboardFocus += (obj, ev) =>
                //{
                //    if (ctl == null) return;
                //    ctl.ypos = ypos.Text;
                //};

                wide.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }

                    if (!ctl.LockWidth)
                    {
                        ctl.wide = wide.Text;
                    }

                    if (wide.IsFocused)
                    {
                        foreach (var cc in Util.SelectedControls)
                        {
                            if (!cc.Locked && !cc.LockWidth && cc.IsEnabled)
                            {
                                cc.wide = wide.Text;
                            }
                        }
                    }

                    //int w = Util.StrToInt(ctl, wide.Text);

                    //if (w != Util.ErrorInt)
                    //    ctl.Width = w;
                };

                tall.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }

                    if (!ctl.LockHeight)
                    {
                        ctl.tall = tall.Text;
                    }

                    if (tall.IsFocused)
                    {
                        foreach (var cc in Util.SelectedControls)
                        {
                            if (!cc.Locked && !cc.LockHeight && cc.IsEnabled)
                            {
                                cc.tall = tall.Text;
                            }
                        }
                    }

                    //int t = Util.StrToInt(ctl, tall.Text);

                    //if (t != Util.ErrorInt)
                    //    ctl.Height = t;
                };

                enabled.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    ctl.enabled = enabled.Text;

                    if (enabled.IsFocused)
                    {
                        foreach (var cc in Util.SelectedControls)
                        {
                            if (!cc.Locked)
                            {
                                cc.enabled = enabled.Text;
                            }
                        }
                    }
                };

                visible.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    ctl.visible = visible.Text;

                    if (visible.IsFocused)
                    {
                        foreach (var cc in Util.SelectedControls)
                        {
                            if (!cc.Locked)
                            {
                                cc.visible = visible.Text;
                            }
                        }
                    }
                };
                #endregion

                #region BitmapImagePanel Handlers
                image.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    (ctl as CBitmapImagePanel).image = image.Text.Trim();

                    if (!image.IsFocused)
                    {
                        return;
                    }

                    foreach (var cc in Util.SelectedControls)
                    {
                        if (!cc.Locked && cc is CBitmapImagePanel)
                        {
                            (cc as CBitmapImagePanel).image = image.Text.Trim();
                        }
                    }
                };

                //image.KeyUp += (obj, ev) =>
                //{
                //    if (ctl == null) return;
                //    if (ev.Key == Key.Enter)
                //    {
                //        (ctl as CBitmapImagePanel).image = image.Text.Trim();

                //        foreach (var cc in Util.SelectedControls)
                //        {
                //            if (!cc.Locked && cc is CBitmapImagePanel)
                //                (cc as CBitmapImagePanel).image = image.Text.Trim();
                //        }
                //    }
                //};

                //image.LostFocus += (obj, ev) =>
                //{
                //    if (ctl == null) return;
                //    (ctl as CBitmapImagePanel).image = image.Text.Trim();

                //    foreach (var cc in Util.SelectedControls)
                //    {
                //        if (!cc.Locked && cc is CBitmapImagePanel)
                //            (cc as CBitmapImagePanel).image = image.Text.Trim();
                //    }
                //};

                imagecolor.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    (ctl as CBitmapImagePanel).imagecolor = imagecolor.Text;

                    if (!imagecolor.IsFocused)
                    {
                        return;
                    }

                    foreach (var cc in Util.SelectedControls)
                    {
                        if (!cc.Locked && cc is CBitmapImagePanel)
                        {
                            (cc as CBitmapImagePanel).imagecolor = imagecolor.Text;
                        }
                    }
                };
                #endregion

                #region ImagePanel Handlers
                scaleImage.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    (ctl as CImagePanel).scaleimage = scaleImage.Text;

                    if (!scaleImage.IsFocused)
                    {
                        return;
                    }

                    foreach (var cc in Util.SelectedControls)
                    {
                        if (!cc.Locked && cc is CImagePanel)
                        {
                            (cc as CImagePanel).scaleimage = scaleImage.Text;
                        }
                    }
                };

                fillcolor.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    (ctl as CImagePanel).fillcolor = fillcolor.Text;

                    if (!fillcolor.IsFocused)
                    {
                        return;
                    }

                    foreach (var cc in Util.SelectedControls)
                    {
                        if (!cc.Locked && cc is CImagePanel)
                        {
                            (cc as CImagePanel).fillcolor = fillcolor.Text;
                        }
                    }
                };
                #endregion

                #region Label/Button Handlers
                labelText.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }

                    if (ctl is CLabel)
                    {
                        (ctl as CLabel).labeltext = labelText.Text;
                    }
                    else if (ctl is CButton)
                    {
                        (ctl as CButton).labeltext = labelText.Text;
                    }

                    if (!labelText.IsFocused)
                    {
                        return;
                    }

                    foreach (var cc in Util.SelectedControls)
                    {
                        if (cc.Locked)
                        {
                            continue;
                        }

                        if (cc is CLabel)
                        {
                            (cc as CLabel).labeltext = labelText.Text;
                        }
                        else if (cc is CButton)
                        {
                            (cc as CButton).labeltext = labelText.Text;
                        }
                    }
                };

                textAlignment.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }

                    if (ctl is CLabel)
                    {
                        (ctl as CLabel).textalignment = textAlignment.Text;
                    }
                    else if (ctl is CButton)
                    {
                        (ctl as CButton).textalignment = textAlignment.Text;
                    }

                    if (!textAlignment.IsFocused)
                    {
                        return;
                    }

                    foreach (var cc in Util.SelectedControls)
                    {
                        if (cc.Locked)
                        {
                            continue;
                        }

                        if (cc is CLabel)
                        {
                            (cc as CLabel).textalignment = textAlignment.Text;
                        }
                        else if (cc is CButton)
                        {
                            (cc as CButton).textalignment = textAlignment.Text;
                        }
                    }
                };

                font.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }

                    if (ctl is CLabel)
                    {
                        (ctl as CLabel).font = font.Text;
                    }
                    else if (ctl is CButton)
                    {
                        (ctl as CButton).font = font.Text;
                    }

                    if (!font.IsFocused)
                    {
                        return;
                    }

                    foreach (var cc in Util.SelectedControls)
                    {
                        if (cc.Locked)
                        {
                            continue;
                        }

                        if (cc is CLabel)
                        {
                            (cc as CLabel).font = font.Text;
                        }
                        else if (cc is CButton)
                        {
                            (cc as CButton).font = font.Text;
                        }
                    }
                };
                #endregion

                #region Button Handlers
                command.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    (ctl as CButton).command = command.Text;

                    if (!command.IsFocused)
                    {
                        return;
                    }

                    foreach (var cc in Util.SelectedControls)
                    {
                        if (!cc.Locked && cc is CButton)
                        {
                            (cc as CButton).command = command.Text;
                        }
                    }
                };

                paintbackground.TextChanged += (obj, ev) =>
                {
                    if (ctl == null)
                    {
                        return;
                    }
                    (ctl as CButton).paintbackground = paintbackground.Text;

                    if (!paintbackground.IsFocused)
                    {
                        return;
                    }

                    foreach (var cc in Util.SelectedControls)
                    {
                        if (!cc.Locked && cc is CButton)
                        {
                            (cc as CButton).paintbackground = paintbackground.Text;
                        }
                    }
                };
                #endregion
            };
        }
Пример #3
0
        private void Load()
        {
            if (filename == string.Empty)
            {
                return;
            }

            if (!File.Exists(filename))
            {
                MessageBox.Show("File not found: " + filename, "Load Failed");
                Util.OriginalFileName = string.Empty;
                return;
            }

            Mouse.PrimaryDevice.OverrideCursor = Cursors.Wait;

            ControlArea.Children.Clear();

            if (Util.OutermostParent != null)
            {
                Util.OutermostParent.Children.Clear();
            }
            Util.OutermostParent = null;

            foreach (var cc in Util.SelectedControls)
            {
                cc.IsDeleted = true;
            }

            Util.SelectedControls.Clear();
            Util.OriginalFileName = string.Empty;
            Util.CopiedControl    = null;
            CControl.LastFocused  = null;
            CControl.ClearActiveControls();

            var ccontrols = Util.ParseFile(filename);
            var parented  = false;

            if (ccontrols.Length == 0)
            {
                MessageBox.Show("Cannot parse file: " + filename, "Parse Failed");
                Mouse.PrimaryDevice.OverrideCursor = Cursors.Arrow;
                Title = "Counter Strike 1.6 Resource UI Themer";

                return;
            }

            Title = safeFilename + " - Counter Strike 1.6 Resource UI Themer";

            //.ClearActiveControls();

            //GC.Collect();

            Util.OriginalFileName = filename;
            CControl bgControl = null;

            #region Cheap hack for centering element
            int bgX = -1;
            int bgY = -1;

            switch (safeFilename)
            {
            case "BuyEquipment_CT.res":
            case "BuyEquipment_TER.res":
            case "BuyMachineguns_CT.res":
            case "BuyMachineguns_TER.res":
            case "BuyMenu.res":
            case "BuyPistols_CT.res":
            case "BuyPistols_TER.res":
            case "BuyRifles_CT.res":
            case "BuyRifles_TER.res":
            case "BuyShotguns_CT.res":
            case "BuyShotguns_TER.res":
            case "BuySubMachineguns_CT.res":
            case "BuySubMachineguns_TER.res":
            case "MainBuyMenu.res":
                break;

            case "BuyEquipment.res":
            case "MOTD.res":
            case "Classmenu.res":
            case "Classmenu_CT.res":
            case "Classmenu_TER.res":
            case "Teammenu.res":
                bgX = 0;
                bgY = 0;
                break;
            }
            #endregion

            switch (safeFilename)
            {
            case "BuyEquipment.res":
            case "BuyEquipment_CT.res":
            case "BuyEquipment_TER.res":
            case "BuyMachineguns_CT.res":
            case "BuyMachineguns_TER.res":
            case "BuyMenu.res":
            case "BuyPistols_CT.res":
            case "BuyPistols_TER.res":
            case "BuyRifles_CT.res":
            case "BuyRifles_TER.res":
            case "BuyShotguns_CT.res":
            case "BuyShotguns_TER.res":
            case "BuySubMachineguns_CT.res":
            case "BuySubMachineguns_TER.res":
            case "Classmenu_CT.res":
            case "Classmenu_TER.res":
            case "Teammenu.res":
            case "MainBuyMenu.res":
            case "MOTD.res":
                var bgpanelPath = Directory.GetParent(filename) + "\\" + "BackgroundPanel.res";

                if (File.Exists(bgpanelPath))
                {
                    var bgcontrols = Util.ParseFile(bgpanelPath, false);

                    if (bgcontrols.Length == 0)
                    {
                        MessageBox.Show("BackgroundPanel.res doesn't have any controls.", "BackgroundPanel.res Empty");
                        break;
                    }

                    var bgRoot = bgcontrols[0] as CFrame;
                    bgControl = bgRoot;

                    foreach (CControl ccontrol in bgcontrols.Where(p => p != bgRoot))
                    {
                        bgRoot.Content.Children.Add(ccontrol);
                        ccontrol.IsEnabled = false;
                        ccontrol.Discard   = true;
                    }

                    ControlArea.Children.Add(bgRoot);
                    Util.ForceFrameUpdate(bgRoot);
                    Panel.SetZIndex(bgRoot.Content, -32767);

                    bgRoot.IsEnabled = false;
                    bgRoot.Discard   = true;
                }

                break;
            }

            #region Identify Outmost Parent
            switch (ccontrols[0].controlname)
            {
            case "Frame":
            case "WizardPanel":
            case "WizardSubPanel":
            case "CClientScoreBoardDialog":
            case "CTeamMenu":
                Util.OutermostParent = (ccontrols[0] as CFrame).Content;
                parented             = true;
                break;
            }

            var pcontrol = ccontrols[0];

            if (parented)
            {
                foreach (CControl ccontrol in ccontrols.Where(p => p != ccontrols[0]))
                {
                    Util.OutermostParent.Children.Add(ccontrol);
                    Util.ForceFrameUpdate(ccontrol);

                    ccontrol.OldParent = (pcontrol as CFrame).Content;
                }

                ControlArea.Children.Add(pcontrol);
                Util.ForceFrameUpdate(pcontrol);

                if (bgControl != null)
                {
                    bgControl.xpos = bgX != -1 ? bgX + "" : ccontrols[0].xpos;
                    bgControl.ypos = bgY != -1 ? bgY + "" : ccontrols[0].ypos;
                }
            }
            else
            {
                foreach (CControl ccontrol in ccontrols)
                {
                    ControlArea.Children.Add(ccontrol);
                    ccontrol.OldParent = ControlArea;
                }
            }

            Util.ContainerControl = pcontrol;

            Util.SelectedControls.Clear();
            CControl.LastFocused = null;

            //Panel.SetZIndex(Util.OutermostParent, -999);
            #endregion

            Mouse.PrimaryDevice.OverrideCursor = Cursors.Arrow;
        }