1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2018 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "macrocmd_manager.h"
27 #include "macrocmd_key.h"
29 #include "interface_manager.h"
30 #include "nel/gui/action_handler.h"
31 #include "dbctrl_sheet.h"
32 #include "nel/gui/ctrl_button.h"
33 #include "nel/gui/group_editbox.h"
34 #include "nel/gui/group_list.h"
35 #include "nel/gui/dbgroup_combo_box.h"
36 #include "nel/gui/group_container.h"
37 #include "group_modal_get_key.h"
38 #include "task_bar_manager.h"
39 #include "sphrase_manager.h"
42 using namespace NLMISC
;
44 // ------------------------------------------------------------------------------------------------
45 CMacroCmdManager
*CMacroCmdManager::_Instance
= NULL
;
46 // ------------------------------------------------------------------------------------------------
48 // ------------------------------------------------------------------------------------------------
50 // ------------------------------------------------------------------------------------------------
51 CMacroCmd::CMacroCmd()
57 Combo
.KeyButtons
= noKeyButton
;
61 // ------------------------------------------------------------------------------------------------
62 void CMacroCmd::writeTo (xmlNodePtr node
) const
65 xmlNodePtr macroNode
= xmlNewChild ( node
, NULL
, (const xmlChar
*)"macro", NULL
);
68 xmlSetProp (macroNode
, (const xmlChar
*)"name", (const xmlChar
*)Name
.c_str());
69 xmlSetProp (macroNode
, (const xmlChar
*)"id", (const xmlChar
*)toString(ID
).c_str());
70 xmlSetProp (macroNode
, (const xmlChar
*)"back", (const xmlChar
*)toString(BitmapBack
).c_str());
71 xmlSetProp (macroNode
, (const xmlChar
*)"icon", (const xmlChar
*)toString(BitmapIcon
).c_str());
72 xmlSetProp (macroNode
, (const xmlChar
*)"over", (const xmlChar
*)toString(BitmapOver
).c_str());
73 xmlSetProp (macroNode
, (const xmlChar
*)"text", (const xmlChar
*)DispText
.c_str());
75 for (uint i
= 0; i
< Commands
.size(); ++i
)
77 xmlNodePtr cmdNode
= xmlNewChild ( macroNode
, NULL
, (const xmlChar
*)"command", NULL
);
78 xmlSetProp (cmdNode
, (const xmlChar
*)"name", (const xmlChar
*)Commands
[i
].Name
.c_str());
79 xmlSetProp (cmdNode
, (const xmlChar
*)"params", (const xmlChar
*)Commands
[i
].Params
.c_str());
83 // ------------------------------------------------------------------------------------------------
84 bool CMacroCmd::readFrom (xmlNodePtr node
)
88 ptrName
= (char*) xmlGetProp( node
, (xmlChar
*)"name" );
89 if (ptrName
) Name
= (const char *)ptrName
;
91 ptrName
= (char*) xmlGetProp( node
, (xmlChar
*)"id" );
92 if (ptrName
) fromString((const char*)ptrName
, ID
);
94 ptrName
= (char*) xmlGetProp( node
, (xmlChar
*)"back" );
95 if (ptrName
) fromString((const char*)ptrName
, BitmapBack
);
97 ptrName
= (char*) xmlGetProp( node
, (xmlChar
*)"icon" );
98 if (ptrName
) fromString((const char*)ptrName
, BitmapIcon
);
100 ptrName
= (char*) xmlGetProp( node
, (xmlChar
*)"over" );
101 if (ptrName
) fromString((const char*)ptrName
, BitmapOver
);
103 ptrName
= (char*) xmlGetProp( node
, (xmlChar
*)"text" );
104 if (ptrName
) DispText
= (const char*)ptrName
;
106 node
= node
->children
;
109 if ( stricmp((char*)node
->name
,"command") == 0 )
113 ptrName
= (char*) xmlGetProp( node
, (xmlChar
*)"name" );
114 if (ptrName
) c
.Name
= (const char*)ptrName
;
116 ptrName
= (char*) xmlGetProp( node
, (xmlChar
*)"params" );
117 if (ptrName
) c
.Params
= (const char*)ptrName
;
119 Commands
.push_back(c
);
127 // ------------------------------------------------------------------------------------------------
128 void CMacroCmd::addCommand(const string
&sName
, const string
&sParam
, sint32 nPos
)
130 CCommand
c(sName
.c_str(), sParam
.c_str());
133 Commands
.push_back(c
);
137 Commands
.insert(Commands
.begin()+nPos
, c
);
141 // ------------------------------------------------------------------------------------------------
142 void CMacroCmd::delCommand (uint cmdNb
)
144 Commands
.erase(Commands
.begin()+cmdNb
);
147 // ------------------------------------------------------------------------------------------------
148 void CMacroCmd::moveUpCommand (uint cmdNb
)
150 if (cmdNb
== 0) return;
151 CCommand c
= Commands
[cmdNb
];
152 Commands
[cmdNb
] = Commands
[cmdNb
-1];
153 Commands
[cmdNb
-1] = c
;
156 // ------------------------------------------------------------------------------------------------
157 void CMacroCmd::moveDownCommand (uint cmdNb
)
159 if (cmdNb
== (Commands
.size()-1)) return;
160 CCommand c
= Commands
[cmdNb
];
161 Commands
[cmdNb
] = Commands
[cmdNb
+1];
162 Commands
[cmdNb
+1] = c
;
166 // ------------------------------------------------------------------------------------------------
168 // ------------------------------------------------------------------------------------------------
170 // ------------------------------------------------------------------------------------------------
171 CMacroCmdManager::CMacroCmdManager()
174 ActionManagers
.clear();
175 ActionManagers
.resize(2);
176 ActionManagers
[0] = &Actions
;
177 ActionManagers
[1] = &EditActions
;
180 _CurExecCmdWait
= -1;
184 _MacroIDGenerator
= 0;
187 CMacroCmdManager::~CMacroCmdManager()
191 // ------------------------------------------------------------------------------------------------
192 void CMacroCmdManager::releaseInstance()
201 // ------------------------------------------------------------------------------------------------
202 void CMacroCmdManager::initInGame()
204 // Get all custom icon bitmaps
205 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
206 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
207 CInterfaceOptions
*pIO
= CWidgetManager::getInstance()->getOptions("macro_custom_icon");
213 const string prefix
[3] = { "bg_", "fg_", "ov_" };
214 vector
<sint32
> *wheretostock
[3] = { &_OptBackId
, &_OptIconId
, &_OptOverId
};
216 for (nOpt
= 0; nOpt
< 3; nOpt
++)
221 sTmp
= pIO
->getValStr(prefix
[nOpt
]+NLMISC::toString(i
));
224 sint32 nTexId
= rVR
.getTextureIdFromName(sTmp
);
225 wheretostock
[nOpt
]->push_back(nTexId
);
229 while (!sTmp
.empty());
234 NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_NUMBER")->setValue64(0);
236 // Create the NewKey container. Can edit key, and can assign all actions (not only macroisable ones)
237 NewKey
= new CModalContainerEditCmd
;
238 NewKey
->create("newkey", true, true);
240 // Create the EditCmd container. Cannot edit key, and can assign only macroisable actions
241 EditCmd
= new CModalContainerEditCmd
;
242 EditCmd
->create("editcmd", false, false);
244 // Put the macro id generator after the last macro ID
245 for (uint i
= 0; i
< _Macros
.size(); ++i
)
247 if (_Macros
[i
].ID
>= _MacroIDGenerator
)
249 _MacroIDGenerator
= _Macros
[i
].ID
+ 1;
254 // ------------------------------------------------------------------------------------------------
255 void CMacroCmdManager::uninitInGame()
269 // ------------------------------------------------------------------------------------------------
270 void CMacroCmdManager::removeAllMacros()
275 // ------------------------------------------------------------------------------------------------
276 void CMacroCmdManager::addMacro (const CMacroCmd
&m
, sint32 nPos
)
278 delActionManagerEntries();
284 mCopy
.ID
= _MacroIDGenerator
;
290 _Macros
.push_back(mCopy
);
294 _Macros
.insert(_Macros
.begin()+nPos
, mCopy
);
296 addActionManagerEntries();
299 // ------------------------------------------------------------------------------------------------
300 void CMacroCmdManager::delMacro(sint32 nMacNb
)
302 delActionManagerEntries();
303 _Macros
.erase(_Macros
.begin()+nMacNb
);
304 addActionManagerEntries();
307 // ------------------------------------------------------------------------------------------------
308 // Refresh key association that can be changed in another place than in macro container
309 void CMacroCmdManager::refreshMacroCombo()
311 CActionsManager
*pAM
= ActionManagers
[0];
313 for (uint i
=0; i
< _Macros
.size(); ++i
)
315 const CActionsManager::TActionComboMap
&rACmap
= pAM
->getActionComboMap();
316 CActionsManager::TActionComboMap::const_iterator it
= rACmap
.find(CAction::CName(AH_MACRO_EXEC
,toString(i
).c_str()));
317 if (it
!= rACmap
.end())
318 _Macros
[i
].Combo
= it
->second
;
320 _Macros
[i
].Combo
.Key
= KeyCount
;
324 // ------------------------------------------------------------------------------------------------
325 // Remove all action manager entries
326 void CMacroCmdManager::delActionManagerEntries()
330 CActionsManager
*pAM
= ActionManagers
[0];
332 // Remove all combos (seach them in the action manager)
333 for (uint i
=0; i
< _Macros
.size(); ++i
)
335 const CActionsManager::TActionComboMap
&rACmap
= pAM
->getActionComboMap();
336 CActionsManager::TActionComboMap::const_iterator it
= rACmap
.find(CAction::CName(AH_MACRO_EXEC
,toString(i
).c_str()));
337 if (it
!= rACmap
.end())
339 pAM
->removeCombo(it
->second
);
344 pAM
->removeCategory("MacroCat");
347 // ------------------------------------------------------------------------------------------------
348 // Build the parameters on the action manager
349 void CMacroCmdManager::addActionManagerEntries()
351 CActionsManager
*pAM
= ActionManagers
[0];
353 // Create new category
356 cat
.LocalizedName
= "uiMacroCat";
357 cat
.Name
= "MacroCat";
360 a
.Name
= AH_MACRO_EXEC
;
361 a
.LocalizedName
= "uiMacroExec";
365 CBaseAction::CParameter p
;
366 p
.Type
= CBaseAction::CParameter::Constant
;
367 p
.LocalizedName
= "uiMacroName";
370 for (i
=0; i
< _Macros
.size(); ++i
)
372 CBaseAction::CParameter::CValue v
;
373 v
.LocalizedValue
= _Macros
[i
].Name
;
374 v
.Value
= toString(i
);
376 p
.Values
.push_back(v
);
378 a
.Parameters
.push_back(p
);
379 cat
.BaseActions
.push_back(a
);
380 cat
.Macroisable
= false; // not macroisable (do not allow recurs)
381 pAM
->addCategory(cat
);
384 for (i
=0; i
< _Macros
.size(); ++i
)
386 if (_Macros
[i
].Combo
.Key
!= KeyCount
)
388 pAM
->addCombo(CAction::CName(AH_MACRO_EXEC
,toString(i
).c_str()), _Macros
[i
].Combo
);
393 // ------------------------------------------------------------------------------------------------
395 void CMacroCmdManager::execute(uint nMacronb
)
397 if (_CurExecMac
!= -1) return; // Cannot execute a macro while last macro is not finished
398 _CurExecMac
= nMacronb
;
400 _CurExecCmdWait
= -1;
401 updateMacroExecution();
404 // ------------------------------------------------------------------------------------------------
405 // execute a macro from an ID of macro
406 void CMacroCmdManager::executeID (sint32 nMacroID
)
408 // Look for the macro
409 for (uint i
= 0; i
< _Macros
.size(); ++i
)
411 if (_Macros
[i
].ID
== nMacroID
)
417 nlwarning("Macro (ID:%d) not found", nMacroID
);
420 // ------------------------------------------------------------------------------------------------
421 const CMacroCmd
*CMacroCmdManager::getMacroFromMacroID(sint32 nMacroID
)
423 // Look for the macro
424 for (uint i
= 0; i
< _Macros
.size(); ++i
)
426 if (_Macros
[i
].ID
== nMacroID
)
431 nlwarning("Macro (ID:%d) not found", nMacroID
);
435 // ------------------------------------------------------------------------------------------------
436 void CMacroCmdManager::updateMacroExecution ()
438 if (_CurExecMac
!= -1)
440 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
442 CMacroCmd
&rMC
= _Macros
[_CurExecMac
];
446 // Check if current command is waiting for finish
447 if (_CurExecCmdWait
!= -1)
449 // Is the command ended ?
450 if (_CurExecCmdWaitEnded
)
452 _CurExecCmdWaitEnded
= false;
453 // Yes ! ok lets process next command
454 _CurExecCmdWait
= -1;
456 if (_CurExecCmd
== (sint32
)rMC
.Commands
.size())
464 // The command has not ended : Do not continue executing anything !
469 CMacroCmd::CCommand
&rC
= rMC
.Commands
[_CurExecCmd
];
471 // If this is a 'waitforserver' action command that we have to wait for
472 bool bWaitForServer
= false;
473 for (uint j
= 0; j
< ActionManagers
.size(); ++j
)
475 CAction::CName
c(rC
.Name
.c_str(), rC
.Params
.c_str());
476 const CBaseAction
*pBA
= ActionManagers
[j
]->getBaseAction(c
);
479 if (pBA
->WaitForServer
)
480 bWaitForServer
= true;
485 // Here we have to execute the current command
486 CAHManager::getInstance()->runActionHandler(rC
.Name
, NULL
, rC
.Params
);
488 // Flush interface links (else bug with Macro "Select ShortCutBar/Run Shortcut"
489 IngameDbMngr
.flushObserverCalls();
490 NLGUI::CDBManager::getInstance()->flushObserverCalls();
494 _CurExecCmdWait
= _CurExecCmd
;
495 _CurExecCmdWaitId
= _ActionId
;
496 _CurExecCmdWaitEnded
= false;
502 if (_CurExecCmd
== (sint32
)rMC
.Commands
.size())
511 // ------------------------------------------------------------------------------------------------
512 void CMacroCmdManager::receiveActionEnd(uint8 actionId
)
514 if (_CurExecCmd
!= -1)
515 if (_CurExecCmdWait
!= -1)
516 if (_CurExecCmdWaitId
== actionId
)
518 _CurExecCmdWaitEnded
= true;
522 // ------------------------------------------------------------------------------------------------
523 void CMacroCmdManager::refreshAllKeyDisplays()
525 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
526 // Refresh Key Window
527 CAHManager::getInstance()->runActionHandler("keys_open", NULL
);
528 // Refresh gestion_windows container
529 CAHManager::getInstance()->runActionHandler("gestion_windows_update_key_binding", NULL
);
532 // ------------------------------------------------------------------------------------------------
533 class CHandlerMacroExec
: public IActionHandler
536 virtual void execute(CCtrlBase
* /* pCaller */, const string
&Params
)
538 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
540 fromString(Params
, macro
);
541 pMCM
->execute (macro
);
544 REGISTER_ACTION_HANDLER( CHandlerMacroExec
, AH_MACRO_EXEC
);
546 // ------------------------------------------------------------------------------------------------
547 class CHandlerMacroRecActEnd
: public IActionHandler
550 virtual void execute(CCtrlBase
* /* pCaller */, const string
&/* Params */)
552 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
553 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
554 pMCM
->receiveActionEnd((uint8
)NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_NUMBER")->getValue64());
557 REGISTER_ACTION_HANDLER( CHandlerMacroRecActEnd
, "macro_receive_action_end");
560 // ***************************************************************************
561 // ***************************************************************************
562 // ***************************************************************************
563 // MACRO INTERFACE MACRO INTERFACE MACRO INTERFACE MACRO INTERFACE MACRO
564 // ***************************************************************************
565 // ***************************************************************************
566 // ***************************************************************************
568 // ***************************************************************************
569 // macro_icon_creation CONTAINER
570 // ***************************************************************************
572 // ***************************************************************************
573 class CHandlerSetMacroBack
: public IActionHandler
576 virtual void execute(CCtrlBase
* /* pCaller */, const string
&Params
)
578 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
579 string sTP
= getParam(Params
, "target");
580 if (sTP
.empty()) return;
581 CDBCtrlSheet
*pCS
= dynamic_cast<CDBCtrlSheet
*>(CWidgetManager::getInstance()->getElementFromId(sTP
));
583 fromString(getParam(Params
, "value"), nb
);
584 if (pCS
!= NULL
) pCS
->setMacroBack((uint8
)nb
);
587 REGISTER_ACTION_HANDLER( CHandlerSetMacroBack
, "set_macro_back");
589 // ***************************************************************************
590 class CHandlerSetMacroIcon
: public IActionHandler
593 virtual void execute(CCtrlBase
* /* pCaller */, const string
&Params
)
595 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
596 string sTP
= getParam(Params
, "target");
597 if (sTP
.empty()) return;
598 CDBCtrlSheet
*pCS
= dynamic_cast<CDBCtrlSheet
*>(CWidgetManager::getInstance()->getElementFromId(sTP
));
600 fromString(getParam(Params
, "value"), nb
);
601 if (pCS
!= NULL
) pCS
->setMacroIcon((uint8
)nb
);
604 REGISTER_ACTION_HANDLER( CHandlerSetMacroIcon
, "set_macro_icon");
606 // ***************************************************************************
607 class CHandlerSetMacroOver
: public IActionHandler
610 virtual void execute(CCtrlBase
* /* pCaller */, const string
&Params
)
612 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
613 string sTP
= getParam(Params
, "target");
614 if (sTP
.empty()) return;
615 CDBCtrlSheet
*pCS
= dynamic_cast<CDBCtrlSheet
*>(CWidgetManager::getInstance()->getElementFromId(sTP
));
617 fromString(getParam(Params
, "value"), nb
);
618 if (pCS
!= NULL
) pCS
->setMacroOver((uint8
)nb
);
621 REGISTER_ACTION_HANDLER( CHandlerSetMacroOver
, "set_macro_over");
623 // ***************************************************************************
624 class CHandlerEBUpdateMacroText
: public IActionHandler
627 virtual void execute(CCtrlBase
*pCaller
, const string
&Params
)
629 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
630 CGroupEditBox
*pEB
= dynamic_cast<CGroupEditBox
*>(pCaller
);
631 if (pEB
== NULL
) return;
633 CDBCtrlSheet
*pCS
= dynamic_cast<CDBCtrlSheet
*>(CWidgetManager::getInstance()->getElementFromId(Params
));
634 if (pCS
== NULL
) return;
635 pCS
->setMacroText(pEB
->getInputString());
638 REGISTER_ACTION_HANDLER( CHandlerEBUpdateMacroText
, "eb_update_macro_text");
640 // ***************************************************************************
641 // Called when we click on the ok button from the macro_icon_creation container
642 class CHandlerMacroIconCreation
: public IActionHandler
645 virtual void execute(CCtrlBase
* /* pCaller */, const string
&/* Params */)
647 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
648 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
650 CDBCtrlSheet
*pCS
= dynamic_cast<CDBCtrlSheet
*>(CWidgetManager::getInstance()->getElementFromId(CTRL_MACROICONCREATION_ICON
));
651 if (pCS
!= NULL
) pCS
->writeToMacro(pMCM
->CurrentEditMacro
);
653 pCS
= dynamic_cast<CDBCtrlSheet
*>(CWidgetManager::getInstance()->getElementFromId(CTRL_NEWMACRO_ICON
));
654 if (pCS
!= NULL
) pCS
->readFromMacro(pMCM
->CurrentEditMacro
);
656 CWidgetManager::getInstance()->disableModalWindow();
659 REGISTER_ACTION_HANDLER( CHandlerMacroIconCreation
, "macro_icon_creation_ok");
661 // ***************************************************************************
662 // Called when the modal macro icon creation opens
663 class CHandlerMacroIconCreationOpen
: public IActionHandler
666 virtual void execute(CCtrlBase
* /* pCaller */, const string
&/* Params */)
668 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
669 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
671 CAHManager::getInstance()->runActionHandler("reset_pushed", NULL
, string("dblink=")+GROUP_MACROICONCREATION_BACK
);
672 CAHManager::getInstance()->runActionHandler("reset_pushed", NULL
, string("dblink=")+GROUP_MACROICONCREATION_ICON
);
673 CAHManager::getInstance()->runActionHandler("reset_pushed", NULL
, string("dblink=")+GROUP_MACROICONCREATION_OVER
);
675 uint8 back
= pMCM
->CurrentEditMacro
.BitmapBack
;
678 string sButton
= string(GROUP_MACROICONCREATION_BACK
) + CTRL_MACROICONCREATION_BUTTON
+ toString(back
+1);
679 CCtrlBaseButton
*pCB
= dynamic_cast<CCtrlBaseButton
*>(CWidgetManager::getInstance()->getElementFromId(sButton
));
680 if (pCB
!= NULL
) pCB
->setPushed(true);
683 uint8 icon
= pMCM
->CurrentEditMacro
.BitmapIcon
;
686 string sButton
= string(GROUP_MACROICONCREATION_ICON
) + CTRL_MACROICONCREATION_BUTTON
+ toString(icon
+1);
687 CCtrlBaseButton
*pCB
= dynamic_cast<CCtrlBaseButton
*>(CWidgetManager::getInstance()->getElementFromId(sButton
));
688 if (pCB
!= NULL
) pCB
->setPushed(true);
691 uint8 over
= pMCM
->CurrentEditMacro
.BitmapOver
;
694 string sButton
= string(GROUP_MACROICONCREATION_OVER
) + CTRL_MACROICONCREATION_BUTTON
+ toString(over
+1);
695 CCtrlBaseButton
*pCB
= dynamic_cast<CCtrlBaseButton
*>(CWidgetManager::getInstance()->getElementFromId(sButton
));
696 if (pCB
!= NULL
) pCB
->setPushed(true);
699 CGroupEditBox
*pEB
= dynamic_cast<CGroupEditBox
*>(CWidgetManager::getInstance()->getElementFromId(CTRL_MACROICONCREATION_EDITTEXT
));
702 pEB
->setInputString(pMCM
->CurrentEditMacro
.DispText
);
703 CDBCtrlSheet
*pCS
= dynamic_cast<CDBCtrlSheet
*>(CWidgetManager::getInstance()->getElementFromId(CTRL_MACROICONCREATION_ICON
));
705 pCS
->setMacroText(pEB
->getInputString());
708 CAHManager::getInstance()->runActionHandler("set_macro_back", NULL
, string("target=")+CTRL_MACROICONCREATION_ICON
+"|value="+toString(back
));
709 CAHManager::getInstance()->runActionHandler("set_macro_icon", NULL
, string("target=")+CTRL_MACROICONCREATION_ICON
+"|value="+toString(icon
));
710 CAHManager::getInstance()->runActionHandler("set_macro_over", NULL
, string("target=")+CTRL_MACROICONCREATION_ICON
+"|value="+toString(over
));
713 REGISTER_ACTION_HANDLER( CHandlerMacroIconCreationOpen
, "macro_icon_creation_open");
715 // ***************************************************************************
716 // new_macro CONTAINER
717 // ***************************************************************************
719 // ***************************************************************************
720 sint32
getCmdNbFromId(string id
) // copy the string ! (do not change for a const string &)
722 if (id
.rfind(":c") == string::npos
) return -1;
723 id
= id
.substr(id
.rfind(":c")+2,id
.size());
729 // ***************************************************************************
730 // Called from context menu when we right click on a command of the new_macro container
731 class CHandlerNewMacroCmdMoveUp
: public IActionHandler
734 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
736 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
737 sint nCmdNb
= getCmdNbFromId(pCaller
->getId());
738 pMCM
->CurrentEditMacro
.moveUpCommand(nCmdNb
);
739 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
740 CMacroCmdManager::getInstance()->EditCmd
->deactivate();
741 CAHManager::getInstance()->runActionHandler("new_macro_open",NULL
);
744 REGISTER_ACTION_HANDLER( CHandlerNewMacroCmdMoveUp
, "new_macro_cmd_move_up");
746 // ***************************************************************************
747 // Called from context menu when we right click on a command of the new_macro container
748 class CHandlerNewMacroCmdMoveDown
: public IActionHandler
751 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
753 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
754 sint nCmdNb
= getCmdNbFromId(pCaller
->getId());
755 pMCM
->CurrentEditMacro
.moveDownCommand(nCmdNb
);
756 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
757 CMacroCmdManager::getInstance()->EditCmd
->deactivate();
758 CAHManager::getInstance()->runActionHandler("new_macro_open",NULL
);
761 REGISTER_ACTION_HANDLER( CHandlerNewMacroCmdMoveDown
, "new_macro_cmd_move_down");
763 // ***************************************************************************
764 // Called from context menu when we right click on a command of the new_macro container
765 class CHandlerNewMacroCmdEdit
: public IActionHandler
768 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
770 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
771 sint nCmdNb
= getCmdNbFromId(pCaller
->getId());
772 pMCM
->EditCmd
->activateFrom (pMCM
->CurrentEditMacro
.Commands
[nCmdNb
].Name
,
773 pMCM
->CurrentEditMacro
.Commands
[nCmdNb
].Params
,
777 REGISTER_ACTION_HANDLER( CHandlerNewMacroCmdEdit
, "new_macro_cmd_edit");
779 // ***************************************************************************
780 // Called from context menu when we right click on a command of the new_macro container
781 class CHandlerNewMacroCmdCopy
: public IActionHandler
784 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
786 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
787 sint nCmdNb
= getCmdNbFromId(pCaller
->getId());
788 pMCM
->CurrentEditMacro
.addCommand(pMCM
->CurrentEditMacro
.Commands
[nCmdNb
].Name
,
789 pMCM
->CurrentEditMacro
.Commands
[nCmdNb
].Params
,
791 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
792 CMacroCmdManager::getInstance()->EditCmd
->deactivate();
793 CAHManager::getInstance()->runActionHandler("new_macro_open",NULL
);
796 REGISTER_ACTION_HANDLER( CHandlerNewMacroCmdCopy
, "new_macro_cmd_copy");
798 // ***************************************************************************
799 // Called from context menu when we right click on a command of the new_macro container
800 class CHandlerNewMacroCmdDelete
: public IActionHandler
803 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
805 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
806 sint nCmdNb
= getCmdNbFromId(pCaller
->getId());
807 pMCM
->CurrentEditMacro
.delCommand(nCmdNb
);
808 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
809 CMacroCmdManager::getInstance()->EditCmd
->deactivate();
810 CAHManager::getInstance()->runActionHandler("new_macro_open",NULL
);
813 REGISTER_ACTION_HANDLER( CHandlerNewMacroCmdDelete
, "new_macro_cmd_delete");
815 // ***************************************************************************
816 void addCommandLine (CGroupList
*pParent
, uint cmdNb
, const string
&cmdName
)
818 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
820 vector
< pair
<string
, string
> > vParams
;
821 vParams
.push_back(pair
<string
,string
>("id", "c"+toString(cmdNb
)));
822 CInterfaceGroup
*pNewCmd
= CWidgetManager::getInstance()->getParser()->createGroupInstance(TEMPLATE_NEWMACRO_COMMAND
, pParent
->getId(), vParams
);
823 if (pNewCmd
== NULL
) return;
825 CViewText
*pVT
= dynamic_cast<CViewText
*>(pNewCmd
->getView(TEMPLATE_NEWMACRO_COMMAND_TEXT
));
826 if (pVT
!= NULL
) pVT
->setText(cmdName
);
828 pNewCmd
->setParent (pParent
);
829 pParent
->addChild (pNewCmd
);
832 // ***************************************************************************
833 // Called when we push the new command button on the new_macro container
834 class CHandlerNewMacroNewCmd
: public IActionHandler
837 virtual void execute(CCtrlBase
* /* pCaller */, const string
&/* Params */)
839 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
840 CAHManager::getInstance()->runActionHandler("new_macro_enter_name",NULL
);
841 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
842 pMCM
->EditCmd
->activate();
845 REGISTER_ACTION_HANDLER( CHandlerNewMacroNewCmd
, "new_macro_new_cmd");
847 // ***************************************************************************
848 // Called when we enter the name of the current macro
849 class CHandlerNewMacroEnterName
: public IActionHandler
852 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
854 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
856 pCaller
= dynamic_cast<CCtrlBase
*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:new_macro:content:edit_name"));
857 CGroupEditBox
*pEB
= dynamic_cast<CGroupEditBox
*>(pCaller
);
858 if (pEB
== NULL
) return;
860 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
861 pMCM
->CurrentEditMacro
.Name
= pEB
->getInputString();
862 if ((pMCM
->CurrentEditMacro
.Name
.size() >= 2) &&
863 (pMCM
->CurrentEditMacro
.Name
[0] == 'u') && (pMCM
->CurrentEditMacro
.Name
[1] == 'i'))
864 pMCM
->CurrentEditMacro
.Name
[0] = 'U';
865 pEB
->setInputString(pMCM
->CurrentEditMacro
.Name
);
868 REGISTER_ACTION_HANDLER( CHandlerNewMacroEnterName
, "new_macro_enter_name");
870 // ***************************************************************************
871 // Called when the new_macro container opens
872 class CHandlerNewMacroOpen
: public IActionHandler
875 virtual void execute(CCtrlBase
* /* pCaller */, const string
&/* Params */)
877 // Init 'new_macro' container from the global current macro (gCurrentEditMacro)
878 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
879 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
881 CDBCtrlSheet
*pCS
= dynamic_cast<CDBCtrlSheet
*>(CWidgetManager::getInstance()->getElementFromId(CTRL_NEWMACRO_ICON
));
882 if (pCS
!= NULL
) pCS
->readFromMacro(pMCM
->CurrentEditMacro
);
884 CGroupEditBox
*pEB
= dynamic_cast<CGroupEditBox
*>(CWidgetManager::getInstance()->getElementFromId(GROUP_NEWMACRO_EDIT_NAME
));
885 if (pEB
!= NULL
) pEB
->setInputString(pMCM
->CurrentEditMacro
.Name
);
887 CGroupList
*pList
= dynamic_cast<CGroupList
*>(CWidgetManager::getInstance()->getElementFromId(GROUP_NEWMACRO_COMMANDS
));
888 if (pList
== NULL
) return;
890 CViewText
*pVT
= dynamic_cast<CViewText
*>(CWidgetManager::getInstance()->getElementFromId(VIEW_NEWMACRO_KEY
));
893 if (pMCM
->CurrentEditMacro
.Combo
.Key
== KeyCount
)
894 pVT
->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT
));
896 pVT
->setText(pMCM
->CurrentEditMacro
.Combo
.toString());
899 pList
->clearGroups();
900 pList
->setDynamicDisplaySize(true);
902 for (uint i
= 0; i
< pMCM
->CurrentEditMacro
.Commands
.size(); ++i
)
905 for (uint j
= 0; j
< pMCM
->ActionManagers
.size(); ++j
)
907 CAction::CName
c(pMCM
->CurrentEditMacro
.Commands
[i
].Name
.c_str(), pMCM
->CurrentEditMacro
.Commands
[i
].Params
.c_str());
908 if (pMCM
->ActionManagers
[j
]->getBaseAction(c
) != NULL
)
910 commandName
= pMCM
->ActionManagers
[j
]->getBaseAction(c
)->getActionLocalizedText(c
);
915 addCommandLine(pList
, i
, commandName
);
917 pMCM
->EditCmd
->CurAM
= pMCM
->ActionManagers
[0];
920 REGISTER_ACTION_HANDLER( CHandlerNewMacroOpen
, "new_macro_open");
922 // ***************************************************************************
923 // Called when we click on ok button of the new_macro container
924 class CHandlerNewMacroOk
: public IActionHandler
927 virtual void execute(CCtrlBase
* /* pCaller */, const string
&/* Params */)
929 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
930 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
931 CSPhraseManager
*pPM
= CSPhraseManager::getInstance();
934 CAHManager::getInstance()->runActionHandler("new_macro_enter_name",NULL
);
936 // Check if macro has more than one command
937 if (pMCM
->CurrentEditMacro
.Commands
.empty()) return;
940 if (pMCM
->CurrentEditMacroNb
!= -1)
942 // retrieve the Id of the edited macro, to keep the same id in addMacro()
943 pMCM
->CurrentEditMacro
.ID
= pMCM
->getMacros()[pMCM
->CurrentEditMacroNb
].ID
;
944 pMCM
->delMacro(pMCM
->CurrentEditMacroNb
);
945 pMCM
->addMacro(pMCM
->CurrentEditMacro
,pMCM
->CurrentEditMacroNb
);
946 // update the Memory Manager
947 pPM
->updateMacroShortcuts(pMCM
->CurrentEditMacro
.ID
);
948 // reset id of EditMacro
949 pMCM
->CurrentEditMacro
.ID
= -1;
953 pMCM
->addMacro(pMCM
->CurrentEditMacro
);
956 CGroupContainer
*pGC
= dynamic_cast<CGroupContainer
*>(CWidgetManager::getInstance()->getElementFromId(WIN_NEWMACRO
));
957 if (pGC
!= NULL
) pGC
->setActive (false);
959 CAHManager::getInstance()->runActionHandler("macros_open",NULL
);
961 // Refresh key containers
962 pMCM
->refreshAllKeyDisplays();
965 REGISTER_ACTION_HANDLER( CHandlerNewMacroOk
, "new_macro_ok");
967 // ***************************************************************************
969 // ***************************************************************************
971 // ***************************************************************************
972 sint32
getMacroFromId(string id
) // Do not change for a const string &
974 string::size_type npos
= id
.rfind(":m");
975 if (npos
== string::npos
) return -1;
976 id
= id
.substr(npos
+2,id
.size());
982 // ***************************************************************************
983 void addMacroLine (CGroupList
*pParent
, uint macNb
, const CMacroCmd
¯o
)
985 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
987 vector
< pair
<string
, string
> > vParams
;
988 vParams
.push_back(pair
<string
,string
>("id", "m"+toString(macNb
)));
989 CInterfaceGroup
*pNewMacro
= CWidgetManager::getInstance()->getParser()->createGroupInstance(TEMPLATE_MACRO_ELT
, pParent
->getId(), vParams
);
990 if (pNewMacro
== NULL
) return;
992 CViewText
*pVT
= dynamic_cast<CViewText
*>(pNewMacro
->getView(TEMPLATE_MACRO_ELT_TEXT
));
993 if (pVT
!= NULL
) pVT
->setText(macro
.Name
);
995 CDBCtrlSheet
*pCS
= dynamic_cast<CDBCtrlSheet
*>(pNewMacro
->getCtrl(TEMPLATE_MACRO_ELT_ICON
));
996 if (pCS
!= NULL
) pCS
->readFromMacro(macro
);
998 pVT
= dynamic_cast<CViewText
*>(pNewMacro
->getView(TEMPLATE_MACRO_ELT_KEYTEXT
));
1001 if (macro
.Combo
.Key
!= KeyCount
)
1002 pVT
->setText(macro
.Combo
.toString());
1004 pVT
->setText(CI18N::get(VIEW_EDITCMD_TEXT_KEY_DEFAULT
));
1007 pNewMacro
->setParent (pParent
);
1008 pParent
->addChild (pNewMacro
);
1010 // ***************************************************************************
1011 // Called when the macros container opens
1012 class CHandlerMacrosOpen
: public IActionHandler
1015 virtual void execute(CCtrlBase
* /* pCaller */, const string
&/* Params */)
1017 // Init 'macros' container from the macro manager
1018 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
1019 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
1021 CGroupList
*pList
= dynamic_cast<CGroupList
*>(CWidgetManager::getInstance()->getElementFromId(WIN_MACRO_CONTENT
));
1022 if (pList
== NULL
) return;
1024 pList
->clearGroups();
1025 pList
->setDynamicDisplaySize(true);
1027 // Refresh the shortcut key that can be changed in the keys container
1028 pMCM
->refreshMacroCombo();
1030 // Add all macros template
1031 const vector
<CMacroCmd
> &vM
= pMCM
->getMacros();
1032 for (uint i
= 0; i
< vM
.size(); ++i
)
1034 addMacroLine(pList
, i
, vM
[i
]);
1038 REGISTER_ACTION_HANDLER( CHandlerMacrosOpen
, "macros_open");
1040 // ***************************************************************************
1041 // Called when we click the new macro button on the macros container
1042 class CHandlerMacrosNewMacro
: public IActionHandler
1045 virtual void execute(CCtrlBase
* /* pCaller */, const string
&/* Params */)
1047 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
1048 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
1049 // Reinit the new_macro container and variables
1051 mc
.Name
= "NewMacro";
1055 pMCM
->CurrentEditMacro
= mc
;
1057 CGroupContainer
*pGC
= dynamic_cast<CGroupContainer
*>(CWidgetManager::getInstance()->getElementFromId(WIN_NEWMACRO
));
1060 pGC
->setTitle(NEWMACRO_TITLE_NEW
);
1061 pGC
->setActive (false);
1062 pGC
->setActive (true);
1065 pMCM
->CurrentEditMacroNb
= -1;
1066 pMCM
->EditCmd
->deactivate();
1069 REGISTER_ACTION_HANDLER( CHandlerMacrosNewMacro
, "macros_new_macro");
1071 // ***************************************************************************
1072 // Called from context menu on a macro
1073 class CHandlerMacrosExec
: public IActionHandler
1076 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
1078 sint nMacNb
= getMacroFromId(pCaller
->getId());
1080 CAHManager::getInstance()->runActionHandler(AH_MACRO_EXEC
,pCaller
,toString(nMacNb
));
1083 REGISTER_ACTION_HANDLER( CHandlerMacrosExec
, "macros_exec");
1085 // ***************************************************************************
1086 // Called from context menu on a macro
1087 class CHandlerMacrosEdit
: public IActionHandler
1090 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
1092 sint nMacNb
= getMacroFromId(pCaller
->getId());
1093 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
1094 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
1095 pMCM
->CurrentEditMacro
= pMCM
->getMacros()[nMacNb
];
1096 pMCM
->CurrentEditMacroNb
= nMacNb
;
1097 CGroupContainer
*pGC
= dynamic_cast<CGroupContainer
*>(CWidgetManager::getInstance()->getElementFromId(WIN_NEWMACRO
));
1100 pGC
->setTitle(NEWMACRO_TITLE_EDIT
);
1101 pGC
->setActive (false);
1102 pGC
->setActive (true);
1106 REGISTER_ACTION_HANDLER( CHandlerMacrosEdit
, "macros_edit");
1108 // ***************************************************************************
1109 // Called from context menu on a macro
1110 class CHandlerMacrosCopy
: public IActionHandler
1113 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
1115 sint nMacNb
= getMacroFromId(pCaller
->getId());
1116 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
1117 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
1119 // duplicate selected macro
1120 CMacroCmd m
= pMCM
->getMacros()[nMacNb
];
1122 m
.Combo
.Key
= KeyCount
;
1123 m
.Combo
.KeyButtons
= noKeyButton
;
1124 pMCM
->addMacro(m
, nMacNb
+1);
1126 CAHManager::getInstance()->runActionHandler("macros_open",NULL
);
1129 REGISTER_ACTION_HANDLER( CHandlerMacrosCopy
, "macros_copy");
1131 // ***************************************************************************
1132 // Called from context menu on a macro
1133 class CHandlerMacrosDel
: public IActionHandler
1136 virtual void execute(CCtrlBase
*pCaller
, const string
&/* Params */)
1138 // build params string
1139 sint nMacNb
= getMacroFromId(pCaller
->getId());
1140 string
Params("MacroId=" + toString(nMacNb
));
1142 // Ask if ok before calling action handler to delete macro
1143 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
1144 pIM
->validMessageBox(CInterfaceManager::QuestionIconMsg
, CI18N::get("uiQDeleteMacro"), "macros_do_del", Params
);
1147 REGISTER_ACTION_HANDLER( CHandlerMacrosDel
, "macros_del");
1149 // ***************************************************************************
1150 // Called after the player confirmed he wants to delete the macro
1151 class CHandlerMacrosDoDel
: public IActionHandler
1154 virtual void execute(CCtrlBase
* /*pCaller*/, const string
& Params
)
1156 CSPhraseManager
*pPM
= CSPhraseManager::getInstance();
1157 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
1158 CMacroCmdManager
*pMCM
= CMacroCmdManager::getInstance();
1162 fromString(getParam(Params
, "MacroId"), nMacNb
);
1163 // update the TB Manager
1164 pPM
->deleteMacroShortcuts(pMCM
->getMacros()[nMacNb
].ID
);
1166 pMCM
->delMacro(nMacNb
);
1167 CAHManager::getInstance()->runActionHandler("macros_open",NULL
);
1169 // Refresh key containers
1170 pMCM
->refreshAllKeyDisplays();
1173 REGISTER_ACTION_HANDLER( CHandlerMacrosDoDel
, "macros_do_del");