| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
|---|---|
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #include "GUI/BsGUIDropDownBoxManager.h" |
| 4 | #include "Scene/BsSceneObject.h" |
| 5 | |
| 6 | namespace bs |
| 7 | { |
| 8 | GUIDropDownBoxManager::~GUIDropDownBoxManager() |
| 9 | { |
| 10 | closeDropDownBox(); |
| 11 | } |
| 12 | |
| 13 | GameObjectHandle<GUIDropDownMenu> GUIDropDownBoxManager::openDropDownBox(const DROP_DOWN_BOX_DESC& desc, |
| 14 | GUIDropDownType type, std::function<void()> onClosedCallback) |
| 15 | { |
| 16 | closeDropDownBox(); |
| 17 | |
| 18 | mDropDownSO = SceneObject::create("DropDownBox", SOF_Internal | SOF_Persistent | SOF_DontSave); |
| 19 | mDropDownBox = mDropDownSO->addComponent<GUIDropDownMenu>(desc, type); |
| 20 | mOnClosedCallback = onClosedCallback; |
| 21 | |
| 22 | return mDropDownBox; |
| 23 | } |
| 24 | |
| 25 | void GUIDropDownBoxManager::closeDropDownBox() |
| 26 | { |
| 27 | if(mDropDownSO != nullptr) |
| 28 | { |
| 29 | mDropDownSO->destroy(); |
| 30 | mDropDownSO = nullptr; |
| 31 | |
| 32 | if(mOnClosedCallback != nullptr) |
| 33 | mOnClosedCallback(); |
| 34 | |
| 35 | mOnClosedCallback = nullptr; |
| 36 | } |
| 37 | } |
| 38 | } |