Changed: Use popup menu for chat-copy function

--HG--
branch : develop
This commit is contained in:
Nimetu 2019-02-11 14:32:13 +02:00
parent 0e4048661c
commit 838dd14d15
4 changed files with 63 additions and 2 deletions

View file

@ -206,6 +206,11 @@ namespace NLGUI
invalidateContent();
}
/// temporarily enable mouse over effect
// will be automatically disabled when mouse leaves element
void enableTempOver() { _TempOver = true; }
void disableTempOver() { _TempOver = false; }
/// \from CInterfaceElement
void onInvalidateContent();
sint32 getMaxUsedW() const;
@ -233,6 +238,8 @@ namespace NLGUI
// Do we have a color under the element pointed by the mouse
bool _Over;
// Temporarily force mouse over effect. Deactivated when mouse moves away
bool _TempOver;
// If over is true so we have a color
NLMISC::CRGBA _OverColor;

View file

@ -52,6 +52,7 @@ namespace NLGUI
_MinW= 0;
_MinH= 0;
_Over = false;
_TempOver = false;
_OverColor = CRGBA(255,255,255,32);
_OverElt = -1;
_LastW = 0;
@ -967,7 +968,7 @@ namespace NLGUI
// TEMP TEMP
//CViewRenderer &rVR = *CViewRenderer::getInstance();
//rVR.drawRotFlipBitmap _RenderLayer, (_XReal, _YReal, _WReal, _HReal, 0, false, rVR.getBlankTextureId(), CRGBA(0,255,0,255) );
if (_Over)
if (_Over || _TempOver)
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
@ -1052,7 +1053,10 @@ namespace NLGUI
_OverElt = -1;
if (!isIn(eventDesc.getX(), eventDesc.getY()))
{
_TempOver = false;
return false;
}
for (uint32 i = 0; i < _Elements.size(); ++i)
if (_Elements[i].Element->getActive())

View file

@ -3173,4 +3173,13 @@
params="game:chatUrlBrowse()" />
</group>
<group type="menu"
id="chat_copy_action_menu"
extends="base_menu">
<action id="copy"
name="uiCopy"
handler="copy_chat"
params="from_modal" />
</group>
</interface_config>

View file

@ -28,6 +28,9 @@ using namespace NLMISC;
CChatTextManager* CChatTextManager::_Instance = NULL;
// last selected chat from 'copy_chat_popup' action handler
static std::string LastSelectedChat;
//=================================================================================
CChatTextManager::CChatTextManager() :
_TextFontSize(NULL),
@ -403,7 +406,7 @@ CViewBase *CChatTextManager::createMsgTextComplex(const ucstring &msg, NLMISC::C
para->setResizeFromChildH(true);
// use right click because left click might be used to activate chat window
para->setRightClickHandler("copy_to_clipboard");
para->setRightClickHandler("copy_chat_popup");
para->setRightClickHandlerParams(msg.toUtf8());
if (plaintext)
@ -526,3 +529,41 @@ void CChatTextManager::reset ()
_TextShadowed = NULL;
_ShowTimestamps = NULL;
}
// ***************************************************************************
// Called when we right click on a chat line
class CHandlerCopyChatPopup: public IActionHandler
{
public:
virtual void execute(CCtrlBase *pCaller, const string &params )
{
if (pCaller == NULL) return;
LastSelectedChat = params;
CGroupParagraph *pGP = dynamic_cast<CGroupParagraph *>(pCaller);
if (pGP) pGP->enableTempOver();
CWidgetManager::getInstance()->enableModalWindow (pCaller, "ui:interface:chat_copy_action_menu");
}
};
REGISTER_ACTION_HANDLER( CHandlerCopyChatPopup, "copy_chat_popup");
// ***************************************************************************
// Called when we right click on a chat line and choose 'copy' from context menu
class CHandlerCopyChat: public IActionHandler
{
public:
virtual void execute(CCtrlBase *pCaller, const string &params )
{
if (pCaller == NULL) return;
CGroupParagraph *pGP = dynamic_cast<CGroupParagraph *>(pCaller);
if (pGP) pGP->disableTempOver();
CAHManager::getInstance()->runActionHandler("copy_to_clipboard", NULL, LastSelectedChat);
CWidgetManager::getInstance()->disableModalWindow();
}
};
REGISTER_ACTION_HANDLER( CHandlerCopyChat, "copy_chat");