| 155 | |
| 156 | |
| 157 | void UpdateJoystickMenu(IJoystickConfig *selected) |
| 158 | { |
| 159 | DMenuDescriptor **desc = MenuDescriptors.CheckKey(NAME_JoystickOptions); |
| 160 | DMenuDescriptor **ddesc = MenuDescriptors.CheckKey("JoystickOptionsDefaults"); |
| 161 | if (ddesc == nullptr) return; // without any data the menu cannot be set up and must remain empty. |
| 162 | if (desc != NULL && (*desc)->IsKindOf(RUNTIME_CLASS(DOptionMenuDescriptor))) |
| 163 | { |
| 164 | DOptionMenuDescriptor *opt = (DOptionMenuDescriptor *)*desc; |
| 165 | DOptionMenuDescriptor *dopt = (DOptionMenuDescriptor *)*ddesc; |
| 166 | if (dopt == nullptr) return; |
| 167 | DMenuItemBase *it; |
| 168 | |
| 169 | int i; |
| 170 | int itemnum = -1; |
| 171 | |
| 172 | I_GetJoysticks(Joysticks); |
| 173 | if ((unsigned)itemnum >= Joysticks.Size()) |
| 174 | { |
| 175 | itemnum = Joysticks.Size() - 1; |
| 176 | } |
| 177 | if (selected != NULL) |
| 178 | { |
| 179 | for (i = 0; (unsigned)i < Joysticks.Size(); ++i) |
| 180 | { |
| 181 | if (Joysticks[i] == selected) |
| 182 | { |
| 183 | itemnum = i; |
| 184 | break; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | opt->mItems = dopt->mItems; |
| 189 | |
| 190 | it = opt->GetItem("ConfigureMessage"); |
| 191 | if (it != nullptr) it->SetValue(0, !!Joysticks.Size()); |
| 192 | it = opt->GetItem("ConnectMessage1"); |
| 193 | if (it != nullptr) it->SetValue(0, !use_joystick); |
| 194 | it = opt->GetItem("ConnectMessage2"); |
| 195 | if (it != nullptr) it->SetValue(0, !use_joystick); |
| 196 | |
| 197 | for (int ii = 0; ii < (int)Joysticks.Size(); ++ii) |
| 198 | { |
| 199 | it = CreateOptionMenuItemJoyConfigMenu(Joysticks[ii]->GetName().GetChars(), Joysticks[ii]); |
| 200 | GC::WriteBarrier(opt, it); |
| 201 | opt->mItems.Push(it); |
| 202 | if (ii == itemnum) opt->mSelectedItem = opt->mItems.Size(); |
| 203 | } |
| 204 | if (opt->mSelectedItem >= (int)opt->mItems.Size()) |
| 205 | { |
| 206 | opt->mSelectedItem = opt->mItems.Size() - 1; |
| 207 | } |
| 208 | //opt->CalcIndent(); |
| 209 | |
| 210 | // If the joystick config menu is open, close it if the device it's open for is gone. |
| 211 | if (CurrentMenu != nullptr && (CurrentMenu->IsKindOf("JoystickConfigMenu"))) |
| 212 | { |
| 213 | auto p = CurrentMenu->PointerVar<IJoystickConfig>("mJoy"); |
| 214 | if (p != nullptr) |
no test coverage detected