Skip to content

Commit ad27bf1

Browse files
committed
Fixed color parsing issues (switched back to the old way)
1 parent d6fddaf commit ad27bf1

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
lines changed

MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Drawing.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ extern bool g_bAllowAspectRatioAdjustment;
2424
int CLuaFunctionDefs::dxDrawLine ( lua_State* luaVM )
2525
{
2626
// bool dxDrawLine ( int startX, int startY, int endX, int endY, int color, [float width=1, bool postGUI=false] )
27-
CVector2D vecStart; CVector2D vecEnd; uint ulColor; float fWidth; bool bPostGUI;
27+
CVector2D vecStart; CVector2D vecEnd; SColor color; float fWidth; bool bPostGUI;
2828

2929
CScriptArgReader argStream ( luaVM );
3030
argStream.ReadVector2D ( vecStart );
3131
argStream.ReadVector2D ( vecEnd );
32-
argStream.ReadNumber ( ulColor, 0xFFFFFFFF );
32+
argStream.ReadColor ( color, 0xFFFFFFFF );
3333
argStream.ReadNumber ( fWidth, 1 );
3434
argStream.ReadBool ( bPostGUI, false );
3535

3636
if ( !argStream.HasErrors () )
3737
{
38-
g_pCore->GetGraphics ()->DrawLineQueued ( vecStart.fX, vecStart.fY, vecEnd.fX, vecEnd.fY, fWidth, ulColor, bPostGUI );
38+
g_pCore->GetGraphics ()->DrawLineQueued ( vecStart.fX, vecStart.fY, vecEnd.fX, vecEnd.fY, fWidth, color, bPostGUI );
3939
lua_pushboolean ( luaVM, true );
4040
return 1;
4141
}
@@ -51,18 +51,18 @@ int CLuaFunctionDefs::dxDrawLine ( lua_State* luaVM )
5151
int CLuaFunctionDefs::dxDrawLine3D ( lua_State* luaVM )
5252
{
5353
// bool dxDrawLine3D ( float startX, float startY, float startZ, float endX, float endY, float endZ, int color[, int width, bool postGUI ] )
54-
CVector vecBegin; CVector vecEnd; uint ulColor; float fWidth; bool bPostGUI;
54+
CVector vecBegin; CVector vecEnd; SColor color; float fWidth; bool bPostGUI;
5555

5656
CScriptArgReader argStream ( luaVM );
5757
argStream.ReadVector3D ( vecBegin );
5858
argStream.ReadVector3D ( vecEnd );
59-
argStream.ReadNumber ( ulColor, 0xFFFFFFFF );
59+
argStream.ReadColor ( color, 0xFFFFFFFF );
6060
argStream.ReadNumber ( fWidth, 1 );
6161
argStream.ReadBool ( bPostGUI, false );
6262

6363
if ( !argStream.HasErrors () )
6464
{
65-
g_pCore->GetGraphics ()->DrawLine3DQueued ( vecBegin, vecEnd, fWidth, ulColor, bPostGUI );
65+
g_pCore->GetGraphics ()->DrawLine3DQueued ( vecBegin, vecEnd, fWidth, color, bPostGUI );
6666
lua_pushboolean ( luaVM, true );
6767
return 1;
6868
}
@@ -79,15 +79,15 @@ int CLuaFunctionDefs::dxDrawMaterialLine3D ( lua_State* luaVM )
7979
{
8080
// bool dxDrawMaterialLine3D ( float startX, float startY, float startZ, float endX, float endY, float endZ, element material, int width [, int color = white,
8181
// float faceX, float faceY, float faceZ ] )
82-
CVector vecBegin; CVector vecEnd; CClientMaterial* pMaterial; float fWidth; uint ulColor;
82+
CVector vecBegin; CVector vecEnd; CClientMaterial* pMaterial; float fWidth; SColor color;
8383
CVector vecFaceToward; bool bUseFaceToward = false;
8484

8585
CScriptArgReader argStream ( luaVM );
8686
argStream.ReadVector3D ( vecBegin );
8787
argStream.ReadVector3D ( vecEnd );
8888
argStream.ReadUserData ( pMaterial );
8989
argStream.ReadNumber ( fWidth );
90-
argStream.ReadNumber ( ulColor, 0xFFFFFFFF );
90+
argStream.ReadColor ( color, 0xFFFFFFFF );
9191
if ( argStream.NextIsVector3D ( ) )
9292
{
9393
argStream.ReadVector3D ( vecFaceToward );
@@ -96,7 +96,7 @@ int CLuaFunctionDefs::dxDrawMaterialLine3D ( lua_State* luaVM )
9696

9797
if ( !argStream.HasErrors () )
9898
{
99-
g_pCore->GetGraphics ()->DrawMaterialLine3DQueued ( vecBegin, vecEnd, fWidth, ulColor, pMaterial->GetMaterialItem (), 0, 0, 1, 1, true, bUseFaceToward, vecFaceToward );
99+
g_pCore->GetGraphics ()->DrawMaterialLine3DQueued ( vecBegin, vecEnd, fWidth, color, pMaterial->GetMaterialItem (), 0, 0, 1, 1, true, bUseFaceToward, vecFaceToward );
100100
lua_pushboolean ( luaVM, true );
101101
return 1;
102102
}
@@ -114,7 +114,7 @@ int CLuaFunctionDefs::dxDrawMaterialSectionLine3D ( lua_State* luaVM )
114114
// bool dxDrawMaterialSectionLine3D ( float startX, float startY, float startZ, float endX, float endY, float endZ, float u, float v, float usize, float vsize,
115115
// element material, int width, [ int color = white, float faceX, float faceY, float faceZ ] )
116116
CVector vecBegin; CVector vecEnd; CVector2D vecSectionPos; CVector2D vecSectionSize;
117-
CClientMaterial* pMaterial; float fWidth; uint ulColor; CVector vecFaceToward; bool bUseFaceToward = false;
117+
CClientMaterial* pMaterial; float fWidth; SColor color; CVector vecFaceToward; bool bUseFaceToward = false;
118118

119119
CScriptArgReader argStream ( luaVM );
120120
argStream.ReadVector3D ( vecBegin );
@@ -123,7 +123,7 @@ int CLuaFunctionDefs::dxDrawMaterialSectionLine3D ( lua_State* luaVM )
123123
argStream.ReadVector2D ( vecSectionSize );
124124
argStream.ReadUserData ( pMaterial );
125125
argStream.ReadNumber ( fWidth );
126-
argStream.ReadNumber ( ulColor, 0xFFFFFFFF );
126+
argStream.ReadColor ( color, 0xFFFFFFFF );
127127
if ( argStream.NextIsVector3D ( ) )
128128
{
129129
argStream.ReadVector3D ( vecFaceToward );
@@ -132,7 +132,7 @@ int CLuaFunctionDefs::dxDrawMaterialSectionLine3D ( lua_State* luaVM )
132132

133133
if ( !argStream.HasErrors () )
134134
{
135-
g_pCore->GetGraphics ()->DrawMaterialLine3DQueued ( vecBegin, vecEnd, fWidth, ulColor, pMaterial->GetMaterialItem (), vecSectionPos.fX, vecSectionPos.fY, vecSectionSize.fX, vecSectionSize.fY, false, bUseFaceToward, vecFaceToward );
135+
g_pCore->GetGraphics ()->DrawMaterialLine3DQueued ( vecBegin, vecEnd, fWidth, color, pMaterial->GetMaterialItem (), vecSectionPos.fX, vecSectionPos.fY, vecSectionSize.fX, vecSectionSize.fY, false, bUseFaceToward, vecFaceToward );
136136
lua_pushboolean ( luaVM, true );
137137
return 1;
138138
}
@@ -150,7 +150,7 @@ int CLuaFunctionDefs::dxDrawText ( lua_State* luaVM )
150150
// bool dxDrawText ( string text, float left, float top [, float right=left, float bottom=top, int color=white, float scale=1, mixed font="default",
151151
// string alignX="left", string alignY="top", bool clip=false, bool wordBreak=false, bool postGUI=false, bool colorCoded=false, bool subPixelPositioning=false,
152152
// float rotation=0, float rotationCenterX=(left+right)/2, float rotationCenterY=(top+bottom)/2] )
153-
SString strText; CVector2D vecTopLeft; CVector2D vecBottomRight; ulong ulColor; float fScaleX; float fScaleY; eFontType fontType; CClientDxFont* pDxFontElement;
153+
SString strText; CVector2D vecTopLeft; CVector2D vecBottomRight; SColor color; float fScaleX; float fScaleY; eFontType fontType; CClientDxFont* pDxFontElement;
154154
eDXHorizontalAlign alignX; eDXVerticalAlign alignY; bool bClip; bool bWordBreak; bool bPostGUI; bool bColorCoded; bool bSubPixelPositioning;
155155
float fRotation; CVector2D vecRotationOrigin;
156156

@@ -164,7 +164,7 @@ int CLuaFunctionDefs::dxDrawText ( lua_State* luaVM )
164164
argStream.ReadNumber ( vecBottomRight.fX, vecTopLeft.fX );
165165
argStream.ReadNumber ( vecBottomRight.fY, vecTopLeft.fY );
166166
}
167-
argStream.ReadNumber ( ulColor, 0xFFFFFFFF );
167+
argStream.ReadColor ( color, 0xFFFFFFFF );
168168
if ( argStream.NextIsUserDataOfType<CLuaVector2D>() ) {
169169
CVector2D vecScale;
170170
argStream.ReadVector2D ( vecScale );
@@ -201,7 +201,7 @@ int CLuaFunctionDefs::dxDrawText ( lua_State* luaVM )
201201
if ( bWordBreak ) ulFormat |= DT_WORDBREAK;
202202
if ( !bClip ) ulFormat |= DT_NOCLIP;
203203

204-
CStaticFunctionDefinitions::DrawText ( vecTopLeft.fX, vecTopLeft.fY, vecBottomRight.fX, vecBottomRight.fY, ulColor, strText, fScaleX, fScaleY, ulFormat, pD3DXFont, bPostGUI, bColorCoded, bSubPixelPositioning, fRotation, vecRotationOrigin.fX, vecRotationOrigin.fY );
204+
CStaticFunctionDefinitions::DrawText ( vecTopLeft.fX, vecTopLeft.fY, vecBottomRight.fX, vecBottomRight.fY, color, strText, fScaleX, fScaleY, ulFormat, pD3DXFont, bPostGUI, bColorCoded, bSubPixelPositioning, fRotation, vecRotationOrigin.fX, vecRotationOrigin.fY );
205205

206206
lua_pushboolean ( luaVM, true );
207207
return 1;
@@ -218,18 +218,18 @@ int CLuaFunctionDefs::dxDrawText ( lua_State* luaVM )
218218
int CLuaFunctionDefs::dxDrawRectangle ( lua_State* luaVM )
219219
{
220220
// bool dxDrawRectangle ( float startX, float startY, float width, float height [, int color = white, bool postGUI = false, bool subPixelPositioning=false] )
221-
CVector2D vecPosition; CVector2D vecSize; uint ulColor; bool bPostGUI; bool bSubPixelPositioning;
221+
CVector2D vecPosition; CVector2D vecSize; SColor color; bool bPostGUI; bool bSubPixelPositioning;
222222

223223
CScriptArgReader argStream ( luaVM );
224224
argStream.ReadVector2D ( vecPosition );
225225
argStream.ReadVector2D ( vecSize );
226-
argStream.ReadNumber ( ulColor, 0xFFFFFFFF );
226+
argStream.ReadColor ( color, 0xFFFFFFFF );
227227
argStream.ReadBool ( bPostGUI, false );
228228
argStream.ReadBool ( bSubPixelPositioning, false );
229229

230230
if ( !argStream.HasErrors () )
231231
{
232-
g_pCore->GetGraphics ()->DrawRectQueued ( vecPosition.fX, vecPosition.fY, vecSize.fX, vecSize.fY, ulColor, bPostGUI, bSubPixelPositioning );
232+
g_pCore->GetGraphics ()->DrawRectQueued ( vecPosition.fX, vecPosition.fY, vecSize.fX, vecSize.fY, color, bPostGUI, bSubPixelPositioning );
233233
lua_pushboolean ( luaVM, true );
234234
return 1;
235235
}
@@ -252,7 +252,7 @@ int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM )
252252
CClientMaterial* pMaterialElement;
253253
float fRotation;
254254
CVector2D vecRotationCenter;
255-
uint ulColor;
255+
SColor color;
256256
bool bPostGUI;
257257

258258
CScriptArgReader argStream ( luaVM );
@@ -261,14 +261,14 @@ int CLuaFunctionDefs::dxDrawImage ( lua_State* luaVM )
261261
MixedReadMaterialString ( argStream, pMaterialElement );
262262
argStream.ReadNumber ( fRotation, 0 );
263263
argStream.ReadVector2D ( vecRotationCenter, CVector2D ( ) );
264-
argStream.ReadNumber ( ulColor, 0xffffffff );
264+
argStream.ReadColor ( color, 0xffffffff );
265265
argStream.ReadBool ( bPostGUI, false );
266266

267267
if ( !argStream.HasErrors () )
268268
{
269269
if ( pMaterialElement )
270270
{
271-
g_pCore->GetGraphics ()->DrawTextureQueued ( vecPosition.fX, vecPosition.fY, vecSize.fX, vecSize.fY, 0, 0, 1, 1, true, pMaterialElement->GetMaterialItem (), fRotation, vecRotationCenter.fX, vecRotationCenter.fY, ulColor, bPostGUI );
271+
g_pCore->GetGraphics ()->DrawTextureQueued ( vecPosition.fX, vecPosition.fY, vecSize.fX, vecSize.fY, 0, 0, 1, 1, true, pMaterialElement->GetMaterialItem (), fRotation, vecRotationCenter.fX, vecRotationCenter.fY, color, bPostGUI );
272272
lua_pushboolean ( luaVM, true );
273273
return 1;
274274
}
@@ -293,7 +293,7 @@ int CLuaFunctionDefs::dxDrawImageSection ( lua_State* luaVM )
293293
CClientMaterial* pMaterialElement;
294294
float fRotation;
295295
CVector2D vecRotationCenter;
296-
uint ulColor;
296+
SColor color;
297297
bool bPostGUI;
298298

299299
CScriptArgReader argStream ( luaVM );
@@ -304,14 +304,14 @@ int CLuaFunctionDefs::dxDrawImageSection ( lua_State* luaVM )
304304
MixedReadMaterialString ( argStream, pMaterialElement );
305305
argStream.ReadNumber ( fRotation, 0 );
306306
argStream.ReadVector2D ( vecRotationCenter, CVector2D ( ) );
307-
argStream.ReadNumber ( ulColor, 0xffffffff );
307+
argStream.ReadColor ( color, 0xffffffff );
308308
argStream.ReadBool ( bPostGUI, false );
309309

310310
if ( !argStream.HasErrors () )
311311
{
312312
if ( pMaterialElement )
313313
{
314-
g_pCore->GetGraphics ()->DrawTextureQueued ( vecPosition.fX, vecPosition.fY, vecSize.fX, vecSize.fY, vecSectionPosition.fX, vecSectionPosition.fY, vecSectionSize.fX, vecSectionSize.fY, false, pMaterialElement->GetMaterialItem (), fRotation, vecRotationCenter.fX, vecRotationCenter.fY, ulColor, bPostGUI );
314+
g_pCore->GetGraphics ()->DrawTextureQueued ( vecPosition.fX, vecPosition.fY, vecSize.fX, vecSize.fY, vecSectionPosition.fX, vecSectionPosition.fY, vecSectionSize.fX, vecSectionSize.fY, false, pMaterialElement->GetMaterialItem (), fRotation, vecRotationCenter.fX, vecRotationCenter.fY, color, bPostGUI );
315315
lua_pushboolean ( luaVM, true );
316316
return 1;
317317
}
@@ -1335,17 +1335,17 @@ int CLuaFunctionDefs::dxIsAspectRatioAdjustmentEnabled ( lua_State* luaVM )
13351335
int CLuaFunctionDefs::dxSetTextureEdge ( lua_State* luaVM )
13361336
{
13371337
// bool dxSetTextureEdge ( texture theTexture, string textureEdge [, int border-color )
1338-
CClientTexture* pTexture; ETextureAddress textureAddress; unsigned int uiBorderColor;
1338+
CClientTexture* pTexture; ETextureAddress textureAddress; SColor borderColor;
13391339

13401340
CScriptArgReader argStream ( luaVM );
13411341
argStream.ReadUserData ( pTexture );
13421342
argStream.ReadEnumString ( textureAddress );
1343-
argStream.ReadNumber ( uiBorderColor, 0 );
1343+
argStream.ReadColor ( borderColor, 0 );
13441344

13451345
if ( !argStream.HasErrors () )
13461346
{
13471347
pTexture->GetMaterialItem ()->m_TextureAddress = textureAddress;
1348-
pTexture->GetMaterialItem ()->m_uiBorderColor = uiBorderColor;
1348+
pTexture->GetMaterialItem ()->m_uiBorderColor = borderColor;
13491349
lua_pushboolean ( luaVM, true );
13501350
return 1;
13511351
}

Shared/sdk/CScriptArgReader.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,30 @@ class CScriptArgReader
461461
m_iIndex++;
462462
}
463463

464+
//
465+
// Read next color
466+
//
467+
void ReadColor ( SColor& outValue )
468+
{
469+
lua_Number color;
470+
ReadNumber ( color );
471+
472+
if ( !m_bError )
473+
outValue = static_cast<unsigned int> ( color );
474+
}
475+
476+
//
477+
// Read next color
478+
//
479+
void ReadColor ( SColor& outValue, const SColor& defaultValue )
480+
{
481+
lua_Number color;
482+
ReadNumber ( color, static_cast<lua_Number> ( defaultValue ) );
483+
484+
if ( !m_bError )
485+
outValue = static_cast<unsigned int> ( color );
486+
}
487+
464488
//
465489
// Read next bool
466490
//

0 commit comments

Comments
 (0)