| 104 | } |
| 105 | |
| 106 | void 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 | |
| 161 | void ResearchScreen::pause() {} |
| 162 |
nothing calls this directly
no test coverage detected