forked from ddnet/ddnet
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ddnet#7308 from Marmare314/add-editor-object
Add `CEditorObject` class
- Loading branch information
Showing
5 changed files
with
175 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "editor_object.h" | ||
|
||
#include "editor.h" | ||
|
||
void CEditorObject::Init(CEditor *pEditor) | ||
{ | ||
m_pEditor = pEditor; | ||
OnReset(); | ||
} | ||
|
||
void CEditorObject::OnUpdate(CUIRect View) | ||
{ | ||
OnRender(View); | ||
if(IsActive()) | ||
OnActive(); | ||
else if(IsHot()) | ||
OnHot(); | ||
} | ||
|
||
bool CEditorObject::OnInput(const IInput::CEvent &Event) | ||
{ | ||
return false; | ||
} | ||
|
||
void CEditorObject::OnRender(CUIRect View) {} | ||
|
||
void CEditorObject::OnReset() {} | ||
void CEditorObject::OnMapLoad() {} | ||
|
||
bool CEditorObject::IsHot() | ||
{ | ||
return UI()->HotItem() == this; | ||
} | ||
|
||
void CEditorObject::SetHot() | ||
{ | ||
UI()->SetHotItem(this); | ||
} | ||
|
||
void CEditorObject::UnsetHot() | ||
{ | ||
if(IsHot()) | ||
UI()->SetHotItem(nullptr); | ||
} | ||
|
||
void CEditorObject::OnHot() {} | ||
|
||
bool CEditorObject::IsActive() | ||
{ | ||
return UI()->CheckActiveItem(this); | ||
} | ||
|
||
void CEditorObject::SetActive() | ||
{ | ||
SetHot(); | ||
UI()->SetActiveItem(this); | ||
} | ||
|
||
void CEditorObject::SetInactive() | ||
{ | ||
if(IsActive()) | ||
UI()->SetActiveItem(nullptr); | ||
} | ||
|
||
void CEditorObject::OnActive() {} | ||
|
||
CEditor *CEditorObject::Editor() { return m_pEditor; } | ||
const CEditor *CEditorObject::Editor() const { return m_pEditor; } | ||
IInput *CEditorObject::Input() { return m_pEditor->Input(); } | ||
IClient *CEditorObject::Client() { return m_pEditor->Client(); } | ||
CConfig *CEditorObject::Config() { return m_pEditor->Config(); } | ||
IConsole *CEditorObject::Console() { return m_pEditor->Console(); } | ||
IEngine *CEditorObject::Engine() { return m_pEditor->Engine(); } | ||
IGraphics *CEditorObject::Graphics() { return m_pEditor->Graphics(); } | ||
ISound *CEditorObject::Sound() { return m_pEditor->Sound(); } | ||
ITextRender *CEditorObject::TextRender() { return m_pEditor->TextRender(); } | ||
IStorage *CEditorObject::Storage() { return m_pEditor->Storage(); } | ||
CUI *CEditorObject::UI() { return m_pEditor->UI(); } | ||
CRenderTools *CEditorObject::RenderTools() { return m_pEditor->RenderTools(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#ifndef GAME_EDITOR_EDITOR_OBJECT_H | ||
#define GAME_EDITOR_EDITOR_OBJECT_H | ||
|
||
#include <functional> | ||
|
||
#include <engine/input.h> | ||
#include <game/client/ui_rect.h> | ||
|
||
class CUI; | ||
class CEditor; | ||
class IClient; | ||
class CConfig; | ||
class IConsole; | ||
class IEngine; | ||
class IGraphics; | ||
class ISound; | ||
class ITextRender; | ||
class IStorage; | ||
class CRenderTools; | ||
|
||
class CEditorObject | ||
{ | ||
public: | ||
virtual ~CEditorObject() = default; | ||
|
||
/** | ||
* Initialise the component and interface pointers. | ||
* Needs to be the first function that is called. | ||
* The default implentation also resets the component. | ||
*/ | ||
virtual void Init(CEditor *pEditor); | ||
|
||
/** | ||
* Calls `OnRender` and then maybe `OnHot` or `OnActive`. | ||
*/ | ||
void OnUpdate(CUIRect View); | ||
|
||
/** | ||
* Gets called before `OnRender`. Should return true | ||
* if the event was consumed. | ||
*/ | ||
virtual bool OnInput(const IInput::CEvent &Event); | ||
|
||
virtual void OnRender(CUIRect View); | ||
|
||
/** | ||
* Gets called after `OnRender` when the component is hot but not active. | ||
* I | ||
*/ | ||
virtual void OnHot(); | ||
|
||
/** | ||
* Gets called after `OnRender` when the component is active. | ||
*/ | ||
virtual void OnActive(); | ||
|
||
virtual void OnReset(); | ||
virtual void OnMapLoad(); | ||
|
||
bool IsHot(); | ||
void SetHot(); | ||
void UnsetHot(); | ||
|
||
bool IsActive(); | ||
void SetActive(); | ||
void SetInactive(); | ||
|
||
CEditor *Editor(); | ||
const CEditor *Editor() const; | ||
IInput *Input(); | ||
IClient *Client(); | ||
CConfig *Config(); | ||
IConsole *Console(); | ||
IEngine *Engine(); | ||
IGraphics *Graphics(); | ||
ISound *Sound(); | ||
ITextRender *TextRender(); | ||
IStorage *Storage(); | ||
CUI *UI(); | ||
CRenderTools *RenderTools(); | ||
|
||
private: | ||
CEditor *m_pEditor; | ||
}; | ||
|
||
#endif |