MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / eventOccurred

Method eventOccurred

game/ui/general/difficultymenu.cpp:48–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48void DifficultyMenu::eventOccurred(Event *e)
49{
50 difficultymenuform->eventOccured(e);
51
52 if (e->type() == EVENT_KEY_DOWN)
53 {
54 if (e->keyboard().KeyCode == SDLK_ESCAPE)
55 {
56 fw().stageQueueCommand({StageCmd::Command::POP});
57 return;
58 }
59 }
60
61 if (e->type() == EVENT_FORM_INTERACTION && e->forms().EventFlag == FormEventType::ButtonClick)
62 {
63 int difficulty;
64 if (e->forms().RaisedBy->Name.compare("BUTTON_DIFFICULTY1") == 0)
65 {
66 difficulty = 0;
67 }
68 else if (e->forms().RaisedBy->Name.compare("BUTTON_DIFFICULTY2") == 0)
69 {
70 difficulty = 1;
71 }
72 else if (e->forms().RaisedBy->Name.compare("BUTTON_DIFFICULTY3") == 0)
73 {
74 difficulty = 2;
75 }
76 else if (e->forms().RaisedBy->Name.compare("BUTTON_DIFFICULTY4") == 0)
77 {
78 difficulty = 3;
79 }
80 else if (e->forms().RaisedBy->Name.compare("BUTTON_DIFFICULTY5") == 0)
81 {
82 difficulty = 4;
83 }
84 else
85 {
86 LogWarning("Unknown button pressed: %s", e->forms().RaisedBy->Name);
87 return;
88 }
89
90 auto loadedState = mksp<GameState>();
91 loadedState->difficulty = difficulty;
92
93 fw().stageQueueCommand(
94 {StageCmd::Command::PUSH,
95 mksp<LoadingScreen>(nullptr, loadGame(loadedState),
96 [loadedState]() { return mksp<CityView>(loadedState); })});
97 return;
98 }
99}
100
101void DifficultyMenu::update() { difficultymenuform->update(); }
102

Callers

nothing calls this directly

Calls 4

loadGameFunction · 0.85
typeMethod · 0.80
stageQueueCommandMethod · 0.80
eventOccuredMethod · 0.45

Tested by

no test coverage detected