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

View file

@ -584,7 +584,7 @@ public:
~CLayerQuads(); ~CLayerQuads();
virtual void Render(bool QuadPicker = false); virtual void Render(bool QuadPicker = false);
CQuad *NewQuad(); CQuad *NewQuad(int x, int y, int Width, int Height);
virtual void BrushSelecting(CUIRect Rect); virtual void BrushSelecting(CUIRect Rect);
virtual int BrushGrab(CLayerGroup *pBrush, CUIRect Rect); virtual int BrushGrab(CLayerGroup *pBrush, CUIRect Rect);
@ -1173,7 +1173,7 @@ public:
~CLayerSounds(); ~CLayerSounds();
virtual void Render(bool Tileset = false); virtual void Render(bool Tileset = false);
CSoundSource *NewSource(); CSoundSource *NewSource(int x, int y);
virtual void BrushSelecting(CUIRect Rect); virtual void BrushSelecting(CUIRect Rect);
virtual int BrushGrab(CLayerGroup *pBrush, 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); 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; m_pEditor->m_Map.m_Modified = true;
@ -43,18 +43,20 @@ CQuad *CLayerQuads::NewQuad()
q->m_ColorEnv = -1; q->m_ColorEnv = -1;
q->m_PosEnvOffset = 0; q->m_PosEnvOffset = 0;
q->m_ColorEnvOffset = 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 Width /= 2;
q->m_aPoints[4].y = y+32; 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++) for(int i = 0; i < 5; i++)
{ {

View file

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