Merge "Add Quad/Sound" + shortcut to add them at mouse position, add quads true to size

This commit is contained in:
12pm 2019-03-28 13:41:07 +01:00
parent aa98bf824a
commit 427171bb17
4 changed files with 72 additions and 63 deletions

View file

@ -1389,55 +1389,68 @@ void CEditor::DoToolbar(CUIRect ToolBar)
m_GridFactor++;
}
// sound source manipulation
{
// do add button
TB_Bottom.VSplitLeft(5.0f, &Button, &TB_Bottom);
// do add quad/sound button
TB_Bottom.VSplitLeft(60.0f, &Button, &TB_Bottom);
static int s_NewButton = 0;
{
const char *pButtonText = "Add Item";
const char *pButtonToolTip = "[ctrl+q] Add a new item";
int Checked = -1;
CLayerSounds *pSoundLayer = (CLayerSounds *)GetSelectedLayerType(0, LAYERTYPE_SOUNDS);
if(DoButton_Editor(&s_NewButton, "Add Sound", pSoundLayer?0:-1, &Button, 0, "Adds a new sound source"))
CLayer *pLayer = GetSelectedLayer(0);
if(pLayer)
{
if(pSoundLayer)
if(pLayer->m_Type == LAYERTYPE_QUADS)
{
pButtonText = "Add Quad";
pButtonToolTip = "[ctrl+q] Add a new quad";
Checked = 0;
}
else if(pLayer->m_Type == LAYERTYPE_SOUNDS)
{
pButtonText = "Add Sound";
pButtonToolTip = "[ctrl+q] Add a new sound source";
Checked = 0;
}
}
static int s_AddItemButton = 0;
if(DoButton_Editor(&s_AddItemButton, pButtonText, Checked, &Button, 0, pButtonToolTip) ||
(Input()->KeyPress(KEY_Q) && (Input()->KeyIsPressed(KEY_LCTRL) || Input()->KeyIsPressed(KEY_RCTRL))))
{
if(pLayer)
{
CLayerGroup *pGroup = GetSelectedGroup();
float Mapping[4];
CLayerGroup *g = GetSelectedGroup();
g->Mapping(Mapping);
int AddX = f2fx(Mapping[0] + (Mapping[2]-Mapping[0])/2);
int AddY = f2fx(Mapping[1] + (Mapping[3]-Mapping[1])/2);
CSoundSource *pSource = pSoundLayer->NewSource();
pSource->m_Position.x += AddX;
pSource->m_Position.y += AddY;
}
}
pGroup->Mapping(Mapping);
int x = Mapping[0] + (Mapping[2]-Mapping[0]) / 2;
int y = Mapping[1] + (Mapping[3]-Mapping[1]) / 2;
if(Input()->KeyPress(KEY_Q) && (Input()->KeyIsPressed(KEY_LCTRL) || Input()->KeyIsPressed(KEY_RCTRL)))
{
x += UI()->MouseWorldX() - (m_WorldOffsetX*pGroup->m_ParallaxX/100) - pGroup->m_OffsetX;
y += UI()->MouseWorldY() - (m_WorldOffsetY*pGroup->m_ParallaxY/100) - pGroup->m_OffsetY;
}
// quad manipulation
if(pLayer->m_Type == LAYERTYPE_QUADS)
{
// do add button
TB_Bottom.VSplitLeft(5.0f, &Button, &TB_Bottom);
TB_Bottom.VSplitLeft(60.0f, &Button, &TB_Bottom);
static int s_NewButton = 0;
CLayerQuads *pQuadLayer = (CLayerQuads *)pLayer;
CLayerQuads *pQLayer = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS);
//CLayerTiles *tlayer = (CLayerTiles *)get_selected_layer_type(0, LAYERTYPE_TILES);
if(DoButton_Editor(&s_NewButton, "Add Quad", pQLayer?0:-1, &Button, 0, "Adds a new quad"))
int Width = 64;
int Height = 64;
if(pQuadLayer->m_Image >= 0)
{
if(pQLayer)
{
float Mapping[4];
CLayerGroup *g = GetSelectedGroup();
g->Mapping(Mapping);
int AddX = f2fx(Mapping[0] + (Mapping[2]-Mapping[0])/2);
int AddY = f2fx(Mapping[1] + (Mapping[3]-Mapping[1])/2);
Width = m_Map.m_lImages[pQuadLayer->m_Image]->m_Width;
Height = m_Map.m_lImages[pQuadLayer->m_Image]->m_Height;
}
CQuad *q = pQLayer->NewQuad();
for(int i = 0; i < 5; i++)
pQuadLayer->NewQuad(x, y, Width, Height);
}
else if(pLayer->m_Type == LAYERTYPE_SOUNDS)
{
q->m_aPoints[i].x += AddX;
q->m_aPoints[i].y += AddY;
CLayerSounds *pSoundLayer = (CLayerSounds *)pLayer;
pSoundLayer->NewSource(x, y);
}
}
}
@ -5955,13 +5968,7 @@ void CEditorMap::CreateDefault(int EntitiesTexture)
pGroup->m_ParallaxY = 0;
CLayerQuads *pLayer = new CLayerQuads;
pLayer->m_pEditor = m_pEditor;
CQuad *pQuad = pLayer->NewQuad();
const int Width = 800000;
const int Height = 600000;
pQuad->m_aPoints[0].x = pQuad->m_aPoints[2].x = -Width;
pQuad->m_aPoints[1].x = pQuad->m_aPoints[3].x = Width;
pQuad->m_aPoints[0].y = pQuad->m_aPoints[1].y = -Height;
pQuad->m_aPoints[2].y = pQuad->m_aPoints[3].y = Height;
CQuad *pQuad = pLayer->NewQuad(0, 0, 1600, 1200);
pQuad->m_aColors[0].r = pQuad->m_aColors[1].r = 94;
pQuad->m_aColors[0].g = pQuad->m_aColors[1].g = 132;
pQuad->m_aColors[0].b = pQuad->m_aColors[1].b = 174;
@ -6011,7 +6018,7 @@ void CEditor::Init()
m_TilesetPicker.m_Readonly = true;
m_QuadsetPicker.m_pEditor = this;
m_QuadsetPicker.NewQuad();
m_QuadsetPicker.NewQuad(0, 0, 64, 64);
m_QuadsetPicker.m_Readonly = true;
m_Brush.m_pMap = &m_Map;

