mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #7308 from Marmare314/add-editor-object
Add `CEditorObject` class
This commit is contained in:
commit
093edb7803
|
@ -2266,6 +2266,8 @@ if(CLIENT)
|
||||||
component.h
|
component.h
|
||||||
editor.cpp
|
editor.cpp
|
||||||
editor.h
|
editor.h
|
||||||
|
editor_object.cpp
|
||||||
|
editor_object.h
|
||||||
explanations.cpp
|
explanations.cpp
|
||||||
map_grid.cpp
|
map_grid.cpp
|
||||||
map_grid.h
|
map_grid.h
|
||||||
|
|
|
@ -1,22 +1,5 @@
|
||||||
#include "component.h"
|
#include "component.h"
|
||||||
|
|
||||||
#include "editor.h"
|
|
||||||
|
|
||||||
void CEditorComponent::Init(CEditor *pEditor)
|
|
||||||
{
|
|
||||||
m_pEditor = pEditor;
|
|
||||||
OnReset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEditorComponent::OnUpdate(CUIRect View)
|
|
||||||
{
|
|
||||||
OnRender(View);
|
|
||||||
if(IsActive())
|
|
||||||
OnActive();
|
|
||||||
else if(IsHot())
|
|
||||||
OnHot();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CEditorComponent::OnInput(const IInput::CEvent &Event)
|
bool CEditorComponent::OnInput(const IInput::CEvent &Event)
|
||||||
{
|
{
|
||||||
for(CEditorComponent &Component : m_vSubComponents)
|
for(CEditorComponent &Component : m_vSubComponents)
|
||||||
|
@ -27,48 +10,6 @@ bool CEditorComponent::OnInput(const IInput::CEvent &Event)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEditorComponent::OnRender(CUIRect View) {}
|
|
||||||
|
|
||||||
void CEditorComponent::OnReset() {}
|
|
||||||
void CEditorComponent::OnMapLoad() {}
|
|
||||||
|
|
||||||
bool CEditorComponent::IsHot()
|
|
||||||
{
|
|
||||||
return UI()->HotItem() == this;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEditorComponent::SetHot()
|
|
||||||
{
|
|
||||||
UI()->SetHotItem(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEditorComponent::UnsetHot()
|
|
||||||
{
|
|
||||||
if(IsHot())
|
|
||||||
UI()->SetHotItem(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEditorComponent::OnHot() {}
|
|
||||||
|
|
||||||
bool CEditorComponent::IsActive()
|
|
||||||
{
|
|
||||||
return UI()->CheckActiveItem(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEditorComponent::SetActive()
|
|
||||||
{
|
|
||||||
SetHot();
|
|
||||||
UI()->SetActiveItem(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEditorComponent::SetInactive()
|
|
||||||
{
|
|
||||||
if(IsActive())
|
|
||||||
UI()->SetActiveItem(nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CEditorComponent::OnActive() {}
|
|
||||||
|
|
||||||
void CEditorComponent::InitSubComponents()
|
void CEditorComponent::InitSubComponents()
|
||||||
{
|
{
|
||||||
for(CEditorComponent &Component : m_vSubComponents)
|
for(CEditorComponent &Component : m_vSubComponents)
|
||||||
|
@ -81,17 +22,3 @@ void CEditorComponent::RegisterSubComponent(CEditorComponent &Component)
|
||||||
{
|
{
|
||||||
m_vSubComponents.emplace_back(Component);
|
m_vSubComponents.emplace_back(Component);
|
||||||
}
|
}
|
||||||
|
|
||||||
CEditor *CEditorComponent::Editor() { return m_pEditor; }
|
|
||||||
const CEditor *CEditorComponent::Editor() const { return m_pEditor; }
|
|
||||||
IInput *CEditorComponent::Input() { return m_pEditor->Input(); }
|
|
||||||
IClient *CEditorComponent::Client() { return m_pEditor->Client(); }
|
|
||||||
CConfig *CEditorComponent::Config() { return m_pEditor->Config(); }
|
|
||||||
IConsole *CEditorComponent::Console() { return m_pEditor->Console(); }
|
|
||||||
IEngine *CEditorComponent::Engine() { return m_pEditor->Engine(); }
|
|
||||||
IGraphics *CEditorComponent::Graphics() { return m_pEditor->Graphics(); }
|
|
||||||
ISound *CEditorComponent::Sound() { return m_pEditor->Sound(); }
|
|
||||||
ITextRender *CEditorComponent::TextRender() { return m_pEditor->TextRender(); }
|
|
||||||
IStorage *CEditorComponent::Storage() { return m_pEditor->Storage(); }
|
|
||||||
CUI *CEditorComponent::UI() { return m_pEditor->UI(); }
|
|
||||||
CRenderTools *CEditorComponent::RenderTools() { return m_pEditor->RenderTools(); }
|
|
||||||
|
|
|
@ -1,91 +1,30 @@
|
||||||
#ifndef GAME_EDITOR_COMPONENT_H
|
#ifndef GAME_EDITOR_COMPONENT_H
|
||||||
#define GAME_EDITOR_COMPONENT_H
|
#define GAME_EDITOR_COMPONENT_H
|
||||||
|
|
||||||
#include <functional>
|
#include "editor_object.h"
|
||||||
#include <game/client/ui.h>
|
|
||||||
|
|
||||||
class CEditor;
|
#include <vector>
|
||||||
class IInput;
|
|
||||||
class IClient;
|
|
||||||
class CConfig;
|
|
||||||
class IConsole;
|
|
||||||
class IEngine;
|
|
||||||
class IGraphics;
|
|
||||||
class ISound;
|
|
||||||
class ITextRender;
|
|
||||||
class IStorage;
|
|
||||||
class CRenderTools;
|
|
||||||
|
|
||||||
class CEditorComponent
|
class CEditorComponent : public CEditorObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~CEditorComponent() = default;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialise the component and interface pointers.
|
|
||||||
* Needs to be the first function that is called.
|
|
||||||
*/
|
|
||||||
virtual void Init(CEditor *pEditor);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls `OnRender` and then maybe `OnHot` or `OnActive`.
|
|
||||||
*/
|
|
||||||
void OnUpdate(CUIRect View);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets called before `OnRender`. Should return true
|
* Gets called before `OnRender`. Should return true
|
||||||
* if the event was consumed.
|
* if the event was consumed. By default the events
|
||||||
|
* are forwarded to the subcomponents.
|
||||||
*/
|
*/
|
||||||
virtual bool OnInput(const IInput::CEvent &Event);
|
virtual bool OnInput(const IInput::CEvent &Event) override;
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise all registered subcomponents.
|
* Initialise all registered subcomponents.
|
||||||
* Needs to be called after the interfaces have been initialised.
|
* Needs to be called after the interfaces have been initialised.
|
||||||
*/
|
*/
|
||||||
void InitSubComponents();
|
void InitSubComponents();
|
||||||
|
|
||||||
|
// Register a new subcomponent.
|
||||||
void RegisterSubComponent(CEditorComponent &Component);
|
void RegisterSubComponent(CEditorComponent &Component);
|
||||||
|
|
||||||
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:
|
private:
|
||||||
CEditor *m_pEditor;
|
|
||||||
|
|
||||||
std::vector<std::reference_wrapper<CEditorComponent>> m_vSubComponents = {};
|
std::vector<std::reference_wrapper<CEditorComponent>> m_vSubComponents = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
79
src/game/editor/editor_object.cpp
Normal file
79
src/game/editor/editor_object.cpp
Normal file
|
@ -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(); }
|
86
src/game/editor/editor_object.h
Normal file
86
src/game/editor/editor_object.h
Normal file
|
@ -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
|
Loading…
Reference in a new issue