Skip to content

Commit 9717815

Browse files
author
Marek Kulik
committed
Add chat positioning through CVARs and settings
1 parent 27c6032 commit 9717815

File tree

5 files changed

+72
-16
lines changed

5 files changed

+72
-16
lines changed

Client/core/CChat.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ extern CCore* g_pCore;
2121
CChat * g_pChat = NULL;
2222

2323
CChat::CChat ( CGUI* pManager, const CVector2D & vecPosition )
24-
{
24+
{
2525
g_pChat = this;
26-
m_pManager = pManager;
26+
m_pManager = pManager;
2727

2828
// Calculate relative position (assuming a 800x600 native resolution for our defined CCHAT_* values)
2929
CVector2D vecResolution = m_pManager->GetResolution ();
@@ -126,6 +126,12 @@ void CChat::LoadCVars ( void )
126126
CVARS_GET ( "chat_font", (unsigned int &)Font ); SetChatFont ( (eChatFont)Font );
127127
CVARS_GET ( "chat_nickcompletion", m_bNickCompletion );
128128

129+
float fX, fY;
130+
CVARS_GET ( "chat_pos_x", fX );
131+
CVARS_GET ( "chat_pos_y", fY );
132+
m_vecBackgroundPosition = CVector2D( fX, fY ) * m_pManager->GetResolution();
133+
m_pBackground->SetPosition( m_vecBackgroundPosition );
134+
129135
// Modify default chat box to be like 'Transparent' preset
130136
SString strFlags;
131137
CVARS_GET ( "fixup_flags", strFlags );
@@ -591,7 +597,7 @@ bool CChat::CharacterKeyHandler ( CGUIKeyEventArgs KeyboardArgs )
591597
// If theres a command to call, call it
592598
if ( !m_strCommand.empty () && !m_strInputText.empty () )
593599
CCommands::GetSingleton().Execute ( m_strCommand.c_str (), m_strInputText.c_str () );
594-
600+
595601
SetInputVisible ( false );
596602

597603
m_fSmoothScrollResetTime = GetSecondCount ();
@@ -611,7 +617,7 @@ bool CChat::CharacterKeyHandler ( CGUIKeyEventArgs KeyboardArgs )
611617
iFound = 0;
612618
else
613619
++iFound;
614-
620+
615621
SString strPlayerNamePart = strCurrentInput.substr ( iFound );
616622

617623
CModManager* pModManager = CModManager::GetSingletonPtr ();
@@ -674,7 +680,7 @@ bool CChat::CharacterKeyHandler ( CGUIKeyEventArgs KeyboardArgs )
674680
}
675681
break;
676682
}
677-
683+
678684
default:
679685
{
680686
// Clear last namepart when pressing letter
@@ -687,11 +693,11 @@ bool CChat::CharacterKeyHandler ( CGUIKeyEventArgs KeyboardArgs )
687693

688694
// If we haven't exceeded the maximum number of characters per chat message, append the char to the message and update the input control
689695
if ( MbUTF8ToUTF16(m_strInputText).size () < CHAT_MAX_CHAT_LENGTH )
690-
{
696+
{
691697
if ( KeyboardArgs.codepoint >= 32 )
692698
{
693699
unsigned int uiCharacter = KeyboardArgs.codepoint;
694-
if ( uiCharacter < 127 ) // we have any char from ASCII
700+
if ( uiCharacter < 127 ) // we have any char from ASCII
695701
{
696702
// injecting as is
697703
m_strInputText += static_cast < char > ( KeyboardArgs.codepoint );
@@ -730,7 +736,7 @@ void CChat::SetVisible ( bool bVisible )
730736

731737

732738
void CChat::SetInputVisible ( bool bVisible )
733-
{
739+
{
734740
if ( !IsVisible () )
735741
bVisible = false;
736742

@@ -775,7 +781,7 @@ void CChat::SetChatFont ( eChatFont Font )
775781
break;
776782
case ChatFonts::CHAT_FONT_ARIAL:
777783
pDXFont = g_pCore->GetGraphics ()->GetFont ( FONT_ARIAL, &fUsingDxFontScale, fReqestedDxFontScale, "chat" );
778-
break;
784+
break;
779785
}
780786

781787
m_fRcpUsingDxFontScale = 1 / fUsingDxFontScale;
@@ -873,14 +879,14 @@ CVector2D CChat::CalcInputSize ( void )
873879
void CChat::SetInputText ( const char* szText )
874880
{
875881
m_InputLine.Clear ();
876-
882+
877883
CColor color = m_InputTextColor;
878884
const char* szRemainingText = m_InputLine.Format ( szText,
879885
( m_vecInputSize.fX - ( 10.0f * m_vecScale.fX ) - m_InputLine.m_Prefix.GetWidth () ),
880886
color, false );
881887

882888
CChatLine* pLine = NULL;
883-
889+
884890
while ( szRemainingText && m_InputLine.m_ExtraLines.size () < 3 )
885891
{
886892
m_InputLine.m_ExtraLines.resize ( m_InputLine.m_ExtraLines.size () + 1 );
@@ -1134,7 +1140,7 @@ void CChatInputLine::Draw ( CVector2D& vecPosition, unsigned char ucAlpha, bool
11341140
m_Prefix.GetColor ( colPrefix );
11351141
if ( colPrefix.A > 0 )
11361142
m_Prefix.Draw ( vecPosition, colPrefix.A, bShadow, RenderBounds );
1137-
1143+
11381144
if ( g_pChat->m_InputTextColor.A > 0 && m_Sections.size () > 0 )
11391145
{
11401146
m_Sections [ 0 ].Draw ( CVector2D ( vecPosition.fX + m_Prefix.GetWidth (), vecPosition.fY ),
@@ -1185,7 +1191,7 @@ void CChatLineSection::Draw ( const CVector2D& vecPosition, unsigned char ucAlph
11851191
if ( bShadow )
11861192
{
11871193
CRect2D drawShadowAt ( vecPosition.fX + 1.0f, vecPosition.fY + 1.0f, vecPosition.fX + 1000.0f, vecPosition.fY + 1000.0f );
1188-
CChat::DrawTextString ( m_strText.c_str (), drawShadowAt, 0.0f, drawShadowAt, 0, COLOR_ARGB ( ucAlpha, 0, 0, 0 ), g_pChat->m_vecScale.fX, g_pChat->m_vecScale.fY, RenderBounds );
1194+
CChat::DrawTextString ( m_strText.c_str (), drawShadowAt, 0.0f, drawShadowAt, 0, COLOR_ARGB ( ucAlpha, 0, 0, 0 ), g_pChat->m_vecScale.fX, g_pChat->m_vecScale.fY, RenderBounds );
11891195
}
11901196
CRect2D drawAt ( vecPosition.fX, vecPosition.fY, vecPosition.fX + 1000.0f, vecPosition.fY + 1000.0f );
11911197
CChat::DrawTextString ( m_strText.c_str (), drawAt, 0.0f, drawAt, 0, COLOR_ARGB ( ucAlpha, m_Color.R, m_Color.G, m_Color.B ), g_pChat->m_vecScale.fX, g_pChat->m_vecScale.fY, RenderBounds );

Client/core/CClientVariables.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ void CClientVariables::ValidateValues ( void )
241241
ClampValue ( "chat_width", 0.5f, 4.f );
242242
ClampValue ( "chat_line_life", 1000, 120000000 );
243243
ClampValue ( "chat_line_fade_out", 1000, 30000000 );
244+
ClampValue ( "chat_pos_x", 0.0f, 1.0f );
245+
ClampValue ( "chat_pos_y", 0.0f, 1.0f );
244246
ClampValue ( "text_scale", 0.8f, 3.0f );
245247
ClampValue ( "mtavolume", 0.0f, 1.0f );
246248
ClampValue ( "voicevolume", 0.0f, 1.0f );
@@ -286,6 +288,8 @@ void CClientVariables::LoadDefaults ( void )
286288
DEFAULT ( "chat_line_fade_out", 3000 ); // chatbox line fade out time
287289
DEFAULT ( "chat_use_cegui", false ); // chatbox uses cegui
288290
DEFAULT ( "chat_nickcompletion", true ); // chatbox nick completion
291+
DEFAULT ( "chat_pos_x", 0.0125f ); // chatbox relative x position
292+
DEFAULT ( "chat_pos_y", 0.015f ); // chatbox relative y position
289293
DEFAULT ( "server_can_flash_window", true ); // allow server to flash the window
290294
DEFAULT ( "allow_tray_notifications", true ); // allow scripts to create tray balloon notifications
291295
DEFAULT ( "text_scale", 1.0f ); // text scale

Client/core/CSettings.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ void CSettings::CreateGUI ( void )
985985
);
986986

987987
// Add a small indent for edit boxes
988-
fIndentX += 10.0f;
988+
fIndentX += 20.0f;
989989

990990
// Cache position and size from color tab panel (for positioning and height)
991991
pColorTabPanel->GetPosition ( vecTemp );
@@ -1000,18 +1000,41 @@ void CSettings::CreateGUI ( void )
10001000
pChatOptionsPanel->SetSize ( CVector2D ( fBGSizeX, fBGSizeY ) );
10011001

10021002
// Size of lines and gaps
1003-
float fLineSizeY = 30;
1003+
float fLineSizeY = 25;
10041004
float fLineGapY = 4;
10051005

10061006
// Layout tab
10071007
CGUITab* pLayoutTab = pChatOptionsPanel->CreateTab ( _("Layout") );
10081008

1009-
pLabel = reinterpret_cast < CGUILabel* > ( pManager->CreateLabel ( pLayoutTab, _("Lines:") ) );
1009+
pLabel = reinterpret_cast < CGUILabel* > ( pManager->CreateLabel ( pLayoutTab, "X:" ) );
10101010
pLabel->SetPosition ( CVector2D ( 10.0f, 10.0f ) );
10111011
pLabel->GetPosition ( vecTemp );
10121012
pLabel->AutoSize ( );
10131013
pLabel->SetAlwaysOnTop ( true );
10141014

1015+
m_pChatPosX = reinterpret_cast < CGUIEdit* > ( pManager->CreateEdit ( pLayoutTab, "") );
1016+
m_pChatPosX->SetPosition ( CVector2D ( vecTemp.fX + 12.0f, vecTemp.fY - 2.0f ) );
1017+
m_pChatPosX->GetPosition ( vecTemp );
1018+
m_pChatPosX->SetSize ( CVector2D ( 70.0f, 24.0f ) );
1019+
m_pChatPosX->SetAlwaysOnTop ( true );
1020+
1021+
pLabel = reinterpret_cast < CGUILabel* > ( pManager->CreateLabel ( pLayoutTab, "Y:" ) );
1022+
pLabel->SetPosition ( CVector2D ( vecTemp.fX + 75.0f, vecTemp.fY + 2.0f ) );
1023+
pLabel->GetPosition ( vecTemp );
1024+
pLabel->AutoSize ( );
1025+
pLabel->SetAlwaysOnTop ( true );
1026+
1027+
m_pChatPosY = reinterpret_cast < CGUIEdit* > ( pManager->CreateEdit ( pLayoutTab, "") );
1028+
m_pChatPosY->SetPosition ( CVector2D ( vecTemp.fX + 12.0f, vecTemp.fY - 2.0f ) );
1029+
m_pChatPosY->SetSize ( CVector2D ( 70.0f, 24.0f ) );
1030+
m_pChatPosY->SetAlwaysOnTop ( true );
1031+
1032+
pLabel = reinterpret_cast < CGUILabel* > ( pManager->CreateLabel ( pLayoutTab, _("Lines:") ) );
1033+
pLabel->SetPosition ( CVector2D ( 10.0f, vecTemp.fY + fLineSizeY + fLineGapY ) );
1034+
pLabel->GetPosition ( vecTemp );
1035+
pLabel->AutoSize ( );
1036+
pLabel->SetAlwaysOnTop ( true );
1037+
10151038
m_pChatLines = reinterpret_cast < CGUIEdit* > ( pManager->CreateEdit ( pLayoutTab, "" ) );
10161039
m_pChatLines->SetPosition ( CVector2D ( vecTemp.fX + fIndentX, vecTemp.fY - 2.0f ) );
10171040
m_pChatLines->SetSize ( CVector2D ( 80.0f, 24.0f ) );
@@ -2882,6 +2905,8 @@ void CSettings::LoadData ( void )
28822905
{
28832906
}
28842907

2908+
CVARS_GET ( "chat_pos_x", strVar ); m_pChatPosX->SetText( strVar.c_str() );
2909+
CVARS_GET ( "chat_pos_y", strVar ); m_pChatPosY->SetText( strVar.c_str() );
28852910
CVARS_GET ( "chat_width", strVar ); m_pChatWidth->SetText ( strVar.c_str () );
28862911
CVARS_GET ( "chat_css_style_text", bVar ); m_pChatCssText->SetSelected ( bVar );
28872912
CVARS_GET ( "chat_css_style_background", bVar ); m_pChatCssBackground->SetSelected ( bVar );
@@ -3195,6 +3220,8 @@ void CSettings::SaveData ( void )
31953220
strVar = m_pChatScaleX->GetText () + " " + m_pChatScaleY->GetText ();
31963221
CVARS_SET ( "chat_scale", strVar );
31973222
CVARS_SET ( "chat_lines", m_pChatLines->GetText () );
3223+
CVARS_SET ( "chat_pos_x", m_pChatPosX->GetText () );
3224+
CVARS_SET ( "chat_pos_y", m_pChatPosY->GetText () );
31983225
CVARS_SET ( "chat_width", m_pChatWidth->GetText () );
31993226
CVARS_SET ( "chat_css_style_text", m_pChatCssText->GetSelected () );
32003227
CVARS_SET ( "chat_css_style_background", m_pChatCssBackground->GetSelected () );
@@ -3549,6 +3576,14 @@ bool CSettings::OnChatLoadPresetClick( CGUIElement* pElement )
35493576
{
35503577
}
35513578
}
3579+
else if ( strTag == "pos_x" )
3580+
{
3581+
m_pChatPosX->SetText ( strValue.c_str () );
3582+
}
3583+
else if ( strTag == "pos_y" )
3584+
{
3585+
m_pChatPosY->SetText ( strValue.c_str () );
3586+
}
35523587
else if ( strTag == "width" )
35533588
{
35543589
m_pChatWidth->SetText ( strValue.c_str () );

Client/core/CSettings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ class CSettings
307307
CGUIScrollPane* m_pPaneChatFont;
308308
CGUIRadioButton* m_pRadioChatFont [ ChatFonts::CHAT_FONT_MAX ];
309309

310+
CGUIEdit* m_pChatPosX;
311+
CGUIEdit* m_pChatPosY;
310312
CGUIEdit* m_pChatLines;
311313
CGUIEdit* m_pChatScaleX;
312314
CGUIEdit* m_pChatScaleY;

Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,6 +3330,8 @@ int CLuaGUIDefs::GUIGetChatboxLayout ( lua_State* luaVM )
33303330
//* chat_input_prefix_color - Returns the color of the input prefix text
33313331
//* chat_input_text_color - Returns the color of the text in the chatbox input
33323332
//* chat_scale - Returns the scale of the text in the chatbox
3333+
//* chat_pos_x - Returns the position of the chatbox on the x axis
3334+
//* chat_pos_y - Returns the position of the chatbox on the y axis
33333335
//* chat_width - Returns the scale of the background width
33343336
//* chat_css_style_text - Returns whether text fades out over time
33353337
//* chat_css_style_background - Returns whether the background fades out over time
@@ -3350,6 +3352,12 @@ int CLuaGUIDefs::GUIGetChatboxLayout ( lua_State* luaVM )
33503352
pCVars->Get("chat_width", fNumber);
33513353
lua_pushnumber ( luaVM, fNumber );
33523354
lua_setfield ( luaVM, -2, "chat_width" );
3355+
pCVars->Get("chat_pos_x", fNumber);
3356+
lua_pushnumber ( luaVM, fNumber );
3357+
lua_setfield ( luaVM, -2, "chat_pos_x" );
3358+
pCVars->Get("chat_pos_y", fNumber);
3359+
lua_pushnumber ( luaVM, fNumber );
3360+
lua_setfield ( luaVM, -2, "chat_pos_y" );
33533361
pCVars->Get("chat_css_style_text", fNumber);
33543362
lua_pushnumber ( luaVM, fNumber );
33553363
lua_setfield ( luaVM, -2, "chat_css_style_text" );
@@ -3491,6 +3499,7 @@ int CLuaGUIDefs::GUIGetChatboxLayout ( lua_State* luaVM )
34913499
lua_settable( luaVM, -3 );
34923500
lua_setfield ( luaVM, -2, "chat_scale" );
34933501
}
3502+
34943503
return 1;
34953504
}
34963505

0 commit comments

Comments
 (0)