[Add] More scrolling work and laying some additional groundwork for GUI.

This commit is contained in:
Allanis 2018-08-21 20:34:34 +01:00
parent c2ec30a048
commit b1dac828d6
16 changed files with 250 additions and 130 deletions

View File

@ -3,9 +3,9 @@
namespace Gui { namespace Gui {
namespace RawEvents { namespace RawEvents {
sigc::signal<void, SDL_MouseMotionEvent*> onMouseMotion; sigc::signal<void, MouseMotionEvent*> onMouseMotion;
sigc::signal<void, SDL_MouseButtonEvent*> onMouseDown; sigc::signal<void, MouseButtonEvent*> onMouseDown;
sigc::signal<void, SDL_MouseButtonEvent*> onMouseUp; sigc::signal<void, MouseButtonEvent*> onMouseUp;
sigc::signal<void, SDL_KeyboardEvent*> onKeyDown; sigc::signal<void, SDL_KeyboardEvent*> onKeyDown;
sigc::signal<void, SDL_KeyboardEvent*> onKeyUp; sigc::signal<void, SDL_KeyboardEvent*> onKeyUp;
} }
@ -19,22 +19,18 @@ void HandleSDLEvent(SDL_Event* event) {
switch(event->type) { switch(event->type) {
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
Screen::OnClick(&event->button); Screen::OnClick(&event->button);
RawEvents::onMouseDown.emit(&event->button);
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
Screen::OnClick(&event->button); Screen::OnClick(&event->button);
RawEvents::onMouseUp.emit(&event->button);
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
Screen::OnKeyDown(&event->key.keysym); Screen::OnKeyDown(&event->key.keysym);
RawEvents::onKeyDown.emit(&event->key);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
RawEvents::onKeyUp.emit(&event->key); RawEvents::onKeyUp.emit(&event->key);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
Screen::OnMouseMotion(&event->motion); Screen::OnMouseMotion(&event->motion);
RawEvents::onMouseMotion.emit(&event->motion);
break; break;
} }
} }
@ -86,5 +82,75 @@ void Init(int screen_width, int screen_height, int ui_width, int ui_height) {
Screen::Init(screen_width, screen_height, ui_width, ui_height); Screen::Init(screen_width, screen_height, ui_width, ui_height);
} }
namespace Theme {
static const float BORDER_WIDTH = 2.0;
void DrawHollowRect(const float size[2]) {
GLfloat vertices[] = { 0,0,
0, size[1],
size[0], size[1],
size[0], 0,
BORDER_WIDTH, BORDER_WIDTH,
BORDER_WIDTH, size[1]-BORDER_WIDTH,
size[0]-BORDER_WIDTH, size[1]-BORDER_WIDTH,
size[0]-BORDER_WIDTH, BORDER_WIDTH };
GLubyte indices[] = {
0,1,5,4, 0,4,7,3,
3,7,6,2, 1,2,6,5 };
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(w, GL_FLOAT, 0, vertices);
glDrawElements(GL_QUADS, 16, GL_UNSIGNED_BYTE, indices);
glDisableClientState(GL_VERTEX_ARRAY);
}
void DrawIndent(const float size[2]) {
GLfloat vertices[] = { 0,0,
0, size[1],
size[0], size[1],
size[0], 0,
BORDER_WIDTH, BORDER_WIDTH,
BORDER_WIDTH, size[1]-BORDER_WIDTH,
size[0]-BORDER_WIDTH, size[1]-BORDER_WIDTH,
size[0]-BORDER_WIDTH, BORDER_WIDTH };
GLubyte indices[] = {
0,1,5,4, 0,4,7,3,
3,7,6,2, 1,2,6,5,
4,5,6,7 };
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glColor3fv(Color::bgShadow);
glDrawElements(GL_QUADS, 8, GL_UNSIGNED_BYTE, indices);
glColor3f(.6, .6, .6);
glDrawElements(GL_QUADS, 8, GL_UNSIGNED_BYTE, indices+8);
glColor3fv(Color::bg);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, indices+16);
glDisableClientState(GL_VERTEX_ARRAY);
}
void DrawOutdent(const float size[2]) {
GLfloat vertices[] = {0,0,
0, size[1],
size[0], size[1],
size[0], 0,
BORDER_WIDTH, BORDER_WIDTH,
BORDER_WIDTH, size[1]-BORDER_WIDTH,
size[0] - BORDER_WIDTH, size[1] - BORDER_WIDTH,
size[0] - BORDER_WIDTH, BORDER_WIDTH };
GLubyte indices = {
0,1,5,4, 0,4,7,3,
3,7,6,2, 1,2,6,5,
4,5,6,7 };
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glColor3f(.6, .6, .6);
glDrawElements(GL_QUADS, 8, GL_UNSIGNED_BYTE, indices);
glColor3fv(Color::bgShadow);
glDrawElements(GL_QUADS, 8, GL_UNSIGNED_BYTE, indices+8);
glColor3fv(Color::bg);
glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, indices+16);
glDisableClientState(GL_VERTEX_ARRAY);
}
}
} }

