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(); }
private bool IsElementInsideTargetBoundaries(UICommandElement element, Point target) { return(IsPointInsideTargetBoundaries(element.GetDragLocation(), target)); }