Skip to content

Commit d1c6067

Browse files
authored
Merge pull request #1306 from multitheftauto/feature/qc_rightclick
Add CVAR _beta_qc_rightclick_command
2 parents 2c5251a + 92e1c73 commit d1c6067

File tree

8 files changed

+119
-72
lines changed

8 files changed

+119
-72
lines changed

Client/core/CClientVariables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ void CClientVariables::LoadDefaults()
350350
DEFAULT("browser_remote_websites", true); // Load remote websites?
351351
DEFAULT("browser_remote_javascript", true); // Execute javascript on remote websites?
352352
DEFAULT("filter_duplicate_log_lines", true); // Filter duplicate log lines for debug view and clientscript.log
353+
DEFAULT("_beta_qc_rightclick_command", _S("reconnect")); // Command to run when right clicking quick connect (beta - can be removed at any time)
353354

354355
if (!Exists("locale"))
355356
{

Client/core/CMainMenu.cpp

Lines changed: 58 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ CMainMenu::CMainMenu(CGUI* pManager)
205205
m_pMenuArea->SetSize(CVector2D(m_menuBX - m_menuAX, m_menuBY - m_menuAY) + BODGE_FACTOR_6, false);
206206
m_pMenuArea->SetAlpha(0);
207207
m_pMenuArea->SetZOrderingEnabled(false);
208-
m_pMenuArea->SetClickHandler(GUI_CALLBACK(&CMainMenu::OnMenuClick, this));
208+
m_pMenuArea->SetClickHandler(GUI_CALLBACK_MOUSE(&CMainMenu::OnMenuClick, this));
209209
m_pMenuArea->SetMouseEnterHandler(GUI_CALLBACK(&CMainMenu::OnMenuEnter, this));
210210
m_pMenuArea->SetMouseLeaveHandler(GUI_CALLBACK(&CMainMenu::OnMenuExit, this));
211211

@@ -792,76 +792,84 @@ bool CMainMenu::OnMenuExit(CGUIElement* pElement)
792792
return true;
793793
}
794794

