Skip to content

Commit

Permalink
xrGame/ui/UIScriptWnd.h: preparations before returning ListWnd (#382
Browse files Browse the repository at this point in the history
…and #392)
  • Loading branch information
Xottab-DUTY committed May 20, 2019
1 parent 30249e2 commit 3443832
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/xrGame/ui/UIScriptWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class CUIDialogWndEx : public CUIDialogWnd, public FactoryObjectBase
virtual void Update();
virtual bool OnKeyboardAction(int dik, EUIMessages keyboard_action);
virtual bool Dispatch(int cmd, int param) { return true; }
/*
template<typename T>
IC T* GetControl(LPCSTR name);
*/

template <typename T>
T* GetControl(pcstr name);
};
12 changes: 12 additions & 0 deletions src/xrGame/ui/UIScriptWnd_script.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "pch_script.h"
#include "UIScriptWnd.h"
#include "xrUICore/TabControl/UITabControl.h" // Don't remove
#include "uiscriptwnd_script.h"
#include "xrScriptEngine/ScriptExporter.hpp"
#include "xrScriptEngine/Functor.hpp"
Expand All @@ -20,6 +21,17 @@ SCRIPT_EXPORT(CUIDialogWndEx, (CUIDialogWnd, IFactoryObject),
.def("Update", &BaseType::Update, &WrapType::Update_static)
.def("Dispatch", &BaseType::Dispatch, &WrapType::Dispatch_static)
.def("Load", &BaseType::Load)

.def("GetStatic", (CUIStatic* (BaseType::*)(pcstr)) &BaseType::GetControl<CUIStatic>)
.def("GetEditBox", (CUIEditBox* (BaseType::*)(pcstr)) &BaseType::GetControl<CUIEditBox>)
.def("GetDialogWnd", (CUIDialogWnd* (BaseType::*)(pcstr)) &BaseType::GetControl<CUIDialogWnd>)
.def("GetFrameWindow", (CUIFrameWindow* (BaseType::*)(pcstr)) &BaseType::GetControl<CUIFrameWindow>)
.def("GetFrameLineWnd", (CUIFrameLineWnd* (BaseType::*)(pcstr)) &BaseType::GetControl<CUIFrameLineWnd>)
.def("GetProgressBar", (CUIProgressBar* (BaseType::*)(pcstr)) &BaseType::GetControl<CUIProgressBar>)
.def("GetTabControl", (CUITabControl* (BaseType::*)(pcstr)) &BaseType::GetControl<CUITabControl>)
// XXX: ListWnd and ListBox has the same functionality but different function prototypes
// We should not use ListBox for CS and SOC, we should return ListWnd class
//.def("GetListWnd", (CUIListBox* (BaseType::*)(pcstr)) &BaseType::GetControl<CUIListBox>)
];
});
// clang-format on
21 changes: 21 additions & 0 deletions src/xrGame/ui/uiscriptwnd_script.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#pragma once

//UI-controls
class CUIStatic;
class CUIEditBox;
class CUIDialogWnd;
class CUIFrameWindow;
class CUIFrameLineWnd;
class CUIProgressBar;
class CUITabControl;
class CUIListBox;

template <typename T>
struct CWrapperBase : public T, public luabind::wrap_base
{
Expand All @@ -26,3 +36,14 @@ struct CWrapperBase : public T, public luabind::wrap_base

typedef CWrapperBase<CUIDialogWndEx> WrapType;
typedef CUIDialogWndEx BaseType;

template <typename T>
T* CUIDialogWndEx::GetControl(pcstr name)
{
shared_str n = name;
CUIWindow* pWnd = FindChild(n);
if (pWnd == nullptr)
return nullptr;

return smart_cast<T*>(pWnd);
}

0 comments on commit 3443832

Please sign in to comment.