added possibility to delete envelopes and to save their names within a map by sushitee

This commit is contained in:
oy 2010-08-06 20:18:53 +02:00
parent 05f3757491
commit 2967c57ddc
4 changed files with 61 additions and 16 deletions

View file

@ -2286,31 +2286,18 @@ void CEditor::RenderStatusbar(CUIRect View)
void CEditor::RenderEnvelopeEditor(CUIRect View) void CEditor::RenderEnvelopeEditor(CUIRect View)
{ {
if(m_SelectedEnvelope < 0) m_SelectedEnvelope = 0; if(m_SelectedEnvelope < 0) m_SelectedEnvelope = 0;
if(m_SelectedEnvelope >= m_Map.m_lEnvelopes.size()) m_SelectedEnvelope--; if(m_SelectedEnvelope >= m_Map.m_lEnvelopes.size()) m_SelectedEnvelope = m_Map.m_lEnvelopes.size()-1;
CEnvelope *pEnvelope = 0; CEnvelope *pEnvelope = 0;
if(m_SelectedEnvelope >= 0 && m_SelectedEnvelope < m_Map.m_lEnvelopes.size()) if(m_SelectedEnvelope >= 0 && m_SelectedEnvelope < m_Map.m_lEnvelopes.size())
pEnvelope = m_Map.m_lEnvelopes[m_SelectedEnvelope]; pEnvelope = m_Map.m_lEnvelopes[m_SelectedEnvelope];
bool ShowColorBar = false;
if(pEnvelope && pEnvelope->m_Channels == 4)
ShowColorBar = true;
CUIRect ToolBar, CurveBar, ColorBar; CUIRect ToolBar, CurveBar, ColorBar;
View.HSplitTop(15.0f, &ToolBar, &View); View.HSplitTop(15.0f, &ToolBar, &View);
View.HSplitTop(15.0f, &CurveBar, &View); View.HSplitTop(15.0f, &CurveBar, &View);
ToolBar.Margin(2.0f, &ToolBar); ToolBar.Margin(2.0f, &ToolBar);
CurveBar.Margin(2.0f, &CurveBar); CurveBar.Margin(2.0f, &CurveBar);
if(ShowColorBar)
{
View.HSplitTop(20.0f, &ColorBar, &View);
ColorBar.Margin(2.0f, &ColorBar);
RenderBackground(ColorBar, ms_CheckerTexture, 16.0f, 1.0f);
}
RenderBackground(View, ms_CheckerTexture, 32.0f, 0.1f);
// do the toolbar // do the toolbar
{ {
CUIRect Button; CUIRect Button;
@ -2327,6 +2314,21 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
if(DoButton_Editor(&s_New2dButton, Localize("Pos.+"), 0, &Button, 0, Localize("Creates a new pos envelope"))) if(DoButton_Editor(&s_New2dButton, Localize("Pos.+"), 0, &Button, 0, Localize("Creates a new pos envelope")))
pNewEnv = m_Map.NewEnvelope(3); pNewEnv = m_Map.NewEnvelope(3);
// Delete button
if(m_SelectedEnvelope >= 0)
{
ToolBar.VSplitRight(10.0f, &ToolBar, &Button);
ToolBar.VSplitRight(50.0f, &ToolBar, &Button);
static int s_DelButton = 0;
if(DoButton_Editor(&s_DelButton, Localize("Delete"), 0, &Button, 0, Localize("Delete this envelope")))
{
m_Map.DeleteEnvelope(m_SelectedEnvelope);
if(m_SelectedEnvelope >= m_Map.m_lEnvelopes.size())
m_SelectedEnvelope = m_Map.m_lEnvelopes.size()-1;
pEnvelope = m_SelectedEnvelope >= 0 ? m_Map.m_lEnvelopes[m_SelectedEnvelope] : 0;
}
}
if(pNewEnv) // add the default points if(pNewEnv) // add the default points
{ {
if(pNewEnv->m_Channels == 4) if(pNewEnv->m_Channels == 4)
@ -2371,6 +2373,17 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
} }
} }
bool ShowColorBar = false;
if(pEnvelope && pEnvelope->m_Channels == 4)
{
ShowColorBar = true;
View.HSplitTop(20.0f, &ColorBar, &View);
ColorBar.Margin(2.0f, &ColorBar);
RenderBackground(ColorBar, ms_CheckerTexture, 16.0f, 1.0f);
}
RenderBackground(View, ms_CheckerTexture, 32.0f, 0.1f);
if(pEnvelope) if(pEnvelope)
{ {
static array<int> Selection; static array<int> Selection;
@ -2900,6 +2913,33 @@ void CEditor::Reset(bool CreateDefault)
m_MouseDeltaWy = 0; m_MouseDeltaWy = 0;
} }
void CEditorMap::DeleteEnvelope(int Index)
{
if(Index < 0 || Index >= m_lEnvelopes.size())
return;
// fix links between envelopes and quads
for(int i = 0; i < m_lGroups.size(); ++i)
for(int j = 0; j < m_lGroups[i]->m_lLayers.size(); ++j)
if(m_lGroups[i]->m_lLayers[j]->m_Type == LAYERTYPE_QUADS)
{
CLayerQuads *Layer = static_cast<CLayerQuads *>(m_lGroups[i]->m_lLayers[j]);
for(int k = 0; k < Layer->m_lQuads.size(); ++k)
{
if(Layer->m_lQuads[k].m_PosEnv == Index)
Layer->m_lQuads[k].m_PosEnv = -1;
else if(Layer->m_lQuads[k].m_PosEnv > Index)
Layer->m_lQuads[k].m_PosEnv--;
if(Layer->m_lQuads[k].m_ColorEnv == Index)
Layer->m_lQuads[k].m_ColorEnv = -1;
else if(Layer->m_lQuads[k].m_ColorEnv > Index)
Layer->m_lQuads[k].m_ColorEnv--;
}
}
m_lEnvelopes.remove_index(Index);
}
void CEditorMap::MakeGameLayer(CLayer *pLayer) void CEditorMap::MakeGameLayer(CLayer *pLayer)
{ {
m_pGameLayer = (CLayerGame *)pLayer; m_pGameLayer = (CLayerGame *)pLayer;

View file

@ -273,6 +273,8 @@ public:
return e; return e;
} }
void DeleteEnvelope(int Index);
CLayerGroup *NewGroup() CLayerGroup *NewGroup()
{ {
CLayerGroup *g = new CLayerGroup; CLayerGroup *g = new CLayerGroup;

View file

@ -1,5 +1,6 @@
#include <engine/graphics.h> #include <engine/graphics.h>
#include <engine/storage.h> #include <engine/storage.h>
#include <game/gamecore.h>
#include "ed_editor.h" #include "ed_editor.h"
template<typename T> template<typename T>
@ -323,7 +324,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
Item.m_Channels = m_lEnvelopes[e]->m_Channels; Item.m_Channels = m_lEnvelopes[e]->m_Channels;
Item.m_StartPoint = PointCount; Item.m_StartPoint = PointCount;
Item.m_NumPoints = m_lEnvelopes[e]->m_lPoints.size(); Item.m_NumPoints = m_lEnvelopes[e]->m_lPoints.size();
Item.m_Name = -1; StrToInts(Item.m_aName, sizeof(Item.m_aName)/sizeof(int), m_lEnvelopes[e]->m_aName);
df.AddItem(MAPITEMTYPE_ENVELOPE, e, sizeof(Item), &Item); df.AddItem(MAPITEMTYPE_ENVELOPE, e, sizeof(Item), &Item);
PointCount += Item.m_NumPoints; PointCount += Item.m_NumPoints;
@ -552,6 +553,8 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName)
CEnvelope *pEnv = new CEnvelope(pItem->m_Channels); CEnvelope *pEnv = new CEnvelope(pItem->m_Channels);
pEnv->m_lPoints.set_size(pItem->m_NumPoints); pEnv->m_lPoints.set_size(pItem->m_NumPoints);
mem_copy(pEnv->m_lPoints.base_ptr(), &pPoints[pItem->m_StartPoint], sizeof(CEnvPoint)*pItem->m_NumPoints); mem_copy(pEnv->m_lPoints.base_ptr(), &pPoints[pItem->m_StartPoint], sizeof(CEnvPoint)*pItem->m_NumPoints);
if(pItem->m_aName[0] != -1) // compatibility with old maps
IntsToStr(pItem->m_aName, sizeof(pItem->m_aName)/sizeof(int), pEnv->m_aName);
m_lEnvelopes.add(pEnv); m_lEnvelopes.add(pEnv);
} }
} }

View file

@ -174,7 +174,7 @@ struct CMapItemEnvelope
int m_Channels; int m_Channels;
int m_StartPoint; int m_StartPoint;
int m_NumPoints; int m_NumPoints;
int m_Name; int m_aName[8];
} ; } ;
#endif #endif