795-
bool CMainMenu::OnMenuClick(CGUIElement* pElement)
795+
bool CMainMenu::OnMenuClick(CGUIMouseEventArgs Args)
796796
{
797-
// Handle all our clicks to the menu from here
798-
if (m_pHoveredItem)
799-
{
800-
// For detecting startup problems
801-
WatchDogUserDidInteractWithMenu();
797+
CGUIElement* pElement = Args.pWindow;
802798

803-
// Possible disconnect question for user
804-
if (g_pCore->IsConnected())
805-
{
806-
switch (m_pHoveredItem->menuType)
807-
{
808-
case MENU_ITEM_HOST_GAME:
809-
case MENU_ITEM_MAP_EDITOR:
810-
AskUserIfHeWantsToDisconnect(m_pHoveredItem->menuType);
811-
return true;
812-
default:
813-
break;
814-
}
815-
}
799+
// Only handle all our clicks to the menu from here
800+
if (!m_pHoveredItem)
801+
return true;
802+
803+
if (Args.button != LeftButton && m_pHoveredItem->menuType != MENU_ITEM_QUICK_CONNECT)
804+
return true;
805+
806+
// For detecting startup problems
807+
WatchDogUserDidInteractWithMenu();
816808

809+
// Possible disconnect question for user
810+
if (g_pCore->IsConnected())
811+
{
817812
switch (m_pHoveredItem->menuType)
818813
{
819-
case MENU_ITEM_DISCONNECT:
820-
OnDisconnectButtonClick(pElement);
821-
break;
822-
case MENU_ITEM_QUICK_CONNECT:
823-
OnQuickConnectButtonClick(pElement);
824-
break;
825-
case MENU_ITEM_BROWSE_SERVERS:
826-
OnBrowseServersButtonClick(pElement);
827-
break;
828814
case MENU_ITEM_HOST_GAME:
829-
OnHostGameButtonClick();
830-
break;
831815
case MENU_ITEM_MAP_EDITOR:
832-
OnEditorButtonClick();
833-
break;
834-
case MENU_ITEM_SETTINGS:
835-
OnSettingsButtonClick(pElement);
836-
break;
837-
case MENU_ITEM_ABOUT:
838-
OnAboutButtonClick(pElement);
839-
break;
840-
case MENU_ITEM_QUIT:
841-
OnQuitButtonClick(pElement);
842-
break;
816+
AskUserIfHeWantsToDisconnect(m_pHoveredItem->menuType);
817+
return true;
843818
default:
844819
break;
845820
}
846821
}
822+
823+
switch (m_pHoveredItem->menuType)
824+
{
825+
case MENU_ITEM_DISCONNECT:
826+
OnDisconnectButtonClick(pElement);
827+
break;
828+
case MENU_ITEM_QUICK_CONNECT:
829+
OnQuickConnectButtonClick(pElement, Args.button == LeftButton);
830+
break;
831+
case MENU_ITEM_BROWSE_SERVERS:
832+
OnBrowseServersButtonClick(pElement);
833+
break;
834+
case MENU_ITEM_HOST_GAME:
835+
OnHostGameButtonClick();
836+
break;
837+
case MENU_ITEM_MAP_EDITOR:
838+
OnEditorButtonClick();
839+
break;
840+
case MENU_ITEM_SETTINGS:
841+
OnSettingsButtonClick(pElement);
842+
break;
843+
case MENU_ITEM_ABOUT:
844+
OnAboutButtonClick(pElement);
845+
break;
846+
case MENU_ITEM_QUIT:
847+
OnQuitButtonClick(pElement);
848+
break;
849+
default:
850+
break;
851+
}
852+
847853
return true;
848854
}
849855

850-
bool CMainMenu::OnQuickConnectButtonClick(CGUIElement* pElement)
856+
bool CMainMenu::OnQuickConnectButtonClick(CGUIElement* pElement, bool left)
851857
{
852858
// Return if we haven't faded in yet
853859
if (m_ucFade != FADE_VISIBLE)
854860
return false;
855861

862+
// If we're right clicking, execute special command
863+
if (!left)
864+
{
865+
std::string command;
866+
CVARS_GET("_beta_qc_rightclick_command", command);
867+
g_pCore->GetCommands()->Execute(command.data());
868+
return true;
869+
}
870+
856871
m_ServerBrowser.SetVisible(true);
857872
m_ServerBrowser.OnQuickConnectButtonClick();
858-
/*
859-
// if ( !m_bIsInSubWindow )
860-
{
861-
m_QuickConnect.SetVisible ( true );
862-
// m_bIsInSubWindow = true;
863-
}
864-
*/
865873
return true;
866874
}
867875

Client/core/CMainMenu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ class CMainMenu
8181

8282
bool OnMenuEnter(CGUIElement* pElement);
8383
bool OnMenuExit(CGUIElement* pElement);
84-
bool OnMenuClick(CGUIElement* pElement);
85-
bool OnQuickConnectButtonClick(CGUIElement* pElement);
84+
bool OnMenuClick(CGUIMouseEventArgs Args);
85+
bool OnQuickConnectButtonClick(CGUIElement* pElement, bool left);
8686
bool OnResumeButtonClick(CGUIElement* pElement);
8787
bool OnBrowseServersButtonClick(CGUIElement* pElement);
8888
bool OnHostGameButtonClick();

Client/gui/CGUIElement_Impl.cpp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,11 @@ void CGUIElement_Impl::SetClickHandler(GUI_CALLBACK Callback)
495495
m_OnClick = Callback;
496496
}
497497

