1 /*!
2 	@file
3 	@author		Albert Semenov
4 	@date		11/2009
5 */
6 #include "Precompiled.h"
7 #include "ControlPanel.h"
8 
9 namespace demo
10 {
11 
ControlPanel(PointerContextManager * _manager)12 	ControlPanel::ControlPanel(PointerContextManager* _manager) :
13 		mPointerContextManager(_manager)
14 	{
15 		initialiseByAttributes(this);
16 
17 		const MyGUI::IntSize& size = mMainWidget->getParentSize();
18 		mMainWidget->setPosition(10, size.height - 10 - mMainWidget->getHeight());
19 
20 		mBusy->eventMouseButtonClick += MyGUI::newDelegate(this, &ControlPanel::notifyMouseButtonClick);
21 		mRepair->eventMouseButtonClick += MyGUI::newDelegate(this, &ControlPanel::notifyMouseButtonClick);
22 		mAttack->eventMouseButtonClick += MyGUI::newDelegate(this, &ControlPanel::notifyMouseButtonClick);
23 	}
24 
notifyMouseButtonClick(MyGUI::Widget * _sender)25 	void ControlPanel::notifyMouseButtonClick(MyGUI::Widget* _sender)
26 	{
27 		MyGUI::Button* button = _sender->castType<MyGUI::Button>();
28 		std::string context = button->getUserString("Context");
29 
30 		bool pressed = button->getStateSelected();
31 		button->setStateSelected(!pressed);
32 		if (pressed)
33 			mPointerContextManager->removeContext(context);
34 		else
35 			mPointerContextManager->addContext(context);
36 
37 		// сбрасываем радио
38 		if (button == mRepair)
39 		{
40 			if (mAttack->getStateSelected())
41 			{
42 				mAttack->setStateSelected(false);
43 				mPointerContextManager->removeContext(mAttack->getUserString("Context"));
44 			}
45 		}
46 		else if (button == mAttack)
47 		{
48 			if (mRepair->getStateSelected())
49 			{
50 				mRepair->setStateSelected(false);
51 				mPointerContextManager->removeContext(mRepair->getUserString("Context"));
52 			}
53 		}
54 
55 	}
56 
injectKeyPress(MyGUI::KeyCode _key)57 	void ControlPanel::injectKeyPress(MyGUI::KeyCode _key)
58 	{
59 		if (_key == MyGUI::KeyCode::F1)
60 			notifyMouseButtonClick(mBusy);
61 		else if (_key == MyGUI::KeyCode::F2)
62 			notifyMouseButtonClick(mRepair);
63 		else if (_key == MyGUI::KeyCode::F3)
64 			notifyMouseButtonClick(mAttack);
65 	}
66 
67 } // namespace demo
68