mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
Merge pull request #7976 from ChillerDragon/pr_ed_hover_tiles_vector
[vector] Move select layer to editor component
This commit is contained in:
commit
a720bb0c29
|
@ -2304,6 +2304,8 @@ if(CLIENT)
|
||||||
editor_trackers.h
|
editor_trackers.h
|
||||||
editor_ui.h
|
editor_ui.h
|
||||||
explanations.cpp
|
explanations.cpp
|
||||||
|
layer_selector.cpp
|
||||||
|
layer_selector.h
|
||||||
map_grid.cpp
|
map_grid.cpp
|
||||||
map_grid.h
|
map_grid.h
|
||||||
map_view.cpp
|
map_view.cpp
|
||||||
|
|
|
@ -3849,7 +3849,7 @@ void CEditor::RenderLayers(CUIRect LayersBox)
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool s_ScrollToSelectionNext = false;
|
static bool s_ScrollToSelectionNext = false;
|
||||||
const bool ScrollToSelection = SelectLayerByTile() || s_ScrollToSelectionNext;
|
const bool ScrollToSelection = LayerSelector()->SelectByTile() || s_ScrollToSelectionNext;
|
||||||
s_ScrollToSelectionNext = false;
|
s_ScrollToSelectionNext = false;
|
||||||
|
|
||||||
// render layers
|
// render layers
|
||||||
|
@ -4386,69 +4386,6 @@ void CEditor::RenderLayers(CUIRect LayersBox)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CEditor::SelectLayerByTile()
|
|
||||||
{
|
|
||||||
// ctrl+rightclick a map index to select the layer that has a tile there
|
|
||||||
static int s_Selected = 0;
|
|
||||||
int MatchedGroup = -1;
|
|
||||||
int MatchedLayer = -1;
|
|
||||||
int Matches = 0;
|
|
||||||
bool IsFound = false;
|
|
||||||
if(Input()->ModifierIsPressed() && UI()->HotItem() == &m_MapEditorId && UI()->MouseButtonClicked(1))
|
|
||||||
{
|
|
||||||
for(size_t g = 0; g < m_Map.m_vpGroups.size(); g++)
|
|
||||||
{
|
|
||||||
for(size_t l = 0; l < m_Map.m_vpGroups[g]->m_vpLayers.size(); l++)
|
|
||||||
{
|
|
||||||
if(IsFound)
|
|
||||||
continue;
|
|
||||||
if(m_Map.m_vpGroups[g]->m_vpLayers[l]->m_Type != LAYERTYPE_TILES)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
std::shared_ptr<CLayerTiles> pTiles = std::static_pointer_cast<CLayerTiles>(m_Map.m_vpGroups[g]->m_vpLayers[l]);
|
|
||||||
|
|
||||||
float aMapping[4];
|
|
||||||
m_Map.m_vpGroups[g]->Mapping(aMapping);
|
|
||||||
int x = aMapping[0] + (aMapping[2] - aMapping[0]) / 2;
|
|
||||||
int y = aMapping[1] + (aMapping[3] - aMapping[1]) / 2;
|
|
||||||
x += UI()->MouseWorldX() - (MapView()->GetWorldOffset().x * m_Map.m_vpGroups[g]->m_ParallaxX / 100) - m_Map.m_vpGroups[g]->m_OffsetX;
|
|
||||||
y += UI()->MouseWorldY() - (MapView()->GetWorldOffset().y * m_Map.m_vpGroups[g]->m_ParallaxY / 100) - m_Map.m_vpGroups[g]->m_OffsetY;
|
|
||||||
x /= 32;
|
|
||||||
y /= 32;
|
|
||||||
|
|
||||||
if(x < 0 || x >= pTiles->m_Width)
|
|
||||||
continue;
|
|
||||||
if(y < 0 || y >= pTiles->m_Height)
|
|
||||||
continue;
|
|
||||||
CTile Tile = pTiles->GetTile(x, y);
|
|
||||||
if(Tile.m_Index)
|
|
||||||
{
|
|
||||||
if(MatchedGroup == -1)
|
|
||||||
{
|
|
||||||
MatchedGroup = g;
|
|
||||||
MatchedLayer = l;
|
|
||||||
}
|
|
||||||
if(++Matches > s_Selected)
|
|
||||||
{
|
|
||||||
s_Selected++;
|
|
||||||
MatchedGroup = g;
|
|
||||||
MatchedLayer = l;
|
|
||||||
IsFound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(MatchedGroup != -1 && MatchedLayer != -1)
|
|
||||||
{
|
|
||||||
if(!IsFound)
|
|
||||||
s_Selected = 1;
|
|
||||||
SelectLayer(MatchedLayer, MatchedGroup);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDuplicate)
|
bool CEditor::ReplaceImage(const char *pFileName, int StorageType, bool CheckDuplicate)
|
||||||
{
|
{
|
||||||
// check if we have that image already
|
// check if we have that image already
|
||||||
|
@ -8424,6 +8361,7 @@ void CEditor::Init()
|
||||||
|
|
||||||
m_vComponents.emplace_back(m_MapView);
|
m_vComponents.emplace_back(m_MapView);
|
||||||
m_vComponents.emplace_back(m_MapSettingsBackend);
|
m_vComponents.emplace_back(m_MapSettingsBackend);
|
||||||
|
m_vComponents.emplace_back(m_LayerSelector);
|
||||||
for(CEditorComponent &Component : m_vComponents)
|
for(CEditorComponent &Component : m_vComponents)
|
||||||
Component.Init(this);
|
Component.Init(this);
|
||||||
|
|
||||||
|
@ -8530,6 +8468,56 @@ void CEditor::HandleCursorMovement()
|
||||||
m_MouseWorldNoParaX = aPoints[0] + WorldWidth * (s_MouseX / Graphics()->WindowWidth());
|
m_MouseWorldNoParaX = aPoints[0] + WorldWidth * (s_MouseX / Graphics()->WindowWidth());
|
||||||
m_MouseWorldNoParaY = aPoints[1] + WorldHeight * (s_MouseY / Graphics()->WindowHeight());
|
m_MouseWorldNoParaY = aPoints[1] + WorldHeight * (s_MouseY / Graphics()->WindowHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OnMouseMove(s_MouseX, s_MouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEditor::OnMouseMove(float MouseX, float MouseY)
|
||||||
|
{
|
||||||
|
m_vHoverTiles.clear();
|
||||||
|
for(size_t g = 0; g < m_Map.m_vpGroups.size(); g++)
|
||||||
|
{
|
||||||
|
const std::shared_ptr<CLayerGroup> pGroup = m_Map.m_vpGroups[g];
|
||||||
|
for(size_t l = 0; l < pGroup->m_vpLayers.size(); l++)
|
||||||
|
{
|
||||||
|
const std::shared_ptr<CLayer> pLayer = pGroup->m_vpLayers[l];
|
||||||
|
int LayerType = pLayer->m_Type;
|
||||||
|
if(LayerType != LAYERTYPE_TILES &&
|
||||||
|
LayerType != LAYERTYPE_FRONT &&
|
||||||
|
LayerType != LAYERTYPE_TELE &&
|
||||||
|
LayerType != LAYERTYPE_SPEEDUP &&
|
||||||
|
LayerType != LAYERTYPE_SWITCH &&
|
||||||
|
LayerType != LAYERTYPE_TUNE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::shared_ptr<CLayerTiles> pTiles = std::static_pointer_cast<CLayerTiles>(pLayer);
|
||||||
|
pGroup->MapScreen();
|
||||||
|
float aPoints[4];
|
||||||
|
pGroup->Mapping(aPoints);
|
||||||
|
float WorldWidth = aPoints[2] - aPoints[0];
|
||||||
|
float WorldHeight = aPoints[3] - aPoints[1];
|
||||||
|
CUIRect Rect;
|
||||||
|
Rect.x = aPoints[0] + WorldWidth * (MouseX / Graphics()->WindowWidth());
|
||||||
|
Rect.y = aPoints[1] + WorldHeight * (MouseY / Graphics()->WindowHeight());
|
||||||
|
Rect.w = 0;
|
||||||
|
Rect.h = 0;
|
||||||
|
RECTi r;
|
||||||
|
pTiles->Convert(Rect, &r);
|
||||||
|
pTiles->Clamp(&r);
|
||||||
|
int x = r.x;
|
||||||
|
int y = r.y;
|
||||||
|
|
||||||
|
if(x < 0 || x >= pTiles->m_Width)
|
||||||
|
continue;
|
||||||
|
if(y < 0 || y >= pTiles->m_Height)
|
||||||
|
continue;
|
||||||
|
CTile Tile = pTiles->GetTile(x, y);
|
||||||
|
if(Tile.m_Index)
|
||||||
|
m_vHoverTiles.emplace_back(CHoverTile(
|
||||||
|
g, l, x, y, Tile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
UI()->MapScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CEditor::DispatchInputEvents()
|
void CEditor::DispatchInputEvents()
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "editor_server_settings.h"
|
#include "editor_server_settings.h"
|
||||||
#include "editor_trackers.h"
|
#include "editor_trackers.h"
|
||||||
#include "editor_ui.h"
|
#include "editor_ui.h"
|
||||||
|
#include "layer_selector.h"
|
||||||
#include "map_view.h"
|
#include "map_view.h"
|
||||||
#include "smooth_value.h"
|
#include "smooth_value.h"
|
||||||
|
|
||||||
|
@ -277,6 +278,7 @@ class CEditor : public IEditor
|
||||||
|
|
||||||
std::vector<std::reference_wrapper<CEditorComponent>> m_vComponents;
|
std::vector<std::reference_wrapper<CEditorComponent>> m_vComponents;
|
||||||
CMapView m_MapView;
|
CMapView m_MapView;
|
||||||
|
CLayerSelector m_LayerSelector;
|
||||||
|
|
||||||
bool m_EditorWasUsedBefore = false;
|
bool m_EditorWasUsedBefore = false;
|
||||||
|
|
||||||
|
@ -316,6 +318,7 @@ public:
|
||||||
|
|
||||||
CMapView *MapView() { return &m_MapView; }
|
CMapView *MapView() { return &m_MapView; }
|
||||||
const CMapView *MapView() const { return &m_MapView; }
|
const CMapView *MapView() const { return &m_MapView; }
|
||||||
|
CLayerSelector *LayerSelector() { return &m_LayerSelector; }
|
||||||
|
|
||||||
CEditor() :
|
CEditor() :
|
||||||
m_ZoomEnvelopeX(1.0f, 0.1f, 600.0f),
|
m_ZoomEnvelopeX(1.0f, 0.1f, 600.0f),
|
||||||
|
@ -426,6 +429,27 @@ public:
|
||||||
m_BrushDrawDestructive = true;
|
m_BrushDrawDestructive = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CHoverTile
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CHoverTile(int Group, int Layer, int x, int y, const CTile Tile) :
|
||||||
|
m_Group(Group),
|
||||||
|
m_Layer(Layer),
|
||||||
|
m_X(x),
|
||||||
|
m_Y(y),
|
||||||
|
m_Tile(Tile)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int m_Group;
|
||||||
|
int m_Layer;
|
||||||
|
int m_X;
|
||||||
|
int m_Y;
|
||||||
|
const CTile m_Tile;
|
||||||
|
};
|
||||||
|
std::vector<CHoverTile> m_vHoverTiles;
|
||||||
|
const std::vector<CHoverTile> &HoverTiles() const { return m_vHoverTiles; }
|
||||||
|
|
||||||
void Init() override;
|
void Init() override;
|
||||||
void OnUpdate() override;
|
void OnUpdate() override;
|
||||||
void OnRender() override;
|
void OnRender() override;
|
||||||
|
@ -440,6 +464,7 @@ public:
|
||||||
void ResetIngameMoved() override { m_IngameMoved = false; }
|
void ResetIngameMoved() override { m_IngameMoved = false; }
|
||||||
|
|
||||||
void HandleCursorMovement();
|
void HandleCursorMovement();
|
||||||
|
void OnMouseMove(float MouseX, float MouseY);
|
||||||
void DispatchInputEvents();
|
void DispatchInputEvents();
|
||||||
void HandleAutosave();
|
void HandleAutosave();
|
||||||
bool PerformAutosave();
|
bool PerformAutosave();
|
||||||
|
@ -995,7 +1020,6 @@ public:
|
||||||
|
|
||||||
void SelectGameLayer();
|
void SelectGameLayer();
|
||||||
std::vector<int> SortImages();
|
std::vector<int> SortImages();
|
||||||
bool SelectLayerByTile();
|
|
||||||
|
|
||||||
void DoAudioPreview(CUIRect View, const void *pPlayPauseButtonID, const void *pStopButtonID, const void *pSeekBarID, const int SampleID);
|
void DoAudioPreview(CUIRect View, const void *pPlayPauseButtonID, const void *pStopButtonID, const void *pSeekBarID, const int SampleID);
|
||||||
|
|
||||||
|
|
48
src/game/editor/layer_selector.cpp
Normal file
48
src/game/editor/layer_selector.cpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#include "editor.h"
|
||||||
|
|
||||||
|
#include "layer_selector.h"
|
||||||
|
|
||||||
|
void CLayerSelector::Init(CEditor *pEditor)
|
||||||
|
{
|
||||||
|
CEditorComponent::Init(pEditor);
|
||||||
|
|
||||||
|
m_SelectionOffset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CLayerSelector::SelectByTile()
|
||||||
|
{
|
||||||
|
// ctrl+rightclick a map index to select the layer that has a tile there
|
||||||
|
if(UI()->HotItem() != &Editor()->m_MapEditorId)
|
||||||
|
return false;
|
||||||
|
if(!Input()->ModifierIsPressed() || !UI()->MouseButtonClicked(1))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int MatchedGroup = -1;
|
||||||
|
int MatchedLayer = -1;
|
||||||
|
int Matches = 0;
|
||||||
|
bool IsFound = false;
|
||||||
|
for(auto HoverTile : Editor()->HoverTiles())
|
||||||
|
{
|
||||||
|
if(MatchedGroup == -1)
|
||||||
|
{
|
||||||
|
MatchedGroup = HoverTile.m_Group;
|
||||||
|
MatchedLayer = HoverTile.m_Layer;
|
||||||
|
}
|
||||||
|
if(++Matches > m_SelectionOffset)
|
||||||
|
{
|
||||||
|
m_SelectionOffset++;
|
||||||
|
MatchedGroup = HoverTile.m_Group;
|
||||||
|
MatchedLayer = HoverTile.m_Layer;
|
||||||
|
IsFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(MatchedGroup != -1 && MatchedLayer != -1)
|
||||||
|
{
|
||||||
|
if(!IsFound)
|
||||||
|
m_SelectionOffset = 1;
|
||||||
|
Editor()->SelectLayer(MatchedLayer, MatchedGroup);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
15
src/game/editor/layer_selector.h
Normal file
15
src/game/editor/layer_selector.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef GAME_EDITOR_LAYER_SELECTOR_H
|
||||||
|
#define GAME_EDITOR_LAYER_SELECTOR_H
|
||||||
|
|
||||||
|
#include "component.h"
|
||||||
|
|
||||||
|
class CLayerSelector : public CEditorComponent
|
||||||
|
{
|
||||||
|
int m_SelectionOffset;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void Init(CEditor *pEditor) override;
|
||||||
|
bool SelectByTile();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue