added the possibility to shift the tiles of a layer into any direction

This commit is contained in:
oy 2010-10-09 18:38:23 +02:00
parent ab2df14641
commit b3c81e7258
3 changed files with 76 additions and 2 deletions

View file

@ -1668,6 +1668,41 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIds, int *
Change = i;
}
}
else if(pProps[i].m_Type == PROPTYPE_SHIFT)
{
CUIRect Left, Right, Up, Down;
Shifter.VSplitMid(&Left, &Up);
Left.VSplitRight(1.0f, &Left, 0);
Up.VSplitLeft(1.0f, 0, &Up);
Left.VSplitLeft(10.0f, &Left, &Shifter);
Shifter.VSplitRight(10.0f, &Shifter, &Right);
RenderTools()->DrawUIRect(&Shifter, vec4(1,1,1,0.5f), 0, 0.0f);
UI()->DoLabel(&Shifter, "X", 10.0f, 0, -1);
Up.VSplitLeft(10.0f, &Up, &Shifter);
Shifter.VSplitRight(10.0f, &Shifter, &Down);
RenderTools()->DrawUIRect(&Shifter, vec4(1,1,1,0.5f), 0, 0.0f);
UI()->DoLabel(&Shifter, "Y", 10.0f, 0, -1);
if(DoButton_ButtonDec(&pIds[i], "-", 0, &Left, 0, Localize("Left")))
{
*pNewVal = 1;
Change = i;
}
if(DoButton_ButtonInc(((char *)&pIds[i])+3, "+", 0, &Right, 0, Localize("Right")))
{
*pNewVal = 2;
Change = i;
}
if(DoButton_ButtonDec(((char *)&pIds[i])+1, "-", 0, &Up, 0, Localize("Up")))
{
*pNewVal = 4;
Change = i;
}
if(DoButton_ButtonInc(((char *)&pIds[i])+2, "+", 0, &Down, 0, Localize("Down")))
{
*pNewVal = 8;
Change = i;
}
}
}
return Change;
@ -1779,7 +1814,7 @@ void CEditor::RenderLayers(CUIRect ToolBox, CUIRect ToolBar, CUIRect View)
m_SelectedGroup = g;
static int s_LayerPopupId = 0;
if(Result == 2)
UiInvokePopupMenu(&s_LayerPopupId, 0, UI()->MouseX(), UI()->MouseY(), 120, 150, PopupLayer);
UiInvokePopupMenu(&s_LayerPopupId, 0, UI()->MouseX(), UI()->MouseY(), 120, 180, PopupLayer);
}
LayerCur += 14.0f;

View file

@ -340,6 +340,7 @@ enum
PROPTYPE_COLOR,
PROPTYPE_IMAGE,
PROPTYPE_ENVELOPE,
PROPTYPE_SHIFT,
};
typedef struct
@ -355,6 +356,7 @@ public:
~CLayerTiles();
void Resize(int NewW, int NewH);
void Shift(int Direction);
void MakePalette();
virtual void Render();

View file

@ -280,6 +280,39 @@ void CLayerTiles::Resize(int NewW, int NewH)
m_Height = NewH;
}
void CLayerTiles::Shift(int Direction)
{
switch(Direction)
{
case 1:
{
// left
for(int y = 0; y < m_Height; ++y)
mem_move(&m_pTiles[y*m_Width], &m_pTiles[y*m_Width+1], (m_Width-1)*sizeof(CTile));
}
break;
case 2:
{
// right
for(int y = 0; y < m_Height; ++y)
mem_move(&m_pTiles[y*m_Width+1], &m_pTiles[y*m_Width], (m_Width-1)*sizeof(CTile));
}
break;
case 4:
{
// up
for(int y = 0; y < m_Height-1; ++y)
mem_copy(&m_pTiles[y*m_Width], &m_pTiles[(y+1)*m_Width], m_Width*sizeof(CTile));
}
break;
case 8:
{
// down
for(int y = m_Height-1; y > 0; --y)
mem_copy(&m_pTiles[y*m_Width], &m_pTiles[(y-1)*m_Width], m_Width*sizeof(CTile));
}
}
}
int CLayerTiles::RenderProperties(CUIRect *pToolBox)
{
@ -327,6 +360,7 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox)
{
PROP_WIDTH=0,
PROP_HEIGHT,
PROP_SHIFT,
PROP_IMAGE,
NUM_PROPS,
};
@ -334,12 +368,13 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox)
CProperty aProps[] = {
{Localize("Width"), m_Width, PROPTYPE_INT_SCROLL, 1, 1000000000},
{Localize("Height"), m_Height, PROPTYPE_INT_SCROLL, 1, 1000000000},
{Localize("Shift"), 0, PROPTYPE_SHIFT, 0, 0},
{Localize("Image"), m_Image, PROPTYPE_IMAGE, 0, 0},
{0},
};
if(m_pEditor->m_Map.m_pGameLayer == this) // remove the image from the selection if this is the game layer
aProps[2].m_pName = 0;
aProps[3].m_pName = 0;
static int s_aIds[NUM_PROPS] = {0};
int NewVal = 0;
@ -349,6 +384,8 @@ int CLayerTiles::RenderProperties(CUIRect *pToolBox)
Resize(NewVal, m_Height);
else if(Prop == PROP_HEIGHT && NewVal > 1)
Resize(m_Width, NewVal);
else if(Prop == PROP_SHIFT)
Shift(NewVal);
else if(Prop == PROP_IMAGE)
{
if (NewVal == -1)