MCPcopy Create free account
hub / github.com/OpenDUNE/OpenDUNE / GUI_Widget_TextButton_Click

Function GUI_Widget_TextButton_Click

src/gui/widget_click.c:239–308  ·  view source on GitHub ↗

* Handles Click event for unit commands button. * * @param w The widget. * @return True, always. */

Source from the content-addressed store, hash-verified

237 * @return True, always.
238 */
239bool GUI_Widget_TextButton_Click(Widget *w)
240{
241 const UnitInfo *ui;
242 const ActionInfo *ai;
243 const uint16 *actions;
244 ActionType action;
245 Unit *u;
246 uint16 *found;
247 ActionType unitAction;
248
249 u = g_unitSelected;
250 ui = &g_table_unitInfo[u->o.type];
251
252 actions = ui->o.actionsPlayer;
253 if (Unit_GetHouseID(u) != g_playerHouseID && u->o.type != UNIT_HARVESTER) {
254 actions = g_table_actionsAI;
255 }
256
257 action = actions[w->index - 8];
258 if (g_dune2_enhanced) {
259 if (Input_Test(0x2c) || Input_Test(0x39)) { /* LSHIFT or RSHIFT is pressed */
260 if (action == ACTION_GUARD) action = ACTION_AREA_GUARD; /* AREA GUARD instead of GUARD */
261 else if (action == ACTION_ATTACK) action = ACTION_AMBUSH; /* AMBUSH instead of ATTACK */
262 }
263 Debug("GUI_Widget_TextButton_Click(%p index=%d) action=%d\n", w, w->index, action);
264 }
265
266 unitAction = u->nextActionID;
267 if (unitAction == ACTION_INVALID) {
268 unitAction = u->actionID;
269 }
270
271 if (u->deviated != 0) {
272 Unit_Deviation_Decrease(u, 5);
273 if (u->deviated == 0) {
274 GUI_Widget_MakeNormal(w, false);
275 return true;
276 }
277 }
278
279 GUI_Widget_MakeSelected(w, false);
280
281 ai = &g_table_actionInfo[action];
282
283 if (ai->selectionType != g_selectionType) {
284 g_unitActive = g_unitSelected;
285 g_activeAction = action;
286 GUI_ChangeSelectionType(ai->selectionType);
287
288 return true;
289 }
290
291 Object_Script_Variable4_Clear(&u->o);
292 u->targetAttack = 0;
293 u->targetMove = 0;
294 u->route[0] = 0xFF;
295
296 Unit_SetAction(u, action);

Callers

nothing calls this directly

Calls 11

Unit_GetHouseIDFunction · 0.85
Input_TestFunction · 0.85
Unit_Deviation_DecreaseFunction · 0.85
GUI_Widget_MakeNormalFunction · 0.85
GUI_Widget_MakeSelectedFunction · 0.85
GUI_ChangeSelectionTypeFunction · 0.85
Unit_SetActionFunction · 0.85
Sound_StartSoundFunction · 0.85
GUI_Widget_Get_ByIndexFunction · 0.85
DebugFunction · 0.50

Tested by

no test coverage detected