498+
void CGUIElement_Impl::SetClickHandler(const GUI_CALLBACK_MOUSE& Callback)
499+
{
500+
m_OnClickWithArgs = Callback;
501+
}
502+
498503
void CGUIElement_Impl::SetDoubleClickHandler(GUI_CALLBACK Callback)
499504
{
500505
m_OnDoubleClick = Callback;
@@ -565,10 +570,29 @@ bool CGUIElement_Impl::Event_OnSized(const CEGUI::EventArgs& e)
565570
return true;
566571
}
567572

568-
bool CGUIElement_Impl::Event_OnClick()
573+
bool CGUIElement_Impl::Event_OnClick(const CEGUI::EventArgs& eBase)
569574
{
575+
const CEGUI::MouseEventArgs& e = reinterpret_cast<const CEGUI::MouseEventArgs&>(eBase);
576+
CGUIElement* pElement = reinterpret_cast<CGUIElement*>(this);
577+
570578
if (m_OnClick)
571-
m_OnClick(reinterpret_cast<CGUIElement*>(this));
579+
m_OnClick(pElement);
580+
581+
if (m_OnClickWithArgs)
582+
{
583+
CGUIMouseEventArgs NewArgs;
584+
585+
// copy the variables
586+
NewArgs.button = static_cast<CGUIMouse::MouseButton>(e.button);
587+
NewArgs.moveDelta = CVector2D(e.moveDelta.d_x, e.moveDelta.d_y);
588+
NewArgs.position = CGUIPosition(e.position.d_x, e.position.d_y);
589+
NewArgs.sysKeys = e.sysKeys;
590+
NewArgs.wheelChange = e.wheelChange;
591+
NewArgs.pWindow = pElement;
592+
593+
m_OnClickWithArgs(NewArgs);
594+
}
595+
572596
return true;
573597
}
574598

@@ -661,4 +685,4 @@ bool CGUIElement_Impl::Event_OnKeyDown(const CEGUI::EventArgs& e)
661685
inline void CGUIElement_Impl::ForceRedraw()
662686
{
663687
m_pWindow->forceRedraw();
664-
}
688+
}

Client/gui/CGUIElement_Impl.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class CGUIElement_Impl : public CGUIElement
103103
void SetMovedHandler(GUI_CALLBACK Callback);
104104
void SetSizedHandler(GUI_CALLBACK Callback);
105105
void SetClickHandler(GUI_CALLBACK Callback);
106+
void SetClickHandler(const GUI_CALLBACK_MOUSE& Callback);
106107
void SetDoubleClickHandler(GUI_CALLBACK Callback);
107108
void SetMouseEnterHandler(GUI_CALLBACK Callback);
108109
void SetMouseLeaveHandler(GUI_CALLBACK Callback);
@@ -113,7 +114,7 @@ class CGUIElement_Impl : public CGUIElement
113114
void SetKeyDownHandler(const GUI_CALLBACK_KEY& Callback);
114115
void SetEnterKeyHandler(GUI_CALLBACK Callback);
115116

116-
bool Event_OnClick();
117+
bool Event_OnClick(const CEGUI::EventArgs& e);
117118
bool Event_OnDoubleClick();
118119
bool Event_OnMouseEnter();
119120
bool Event_OnMouseLeave();
@@ -143,16 +144,18 @@ class CGUIElement_Impl : public CGUIElement
143144

144145
std::list<CGUIProperty*> m_Properties;
145146

146-
GUI_CALLBACK m_OnClick;
147-
GUI_CALLBACK m_OnDoubleClick;
148-
GUI_CALLBACK m_OnMoved;
149-
GUI_CALLBACK m_OnSized;
150-
GUI_CALLBACK m_OnMouseEnter;
151-
GUI_CALLBACK m_OnMouseLeave;
152-
GUI_CALLBACK m_OnMouseDown;
153-
GUI_CALLBACK m_OnActivate;
154-
GUI_CALLBACK m_OnDeactivate;
155-
GUI_CALLBACK m_OnKeyDown;
156-
GUI_CALLBACK m_OnEnter;
157-
GUI_CALLBACK_KEY m_OnKeyDownWithArgs;
147+
GUI_CALLBACK m_OnClick;
148+
GUI_CALLBACK m_OnDoubleClick;
149+
GUI_CALLBACK m_OnMoved;
150+
GUI_CALLBACK m_OnSized;
151+
GUI_CALLBACK m_OnMouseEnter;
152+
GUI_CALLBACK m_OnMouseLeave;
153+
GUI_CALLBACK m_OnMouseDown;
154+
GUI_CALLBACK m_OnActivate;
155+
GUI_CALLBACK m_OnDeactivate;
156+
GUI_CALLBACK m_OnKeyDown;
157+
GUI_CALLBACK m_OnEnter;
158+
159+
GUI_CALLBACK_MOUSE m_OnClickWithArgs;
160+
GUI_CALLBACK_KEY m_OnKeyDownWithArgs;
158161
};

