#ifndef _VIEWCTRL_H
#define _VIEWCTRL_H
#include <CasualCore.h>
struct IncreaseOrder;
class ViewCtrl
{
ViewCtrl(const ViewCtrl&);
ViewCtrl& operator=(const ViewCtrl&);
public:
ViewCtrl();
explicit ViewCtrl(const gameswf::CharacterHandle& handle);
explicit ViewCtrl(const std::string& flashSourceFile);
virtual ~ViewCtrl();
// take the ownership of the child
void AddChildViewCtrl(ViewCtrl* a_pCtrl);
void RemoveChildViewCtrl(ViewCtrl* a_pCtrl);
// no ownership of the parent
void SetParentViewCtrl(ViewCtrl * vc) { m_parentCtrl = vc; }
bool IsPresentingModalViewCtrl() const { return m_bBresentingModalViewCtrl || (m_parentCtrl && m_parentCtrl->IsPresentingModalViewCtrl()); }
// take ownership of the modal view controller
// return false if there is a modal dialog already
virtual bool PresentModalViewCtrl(ViewCtrl* a_pCtrl);
virtual void DismissModalViewCtrl();
// update must be called by the subclasses if override,
// also must be included in the game update
virtual void Update(float time_elapsed);
virtual void TouchDown(int x, int y) {}
virtual void TouchDrag(int x, int y) {}
virtual void TouchUp(int x, int y) {}
virtual void SetVisible(bool isVisible);
virtual void Show();
virtual void Hide();
void SetEnable(bool isEnabled);
virtual void OnTooltipLoadedCallback() {}
gameswf::FlashFX* GetFlash() { return m_pFlash; }
gameswf::CharacterHandle GetHandle() { return m_handle; }
const RKString& GetName() { return m_strName; }
bool SetCustomizedOrder(int aOrder);
int GetCustomizedOrder();
void UpdateFlashOrder(const IncreaseOrder &pIncreaseOrder);
private:
void TryRemoveChildren();
void DismissModalViewCtrl(ViewCtrl* a_pCtrl);
void SetPresentingModalViewCtrl(bool b);
void NotifyFlashOrderChange();
void CommitFlashOrderChange();
protected:
bool m_bBresentingModalViewCtrl;
gameswf::FlashFX * m_pFlash; // strong reference, take ownership
ViewCtrl * m_parentCtrl; // weak reference
gameswf::CharacterHandle m_handle;
RKString m_strName;
std::vector<ViewCtrl*> m_children; // strong reference, take ownership
std::vector<ViewCtrl*> m_childrenToBeRemoved; // weak reference
};
#endif // _VIEWCTRL_H