From 995d63d7f447d68771f0ea87a599a0d804cff8d3 Mon Sep 17 00:00:00 2001 From: oy Date: Sun, 5 Sep 2010 19:01:01 +0200 Subject: added the possibility to rotate tiles in the editor by SushiTee --- src/game/client/render_map.cpp | 42 ++++++++++++++++++++++++++++---------- src/game/editor/ed_editor.cpp | 19 ++++++++++++----- src/game/editor/ed_editor.h | 3 ++- src/game/editor/ed_layer_tiles.cpp | 40 +++++++++++++++++++++++++++++++++--- src/game/mapitems.h | 1 + 5 files changed, 85 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/game/client/render_map.cpp b/src/game/client/render_map.cpp index 2d0875ca..1af41f99 100644 --- a/src/game/client/render_map.cpp +++ b/src/game/client/render_map.cpp @@ -244,26 +244,46 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4 int Px1 = Px0+(1024/16)-1; int Py1 = Py0+(1024/16)-1; - float u0 = Nudge + Px0/TexSize+Frac; - float v0 = Nudge + Py0/TexSize+Frac; - float u1 = Nudge + Px1/TexSize-Frac; - float v1 = Nudge + Py1/TexSize-Frac; + float x0 = Nudge + Px0/TexSize+Frac; + float y0 = Nudge + Py0/TexSize+Frac; + float x1 = Nudge + Px1/TexSize-Frac; + float y1 = Nudge + Py0/TexSize+Frac; + float x2 = Nudge + Px1/TexSize-Frac; + float y2 = Nudge + Py1/TexSize-Frac; + float x3 = Nudge + Px0/TexSize+Frac; + float y3 = Nudge + Py1/TexSize-Frac; if(Flags&TILEFLAG_VFLIP) { - float Tmp = u0; - u0 = u1; - u1 = Tmp; + x0 = x2; + x1 = x3; + x2 = x3; + x3 = x0; } if(Flags&TILEFLAG_HFLIP) { - float Tmp = v0; - v0 = v1; - v1 = Tmp; + y0 = y3; + y2 = y1; + y3 = y1; + y1 = y0; } - Graphics()->QuadsSetSubset(u0,v0,u1,v1); + if(Flags&TILEFLAG_ROTATE) + { + float Tmp = x0; + x0 = x3; + x3 = x2; + x2 = x1; + x1 = Tmp; + Tmp = y0; + y0 = y3; + y3 = y2; + y2 = y1; + y1 = Tmp; + } + + Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3); IGraphics::CQuadItem QuadItem(x*Scale, y*Scale, Scale, Scale); Graphics()->QuadsDrawTL(&QuadItem, 1); } diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index aa6b7829..7046f1c4 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -463,7 +463,7 @@ void CEditor::RenderBackground(CUIRect View, int Texture, float Size, float Brig Graphics()->QuadsEnd(); } -int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, float Scale, const char *pToolTip) +int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip) { // logic static float s_Value; @@ -490,7 +490,7 @@ int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Cu { int Count = (int)(s_Value/Scale); s_Value = fmod(s_Value, Scale); - Current += Count; + Current += Step*Count; if(Current < Min) Current = Min; if(Current > Max) @@ -731,7 +731,16 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_RotationAmount = 90; - s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, 1, 360, 2.0f, Localize("Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.")); + bool TileLayer = false; + // check for tile layers in brush selection + for(int i = 0; i < m_Brush.m_lLayers.size(); i++) + if(m_Brush.m_lLayers[i]->m_Type == LAYERTYPE_TILES) + { + TileLayer = true; + s_RotationAmount = max(90, (s_RotationAmount/90)*90); + break; + } + s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, TileLayer?90:1, 360, TileLayer?90:1, TileLayer?10.0f:2.0f, Localize("Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.")); TB_Top.VSplitLeft(5.0f, &Button, &TB_Top); TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); @@ -1608,7 +1617,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIds, int * } else if(pProps[i].m_Type == PROPTYPE_INT_SCROLL) { - int NewValue = UiDoValueSelector(&pIds[i], &Shifter, "", pProps[i].m_Value, pProps[i].m_Min, pProps[i].m_Max, 1.0f, Localize("Use left mouse button to drag and change the value. Hold shift to be more precise.")); + int NewValue = UiDoValueSelector(&pIds[i], &Shifter, "", pProps[i].m_Value, pProps[i].m_Min, pProps[i].m_Max, 1, 1.0f, Localize("Use left mouse button to drag and change the value. Hold shift to be more precise.")); if(NewValue != pProps[i].m_Value) { *pNewVal = NewValue; @@ -1624,7 +1633,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIds, int * for(int c = 0; c < 4; c++) { int v = (pProps[i].m_Value >> s_aShift[c])&0xff; - NewColor |= UiDoValueSelector(((char *)&pIds[i])+c, &Shifter, s_paTexts[c], v, 0, 255, 1.0f, Localize("Use left mouse button to drag and change the color value. Hold shift to be more precise."))<= 0; --y, ++pDst) + { + *pDst = pTempData[y*m_Width+x]; + if(pDst->m_Flags&TILEFLAG_ROTATE) + pDst->m_Flags ^= (TILEFLAG_HFLIP|TILEFLAG_VFLIP); + pDst->m_Flags ^= TILEFLAG_ROTATE; + } + + int Temp = m_Width; + m_Width = m_Height; + m_Height = Temp; + delete[] pTempData; + } + + if(Rotation == 2 || Rotation == 3) + { + BrushFlipX(); + BrushFlipY(); + } } void CLayerTiles::Resize(int NewW, int NewH) diff --git a/src/game/mapitems.h b/src/game/mapitems.h index 06ceab4e..3c309561 100644 --- a/src/game/mapitems.h +++ b/src/game/mapitems.h @@ -48,6 +48,7 @@ enum TILEFLAG_VFLIP=1, TILEFLAG_HFLIP=2, TILEFLAG_OPAQUE=4, + TILEFLAG_ROTATE=8, LAYERFLAG_DETAIL=1, -- cgit 1.4.1