View file

@ -584,7 +584,7 @@ public:
~CLayerQuads();
virtual void Render(bool QuadPicker = false);
CQuad *NewQuad();
CQuad *NewQuad(int x, int y, int Width, int Height);
virtual void BrushSelecting(CUIRect Rect);
virtual int BrushGrab(CLayerGroup *pBrush, CUIRect Rect);
@ -1173,7 +1173,7 @@ public:
~CLayerSounds();
virtual void Render(bool Tileset = false);
CSoundSource *NewSource();
CSoundSource *NewSource(int x, int y);
virtual void BrushSelecting(CUIRect Rect);
virtual int BrushGrab(CLayerGroup *pBrush, CUIRect Rect);

View file

@ -33,7 +33,7 @@ void CLayerQuads::Render(bool QuadPicker)
m_pEditor->RenderTools()->ForceRenderQuads(m_lQuads.base_ptr(), m_lQuads.size(), LAYERRENDERFLAG_TRANSPARENT, m_pEditor->EnvelopeEval, m_pEditor);
}
CQuad *CLayerQuads::NewQuad()
CQuad *CLayerQuads::NewQuad(int x, int y, int Width, int Height)
{
m_pEditor->m_Map.m_Modified = true;
@ -43,18 +43,20 @@ CQuad *CLayerQuads::NewQuad()
q->m_ColorEnv = -1;
q->m_PosEnvOffset = 0;
q->m_ColorEnvOffset = 0;
int x = 0, y = 0;
q->m_aPoints[0].x = x;
q->m_aPoints[0].y = y;
q->m_aPoints[1].x = x+64;
q->m_aPoints[1].y = y;
q->m_aPoints[2].x = x;
q->m_aPoints[2].y = y+64;
q->m_aPoints[3].x = x+64;
q->m_aPoints[3].y = y+64;
q->m_aPoints[4].x = x+32; // pivot
q->m_aPoints[4].y = y+32;
Width /= 2;
Height /= 2;
q->m_aPoints[0].x = x - Width;
q->m_aPoints[0].y = y - Height;
q->m_aPoints[1].x = x + Width;
q->m_aPoints[1].y = y - Height;
q->m_aPoints[2].x = x - Width;
q->m_aPoints[2].y = y + Height;
q->m_aPoints[3].x = x + Width;
q->m_aPoints[3].y = y + Height;
q->m_aPoints[4].x = x; // pivot
q->m_aPoints[4].y = y;
for(int i = 0; i < 5; i++)
{

View file

@ -99,14 +99,14 @@ void CLayerSounds::Render(bool Tileset)
Graphics()->QuadsEnd();
}
CSoundSource *CLayerSounds::NewSource()
CSoundSource *CLayerSounds::NewSource(int x, int y)
{
m_pEditor->m_Map.m_Modified = true;
CSoundSource *pSource = &m_lSources[m_lSources.add(CSoundSource())];
pSource->m_Position.x = 0;
pSource->m_Position.y = 0;
pSource->m_Position.x = f2fx(x);
pSource->m_Position.y = f2fx(y);
pSource->m_Loop = 1;
pSource->m_Pan = 1;