|
5 | 5 | #include "../game_cl_teamdeathmatch.h" |
6 | 6 | #include "UIKickPlayer.h" |
7 | 7 | #include "UIChangeMap.h" |
8 | | -//#include "UIMapList.h" |
9 | | - |
10 | | -CUIChangeWeather::CUIChangeWeather(){ |
11 | | - bkgrnd = xr_new<CUIStatic>(); |
12 | | - bkgrnd->SetAutoDelete(true); |
13 | | - AttachChild(bkgrnd); |
14 | | - |
15 | | - header = xr_new<CUITextWnd>(); |
16 | | - header->SetAutoDelete(true); |
17 | | - AttachChild(header); |
18 | | - |
19 | | - btn_cancel = xr_new<CUI3tButton>(); |
20 | | - btn_cancel->SetAutoDelete(true); |
21 | | - AttachChild(btn_cancel); |
22 | | - |
23 | | - for (int i = 0; i<4; i++) |
24 | | - { |
25 | | - btn[i] = xr_new<CUI3tButton>(); |
26 | | - btn[i]->SetAutoDelete(true); |
27 | | - AttachChild(btn[i]); |
28 | | - |
29 | | - m_data[i].m_text = xr_new<CUITextWnd>(); |
30 | | - m_data[i].m_text->SetAutoDelete(true); |
31 | | - AttachChild(m_data[i].m_text); |
32 | | - } |
| 8 | +#include <dinput.h> |
| 9 | +#include "xrEngine/XR_IOConsole.h" |
| 10 | +#include "UIMapList.h" |
| 11 | +#include "../UIGameCustom.h" |
33 | 12 |
|
34 | | - weather_counter = 0; |
| 13 | +ButtonListDialog::ButtonListDialog() |
| 14 | +{ |
| 15 | + Background = xr_new<CUIStatic>(); |
| 16 | + Background->SetAutoDelete(true); |
| 17 | + AttachChild(Background); |
| 18 | + Header = xr_new<CUITextWnd>(); |
| 19 | + Header->SetAutoDelete(true); |
| 20 | + AttachChild(Header); |
| 21 | + CancelButton = xr_new<CUI3tButton>(); |
| 22 | + CancelButton->SetAutoDelete(true); |
| 23 | + AttachChild(CancelButton); |
35 | 24 | } |
36 | 25 |
|
37 | | -void CUIChangeWeather::InitChangeWeather(CUIXml& xml_doc) |
| 26 | +void ButtonListDialog::Initialize(int buttonCount) |
38 | 27 | { |
39 | | - CUIXmlInit::InitWindow(xml_doc, "change_weather", 0, this); |
40 | | - |
41 | | - CUIXmlInit::InitTextWnd(xml_doc, "change_weather:header", 0, header); |
42 | | - CUIXmlInit::InitStatic(xml_doc, "change_weather:background", 0, bkgrnd); |
43 | | - |
44 | | - string256 _path; |
45 | | - for (int i = 0; i<4; i++){ |
46 | | - xr_sprintf(_path, "change_weather:btn_%d", i + 1); |
47 | | - CUIXmlInit::Init3tButton(xml_doc, _path, 0, btn[i]); |
48 | | - xr_sprintf(_path, "change_weather:txt_%d", i + 1); |
49 | | - CUIXmlInit::InitTextWnd(xml_doc, _path, 0, m_data[i].m_text); |
50 | | - } |
51 | | - |
52 | | - CUIXmlInit::Init3tButton(xml_doc, "change_weather:btn_cancel", 0, btn_cancel); |
53 | | - |
54 | | - ParseWeather(); |
| 28 | + buttons.reserve(buttonCount); |
| 29 | + for (int i = 0; i < buttonCount; i++) |
| 30 | + { |
| 31 | + NamedButton btn; |
| 32 | + btn.Button = xr_new<CUI3tButton>(); |
| 33 | + btn.Button->SetAutoDelete(true); |
| 34 | + AttachChild(btn.Button); |
| 35 | + btn.Text = xr_new<CUITextWnd>(); |
| 36 | + btn.Text->SetAutoDelete(true); |
| 37 | + AttachChild(btn.Text); |
| 38 | + buttons.push_back(btn); |
| 39 | + } |
55 | 40 | } |
56 | 41 |
|
57 | | -void CUIChangeWeather::SendMessage(CUIWindow* pWnd, s16 msg, void* pData){ |
58 | | - if (BUTTON_CLICKED == msg) |
59 | | - { |
60 | | - if (btn_cancel == pWnd) |
61 | | - OnBtnCancel(); |
62 | | - for (int i=0; i<4; i++){ |
63 | | - if (btn[i] == pWnd){ |
64 | | - OnBtn(i); |
65 | | - return; |
66 | | - } |
67 | | - } |
68 | | - } |
69 | | - |
| 42 | +void ButtonListDialog::OnCancel() |
| 43 | +{ |
| 44 | + HideDialog(); |
70 | 45 | } |
71 | 46 |
|
72 | | -#include <dinput.h> |
73 | | - |
74 | | -bool CUIChangeWeather::OnKeyboardAction(int dik, EUIMessages keyboard_action){ |
75 | | - CUIDialogWnd::OnKeyboardAction(dik, keyboard_action); |
76 | | - if (WINDOW_KEY_PRESSED == keyboard_action){ |
77 | | - if (DIK_ESCAPE == dik){ |
78 | | - OnBtnCancel(); |
79 | | - return true; |
80 | | - } |
81 | | - if (dik >= DIK_1 && dik <= DIK_4){ |
82 | | - OnBtn(dik - DIK_1); |
83 | | - return true; |
84 | | - } |
85 | | - } |
86 | | - |
87 | | - return false; |
| 47 | +const ButtonListDialog::NamedButton& ButtonListDialog::GetButton(int i) const |
| 48 | +{ |
| 49 | + return buttons[i]; |
88 | 50 | } |
89 | 51 |
|
90 | | -#include "../../xrEngine/xr_ioconsole.h" |
91 | | - |
92 | | -void CUIChangeWeather::OnBtn(int i) |
| 52 | +bool ButtonListDialog::OnKeyboardAction(int dik, EUIMessages keyboardAction) |
93 | 53 | { |
94 | | - string1024 command; |
95 | | - xr_sprintf (command, "cl_votestart changeweather %s %s", *m_data[i].m_weather_name, *m_data[i].m_weather_time); |
96 | | - Console->Execute (command); |
97 | | - HideDialog (); |
| 54 | + CUIDialogWnd::OnKeyboardAction(dik, keyboardAction); |
| 55 | + if (WINDOW_KEY_PRESSED == keyboardAction) |
| 56 | + { |
| 57 | + if (DIK_ESCAPE == dik) |
| 58 | + { |
| 59 | + OnCancel(); |
| 60 | + return true; |
| 61 | + } |
| 62 | + int btnCount = buttons.size(); |
| 63 | + if (dik >= DIK_1 && dik <= DIK_1-1+btnCount && btnCount <= 9) // handle 1..9 keys only |
| 64 | + { |
| 65 | + OnButtonClick(dik-DIK_1); |
| 66 | + return true; |
| 67 | + } |
| 68 | + } |
| 69 | + return false; |
98 | 70 | } |
99 | 71 |
|
100 | | -void CUIChangeWeather::OnBtnCancel() |
| 72 | +void ButtonListDialog::SendMessage(CUIWindow* wnd, s16 msg, void* data /*= nullptr */) |
101 | 73 | { |
102 | | - HideDialog (); |
| 74 | + if (BUTTON_CLICKED == msg) |
| 75 | + { |
| 76 | + if (CancelButton == wnd) |
| 77 | + OnCancel(); |
| 78 | + for (u32 i = 0; i < buttons.size(); i++) |
| 79 | + { |
| 80 | + if (buttons[i].Button == wnd) |
| 81 | + { |
| 82 | + OnButtonClick(i); |
| 83 | + return; |
| 84 | + } |
| 85 | + } |
| 86 | + } |
103 | 87 | } |
104 | 88 |
|
105 | | -#include "UIMapList.h" |
106 | | -#include "../UIGameCustom.h" |
107 | | - |
108 | | -void CUIChangeWeather::ParseWeather() |
| 89 | +void CUIChangeWeather::InitChangeWeather(CUIXml& xmlDoc) |
109 | 90 | { |
110 | | - weather_counter = 0; |
111 | | - |
112 | | - GAME_WEATHERS game_weathers = gMapListHelper.GetGameWeathers(); |
113 | | - GAME_WEATHERS_CIT it = game_weathers.begin(); |
114 | | - GAME_WEATHERS_CIT it_e = game_weathers.end(); |
115 | | - |
116 | | - for( ;it!=it_e; ++it) |
117 | | - { |
118 | | - AddWeather ( (*it).m_weather_name, (*it).m_start_time); |
119 | | - } |
120 | | -}; |
121 | | - |
122 | | -void CUIChangeWeather::AddWeather(const shared_str& weather, const shared_str& time){ |
123 | | -// m_data[weather_counter].m_text->SetTextST (weather.c_str()); |
124 | | - m_data[weather_counter].m_weather_name = weather; |
125 | | - m_data[weather_counter].m_weather_time = time; |
126 | | - weather_counter++; |
| 91 | + CUIXmlInit::InitWindow(xmlDoc, "change_weather", 0, this); |
| 92 | + CUIXmlInit::InitTextWnd(xmlDoc, "change_weather:header", 0, Header); |
| 93 | + CUIXmlInit::InitStatic(xmlDoc, "change_weather:background", 0, Background); |
| 94 | + CUIXmlInit::Init3tButton(xmlDoc, "change_weather:btn_cancel", 0, CancelButton); |
| 95 | + auto& gameWeathers = gMapListHelper.GetGameWeathers(); |
| 96 | + Initialize(gameWeathers.size()); |
| 97 | + weatherItems.resize(gameWeathers.size()); |
| 98 | + string256 path; |
| 99 | + for (u32 i = 0; i < weatherItems.size(); i++) |
| 100 | + { |
| 101 | + xr_sprintf(path, "change_weather:btn_%d", i+1); |
| 102 | + CUIXmlInit::Init3tButton(xmlDoc, path, 0, GetButton(i).Button); |
| 103 | + xr_sprintf(path, "change_weather:txt_%d", i+1); |
| 104 | + CUIXmlInit::InitTextWnd(xmlDoc, path, 0, GetButton(i).Text); |
| 105 | + weatherItems[i].Name = gameWeathers[i].m_weather_name; |
| 106 | + weatherItems[i].Time = gameWeathers[i].m_start_time; |
| 107 | + } |
127 | 108 | } |
128 | 109 |
|
129 | | -void CUIChangeGameType::InitChangeGameType(CUIXml& xml_doc) |
| 110 | +void CUIChangeWeather::OnButtonClick(int i) |
130 | 111 | { |
131 | | - CUIXmlInit::InitWindow(xml_doc, "change_gametype", 0, this); |
132 | | - |
133 | | - CUIXmlInit::InitTextWnd(xml_doc, "change_gametype:header", 0, header); |
134 | | - CUIXmlInit::InitStatic(xml_doc, "change_gametype:background", 0, bkgrnd); |
135 | | - |
136 | | - string256 _path; |
137 | | - for (int i = 0; i<4; i++) |
138 | | - { |
139 | | - xr_sprintf(_path, "change_gametype:btn_%d", i + 1); |
140 | | - CUIXmlInit::Init3tButton(xml_doc, _path, 0, btn[i]); |
141 | | - xr_sprintf(_path, "change_gametype:txt_%d", i + 1); |
142 | | - CUIXmlInit::InitTextWnd(xml_doc, _path, 0, m_data[i].m_text); |
143 | | - m_data[i].m_weather_name = xml_doc.ReadAttrib(_path,0,"id"); |
144 | | - } |
| 112 | + string1024 command; |
| 113 | + xr_sprintf(command, "cl_votestart changeweather %s %s", *weatherItems[i].Name, *weatherItems[i].Time); |
| 114 | + Console->Execute(command); |
| 115 | + HideDialog(); |
| 116 | +} |
145 | 117 |
|
146 | | - CUIXmlInit::Init3tButton(xml_doc, "change_gametype:btn_cancel", 0, btn_cancel); |
| 118 | +void CUIChangeGameType::InitChangeGameType(CUIXml& xmlDoc) |
| 119 | +{ |
| 120 | + CUIXmlInit::InitWindow(xmlDoc, "change_gametype", 0, this); |
| 121 | + CUIXmlInit::InitTextWnd(xmlDoc, "change_gametype:header", 0, Header); |
| 122 | + CUIXmlInit::InitStatic(xmlDoc, "change_gametype:background", 0, Background); |
| 123 | + CUIXmlInit::Init3tButton(xmlDoc, "change_gametype:btn_cancel", 0, CancelButton); |
| 124 | + // XXX nitrocaster: get it from somewhere |
| 125 | + const int gameTypeCount = 4; |
| 126 | + Initialize(gameTypeCount); |
| 127 | + gameTypeItems.resize(gameTypeCount); |
| 128 | + string256 path; |
| 129 | + for (u32 i = 0; i < gameTypeItems.size(); i++) |
| 130 | + { |
| 131 | + xr_sprintf(path, "change_gametype:btn_%d", i+1); |
| 132 | + CUIXmlInit::Init3tButton(xmlDoc, path, 0, GetButton(i).Button); |
| 133 | + xr_sprintf(path, "change_gametype:txt_%d", i+1); |
| 134 | + CUIXmlInit::InitTextWnd(xmlDoc, path, 0, GetButton(i).Text); |
| 135 | + gameTypeItems[i] = xmlDoc.ReadAttrib(path, 0, "id"); |
| 136 | + } |
147 | 137 | } |
148 | 138 |
|
149 | | -void CUIChangeGameType::OnBtn(int i) |
| 139 | +void CUIChangeGameType::OnButtonClick(int i) |
150 | 140 | { |
151 | | - string1024 command; |
152 | | - xr_sprintf (command, "cl_votestart changegametype %s", m_data[i].m_weather_name.c_str()); |
153 | | - Console->Execute (command); |
154 | | - HideDialog (); |
| 141 | + string1024 command; |
| 142 | + xr_sprintf(command, "cl_votestart changegametype %s", gameTypeItems[i].c_str()); |
| 143 | + Console->Execute(command); |
| 144 | + HideDialog(); |
155 | 145 | } |
0 commit comments