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

Method begin

game/ui/base/researchscreen.cpp:106–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106void ResearchScreen::begin()
107{
108 BaseStage::begin();
109
110 if (viewFacility)
111 {
112 state->current_base->selectedLab = viewFacility;
113 }
114
115 auto unassignedAgentList = form->findControlTyped<ListBox>("LIST_UNASSIGNED");
116 unassignedAgentList->addCallback(FormEventType::ListBoxChangeSelected, [this](FormsEvent *e) {
117 LogWarning("unassigned agent selected");
118 if (this->assigned_agent_count >= this->viewFacility->type->capacityAmount)
119 {
120 LogWarning("no free space in lab");
121 return;
122 }
123 auto list = std::static_pointer_cast<ListBox>(e->forms().RaisedBy);
124 auto agent = list->getSelectedData<Agent>();
125 if (!agent)
126 {
127 LogError("No agent in selected data");
128 return;
129 }
130 if (agent->assigned_to_lab)
131 {
132 LogError("Agent \"%s\" already assigned to a lab?", agent->name);
133 return;
134 }
135 agent->assigned_to_lab = true;
136 this->viewFacility->lab->assigned_agents.push_back({state.get(), agent});
137 this->setCurrentLabInfo();
138 });
139 auto removeFn = [this](FormsEvent *e) {
140 LogWarning("assigned agent selected");
141 auto list = std::static_pointer_cast<ListBox>(e->forms().RaisedBy);
142 auto agent = list->getSelectedData<Agent>();
143 if (!agent)
144 {
145 LogError("No agent in selected data");
146 return;
147 }
148 if (!agent->assigned_to_lab)
149 {
150 LogError("Agent \"%s\" not assigned to a lab?", agent->name);
151 return;
152 }
153 agent->assigned_to_lab = false;
154 this->viewFacility->lab->assigned_agents.remove({state.get(), agent});
155 this->setCurrentLabInfo();
156 };
157 auto assignedAgentList = form->findControlTyped<ListBox>("LIST_ASSIGNED");
158 assignedAgentList->addCallback(FormEventType::ListBoxChangeSelected, removeFn);
159}
160
161void ResearchScreen::pause() {}
162

Callers

nothing calls this directly

Calls 4

setCurrentLabInfoMethod · 0.95
addCallbackMethod · 0.80
removeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected