forked from pioneerspacesim/pioneer
/
StationShipMarketForm.cpp
95 lines (73 loc) · 2.88 KB
/
StationShipMarketForm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "StationShipMarketForm.h"
#include "Pi.h"
#include "Player.h"
#include "SpaceStation.h"
#include "SpaceStationView.h"
#include "StationShipViewForm.h"
#include "Lang.h"
#include "StringF.h"
StationShipMarketForm::StationShipMarketForm(FormController *controller) : FaceForm(controller)
{
m_station = Pi::player->GetDockedWith();
SetTitle(stringf(Lang::SOMEWHERE_SHIP_MARKET, formatarg("station", m_station->GetLabel())));
Gui::VScrollBar *scroll = new Gui::VScrollBar();
Gui::VScrollPortal *portal = new Gui::VScrollPortal(450);
scroll->SetAdjustment(&portal->vscrollAdjust);
float line_height = Gui::Screen::GetFontHeight();
m_shiplistBox = new Gui::VBox();
m_shiplistBox->SetSpacing(line_height*0.5f);
UpdateShipList();
m_shiplistBox->ShowAll();
portal->Add(m_shiplistBox);
portal->ShowAll();
Gui::VBox *outerbox = new Gui::VBox();
outerbox->SetSpacing(line_height);
Gui::Fixed *heading = new Gui::Fixed(470, Gui::Screen::GetFontHeight());
const float *col = Gui::Theme::Colors::tableHeading;
heading->Add((new Gui::Label(Lang::SHIP))->Color(col), 0, 0);
heading->Add((new Gui::Label(Lang::PRICE))->Color(col), 200, 0);
heading->Add((new Gui::Label(Lang::PART_EX))->Color(col), 275, 0);
heading->Add((new Gui::Label(Lang::CAPACITY))->Color(col), 370, 0);
heading->Add((new Gui::Label(Lang::VIEW))->Color(col), 430, 0);
outerbox->PackEnd(heading);
Gui::HBox *body = new Gui::HBox();
body->PackEnd(portal);
body->PackEnd(scroll);
outerbox->PackEnd(body);
Add(outerbox, 0, 0);
ShowAll();
m_onShipsForSaleChangedConnection = m_station->onShipsForSaleChanged.connect(sigc::mem_fun(this, &StationShipMarketForm::OnShipsForSaleChanged));
}
StationShipMarketForm::~StationShipMarketForm()
{
m_onShipsForSaleChangedConnection.disconnect();
}
void StationShipMarketForm::OnShipsForSaleChanged()
{
UpdateShipList();
m_shiplistBox->ShowAll();
}
void StationShipMarketForm::UpdateShipList()
{
m_shiplistBox->DeleteAllChildren();
float line_height = Gui::Screen::GetFontHeight();
std::vector<ShipFlavour> &ships = m_station->GetShipsOnSale();
int num = 0;
for (std::vector<ShipFlavour>::iterator i = ships.begin(); i!=ships.end(); ++i) {
Gui::Fixed *f = new Gui::Fixed(450, line_height*1.5f);
Gui::Label *l = new Gui::Label(ShipType::types[(*i).type].name);
f->Add(l,0,0);
f->Add(new Gui::Label(format_money((*i).price)), 200, 0);
f->Add(new Gui::Label(format_money((*i).price - Pi::player->GetFlavour()->price) ), 275, 0);
f->Add(new Gui::Label(stringf(Lang::NUMBER_TONNES, formatarg("mass", ShipType::types[(*i).type].capacity))), 370, 0);
Gui::SolidButton *sb = new Gui::SolidButton();
sb->onClick.connect(sigc::bind(sigc::mem_fun(this, &StationShipMarketForm::ViewShip), num));
f->Add(sb, 430, 0);
m_shiplistBox->PackEnd(f);
num++;
}
}
void StationShipMarketForm::ViewShip(int num)
{
m_formController->ActivateForm(new StationShipViewForm(m_formController, num));
}