Beispiel #1
0
        private void AddItemsToContextMenuStrip()
        {
            ToolStripMenuItem resetVariablesItem = new ToolStripMenuItem("Reset Variables");

            resetVariablesItem.Click += (sender, e) => ResetVariables();

            ToolStripMenuItem clearAllButHighlightedItem = new ToolStripMenuItem("Clear All But Highlighted");

            clearAllButHighlightedItem.Click += (sender, e) => ClearAllButHighlightedVariables();

            ToolStripMenuItem fixVerticalScrollItem = new ToolStripMenuItem("Fix Vertical Scroll");

            fixVerticalScrollItem.Click += (sender, e) => FixVerticalScroll();

            ToolStripMenuItem addCustomVariablesItem = new ToolStripMenuItem("Add Custom Variables");

            addCustomVariablesItem.Click += (sender, e) =>
            {
                VariableCreationForm form = new VariableCreationForm();
                form.Initialize(this);
                form.Show();
            };

            ToolStripMenuItem addMappingVariablesItem = new ToolStripMenuItem("Add Mapping Variables");

            addMappingVariablesItem.Click += (sender, e) => AddVariables(MappingConfig.GetVariables());

            ToolStripMenuItem addDummyVariableItem = new ToolStripMenuItem("Add Dummy Variable...");
            List <string>     types = new List <string>(TypeUtilities.InGameTypeList);

            types.Add("string");
            foreach (string typeString in types)
            {
                ToolStripMenuItem typeItem = new ToolStripMenuItem(typeString);
                addDummyVariableItem.DropDownItems.Add(typeItem);
                typeItem.Click += (sender, e) =>
                {
                    int numEntries = 1;
                    if (KeyboardUtilities.IsCtrlHeld())
                    {
                        string numEntriesString = DialogUtilities.GetStringFromDialog(labelText: "Enter Num Vars:");
                        if (numEntriesString == null)
                        {
                            return;
                        }
                        int parsed = ParsingUtilities.ParseInt(numEntriesString);
                        parsed     = Math.Max(parsed, 0);
                        numEntries = parsed;
                    }

                    List <WatchVariableControl> controls = new List <WatchVariableControl>();
                    for (int i = 0; i < numEntries; i++)
                    {
                        string        specialType   = WatchVariableSpecialUtilities.AddDummyEntry(typeString);
                        WatchVariable watchVariable =
                            new WatchVariable(
                                name: specialType,
                                memoryTypeName: null,
                                specialType: specialType,
                                baseAddressType: BaseAddressTypeEnum.None,
                                offsetUS: null,
                                offsetJP: null,
                                offsetSH: null,
                                offsetEU: null,
                                offsetDefault: null,
                                mask: null,
                                shift: null,
                                handleMapping: true);
                        WatchVariableControlPrecursor precursor =
                            new WatchVariableControlPrecursor(
                                name: specialType,
                                watchVar: watchVariable,
                                subclass: typeString == "string" ? WatchVariableSubclass.String : WatchVariableSubclass.Number,
                                backgroundColor: null,
                                displayType: null,
                                roundingLimit: null,
                                useHex: null,
                                invertBool: null,
                                isYaw: null,
                                coordinate: null,
                                groupList: new List <VariableGroup>()
                        {
                            VariableGroup.Custom
                        });
                        WatchVariableControl control = precursor.CreateWatchVariableControl();
                        controls.Add(control);
                    }
                    AddVariables(controls);
                };
            }

            ToolStripMenuItem openSaveClearItem = new ToolStripMenuItem("Open / Save / Clear ...");

            ControlUtilities.AddDropDownItems(
                openSaveClearItem,
                new List <string>()
            {
                "Open", "Open as Pop Out", "Save in Place", "Save As", "Clear"
            },
                new List <Action>()
            {
                () => OpenVariables(),
                () => OpenVariablesAsPopOut(),
                () => SaveVariablesInPlace(),
                () => SaveVariables(),
                () => ClearVariables(),
            });

            ToolStripMenuItem doToAllVariablesItem = new ToolStripMenuItem("Do to all variables...");

            WatchVariableSelectionUtilities.CreateSelectionToolStripItems(
                () => GetCurrentVariableControls(), this)
            .ForEach(item => doToAllVariablesItem.DropDownItems.Add(item));

            ToolStripMenuItem filterVariablesItem = new ToolStripMenuItem("Filter Variables...");

            _filteringDropDownItems = _allGroups.ConvertAll(varGroup => CreateFilterItem(varGroup));
            UpdateFilterItemCheckedStatuses();
            _filteringDropDownItems.ForEach(item => filterVariablesItem.DropDownItems.Add(item));
            filterVariablesItem.DropDown.MouseEnter += (sender, e) =>
            {
                filterVariablesItem.DropDown.AutoClose = false;
            };
            filterVariablesItem.DropDown.MouseLeave += (sender, e) =>
            {
                filterVariablesItem.DropDown.AutoClose = true;
                filterVariablesItem.DropDown.Close();
            };

            ContextMenuStrip.Items.Add(resetVariablesItem);
            ContextMenuStrip.Items.Add(clearAllButHighlightedItem);
            ContextMenuStrip.Items.Add(fixVerticalScrollItem);
            ContextMenuStrip.Items.Add(addCustomVariablesItem);
            ContextMenuStrip.Items.Add(addMappingVariablesItem);
            ContextMenuStrip.Items.Add(addDummyVariableItem);
            ContextMenuStrip.Items.Add(openSaveClearItem);
            ContextMenuStrip.Items.Add(doToAllVariablesItem);
            ContextMenuStrip.Items.Add(filterVariablesItem);
        }
        public WatchVariableControl(
            WatchVariableControlPrecursor watchVarPrecursor,
            string name,
            WatchVariable watchVar,
            WatchVariableSubclass subclass,
            Color?backgroundColor,
            bool?useHex,
            bool?invertBool,
            WatchVariableCoordinate?coordinate,
            List <VariableGroup> groupList)
        {
            // Store the precursor
            _watchVarPrecursor = watchVarPrecursor;

            // Initialize main fields
            _varName         = name;
            GroupList        = groupList;
            _showBorder      = false;
            _editMode        = false;
            _renameMode      = false;
            FixedAddressList = null;

            // Initialize color fields
            _baseColor      = backgroundColor ?? DEFAULT_COLOR;
            _currentColor   = _baseColor;
            _isFlashing     = false;
            _flashStartTime = DateTime.Now;

            // Initialize size fields
            _variableNameWidth  = VariableNameWidth;
            _variableValueWidth = VariableValueWidth;
            _variableHeight     = VariableHeight;

            // Create controls
            InitializeBase();
            _namePanel      = CreateNamePanel();
            _nameTextBox    = CreateNameTextBox();
            _lockPictureBox = CreateLockPictureBox();
            _pinPictureBox  = CreatePinPictureBox();
            _valueTextBox   = CreateValueTextBox();
            _valueCheckBox  = CreateValueCheckBox();

            // Add controls to their containers
            base.Controls.Add(_valueTextBox, 1, 0);
            base.Controls.Add(_valueCheckBox, 1, 0);
            base.Controls.Add(_namePanel, 0, 0);
            _namePanel.Controls.Add(_pinPictureBox);
            _namePanel.Controls.Add(_lockPictureBox);
            _namePanel.Controls.Add(_nameTextBox);

            // Create var x
            _watchVarWrapper = WatchVariableWrapper.CreateWatchVariableWrapper(
                watchVar, this, subclass, useHex, invertBool, coordinate);

            // Initialize context menu strip
            _valueTextboxOriginalContextMenuStrip = _valueTextBox.ContextMenuStrip;
            _nameTextboxOriginalContextMenuStrip  = _nameTextBox.ContextMenuStrip;
            ContextMenuStrip = _watchVarWrapper.GetContextMenuStrip();
            _nameTextBox.ContextMenuStrip  = ContextMenuStrip;
            _valueTextBox.ContextMenuStrip = ContextMenuStrip;

            // Set whether to start as a checkbox
            SetUseCheckbox(_watchVarWrapper.StartsAsCheckbox());

            // Add functions
            _namePanel.Click          += (sender, e) => OnNameTextBoxClick();
            _nameTextBox.Click        += (sender, e) => OnNameTextBoxClick();
            _nameTextBox.Leave        += (sender, e) => { RenameMode = false; };
            _nameTextBox.KeyDown      += (sender, e) => OnNameTextValueKeyDown(e);
            _valueTextBox.DoubleClick += (sender, e) => { EditMode = true; };
            _valueTextBox.KeyDown     += (sender, e) => OnValueTextValueKeyDown(e);
            _valueTextBox.Leave       += (sender, e) => { EditMode = false; };
            _valueCheckBox.Click      += (sender, e) => OnCheckboxClick();
        }
        public WatchVariableControl(
            WatchVariableControlPrecursor watchVarPrecursor,
            string name,
            WatchVariable watchVar,
            WatchVariableSubclass subclass,
            Color?backgroundColor,
            Type displayType,
            int?roundingLimit,
            bool?useHex,
            bool?invertBool,
            bool?isYaw,
            Coordinate?coordinate,
            List <VariableGroup> groupList,
            List <uint> fixedAddresses)
        {
            // Initialize controls
            InitializeComponent();

            _tableLayoutPanel.BorderColor = Color.Red;
            _tableLayoutPanel.BorderWidth = 3;
            _nameTextBox.Text             = name;

            // Store the precursor
            WatchVarPrecursor = watchVarPrecursor;

            // Initialize main fields
            _varName    = name;
            GroupList   = groupList;
            _editMode   = false;
            _renameMode = false;
            IsSelected  = false;

            List <uint> copy1 = fixedAddresses == null ? null : new List <uint>(fixedAddresses);

            _defaultFixedAddressListGetter = () => copy1;
            List <uint> copy2 = fixedAddresses == null ? null : new List <uint>(fixedAddresses);

            FixedAddressListGetter = () => copy2;

            // Initialize color fields
            _initialBaseColor = backgroundColor ?? DEFAULT_COLOR;
            _baseColor        = _initialBaseColor;
            _currentColor     = _baseColor;
            _isFlashing       = false;
            _flashStartTime   = DateTime.Now;

            // Initialize flush/size fields
            _rightFlush         = true;
            _variableNameWidth  = 0;
            _variableValueWidth = 0;
            _variableHeight     = 0;
            _variableTextSize   = 0;
            _variableOffset     = 0;

            // Create watch var wrapper
            WatchVarWrapper = WatchVariableWrapper.CreateWatchVariableWrapper(
                watchVar, this, subclass, displayType, roundingLimit, useHex, invertBool, isYaw, coordinate);

            // Set whether to start as a checkbox
            SetUseCheckbox(WatchVarWrapper.StartsAsCheckbox());

            // Add functions
            _namePanel.Click       += (sender, e) => OnVariableClick();
            _namePanel.DoubleClick += (sender, e) => OnNameTextBoxDoubleClick();

            _nameTextBox.Click       += (sender, e) => OnVariableClick();
            _nameTextBox.DoubleClick += (sender, e) => OnNameTextBoxDoubleClick();
            _nameTextBox.Leave       += (sender, e) => { RenameMode = false; };
            _nameTextBox.KeyDown     += (sender, e) => OnNameTextValueKeyDown(e);

            _valueTextBox.Click       += (sender, e) => _watchVariablePanel.UnselectAllVariables();
            _valueTextBox.DoubleClick += (sender, e) => { EditMode = true; };
            _valueTextBox.KeyDown     += (sender, e) => OnValueTextValueKeyDown(e);
            _valueTextBox.Leave       += (sender, e) => { EditMode = false; };

            _valueCheckBox.Click += (sender, e) => OnCheckboxClick();

            MouseDown += ShowMainContextMenu;
            _valueTextBox.MouseDown += ShowMainContextMenu;
            _namePanel.MouseDown    += ShowMainContextMenu;
            _valuePanel.MouseDown   += ShowMainContextMenu;

            _nameTextBox.MouseDown += (sender, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    if (RenameMode)
                    {
                        ShowRenameContextMenu();
                    }
                    else
                    {
                        ShowContextMenu();
                    }
                }
            };

            _valueTextBox.ContextMenu = _nameTextBox.ContextMenu = DummyContextMenu;
        }