forked from pioneerspacesim/pioneer
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
StationShipRepairForm.cpp
95 lines (77 loc) · 2.56 KB
/
StationShipRepairForm.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
#include "StationShipRepairForm.h"
#include "Pi.h"
#include "Player.h"
#include "ShipCpanel.h"
#include "Lang.h"
StationShipRepairForm::StationShipRepairForm(FormController *controller) : FaceForm(controller)
{
m_station = Pi::player->GetDockedWith();
SetTitle(stringf(256, Lang::SOMEWHERE_SHIP_REPAIRS, m_station->GetLabel().c_str()));
m_working = new Gui::Label(Lang::SHIP_IS_ALREADY_FULLY_REPAIRED);
Add(m_working, 0, 0);
m_tableBox = new Gui::HBox();
m_tableBox->SetSpacing(15.0f);
Add(m_tableBox, 0, 0);
Gui::VBox *columnBox = new Gui::VBox();
m_tableBox->PackEnd(columnBox);
Gui::HBox *buttonBox = new Gui::HBox();
buttonBox->SetSpacing(5.0f);
Gui::Button *b = new Gui::SolidButton();
b->onClick.connect(sigc::bind(sigc::mem_fun(this, &StationShipRepairForm::RepairHull), 1.0f));
buttonBox->PackEnd(b);
buttonBox->PackEnd(new Gui::Label(Lang::REPAIR_1_PERCENT_HULL));
columnBox->PackEnd(buttonBox);
buttonBox = new Gui::HBox();
buttonBox->SetSpacing(5.0f);
b = new Gui::SolidButton();
b->onClick.connect(sigc::bind(sigc::mem_fun(this, &StationShipRepairForm::RepairHull), 100.0f));
buttonBox->PackEnd(b);
m_repairAllDesc = new Gui::Label("");
buttonBox->PackEnd(m_repairAllDesc);
columnBox->PackEnd(buttonBox);
columnBox = new Gui::VBox();
m_tableBox->PackEnd(columnBox);
m_repairOneCost = new Gui::Label("");
columnBox->PackEnd(m_repairOneCost);
m_repairAllCost = new Gui::Label("");
columnBox->PackEnd(m_repairAllCost);
UpdateLabels();
}
void StationShipRepairForm::ShowAll()
{
FaceForm::ShowAll();
UpdateLabels();
}
int StationShipRepairForm::GetRepairCost(float percent)
{
return int(Pi::player->GetFlavour()->price * 0.001 * percent);
}
void StationShipRepairForm::RepairHull(float percent)
{
float hullDamage = 100.0f - Pi::player->GetPercentHull();
if (percent > hullDamage) percent = hullDamage;
int cost = GetRepairCost(percent);
if (Pi::player->GetMoney() < cost) {
Pi::cpan->MsgLog()->Message("", Lang::YOU_NOT_ENOUGH_MONEY);
} else {
Pi::player->SetMoney(Pi::player->GetMoney() - cost);
Pi::player->SetPercentHull(Pi::player->GetPercentHull() + percent);
UpdateLabels();
}
}
void StationShipRepairForm::UpdateLabels()
{
float hullPercent = Pi::player->GetPercentHull();
if (hullPercent >= 100.0f)
{
m_working->Show();
m_tableBox->Hide();
}
else {
m_repairAllDesc->SetText(stringf(128, Lang::REPAIR_ENTIRE_HULL, 100.0f - hullPercent));
m_repairOneCost->SetText(format_money(GetRepairCost(1.0f)));
m_repairAllCost->SetText(format_money(GetRepairCost(100.f - hullPercent)));
m_working->Hide();
m_tableBox->Show();
}
}