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

Method createVehicleControl

game/ui/components/controlgenerator.cpp:182–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

180}
181
182sp<Control> ControlGenerator::createVehicleControl(GameState &state, const VehicleTileInfo &info)
183{
184 if (!singleton.initialised)
185 {
186 singleton.init(state);
187 }
188
189 auto frame = singleton.citySelect[(int)info.selected];
190 auto baseControl = mksp<Graphic>(frame);
191 baseControl->Size = frame->size;
192 // FIXME: There's an extra 1 pixel here that's annoying
193 baseControl->Size.x -= 1;
194 baseControl->Name = "OWNED_VEHICLE_FRAME_" + info.vehicle->name;
195 baseControl->setData(info.vehicle);
196
197 auto vehicleIcon = baseControl->createChild<Graphic>(info.vehicle->type->icon);
198 if (vehicleIcon->getImage())
199 {
200 vehicleIcon->Size = vehicleIcon->getImage()->size;
201 }
202 else
203 {
204 vehicleIcon->AutoSize = true;
205 }
206 vehicleIcon->Location = {1, 1};
207 vehicleIcon->Name = "OWNED_VEHICLE_ICON_" + info.vehicle->name;
208
209 // FIXME: Put these somewhere slightly less magic?
210 Vec2<int> healthBarOffset = {27, 2};
211 Vec2<int> healthBarSize = {3, 20};
212
213 auto healthImg = info.shield ? singleton.shieldImage : singleton.healthImage;
214
215 auto healthGraphic = baseControl->createChild<Graphic>(healthImg);
216 // This is a bit annoying as the health bar starts at the bottom, but the coord origin is
217 // top-left, so fix that up a bit
218 int healthBarHeight = (int)((float)healthBarSize.y * info.healthProportion);
219 healthBarOffset.y = healthBarOffset.y + (healthBarSize.y - healthBarHeight);
220 healthBarSize.y = healthBarHeight;
221 healthGraphic->Location = healthBarOffset;
222 healthGraphic->Size = healthBarSize;
223 healthGraphic->ImagePosition = FillMethod::Stretch;
224
225 sp<Graphic> stateGraphic;
226
227 stateGraphic = baseControl->createChild<Graphic>(singleton.icons[(int)info.state]);
228 if (stateGraphic->getImage())
229 {
230 stateGraphic->Size = stateGraphic->getImage()->size;
231 }
232 else
233 {
234 stateGraphic->AutoSize = true;
235 }
236 stateGraphic->Location = {0, 0};
237 stateGraphic->Name = "OWNED_VEHICLE_STATE_" + info.vehicle->name;
238 stateGraphic->ToolTipText = info.vehicle->name;
239

Callers

nothing calls this directly

Calls 3

setDataMethod · 0.80
initMethod · 0.45
getImageMethod · 0.45

Tested by

no test coverage detected