View File

@ -2,6 +2,13 @@
#include "libs.h" #include "libs.h"
namespace Gui { namespace Gui {
namespace Theme {
void DrawIndent(const float size[2]);
void DrawOutdent(const float size[2]);
void DrawHollowRect(const float size[2]);
}
namespace Color { namespace Color {
extern const float bg[]; extern const float bg[];
extern const float bgShadow[]; extern const float bgShadow[];
@ -18,9 +25,9 @@
namespace Gui { namespace Gui {
namespace RawEvents { namespace RawEvents {
extern sigc::signal<void, SDL_MouseMotionEvent*> onMouseMotion; extern sigc::signal<void, MouseMotionEvent*> onMouseMotion;
extern sigc::signal<void, SDL_MouseButtonEvent*> onMouseDown; extern sigc::signal<void, MouseButtonEvent*> onMouseDown;
extern sigc::signal<void, SDL_MouseButtonEvent*> onMouseUp; extern sigc::signal<void, MouseButtonEvent*> onMouseUp;
extern sigc::signal<void, SDL_KeyboardEvent*> onKeyDown; extern sigc::signal<void, SDL_KeyboardEvent*> onKeyDown;
extern sigc::signal<void, SDL_KeyboardEvent*> onKeyUp; extern sigc::signal<void, SDL_KeyboardEvent*> onKeyUp;
} }

View File

@ -45,7 +45,7 @@ void Button::OnRawKeyUp(SDL_KeyboardEvent* e) {
} }
} }
void Button::OnRawMouseUp(SDL_MouseButtonEvent* e) { void Button::OnRawMouseUp(MouseButtonEvent* e) {
if(e->button == 1) { if(e->button == 1) {
m_isPressed = false; m_isPressed = false;
_m_release.disconnect(); _m_release.disconnect();
@ -62,43 +62,19 @@ void TransparentButton::GetSizeRequested(float size[2]) {
} }
void SolidButton::Draw(void) { void SolidButton::Draw(void) {
glBegin(GL_QUADS); float size[2];
glColor3f(.6, .6, .6); GetSize(size);
glVertex2f(0, 15); if(IsPressed()) {
glVertex2f(15, 15); Theme::DrawIndent(size);
glVertex2f(15, 0); } else {
glVertex2f(0, 0); Theme::DrawOutdent(size);
}
glColor3fv(Color::bgShadow);
glVertex2f(2, 15);
glVertex2f(15, 15);
glVertex2f(15, 2);
glVertex2f(2, 2);
glColor3fv(Color::bg);
glVertex2f(2, 13);
glVertex2f(13, 13);
glVertex2f(13, 2);
glVertex2f(2, 2);
glEnd();
} }
void TransparentButton::Draw(void) { void TransparentButton::Draw(void) {
glColor3f(1, 1, 1); float size[2];
glBegin(GL_LINE_LOOP); GetSize(size);
glVertex2f(0, 0);
glVertex2f(15, 0);
glVertex2f(15, 15);
glVertex2f(0, 15);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex2f(1, 1);
glVertex2f(14, 1);
glVertex2f(14, 14);
glVertex2f(1, 14);
glEnd();
}
Theme::DrawHollowRect(size);
} }

View File

@ -20,7 +20,7 @@ namespace Gui {
sigc::signal<void> onClick; sigc::signal<void> onClick;
bool IsPressed(void) { return m_isPressed; } bool IsPressed(void) { return m_isPressed; }
private: private:
void OnRawMouseUp(SDL_MouseButtonEvent* e); void OnRawMouseUp(MouseButtonEvent* e);
void OnRawKeyUp(SDL_KeyboardEvent* e); void OnRawKeyUp(SDL_KeyboardEvent* e);
bool m_isPressed; bool m_isPressed;

View File

@ -12,7 +12,8 @@ Fixed::Fixed(float w, float h): Container() {
} }
void Fixed::GetSizeRequested(float size[2]) { void Fixed::GetSizeRequested(float size[2]) {
GetSize(size); size[0] = m_w;
size[1] = m_h;
} }
Fixed::~Fixed(void) { Fixed::~Fixed(void) {

View File

@ -97,6 +97,9 @@ void Screen::OnMouseMotion(SDL_MouseMotionEvent* e) {
ev.screenX = ev.x = x; ev.screenX = ev.x = x;
ev.screenY = ev.y = y; ev.screenY = ev.y = y;
baseContainer->OnMouseMotion(&ev); baseContainer->OnMouseMotion(&ev);
ev.screenX = ev.x = x;
ev.screenY = ev.y = y;
RawEvents::onMouseMotion.emit(&ev);
} }
void Screen::OnClick(SDL_MouseButtonEvent* e) { void Screen::OnClick(SDL_MouseButtonEvent* e) {
@ -108,8 +111,13 @@ void Screen::OnClick(SDL_MouseButtonEvent* e) {
ev.screenX = ev.x = x; ev.screenX = ev.x = x;
ev.screenY = ev.y = y; ev.screenY = ev.y = y;
OnClickTestLabels(ev); OnClickTestLabels(ev);
if(ev.isdown) baseContainer->OnMouseDown(&ev); if(ev.isdown) {
else baseContainer->OnMouseUp(&ev); baseContainer->OnMouseDown(&ev);
RawEvents::OnMouseDown.emit(&ev);
} else {
baseContainer->OnMouseUp(&ev);
RawEvents::onMouseUp.emit(&ev);
}
} }
void Screen::OnClickTestLabels(const Gui::MouseButtonEvent& ev) { void Screen::OnClickTestLabels(const Gui::MouseButtonEvent& ev) {

View File

@ -38,46 +38,13 @@ void ToggleButton::GetSizeRequested(float size[2]) {
} }
void ToggleButton::Draw(void) { void ToggleButton::Draw(void) {
float size[2];
GetSize(size);
if(m_pressed) { if(m_pressed) {
glBegin(GL_QUADS); Theme::DrawIndent(size);
glColor3f(.6, .6, .6);
glVertex2f(0, 15);
glVertex2f(15, 15);
glVertex2f(15, 0);
glVertex2f(0, 0);
glColor3fv(Color::bgShadow);
glVertex2f(0, 13);
glVertex2f(13, 13);
glVertex2f(13, 0);
glVertex2f(0, 0);
glColor3fv(Color::bg);
glVertex2f(2, 13);
glVertex2f(13, 13);
glVertex2f(13, 2);
glVertex2f(2, 2);
glEnd();
} else { } else {
glBegin(GL_QUADS); Theme::DrawOutdent(size);
glColor3f(.6, .6, .6);
glVertex2f(0, 15);
glVertex2f(15, 15);
glVertex2f(15, 0);
glVertex2f(0, 0);
glColor3fv(Color::bgShadow);
glVertex2f(2, 15);
glVertex2f(15, 15);
glVertex2f(15, 2);
glVertex2f(2, 2);
glColor3fv(Color::bg);
glVertex2f(2, 13);
glVertex2f(13, 13);
glVertex2f(13, 2);
glVertex2f(2, 2);
glEnd();
} }
} }

View File

@ -24,7 +24,7 @@ bool VScrollBar::OnMouseDown(MouseButtonEvent* e) {
return false; return false;
} }
void VScrollBar::OnRawMouseUp(SDL_MouseButtonEvent* e) { void VScrollBar::OnRawMouseUp(MouseButtonEvent* e) {
if(e->button == 1) { if(e->button == 1) {
m_isPressed = false; m_isPressed = false;
_m_released.disconnect(); _m_released.disconnect();
@ -32,7 +32,7 @@ void VScrollBar::OnRawMouseUp(SDL_MouseButtonEvent* e) {
} }
} }
void VScrollBar::OnRawMouseMotion(SDL_MouseMotionEvent* e) { void VScrollBar::OnRawMouseMotion(MouseMotionEvent* e) {
if(m_isPressed) { if(m_isPressed) {
float pos[2]; float pos[2];
GetAbsolutePosition(pos); GetAbsolutePosition(pos);
@ -44,27 +44,8 @@ void VScrollBar::OnRawMouseMotion(SDL_MouseMotionEvent* e) {
void VScrollBar::Draw(void) { void VScrollBar::Draw(void) {
float size[2]; GetSize(size); float size[2]; GetSize(size);
glColor3f(1,1,0);
glBegin(GL_QUADS);
glColor3f(.6, .6, .6);
glVertex2f(0, size[1]);
glVertex2f(size[0], size[1]);
glVertex2f(size[0], 0);
glVertex2f(0, 0);
glColor3fv(Color::bgShadow);
glVertex2f(0, size[1]-BORDER);
glVertex2f(size[0]-BORDER, size[1]-BORDER);
glVertex2f(size[0]-BORDER, 0);
glVertex2f(0, 0);
glColor3fv(Color::bg);
glVertex2f(BORDER, size[1]-BORDER);
glVertex2f(size[0]-BORDER, size[1]-BORDER);
glVertex2f(size[0]-BORDER, BORDER);
glVertex2f(BORDER, BORDER);
glEnd();
Theme::DrawIndent(size);
float pos = m_adjustment->GetValue(); float pos = m_adjustment->GetValue();
glColor3f(1, 1, 1); glColor3f(1, 1, 1);
glBegin(GL_LINES); glBegin(GL_LINES);

View File

@ -16,8 +16,8 @@ public:
} }
private: private:
void OnRawMouseUp(SDL_MousebuttonEvent* e); void OnRawMouseUp(MouseButtonEvent* e);
void OnRawMOuseMotion(SDL_MouseMotionEvent* e); void OnRawMOuseMotion(MouseMotionEvent* e);
bool m_isPressed; bool m_isPressed;
sigc::connection m_release, _m_motion; sigc::connection m_release, _m_motion;
Adjustment* m_sdjustment; Adjustment* m_sdjustment;

View File

@ -38,6 +38,27 @@ void VScrollPortal::Remove(Widget* child) {
m_childSizeY = 0; m_childSizeY = 0;
} }
float VScrollPortal::GetScrollPixels(void) {
float size[2];
GetSize(size);
return m_scrollY * (m_childSizeY-size[1]);
}
bool VScrollPortal::OnMouseDown(MouseButtonEvent* e) {
e->y += GetScrollPixels();
return Container::OnMouseDown(e);
}
bool VScrollPortal::OnMouseUp(MouseButtonEvent* e) {
e->y += GetScollPixels();
return Container::OnMouseUp(e);
}
bool VScrollPortal::OnMouseMotion(MouseMotionEvent* e) {
e->y += GetSCrollPixels();
return Container::OnMouseMotion(e);
}
void VSrollPortal::Draw(void) { void VSrollPortal::Draw(void) {
float size[2]; float size[2];
GetSize(size); GetSize(size);

View File

@ -7,6 +7,9 @@ public:
VScrollPortal(float w, float h); VScrollPortal(float w, float h);
void Add(Widget* child); void Add(Widget* child);
void Remove(Widget* child); void Remove(Widget* child);
virtual bool OnMouseDown(MouseButtonEvent* e);
virtual bool OnMouseUp(MouseButtonEvent* e);
virtual bool OnMouseMotion(MouseMotionEvent* e);
virtual void Draw(void); virtual void Draw(void);
virtual void GetSizeRequested(float size[2]); virtual void GetSizeRequested(float size[2]);
virtual void OnChildResizeRequest(Widget*); virtual void OnChildResizeRequest(Widget*);
@ -14,6 +17,7 @@ public:
void SetBgColor(float r, float g, float b); void SetBgColor(float r, float g, float b);
Adjustment vscrollAdjust; Adjustment vscrollAdjust;
private: private:
float GetScrollPixels();
void OnScroll(float); void OnScroll(float);
float m_scrollY, m_childSizeY; float m_scrollY, m_childSizeY;
Widget* m_cild; Widget* m_cild;

View File

@ -55,27 +55,52 @@ const EquipType EquipType::types[] = {
{ {
"Interplanetary Drive", "Interplanetary Drive",
Equip::SLOT_ENGINE, Equip::SLOT_ENGINE,
1, 0 4000, 1, 0
}, },
{ {
"Class 1 Hyperdrive", "Class 1 Hyperdrive",
Equip::SLOT_ENGINE, Equip::SLOT_ENGINE,
4, 1 7000, 4, 1
},
{
"Class 2 Hyperdrive",
Equip::SLOT_ENGINE,
13000, 10, 2
},
{
"Class 3 Hyperdrive",
Equip::SLOT_ENGINE,
25000, 20, 3
},
{
"Class 4 Hyperdrive",
Equip::SLOT_ENGINE,
50000, 40, 4
},
{
"Class 5 Hyperdrive",
Equip::SLOT_ENGINE,
100000, 120, 4
},
{
"Class 6 Hyperdrive",
Equip::SLOT_ENGINE,
200000, 225, 4
}, },
{ {
"1MW beam laser", "1MW beam laser",
Equip::SLOT_LASER, Equip::SLOT_LASER,
1, 1 6000, 1, 1
}, },
{ {
"2MW beam laser", "2MW beam laser",
Equip::SLOT_LASER, Equip::SLOT_LASER,
1, 2 10000, 1, 2
}, },
{ {
"4MW beam laser", "4MW beam laser",
Equip::SLOT_LASER, Equip::SLOT_LASER,
1, 4 22000, 1, 4
} }
}; };

View File

@ -5,8 +5,9 @@
namespace Equip { namespace Equip {
enum Slot { SLOT_ENGINE, SLOT_LASER, SLOT_MISSILE, SLOT_MAX }; enum Slot { SLOT_ENGINE, SLOT_LASER, SLOT_MISSILE, SLOT_MAX };
enum Type { NONE, DRIVE_INTERPLANETARY, DRIVE_CLASS1, enum Type { NONE, DRIVE_INTERPLANETARY, DRIVE_CLASS1, DRIVE_CLASS2,
LASER_1MW_BEAM, LASER_2MW_BEAM, LASER_4MW_BEAM }; DRIVE_CLASS3, DRIVE_CLASS4, DRIVE_CLASS5, DRIVE_CLASS6,
LASER_1MW_BEAM, LASER_2MW_BEAM, LASER_4MW_BEAM, TYPE_MAX };
}; };
struct ShipType { struct ShipType {
@ -58,6 +59,7 @@ private:
struct EquipType { struct EquipType {
const char* name; const char* name;
Equip::Slot slot; Equip::Slot slot;
int basePrice;
int mass; int mass;
int pval; /* Used for general 'power' attribute.. */ int pval; /* Used for general 'power' attribute.. */
static const EquipType types[]; static const EquipType types[];

View File

@ -4,6 +4,7 @@
#include "gameconsts.h" #include "gameconsts.h"
#include "star_system.h" #include "star_system.h"
#include "serializer.h" #include "serializer.h"
#include "l3d.h"
struct SpaceStationType { struct SpaceStationType {
Uint32 sbreModel; Uint32 sbreModel;
@ -19,6 +20,9 @@ void SpaceStation::Save(void) {
using namespace Serializer::Write; using namespace Serializer::Write;
ModelBody::Save(); ModelBody::Save();
wr_int((int)m_type); wr_int((int)m_type);
for(int i = 0; i < Equip::TYPE_MAX; i++) {
wr_int((int)m_equipmentStock[i]);
}
} }
void SpaceStation::Load(void) { void SpaceStation::Load(void) {
@ -26,6 +30,9 @@ void SpaceStation::Load(void) {
ModelBody::Load(); ModelBody::Load();
m_type = (TYPE)rd_int(); m_type = (TYPE)rd_int();
m_numPorts = 0; m_numPorts = 0;
for(int i = 0; i < Equip::TYPE_MAX; i++) {
m_equipmentStock[i] = static_cast<Equip::Type>(rd_int());
}
Init(); Init();
} }
@ -88,6 +95,9 @@ void SpaceStation::GetDockingSurface(CollMeshSet* mset, int midx) {
SpaceStation::SpaceStation(TYPE type) : ModelBody() { SpaceStation::SpaceStation(TYPE type) : ModelBody() {
m_type = type; m_type = type;
m_numPorts = 0; m_numPorts = 0;
for(int i = 1; i < Equip::TYPE_MAX; i++) {
m_equipmentStock[i] = L3D::rng.Int32(0, 100);
}
Init(); Init();
} }
@ -176,6 +186,10 @@ bool SpaceStation::GetDockingClearance(Ship* s) {
return true; return true;
} }
int SpaceStation::GetEquipmentPrice(Equip::Type t) const {
return EquipType::types[t].basePrice;
}
bool SpaceStation::OnCollision(Body* b, Uint32 flags) { bool SpaceStation::OnCollision(Body* b, Uint32 flags) {
if(flags & 0x10) { if(flags & 0x10) {
dockingport_t* dport = &port[flags & 0xf]; dockingport_t* dport = &port[flags & 0xf];

View File

@ -26,6 +26,8 @@ public:
vector3d normal; vector3d normal;
vector3d horiz; vector3d horiz;
} port[MAX_DOCKING_PORTS]; } port[MAX_DOCKING_PORTS];
int GetEquipmentStock(Equip::TYPE t) const { return m_equipmentStock[t]; }
int GetEquipmentPrice(Equip::Type t) const;
protected: protected:
virtual void Save(void); virtual void Save(void);
@ -35,5 +37,6 @@ private:
void Init(void); void Init(void);
TYPE m_type; TYPE m_type;
int m_numPorts; int m_numPorts;
int m_equipmentStock[Equip::TYPE_MAX];
}; };

View File

@ -31,13 +31,6 @@ private:
StationFrontView::StationFrontView(SpaceStationView* parent): StationSubView(parent) { StationFrontView::StationFrontView(SpaceStationView* parent): StationSubView(parent) {
SetTransparency(false); SetTransparency(false);
Gui::Fixed* fbox = new Gui::Fixed(720, 150);
Add(fbox, 40, 100);
Gui::VScrollBar* scroll = new Gui::VScrollBar();
Gui::VScrollPortal* box = new Gui::VScrollPortal(400, 150);
scroll->SetAdjustment(&box->vscollAdjust);
Gui::Label* l = new Gui::Label("Hello friend! Thankyou for docking with this space station! " Gui::Label* l = new Gui::Label("Hello friend! Thankyou for docking with this space station! "
"You may have noticed that the docking procedure was not entirely " "You may have noticed that the docking procedure was not entirely "
"physically correct. this is a result of unimplemented physics in this " "physically correct. this is a result of unimplemented physics in this "
@ -49,10 +42,9 @@ StationFrontView::StationFrontView(SpaceStationView* parent): StationSubView(par
" ADOPT A CAT: THEY CHEW IMPORTANT CABLES!"); " ADOPT A CAT: THEY CHEW IMPORTANT CABLES!");
fbox->Add(box, 0, 0); Gui::Fixed* fbox = new Gui::Fixed(720, 400);
fbox->Add(scroll, 405, 0); fbox->Add(l, 0, 0);
box->Add(l); Add(fbox, 40, 100);
box->ShowAll();
fbox->ShowAll(); fbox->ShowAll();
Gui::SolidButton* b = new Gui::SolidButton(); Gui::SolidButton* b = new Gui::SolidButton();
@ -73,12 +65,65 @@ class StationShipyardView: public StationSubView {
public: public:
StationShipyardView(SpaceStationView* parent); StationShipyardView(SpaceStationView* parent);
private: private:
virtual void ShowAll(void);
}; };
StationShipyardView::StationShipyardView(SpaceStationView* parent): StationSubView(parent) { StationShipyardView::StationShipyardView(SpaceStationView* parent): StationSubView(parent) {
SetTransparency(false); SetTransparency(false);
} }
void StationShipyardView::ShowAll(void) {
DeleteAllChildren();
SpaceStation* station = L3D::player->GetDockedWith();
assert(station);
SetTransparency(false);
Gui::Fixed* fbox = new Gui::Fixed(500, 200);
Add(fbox, 300, 100);
Gui::VScrollBar* scroll = new Gui::VScrollBar();
Gui::VScrollPortal* portal = new Gui::VScrollPortal(450, 200);
scroll->SetAdjustment(&portal->vscollAdjust);
//int GetEquipmentStock(Equip::Type t) cosnt { return m_equipmentStock[t]; }
int NUM_ITEMS = 0;
const float YSEP = Gui::Screen::GetFontHeight() * 1.5;
for(int i = 1; i < Equip::TYPE_MAX; i++) {
if(station->GetEquipmentStock(static_cast<Equip::Type>(i))) NUM_ITEMS++;
}
Gui::Fixed* innerbox = new Gui::Fixed(400, NUM_ITEMS*YSEP);
for(int i = 1, num = 0; i < Equip::TYPE_MAX; i++) {
int stock = station->GetEquipmentStock(static_cast<Equip::Type>(i));
if(!stock) continue;
Gui::Label* l = new Gui::Label(EquipType::types[i].name);
innerbox->Add(l, 0, num*YSEP);
innerbox->Add(new Gui::SolidButton(), 275, num*YSEP);
innerbox->Add(new Gui::SolidButton(), 300, num*YSEP);
char buf[128];
snprintf(buf, sizeof(buf), "$%d", station->GetEquipmentPrice(static_cast<Equip::Type(i)));
innerbox->Add(new Gui::Label(buf), 200, num*YSEP);
snprintf(buf, sizeof(buf), sizeof(buf), "%dt", EquipType::types[i].mass);
innerbox->Add(new Gui::Label(buf), 370, num*YSEP);
num++;
}
innerbox->ShowAll();
fbox->Add(new Gui::Label("Item"), 0, 0);
fbox->Add(new Gui::Label("Price"), 200, 0);
fbox->Add(new Gui::Label("Fit"), 275, 0);
fbox->Add(new Gui::Label("Remove"), 300, 0);
fbox->Add(new Gui::Label("Wt"), 370, 0);
fbox->Add(new Gui::Label("Portal"), 0, YSEP);
fbox->Add(new Gui::Label("Scroll"), 455, YSEP);
portal->Add(innerbox);
portal->ShowAll();
fbox->ShowAll();
Gui::Fixed::ShowAll();
}
/**********************************************************/ /**********************************************************/