Client/gui/CGUIElement_Inc.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ void SetClickHandler(GUI_CALLBACK Callback)
248248
{
249249
CGUIElement_Impl::SetClickHandler(Callback);
250250
};
251+
void SetClickHandler(const GUI_CALLBACK_MOUSE& Callback)
252+
{
253+
CGUIElement_Impl::SetClickHandler(Callback);
254+
};
251255
void SetDoubleClickHandler(GUI_CALLBACK Callback)
252256
{
253257
CGUIElement_Impl::SetDoubleClickHandler(Callback);
@@ -293,9 +297,9 @@ void SetEnterKeyHandler(GUI_CALLBACK Callback)
293297
CGUIElement_Impl::SetEnterKeyHandler(Callback);
294298
};
295299

296-
bool Event_OnClick()
300+
bool Event_OnClick(const CEGUI::EventArgs& e)
297301
{
298-
return CGUIElement_Impl::Event_OnClick();
302+
return CGUIElement_Impl::Event_OnClick(e);
299303
};
300304
bool Event_OnDoubleClick()
301305
{

Client/gui/CGUI_Impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ bool CGUI_Impl::Event_MouseClick(const CEGUI::EventArgs& Args)
10411041

10421042
// Call global and object handlers
10431043
if (pElement)
1044-
pElement->Event_OnClick();
1044+
pElement->Event_OnClick(Args);
10451045

10461046
if (m_MouseClickHandlers[m_Channel])
10471047
{

Client/sdk/gui/CGUIElement.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class CGUIElement;
1818
#include <string>
1919
#include "CGUITypes.h"
2020

21+
// Forward declaration
22+
namespace CEGUI
23+
{
24+
class EventArgs;
25+
}
26+
2127
enum eCGUIType
2228
{
2329
CGUI_BUTTON,
@@ -119,6 +125,7 @@ class CGUIElement
119125
virtual void SetMovedHandler(GUI_CALLBACK Callback) = 0;
120126
virtual void SetSizedHandler(GUI_CALLBACK Callback) = 0;
121127
virtual void SetClickHandler(GUI_CALLBACK Callback) = 0;
128+
virtual void SetClickHandler(const GUI_CALLBACK_MOUSE& Callback) = 0;
122129
virtual void SetDoubleClickHandler(GUI_CALLBACK Callback) = 0;
123130
virtual void SetMouseEnterHandler(GUI_CALLBACK Callback) = 0;
124131
virtual void SetMouseLeaveHandler(GUI_CALLBACK Callback) = 0;
@@ -129,7 +136,7 @@ class CGUIElement
129136
virtual void SetKeyDownHandler(const GUI_CALLBACK_KEY& Callback) = 0;
130137
virtual void SetEnterKeyHandler(GUI_CALLBACK Callback) = 0;
131138

132-
virtual bool Event_OnClick() = 0;
139+
virtual bool Event_OnClick(const CEGUI::EventArgs& e) = 0;
133140
virtual bool Event_OnDoubleClick() = 0;
134141
virtual bool Event_OnMouseEnter() = 0;
135142
virtual bool Event_OnMouseLeave() = 0;

0 commit comments

Comments
 (0)