From 367bb4b8372dd8c19445c599df3b30ac6aed04d9 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 14 Aug 2011 16:31:48 +0200 Subject: [PATCH] Map Editor: Envelope Preview --- src/game/editor/editor.cpp | 209 ++++++++++++++++++++++++++++++++++++- src/game/editor/editor.h | 12 ++- 2 files changed, 219 insertions(+), 2 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 3d655e718..9280cb5fb 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -1391,6 +1391,180 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V) Graphics()->QuadsDraw(&QuadItem, 1); } +//H-Client +void CEditor::DoQuadEnvelopes(CQuad *q, int Index, int texID) +{ + CEnvelope *pEnvelope = 0x0; + if(q->m_PosEnv >= 0 && q->m_PosEnv < m_Map.m_lEnvelopes.size()) + pEnvelope = m_Map.m_lEnvelopes[q->m_PosEnv]; + if (!pEnvelope) + return; + + //QuadParams + CPoint *pPoints = q->m_aPoints; + + //Draw Lines + Graphics()->TextureSet(-1); + Graphics()->LinesBegin(); + Graphics()->SetColor(80.0f/255, 150.0f/255, 230.f/255, 0.5f); + for(int i = 0; i < pEnvelope->m_lPoints.size()-1; i++) + { + float OffsetX = 0; + float OffsetY = 0; + + OffsetX = fx2f(pEnvelope->m_lPoints[i].m_aValues[0]); + OffsetY = fx2f(pEnvelope->m_lPoints[i].m_aValues[1]); + vec2 pos0 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); + + OffsetX = fx2f(pEnvelope->m_lPoints[i+1].m_aValues[0]); + OffsetY = fx2f(pEnvelope->m_lPoints[i+1].m_aValues[1]); + vec2 pos1 = vec2(fx2f(pPoints[4].x)+OffsetX, fx2f(pPoints[4].y)+OffsetY); + + IGraphics::CLineItem uLine = IGraphics::CLineItem(pos0.x, pos0.y, pos1.x, pos1.y); + Graphics()->LinesDraw(&uLine, 1); + } + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + Graphics()->LinesEnd(); + + //Draw Quads + Graphics()->TextureSet(texID); + Graphics()->QuadsBegin(); + for(int i = 0; i < pEnvelope->m_lPoints.size(); i++) + { + float OffsetX = 0; + float OffsetY = 0; + float Rot = 0; + + //Calc Env Position + OffsetX = fx2f(pEnvelope->m_lPoints[i].m_aValues[0]); + OffsetY = fx2f(pEnvelope->m_lPoints[i].m_aValues[1]); + Rot = fx2f(pEnvelope->m_lPoints[i].m_aValues[2])/360.0f*pi*2; + + //Set Colours + IGraphics::CColorVertex CArray[4] = { + IGraphics::CColorVertex(0, q->m_aColors[0].r, q->m_aColors[0].g, q->m_aColors[0].b, (m_SelectedQuadEnvelope == q->m_PosEnv && m_SelectedEnvelopeChannel == i)?0.65:0.35f), + IGraphics::CColorVertex(1, q->m_aColors[1].r, q->m_aColors[1].g, q->m_aColors[1].b, (m_SelectedQuadEnvelope == q->m_PosEnv && m_SelectedEnvelopeChannel == i)?0.65:0.35f), + IGraphics::CColorVertex(2, q->m_aColors[2].r, q->m_aColors[2].g, q->m_aColors[2].b, (m_SelectedQuadEnvelope == q->m_PosEnv && m_SelectedEnvelopeChannel == i)?0.65:0.35f), + IGraphics::CColorVertex(3, q->m_aColors[3].r, q->m_aColors[3].g, q->m_aColors[3].b, (m_SelectedQuadEnvelope == q->m_PosEnv && m_SelectedEnvelopeChannel == i)?0.65:0.35f)}; + Graphics()->SetColorVertex(CArray, 4); + + //Rotation + if(Rot != 0) + { + static CPoint aRotated[4]; + aRotated[0] = q->m_aPoints[0]; + aRotated[1] = q->m_aPoints[1]; + aRotated[2] = q->m_aPoints[2]; + aRotated[3] = q->m_aPoints[3]; + pPoints = aRotated; + + Rotate(&q->m_aPoints[4], &aRotated[0], Rot); + Rotate(&q->m_aPoints[4], &aRotated[1], Rot); + Rotate(&q->m_aPoints[4], &aRotated[2], Rot); + Rotate(&q->m_aPoints[4], &aRotated[3], Rot); + } + + //Set Texture Coords + Graphics()->QuadsSetSubsetFree( + fx2f(q->m_aTexcoords[0].x), fx2f(q->m_aTexcoords[0].y), + fx2f(q->m_aTexcoords[1].x), fx2f(q->m_aTexcoords[1].y), + fx2f(q->m_aTexcoords[2].x), fx2f(q->m_aTexcoords[2].y), + fx2f(q->m_aTexcoords[3].x), fx2f(q->m_aTexcoords[3].y) + ); + + //Set Quad Coords & Draw + IGraphics::CFreeformItem Freeform( + fx2f(pPoints[0].x)+OffsetX, fx2f(pPoints[0].y)+OffsetY, + fx2f(pPoints[1].x)+OffsetX, fx2f(pPoints[1].y)+OffsetY, + fx2f(pPoints[2].x)+OffsetX, fx2f(pPoints[2].y)+OffsetY, + fx2f(pPoints[3].x)+OffsetX, fx2f(pPoints[3].y)+OffsetY); + Graphics()->QuadsDrawFreeform(&Freeform, 1); + + DoQuadEnvPoint(q, 1, i); + } + Graphics()->QuadsEnd(); + Graphics()->TextureSet(-1); +} + +void CEditor::DoQuadEnvPoint(CQuad *pQuad, int Index, int V) +{ + enum + { + OP_NONE=0, + OP_MOVE_PIVOT, + }; + + // some basic values + static float s_LastWx; + static float s_LastWy; + static int s_Operation = OP_NONE; + float wx = UI()->MouseWorldX(); + float wy = UI()->MouseWorldY(); + CEnvelope *pEnvelope = m_Map.m_lEnvelopes[pQuad->m_PosEnv]; + void *pID = &pEnvelope->m_lPoints[V]; + + // get pivot + float CenterX = fx2f(pQuad->m_aPoints[4].x)+fx2f(pEnvelope->m_lPoints[V].m_aValues[0]); + float CenterY = fx2f(pQuad->m_aPoints[4].y)+fx2f(pEnvelope->m_lPoints[V].m_aValues[1]); + + float dx = (CenterX - wx)/m_WorldZoom; + float dy = (CenterY - wy)/m_WorldZoom; + if(dx*dx+dy*dy < 50) + UI()->SetHotItem(pID); + + if(UI()->ActiveItem() == pID) + { + // check if we only should move pivot + if(s_Operation == OP_MOVE_PIVOT) + { + pEnvelope->m_lPoints[V].m_aValues[0] += f2fx(wx-s_LastWx); + pEnvelope->m_lPoints[V].m_aValues[1] += f2fx(wy-s_LastWy); + } + + s_LastWx = wx; + s_LastWy = wy; + + if(!UI()->MouseButton(0)) + { + m_LockMouse = false; + s_Operation = OP_NONE; + UI()->SetActiveItem(0); + } + + Graphics()->SetColor(1,1,1,1); + } + else if(UI()->HotItem() == pID) + { + ms_pUiGotContext = pID; + + Graphics()->SetColor(1,1,1,1); + //m_pTooltip = ""; + + if(UI()->MouseButton(0)) + { + s_Operation = OP_MOVE_PIVOT; + + m_SelectedEnvelopeChannel = V; + m_SelectedQuadEnvelope = pQuad->m_PosEnv; + + UI()->SetActiveItem(pID); + m_SelectedQuad = Index; + s_LastWx = wx; + s_LastWy = wy; + } + else + { + m_SelectedEnvelopeChannel = -1; + m_SelectedQuadEnvelope = -1; + } + } + else + Graphics()->SetColor(0,1,0,1); + + IGraphics::CQuadItem QuadItem(CenterX, CenterY, 5.0f*m_WorldZoom, 5.0f*m_WorldZoom); + Graphics()->QuadsDraw(&QuadItem, 1); +} + void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar) { // render all good stuff @@ -1688,6 +1862,8 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar) if(pEditLayers[k]->m_Type == LAYERTYPE_QUADS) { CLayerQuads *pLayer = (CLayerQuads *)pEditLayers[k]; + + m_ShowEnvelopePreview = 2; Graphics()->TextureSet(-1); Graphics()->QuadsBegin(); @@ -1846,6 +2022,24 @@ void CEditor::DoMapEditor(CUIRect View, CUIRect ToolBar) Graphics()->LinesEnd(); } + if (!m_ShowPicker && m_ShowTileInfo && m_ShowEnvelopePreview != 0 && GetSelectedLayer(0) && GetSelectedLayer(0)->m_Type == LAYERTYPE_QUADS) + { + GetSelectedGroup()->MapScreen(); + + CLayerQuads *pLayer = (CLayerQuads*)GetSelectedLayer(0); + int texID = -1; + if(pLayer->m_Image >= 0 && pLayer->m_Image < m_Map.m_lImages.size()) + texID = m_Map.m_lImages[pLayer->m_Image]->m_TexID; + + for(int i = 0; i < pLayer->m_lQuads.size(); i++) + { + if ((m_ShowEnvelopePreview == 1 && pLayer->m_lQuads[i].m_PosEnv == m_SelectedEnvelope) || m_ShowEnvelopePreview == 2) + DoQuadEnvelopes(&pLayer->m_lQuads[i], i, texID); + } + + m_ShowEnvelopePreview = 0; + } + Graphics()->MapScreen(UI()->Screen()->x, UI()->Screen()->y, UI()->Screen()->w, UI()->Screen()->h); //UI()->ClipDisable(); } @@ -2991,6 +3185,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) m_Map.m_Modified = true; } + m_ShowEnvelopePreview = 1; m_pTooltip = "Press right mouse button to create a new point"; } } @@ -3129,6 +3324,9 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) { if(!UI()->MouseButton(0)) { + m_SelectedQuadEnvelope = -1; + m_SelectedEnvelopeChannel = -1; + UI()->SetActiveItem(0); } else @@ -3154,6 +3352,9 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) else pEnvelope->m_lPoints[i].m_aValues[c] -= f2fx(m_MouseDeltaY*ValueScale); } + + m_SelectedQuadEnvelope = m_SelectedEnvelope; + m_SelectedEnvelopeChannel = i; m_Map.m_Modified = true; } @@ -3176,6 +3377,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) m_Map.m_Modified = true; } + m_ShowEnvelopePreview = 1; ColorMod = 100.0f; Graphics()->SetColor(1,0.75f,0.75f,1); m_pTooltip = "Left mouse to drag. Hold ctrl to be more precise. Hold shift to alter time point aswell. Right click to delete."; @@ -3187,7 +3389,10 @@ void CEditor::RenderEnvelopeEditor(CUIRect View) CurrentValue = pEnvelope->m_lPoints[i].m_aValues[c]; } - Graphics()->SetColor(aColors[c].r*ColorMod, aColors[c].g*ColorMod, aColors[c].b*ColorMod, 1.0f); + if (m_SelectedQuadEnvelope == m_SelectedEnvelope && m_SelectedEnvelopeChannel == i) + Graphics()->SetColor(1.0f, 1.0f, 1.0f, 1.0f); + else + Graphics()->SetColor(aColors[c].r*ColorMod, aColors[c].g*ColorMod, aColors[c].b*ColorMod, 1.0f); IGraphics::CQuadItem QuadItem(Final.x, Final.y, Final.w, Final.h); Graphics()->QuadsDrawTL(&QuadItem, 1); } @@ -3503,6 +3708,8 @@ void CEditor::Reset(bool CreateDefault) m_MouseDeltaWy = 0; m_Map.m_Modified = false; + + m_ShowEnvelopePreview = 0; } int CEditor::GetLineDistance() diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index bdabd43fe..2c94f3f24 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -529,6 +529,10 @@ public: m_ShowEnvelopeEditor = 0; + m_ShowEnvelopePreview = 0; + m_SelectedQuadEnvelope = -1; + m_SelectedEnvelopeChannel = -1; + ms_CheckerTexture = 0; ms_BackgroundTexture = 0; ms_CursorTexture = 0; @@ -646,13 +650,16 @@ public: float m_AnimateSpeed; int m_ShowEnvelopeEditor; + int m_ShowEnvelopePreview; //Values: 0-Off|1-Selected Envelope|2-All bool m_ShowPicker; int m_SelectedLayer; int m_SelectedGroup; int m_SelectedQuad; int m_SelectedPoints; - int m_SelectedEnvelope; + int m_SelectedEnvelope; + int m_SelectedEnvelopeChannel; + int m_SelectedQuadEnvelope; int m_SelectedImage; static int ms_CheckerTexture; @@ -721,7 +728,10 @@ public: vec4 ButtonColorMul(const void *pID); + void DoQuadEnvelopes(CQuad *q, int Index, int texID = -1); + void DoQuadEnvPoint(CQuad *pQuad, int Index, int V); void DoQuadPoint(CQuad *pQuad, int QuadIndex, int v); + void DoMapEditor(CUIRect View, CUIRect Toolbar); void DoToolbar(CUIRect Toolbar); void DoQuad(CQuad *pQuad, int Index);