コード例 #1
0
        protected void OnButtonReleaseEvent(UICommandElement element, object sender, ButtonReleaseEventArgs args)
        {
            GameConfigButtonDescriptor commandDescriptor = element.GetCommandDescriptor();

            if (args.Event.Button == 1)
            {
                MainApp.GetInstance().OnButtonPressEvent(commandDescriptor);
            }
            else if (args.Event.Button == 3)
            {
                Gtk.Menu rightButtonMenu = new Gtk.Menu();

                Gtk.MenuItem menuItem = new Gtk.MenuItem("Remove command");
                menuItem.ButtonReleaseEvent += OnRemoveCommandButtonPressed;
                menuItem.Data.Add("UICommandElement", element);
                rightButtonMenu.Append(menuItem);

                menuItem = new Gtk.MenuItem("Edit command");
                menuItem.ButtonReleaseEvent += OnEditCommandButtonPressed;
                menuItem.Data.Add("UICommandElement", element);
                rightButtonMenu.Append(menuItem);

                rightButtonMenu.ShowAll();
                rightButtonMenu.Popup();
            }
        }
コード例 #2
0
        public void OnDropUIElement(UICommandElement uiCommandElement)
        {
            GameConfigButtonDescriptor commandDescriptor = uiCommandElement.GetCommandDescriptor();

            int currentSectionIndex = 0;

            //remove it from UI
            foreach (UISection section in _uiSections)
            {
                if (section.GetUIElements().Exists(element => element == uiCommandElement))
                {
                    section.GetUIElements().Remove(uiCommandElement);
                    ++currentSectionIndex;
                    break;
                }
            }

            //remove it from DataBase
            _gameConfigDB.RemoveCommand(commandDescriptor);

            //find target section and position
            int       sectionIndex    = 0;
            UISection sectionTarget   = null;
            Point     commandLocation = uiCommandElement.GetDragLocation();

            foreach (UISection section in _uiSections)
            {
                if (section.IsPointInside(commandLocation))
                {
                    sectionTarget = section;
                    break;
                }

                ++sectionIndex;
            }

            if (sectionTarget == null)
            {
                sectionIndex  = GetNearestSectionIndex(commandLocation);
                sectionTarget = _uiSections[sectionIndex];
            }

            int elementIndex = sectionTarget.GetElementIndex(commandLocation);

            if (elementIndex < 0)
            {
                elementIndex = sectionTarget.GetUIElements().Count;
            }

            //add it to UI
            sectionTarget.InsertButtonAt(elementIndex, uiCommandElement);

            //add it to DataBase
            _gameConfigDB.AddCommandAtLocation(commandDescriptor, sectionIndex, elementIndex);

            RefreshCanvas();
        }
コード例 #3
0
        private void OnEditCommandButtonPressed(object sender, ButtonReleaseEventArgs e)
        {
            Gtk.MenuItem               sourceMenuOption   = Utils.static_cast <Gtk.MenuItem>(sender);
            object                     commandElementData = sourceMenuOption.Data["UICommandElement"];
            UICommandElement           uiCommandElement   = Utils.dynamic_cast <UICommandElement>(commandElementData);
            GameConfigButtonDescriptor commandDescriptor  = uiCommandElement.GetCommandDescriptor();

            _parent.OnEditCommandButtonPressed(uiCommandElement, commandDescriptor);
        }
コード例 #4
0
        private void OnRemoveCommandButtonPressed(object sender, ButtonReleaseEventArgs e)
        {
            Gtk.MenuItem               sourceMenuOption  = Utils.static_cast <Gtk.MenuItem>(sender);
            UICommandElement           uiCommandElement  = Utils.dynamic_cast <UICommandElement>(sourceMenuOption.Data["UICommandElement"]);
            GameConfigButtonDescriptor commandDescriptor = uiCommandElement.GetCommandDescriptor();

            _UIElements.Remove(uiCommandElement);
            uiCommandElement.Uninit();

            _parent.OnRemoveCommandButtonPressed(commandDescriptor);
        }