Ejemplo n.º 1
0
        public UITabPage
            (GameConfigDB gameConfigDB
            , Gtk.ScrolledWindow scrolledWindow
            , Gtk.Viewport viewport
            , Gtk.Label label
            , Gtk.Fixed canvas)
        {
            _scrolledWindow      = scrolledWindow;
            _viewport            = viewport;
            _label               = label;
            _canvas              = canvas;
            _canvas.ScrollEvent += OnScrollEvent;
            _scrolledWindow.ButtonPressEvent += OnMainWindowButtonPressed;
            _label.Parent.ButtonPressEvent   += OnTabButtonPressed;

            _gameConfigDB = gameConfigDB;
            _uiSections   = new List <UISection>();

            Point currentSectionPoint = UISection.DEFAULT_ORIGIN_POINT;

            foreach (GameConfigSectionDescriptor sectionDescriptor in _gameConfigDB.GetSections())
            {
                UISection newSection = new UISection(this, sectionDescriptor, currentSectionPoint);
                currentSectionPoint = newSection.GetNextPosition();
                _uiSections.Add(newSection);
            }

            ResizeCanvas();
        }
Ejemplo n.º 2
0
        public void AddNewButton(GameConfigButtonDescriptor buttonDescriptor, int sectionIndex)
        {
            UISection sectionSelected = _uiSections[sectionIndex];

            sectionSelected.AddButton(buttonDescriptor);
            RefreshCanvas();
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        public void AddNewSection(GameConfigSectionDescriptor sectionDescriptor)
        {
            Point newSectionOriginPoint = UISection.DEFAULT_ORIGIN_POINT;

            if (_uiSections.Count > 0)
            {
                newSectionOriginPoint = _uiSections[_uiSections.Count - 1].GetNextPosition();
            }

            UISection newSection = new UISection(this, sectionDescriptor, newSectionOriginPoint);

            _uiSections.Add(newSection);
            RefreshCanvas();
        }
Ejemplo n.º 5
0
        public int GetNearestSectionIndex(Point targetPoint)
        {
            double minDistance = double.MaxValue;

            int nearestSectionIndex = 0;

            for (int i = 0; i < _uiSections.Count; ++i)
            {
                UISection section  = _uiSections[i];
                double    distance = UIUtils.Distance(targetPoint, section.GetOriginPosition());
                if (distance < minDistance)
                {
                    minDistance         = distance;
                    nearestSectionIndex = i;
                }
            }

            return(nearestSectionIndex);
        }
Ejemplo n.º 6
0
        public void AddNewSection(GameConfigSectionDescriptor sectionDescriptor, int previousSectionIndex)
        {
            Point newSectionOriginPoint = UISection.DEFAULT_ORIGIN_POINT;

            if (_uiSections.Count > 0)
            {
                newSectionOriginPoint = _uiSections[previousSectionIndex].GetNextPosition();
            }

            UISection newSection = new UISection(this, sectionDescriptor, newSectionOriginPoint);

            if (previousSectionIndex < _uiSections.Count - 1)
            {
                _uiSections.Insert(previousSectionIndex + 1, newSection);
            }
            else
            {
                _uiSections.Add(newSection);
            }
            RefreshCanvas();
        }