[Add] Preliminary communications to space stations and ships.
This commit is contained in:
parent
8428a7e892
commit
52819f2878
@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
GenericSystemView::GenericSystemView(void) : View() {
|
GenericSystemView::GenericSystemView(void) : View() {
|
||||||
px = py = pidx = 0xdeadbeef;
|
px = py = pidx = 0xdeadbeef;
|
||||||
m_scannerLayout = new Gui::Fixed(140, 2, 360, 60);
|
m_scannerLayout = new Gui::Fixed(360, 60);
|
||||||
m_scannerLayout->SetTransparency(true);
|
m_scannerLayout->SetTransparency(true);
|
||||||
|
Gui::Screen::AddBaseWidget(m_scannerLayout, 140, 2);
|
||||||
|
|
||||||
m_systemName = new Gui::Label("");
|
m_systemName = new Gui::Label("");
|
||||||
m_systemName->SetColor(1, 1, 0);
|
m_systemName->SetColor(1, 1, 0);
|
||||||
|
@ -299,6 +299,36 @@ void FontFace::RenderString(const char* str) {
|
|||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 'Markup' indeed. #rgb hex is change colour, no sensible escape. */
|
||||||
|
void FontFace::RenderMarkup(const char* str) {
|
||||||
|
glPushMatrix();
|
||||||
|
int len = strlen(str);
|
||||||
|
for(unsigned int i = 0; i < len; i++) {
|
||||||
|
if(str[i] == '#') {
|
||||||
|
int hexcol;
|
||||||
|
if(sscanf(str+i, "#%3x", &hexcol)==1) {
|
||||||
|
Uint8 col[3];
|
||||||
|
col[0] = (hexcol&0xf00)>>4;
|
||||||
|
col[1] = (hexcol&0xf0);
|
||||||
|
col[2] = (hexcol&0xf)<<4;
|
||||||
|
glColor3ubv(col);
|
||||||
|
i+=3;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(str[i] == '\n') {
|
||||||
|
glPopMatrix();
|
||||||
|
glTranslatef(0, -m_height, 0);
|
||||||
|
glPushMatrix();
|
||||||
|
} else {
|
||||||
|
glfglyph_t* glyph = &m_glyphs[str[i]];
|
||||||
|
if(glyph->numidx) RenderGlyph(str[i]);
|
||||||
|
glTranslatef(glyph->advx, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
FontFace::FontFace(const char* filename_ttf) {
|
FontFace::FontFace(const char* filename_ttf) {
|
||||||
FT_Face face;
|
FT_Face face;
|
||||||
if(0 != FT_New_Face(library, filename_ttf, 0, &face)) {
|
if(0 != FT_New_Face(library, filename_ttf, 0, &face)) {
|
||||||
|
@ -7,6 +7,7 @@ public:
|
|||||||
FontFace(const char* filename_ttf);
|
FontFace(const char* filename_ttf);
|
||||||
void RenderGlyph(int chr);
|
void RenderGlyph(int chr);
|
||||||
void RenderString(const char* str);
|
void RenderString(const char* str);
|
||||||
|
void RenderMarkup(const char* str);
|
||||||
|
|
||||||
/* Of Ms. */
|
/* Of Ms. */
|
||||||
float GetHeight(void) { return m_height; }
|
float GetHeight(void) { return m_height; }
|
||||||
|
@ -11,20 +11,22 @@ Button::Button(void) {
|
|||||||
SetSize(BUTTON_SIZE, BUTTON_SIZE);
|
SetSize(BUTTON_SIZE, BUTTON_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::OnMouseDown(MouseButtonEvent* e) {
|
bool Button::OnMouseDown(MouseButtonEvent* e) {
|
||||||
if(e->button == 1) {
|
if(e->button == 1) {
|
||||||
m_isPressed = true;
|
m_isPressed = true;
|
||||||
onPress.emit();
|
onPress.emit();
|
||||||
/* Wait for mouse release, regardless of where on screen. */
|
/* Wait for mouse release, regardless of where on screen. */
|
||||||
_m_release = RawEvents::onMouseUp.connect(sigc::mem_fun(this, &Button::OnRawMouseUp));
|
_m_release = RawEvents::onMouseUp.connect(sigc::mem_fun(this, &Button::OnRawMouseUp));
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::OnMouseUp(MouseButtonEvent* e) {
|
bool Button::OnMouseUp(MouseButtonEvent* e) {
|
||||||
if((e->button == 1) && m_isPressed) {
|
if((e->button == 1) && m_isPressed) {
|
||||||
m_isPressed = false;
|
m_isPressed = false;
|
||||||
onClick.emit();
|
onClick.emit();
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::OnActivate(void) {
|
void Button::OnActivate(void) {
|
||||||
|
@ -7,8 +7,8 @@ namespace Gui {
|
|||||||
public:
|
public:
|
||||||
Button(void);
|
Button(void);
|
||||||
virtual ~Button(void) {}
|
virtual ~Button(void) {}
|
||||||
virtual void OnMouseDown(MouseButtonEvent* e);
|
virtual bool OnMouseDown(MouseButtonEvent* e);
|
||||||
virtual void OnMouseUp(MouseButtonEvent* e);
|
virtual bool OnMouseUp(MouseButtonEvent* e);
|
||||||
virtual void OnActivate(void);
|
virtual void OnActivate(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
namespace Gui {
|
namespace Gui {
|
||||||
|
|
||||||
void Container::HandleMouseEvent(MouseButtonEvent* e) {
|
|
||||||
|
bool Container::HandleMouseEvent(MouseButtonEvent* e) {
|
||||||
float x = e->x;
|
float x = e->x;
|
||||||
float y = e->y;
|
float y = e->y;
|
||||||
for(std::list<widget_pos>::iterator i = m_children.begin(); i != m_children.end(); ++i) {
|
for(std::list<widget_pos>::iterator i = m_children.begin(); i != m_children.end(); ++i) {
|
||||||
@ -22,13 +23,16 @@ void Container::HandleMouseEvent(MouseButtonEvent* e) {
|
|||||||
(y >= pos[1]) && (y < pos[1]+size[1])) {
|
(y >= pos[1]) && (y < pos[1]+size[1])) {
|
||||||
e->x = x-pos[0];
|
e->x = x-pos[0];
|
||||||
e->y = y-pos[1];
|
e->y = y-pos[1];
|
||||||
|
bool alive;
|
||||||
if(e->isdown) {
|
if(e->isdown) {
|
||||||
(*i).w->OnMouseDown(e);
|
alive = (*i).w->OnMouseDown(e);
|
||||||
} else {
|
} else {
|
||||||
(*i).w->OnMouseUp(e);
|
alive = (*i).w->OnMouseUp(e);
|
||||||
}
|
}
|
||||||
|
if(!alive) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::DeleteAllChildren(void) {
|
void Container::DeleteAllChildren(void) {
|
||||||
@ -66,12 +70,12 @@ void Container::Draw(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::OnMouseDown(MouseButtonEvent* e) {
|
bool Container::OnMouseDown(MouseButtonEvent* e) {
|
||||||
HandleMouseEvent(e);
|
return HandleMouseEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::OnMouseUp(MouseButtonEvent* e) {
|
bool Container::OnMouseUp(MouseButtonEvent* e) {
|
||||||
HandleMouseEvent(e);
|
return HandleMouseEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Container::ShowAll(void) {
|
void Container::ShowAll(void) {
|
||||||
|
@ -7,14 +7,14 @@
|
|||||||
namespace Gui {
|
namespace Gui {
|
||||||
class Container : public Widget {
|
class Container : public Widget {
|
||||||
public:
|
public:
|
||||||
void OnMouseDown(MouseButtonEvent* e);
|
bool OnMouseDown(MouseButtonEvent* e);
|
||||||
void OnMouseUp(MouseButtonEvent* e);
|
bool OnMouseUp(MouseButtonEvent* e);
|
||||||
void DeleteAllChildren(void);
|
void DeleteAllChildren(void);
|
||||||
virtual void Draw(void);
|
virtual void Draw(void);
|
||||||
virtual void ShowAll(void);
|
virtual void ShowAll(void);
|
||||||
virtual void HideAll(void);
|
virtual void HideAll(void);
|
||||||
private:
|
private:
|
||||||
void HandleMouseEvent(MouseButtonEvent* e);
|
bool HandleMouseEvent(MouseButtonEvent* e);
|
||||||
protected:
|
protected:
|
||||||
void PrependChild(Widget* w, float x, float y);
|
void PrependChild(Widget* w, float x, float y);
|
||||||
void AppendChild(Widget* w, float x, float y);
|
void AppendChild(Widget* w, float x, float y);
|
||||||
|
@ -3,7 +3,8 @@ namespace Gui {
|
|||||||
struct MouseButtonEvent {
|
struct MouseButtonEvent {
|
||||||
Uint8 isdown;
|
Uint8 isdown;
|
||||||
Uint8 button;
|
Uint8 button;
|
||||||
float x, y;
|
float x, y; /* Widget coords. */
|
||||||
|
float screenX, screenY; /* Screen coords. */
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,14 +4,12 @@
|
|||||||
|
|
||||||
namespace Gui {
|
namespace Gui {
|
||||||
|
|
||||||
Fixed::Fixed(float x, float y, float w, float h) {
|
Fixed::Fixed(float w, float h) {
|
||||||
SetPosition(x, y);
|
|
||||||
SetSize(w, h);
|
SetSize(w, h);
|
||||||
memcpy(m_bgcol, Color::bg, 3*sizeof(float));
|
memcpy(m_bgcol, Color::bg, 3*sizeof(float));
|
||||||
m_w = w; m_h = h;
|
m_w = w; m_h = h;
|
||||||
m_transparent = false;
|
m_transparent = false;
|
||||||
m_eventMask = EVENT_ALL;
|
m_eventMask = EVENT_ALL;
|
||||||
Screen::AddBaseWidget(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Fixed::GetSizeRequested(float size[2]) {
|
void Fixed::GetSizeRequested(float size[2]) {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
namespace Gui {
|
namespace Gui {
|
||||||
class Fixed : public Container {
|
class Fixed : public Container {
|
||||||
public:
|
public:
|
||||||
Fixed(float x, float y, float w, float h);
|
Fixed(float w, float h);
|
||||||
void Add(Widget* child, float x, float y);
|
void Add(Widget* child, float x, float y);
|
||||||
void Remove(Widget* child);
|
void Remove(Widget* child);
|
||||||
virtual void Draw(void);
|
virtual void Draw(void);
|
||||||
|
@ -22,7 +22,7 @@ void Label::SetText(std::string& text) {
|
|||||||
|
|
||||||
void Label::Draw(void) {
|
void Label::Draw(void) {
|
||||||
glColor3fv(m_color);
|
glColor3fv(m_color);
|
||||||
Screen::RenderString(m_text);
|
Screen::RenderMarkup(m_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Label::GetSizeRequested(float size[2]) {
|
void Label::GetSizeRequested(float size[2]) {
|
||||||
|
@ -15,9 +15,10 @@ RadioButton::~RadioButton(void) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioButton::OnMouseDown(MouseButtonEvent* e) {
|
bool RadioButton::OnMouseDown(MouseButtonEvent* e) {
|
||||||
onPress.emit();
|
onPress.emit();
|
||||||
OnActivate();
|
OnActivate();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioButton::OnActivate(void) {
|
void RadioButton::OnActivate(void) {
|
||||||
|
@ -14,7 +14,7 @@ namespace Gui {
|
|||||||
virtual ~RadioButton();
|
virtual ~RadioButton();
|
||||||
virtual void Draw();
|
virtual void Draw();
|
||||||
virtual void GetSizeRequested(float &w, float &h);
|
virtual void GetSizeRequested(float &w, float &h);
|
||||||
virtual void OnMouseDown(MouseButtonEvent *e);
|
virtual bool OnMouseDown(MouseButtonEvent *e);
|
||||||
virtual void OnActivate();
|
virtual void OnActivate();
|
||||||
virtual void SetSelected(bool state) { m_pressed = state; }
|
virtual void SetSelected(bool state) { m_pressed = state; }
|
||||||
bool GetSelected() { return m_pressed; }
|
bool GetSelected() { return m_pressed; }
|
||||||
|
@ -79,7 +79,8 @@ void Screen::Draw(void) {
|
|||||||
LeaveOrtho();
|
LeaveOrtho();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::AddBaseWidget(Widget* w) {
|
void Screen::AddBaseWidget(Widget* w, int x, int y) {
|
||||||
|
w->SetPosition(x, y);
|
||||||
Screen::widgets.push_back(w);
|
Screen::widgets.push_back(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,6 +98,8 @@ void Screen::OnClick(SDL_MouseButtonEvent* e) {
|
|||||||
ev.isdown = (e->type == SDL_MOUSEBUTTONDOWN);
|
ev.isdown = (e->type == SDL_MOUSEBUTTONDOWN);
|
||||||
ev.x = x;
|
ev.x = x;
|
||||||
ev.y = y;
|
ev.y = y;
|
||||||
|
ev.screenX = x;
|
||||||
|
ev.screenY = y;
|
||||||
OnClickTestLabels(ev);
|
OnClickTestLabels(ev);
|
||||||
for(std::list<Widget*>::iterator i = Screen::widgets.begin(); i != Screen::widgets.end(); ++i) {
|
for(std::list<Widget*>::iterator i = Screen::widgets.begin(); i != Screen::widgets.end(); ++i) {
|
||||||
float size[2], pos[2];
|
float size[2], pos[2];
|
||||||
@ -151,6 +154,13 @@ void Screen::RenderString(const std::string& s) {
|
|||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Screen::RenderMarkup(const std::string& s) {
|
||||||
|
glPushMatrix();
|
||||||
|
glScalef(Screen::font_xsize, Screen::font_ysize, 1);
|
||||||
|
font->RenderMarkup(s.c_str());
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
bool Screen::CanPutLabel(float x, float y) {
|
bool Screen::CanPutLabel(float x, float y) {
|
||||||
for(std::vector<LabelPos>::iterator i = labelPositions.begin(); i != labelPositions.end(); ++i) {
|
for(std::vector<LabelPos>::iterator i = labelPositions.begin(); i != labelPositions.end(); ++i) {
|
||||||
if((fabs(x-(*i).x) < 5) &&
|
if((fabs(x-(*i).x) < 5) &&
|
||||||
|
@ -9,11 +9,12 @@ namespace Gui {
|
|||||||
public:
|
public:
|
||||||
static void Init(int real_width, int real_height, int ui_width, int ui_height);
|
static void Init(int real_width, int real_height, int ui_width, int ui_height);
|
||||||
static void Draw(void);
|
static void Draw(void);
|
||||||
static void AddBaseWidget(Widget* w);
|
static void AddBaseWidget(Widget* w, int x, int y);
|
||||||
static void RemoveBaseWidget(Widget* w);
|
static void RemoveBaseWidget(Widget* w);
|
||||||
static void OnClick(SDL_MouseButtonEvent* e);
|
static void OnClick(SDL_MouseButtonEvent* e);
|
||||||
static void OnKeyDown(const SDL_keysym* sym);
|
static void OnKeyDown(const SDL_keysym* sym);
|
||||||
static void RenderString(const std::string& s);
|
static void RenderString(const std::string& s);
|
||||||
|
static void RenderMarkup(const std::string& s);
|
||||||
static void PutClickableLabel(const std::string& s, float x, float y,
|
static void PutClickableLabel(const std::string& s, float x, float y,
|
||||||
sigc::slot<void, const Gui::MouseButtonEvent*> slot);
|
sigc::slot<void, const Gui::MouseButtonEvent*> slot);
|
||||||
static void RenderLabel(const std::string& s, float x, float y);
|
static void RenderLabel(const std::string& s, float x, float y);
|
||||||
|
@ -10,7 +10,7 @@ ToggleButton::ToggleButton(void) {
|
|||||||
SetSize(BUTTON_SIZE, BUTTON_SIZE);
|
SetSize(BUTTON_SIZE, BUTTON_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToggleButton::OnMouseDown(MouseButtonEvent* e) {
|
bool ToggleButton::OnMouseDown(MouseButtonEvent* e) {
|
||||||
if(e->button == 1) {
|
if(e->button == 1) {
|
||||||
onPress.emit();
|
onPress.emit();
|
||||||
m_pressed = !m_pressed;
|
m_pressed = !m_pressed;
|
||||||
@ -20,6 +20,7 @@ void ToggleButton::OnMouseDown(MouseButtonEvent* e) {
|
|||||||
onDeselect.emit(this);
|
onDeselect.emit(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToggleButton::GetSizeRequested(float& w, float& h) {
|
void ToggleButton::GetSizeRequested(float& w, float& h) {
|
||||||
|
@ -9,7 +9,7 @@ namespace Gui {
|
|||||||
virtual void Draw(void);
|
virtual void Draw(void);
|
||||||
virtual ~ToggleButton(void) {}
|
virtual ~ToggleButton(void) {}
|
||||||
virtual void GetSizeRequested(float& w, float& h);
|
virtual void GetSizeRequested(float& w, float& h);
|
||||||
virtual void OnMouseDown(MouseButtonEvent* e);
|
virtual bool OnMouseDown(MouseButtonEvent* e);
|
||||||
void SetPressed(bool s) { m_pressed = s; }
|
void SetPressed(bool s) { m_pressed = s; }
|
||||||
bool GetPressed(void) { return m_pressed; }
|
bool GetPressed(void) { return m_pressed; }
|
||||||
|
|
||||||
|
@ -20,8 +20,9 @@ namespace Gui {
|
|||||||
Container* GetParent(void) { return m_parent; }
|
Container* GetParent(void) { return m_parent; }
|
||||||
void SetParent(Container* p) { m_parent = p; }
|
void SetParent(Container* p) { m_parent = p; }
|
||||||
|
|
||||||
virtual void OnMouseDown(MouseButtonEvent* e) {}
|
/* Event handlers should return false to stop propagating event. */
|
||||||
virtual void OnMouseUp(MouseButtonEvent* e) {}
|
virtual bool OnMouseDown(MouseButtonEvent* e) { return false; }
|
||||||
|
virtual bool OnMouseUp(MouseButtonEvent* e) { return false; }
|
||||||
virtual void OnActivate(void) {}
|
virtual void OnActivate(void) {}
|
||||||
/* Only to be called by Screen::OnKeyDown. */
|
/* Only to be called by Screen::OnKeyDown. */
|
||||||
void OnPreShortcut(const SDL_keysym* sym);
|
void OnPreShortcut(const SDL_keysym* sym);
|
||||||
|
15
src/main.cpp
15
src/main.cpp
@ -192,7 +192,7 @@ void L3D::MainLoop(void) {
|
|||||||
StarSystem s(0, 0, 0);
|
StarSystem s(0, 0, 0);
|
||||||
HyperspaceTo(&s);
|
HyperspaceTo(&s);
|
||||||
|
|
||||||
const float zpos = EARTH_RADIUS * 7;
|
const float zpos = EARTH_RADIUS * 1;
|
||||||
Frame* pframe = *(Space::rootFrame->m_children.begin());
|
Frame* pframe = *(Space::rootFrame->m_children.begin());
|
||||||
player->SetFrame(pframe);
|
player->SetFrame(pframe);
|
||||||
player->SetPosition(vector3d(0, zpos*0.1, zpos));
|
player->SetPosition(vector3d(0, zpos*0.1, zpos));
|
||||||
@ -207,13 +207,11 @@ void L3D::MainLoop(void) {
|
|||||||
Space::AddBody(body);
|
Space::AddBody(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
SpaceStation* station = new SpaceStation();
|
||||||
SpaceStation* body = new SpaceStation();
|
station->SetLabel("Poemi-chan's Folly");
|
||||||
body->SetLabel("Poemi-chan's Folly");
|
station->SetFrame(pframe);
|
||||||
body->SetFrame(pframe);
|
station->SetPosition(vector3d(5000, zpos*0.1, zpos-10000));
|
||||||
body->SetPosition(vector3d(5000, zpos*0.1, zpos-10000));
|
Space::AddBody(station);
|
||||||
Space::AddBody(body);
|
|
||||||
}
|
|
||||||
|
|
||||||
Gui::Init(scrWidth, scrHeight, 640, 480);
|
Gui::Init(scrWidth, scrHeight, 640, 480);
|
||||||
|
|
||||||
@ -229,6 +227,7 @@ void L3D::MainLoop(void) {
|
|||||||
infoView = new InfoView();
|
infoView = new InfoView();
|
||||||
|
|
||||||
SetView(world_view);
|
SetView(world_view);
|
||||||
|
player->SetDockedWith(station);
|
||||||
|
|
||||||
Uint32 last_stats = SDL_GetTicks();
|
Uint32 last_stats = SDL_GetTicks();
|
||||||
int frame_stat = 0;
|
int frame_stat = 0;
|
||||||
|
@ -11,7 +11,6 @@ public:
|
|||||||
virtual void Update(void);
|
virtual void Update(void);
|
||||||
virtual void Draw3D(void);
|
virtual void Draw3D(void);
|
||||||
private:
|
private:
|
||||||
virtual void OnMouseDown(Gui::MouseButtonEvent* e) { }
|
|
||||||
matrix4x4d viewingRotation;
|
matrix4x4d viewingRotation;
|
||||||
float viewingDist;
|
float viewingDist;
|
||||||
Gui::Label* m_infoLabel;
|
Gui::Label* m_infoLabel;
|
||||||
|
13
src/ship.cpp
13
src/ship.cpp
@ -27,6 +27,7 @@ Ship::Ship(ShipType::Type shipType) : DynamicBody() {
|
|||||||
m_wheelTransition = 0;
|
m_wheelTransition = 0;
|
||||||
m_wheelState = 0;
|
m_wheelState = 0;
|
||||||
m_dockedWith = 0;
|
m_dockedWith = 0;
|
||||||
|
dockingTimer = 0;
|
||||||
m_navTarget = 0;
|
m_navTarget = 0;
|
||||||
m_combatTarget = 0;
|
m_combatTarget = 0;
|
||||||
m_shipType = shipType;
|
m_shipType = shipType;
|
||||||
@ -83,6 +84,7 @@ void Ship::CalcStats(shipstats_t* stats) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Ship::TimeStepUpdate(const float timeStep) {
|
void Ship::TimeStepUpdate(const float timeStep) {
|
||||||
|
dockingTimer = (dockingTimer-timeStep > 0 ? dockingTimer-timeStep : 0);
|
||||||
/* ODE tri mesh likes to know our old position. */
|
/* ODE tri mesh likes to know our old position. */
|
||||||
TriMeshUpdateLastPos();
|
TriMeshUpdateLastPos();
|
||||||
const ShipType& stype = GetShipType();
|
const ShipType& stype = GetShipType();
|
||||||
@ -163,6 +165,7 @@ void Ship::SetDockedWith(SpaceStation* s) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
m_dockedWith = s;
|
m_dockedWith = s;
|
||||||
|
dockingTimer = 0.0f;
|
||||||
SetVelocity(vector3d(0, 0, 0));
|
SetVelocity(vector3d(0, 0, 0));
|
||||||
SetAngVelocity(vector3d(0, 0, 0));
|
SetAngVelocity(vector3d(0, 0, 0));
|
||||||
}
|
}
|
||||||
@ -177,6 +180,16 @@ void Ship::SetWheelState(bool down) {
|
|||||||
else m_wheelTransition = -1;
|
else m_wheelTransition = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Ship::SetNavTarget(Body* const target) {
|
||||||
|
m_navTarget = target;
|
||||||
|
L3D::world_view->UpdateCommsOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Ship::SetCombatTarget(Body* const target) {
|
||||||
|
m_combatTarget = target;
|
||||||
|
L3D::world_view->UpdateCommsOptions();
|
||||||
|
}
|
||||||
|
|
||||||
/* Assumed to be at model coords. */
|
/* Assumed to be at model coords. */
|
||||||
void Ship::RenderLaserfire(void) {
|
void Ship::RenderLaserfire(void) {
|
||||||
const ShipType& stype = GetShipType();
|
const ShipType& stype = GetShipType();
|
||||||
|
@ -20,9 +20,9 @@ public:
|
|||||||
virtual Object::Type GetType(void) { return Object::SHIP; }
|
virtual Object::Type GetType(void) { return Object::SHIP; }
|
||||||
virtual void SetDockedWith(SpaceStation*);
|
virtual void SetDockedWith(SpaceStation*);
|
||||||
SpaceStation* GetDockedWith(void) { return m_dockedWith; }
|
SpaceStation* GetDockedWith(void) { return m_dockedWith; }
|
||||||
void SetNavTarget(Body* const target) { m_navTarget = target; }
|
void SetNavTarget(Body* const target);
|
||||||
Body* GetNavTarget(void) const { return m_navTarget; }
|
Body* GetNavTarget(void) const { return m_navTarget; }
|
||||||
void SetCombatTarget(Body* const target) { m_combatTarget = target; }
|
void SetCombatTarget(Body* const target);
|
||||||
Body* GetCombatTarget(void) const { return m_combatTarget; }
|
Body* GetCombatTarget(void) const { return m_combatTarget; }
|
||||||
virtual void Render(const Frame* camFrame);
|
virtual void Render(const Frame* camFrame);
|
||||||
void SetThrusterState(enum ShipType::Thruster t, float level);
|
void SetThrusterState(enum ShipType::Thruster t, float level);
|
||||||
@ -33,6 +33,8 @@ public:
|
|||||||
void CalcStats(shipstats_t* stats);
|
void CalcStats(shipstats_t* stats);
|
||||||
void UpdateMass(void);
|
void UpdateMass(void);
|
||||||
void SetWheelState(bool down);
|
void SetWheelState(bool down);
|
||||||
|
float GetDockingTimer(void) { return dockingTimer; }
|
||||||
|
void SetDockingTimer(float t) { dockingTimer = t; }
|
||||||
virtual void TimeStepUpdate(const float timeStep);
|
virtual void TimeStepUpdate(const float timeStep);
|
||||||
virtual void NotifyDeath(const Body* const dyingBody);
|
virtual void NotifyDeath(const Body* const dyingBody);
|
||||||
|
|
||||||
@ -55,6 +57,7 @@ private:
|
|||||||
|
|
||||||
float m_thrusters[ShipType::THRUSTER_MAX];
|
float m_thrusters[ShipType::THRUSTER_MAX];
|
||||||
float m_angThrusters[3];
|
float m_angThrusters[3];
|
||||||
|
float dockingTimer;
|
||||||
dGeomID m_tempLaserGeom[ShipType::GUNMOUNT_MAX];
|
dGeomID m_tempLaserGeom[ShipType::GUNMOUNT_MAX];
|
||||||
|
|
||||||
LaserObj m_laserCollisionObj;
|
LaserObj m_laserCollisionObj;
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "info_view.h"
|
#include "info_view.h"
|
||||||
|
|
||||||
ShipCpanel::ShipCpanel(void) : Gui::Fixed(0, 0, 640, 64) {
|
ShipCpanel::ShipCpanel(void) : Gui::Fixed(640, 64) {
|
||||||
//SetBgColor(1, 0, 0);
|
Gui::Screen::AddBaseWidget(this, 0, 0);
|
||||||
SetTransparency(true);
|
SetTransparency(true);
|
||||||
|
|
||||||
Gui::Image* img = new Gui::Image("icons/cpanel.png");
|
Gui::Image* img = new Gui::Image("icons/cpanel.png");
|
||||||
@ -77,12 +77,31 @@ ShipCpanel::ShipCpanel(void) : Gui::Fixed(0, 0, 640, 64) {
|
|||||||
m_clock = new Gui::Label("");
|
m_clock = new Gui::Label("");
|
||||||
m_clock->SetColor(1, 0.7, 0);
|
m_clock->SetColor(1, 0.7, 0);
|
||||||
Add(m_clock, 2, 48);
|
Add(m_clock, 2, 48);
|
||||||
|
|
||||||
|
tempMsg = new Gui::Label("");
|
||||||
|
Add(tempMsg, 170, 44);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShipCpanel::SetTemporaryMessage(Body* const sender, std::string msg) {
|
||||||
|
std::string str = "#0f0"+msg;
|
||||||
|
if(sender) {
|
||||||
|
str = std::string("'ca0")+"Message from "+sender->GetLabel()+":\n"+str;
|
||||||
|
}
|
||||||
|
tempMsg->SetText(str);
|
||||||
|
tempMsgAge = L3D::GetGameTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShipCpanel::Draw(void) {
|
void ShipCpanel::Draw(void) {
|
||||||
std::string time = date_format(L3D::GetGameTime());
|
std::string time = date_format(L3D::GetGameTime());
|
||||||
m_clock->SetText(time);
|
m_clock->SetText(time);
|
||||||
|
|
||||||
|
if(tempMsgAge) {
|
||||||
|
if(L3D::GetGameTime() - tempMsgAge > 5.0) {
|
||||||
|
tempMsg->SetText("");
|
||||||
|
tempMsgAge = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Gui::Fixed::Draw();
|
Gui::Fixed::Draw();
|
||||||
Remove(m_scannerWidget);
|
Remove(m_scannerWidget);
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,14 @@
|
|||||||
#include "libs.h"
|
#include "libs.h"
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
|
||||||
|
class Body;
|
||||||
|
|
||||||
class ShipCpanel : public Gui::Fixed {
|
class ShipCpanel : public Gui::Fixed {
|
||||||
public:
|
public:
|
||||||
ShipCpanel(void);
|
ShipCpanel(void);
|
||||||
virtual void Draw(void);
|
virtual void Draw(void);
|
||||||
void SetScannerWidget(Widget* w); /* Must be done each frame. */
|
void SetScannerWidget(Widget* w); /* Must be done each frame. */
|
||||||
|
void SetTemporaryMessage(Body* const sender, std::string msg);
|
||||||
private:
|
private:
|
||||||
void OnChangeCamView(Gui::MultiStateImageButton* b);
|
void OnChangeCamView(Gui::MultiStateImageButton* b);
|
||||||
void OnChangeMapView(Gui::MultiStateImageButton* b);
|
void OnChangeMapView(Gui::MultiStateImageButton* b);
|
||||||
@ -16,5 +19,8 @@ private:
|
|||||||
|
|
||||||
Widget* m_scannerWidget;
|
Widget* m_scannerWidget;
|
||||||
Gui::Label* m_clock;
|
Gui::Label* m_clock;
|
||||||
|
|
||||||
|
Gui::Label* tempMsg;
|
||||||
|
float tempMsgAge;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,7 +57,6 @@ void SpaceStation::GetDockingSurface(CollMeshSet* mset, int midx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SpaceStation::SpaceStation(void) : ModelBody() {
|
SpaceStation::SpaceStation(void) : ModelBody() {
|
||||||
allowDocking = true;
|
|
||||||
SetModel(STATION_SBRE_MODEL);
|
SetModel(STATION_SBRE_MODEL);
|
||||||
matrix4x4d m = matrix4x4d::RotateYMatrix(M_PI-M_PI/6);
|
matrix4x4d m = matrix4x4d::RotateYMatrix(M_PI-M_PI/6);
|
||||||
SetRotation(m);
|
SetRotation(m);
|
||||||
@ -83,13 +82,17 @@ SpaceStation::~SpaceStation(void) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SpaceStation::GetDockingClearance(Ship* s) {
|
||||||
|
s->SetDockingTimer(68*10);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool SpaceStation::OnCollision(Body* b, Uint32 flags) {
|
bool SpaceStation::OnCollision(Body* b, Uint32 flags) {
|
||||||
if(flags == 1) {
|
if(flags == 1) {
|
||||||
/* Hitting docking area of a station. */
|
/* Hitting docking area of a station. */
|
||||||
if(b->GetType() == Object::SHIP) {
|
if(b->GetType() == Object::SHIP) {
|
||||||
Ship* s = static_cast<Ship*>(b);
|
Ship* s = static_cast<Ship*>(b);
|
||||||
if(!s->GetDockedWith() && allowDocking) {
|
if((!s->GetDockedWith()) && (s->GetDockingTimer() != 0.0f)) {
|
||||||
allowDocking = false;
|
|
||||||
s->Disable();
|
s->Disable();
|
||||||
s->SetDockedWith(this);
|
s->SetDockedWith(this);
|
||||||
printf("Docking!\n");
|
printf("Docking!\n");
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "model_body.h"
|
#include "model_body.h"
|
||||||
|
|
||||||
class CollMeshSet;
|
class CollMeshSet;
|
||||||
|
class Ship;
|
||||||
|
|
||||||
class SpaceStation : public ModelBody {
|
class SpaceStation : public ModelBody {
|
||||||
public:
|
public:
|
||||||
@ -12,13 +13,11 @@ public:
|
|||||||
virtual Object::Type GetType(void) { return Object::SPACESTATION; }
|
virtual Object::Type GetType(void) { return Object::SPACESTATION; }
|
||||||
virtual void Render(const Frame* camFrame);
|
virtual void Render(const Frame* camFrame);
|
||||||
void GetDockingSurface(CollMeshSet* mset, int midx);
|
void GetDockingSurface(CollMeshSet* mset, int midx);
|
||||||
|
bool GetDockingClearance(Ship* s);
|
||||||
struct dockingport_t {
|
struct dockingport_t {
|
||||||
vector3d center;
|
vector3d center;
|
||||||
vector3d normal;
|
vector3d normal;
|
||||||
vector3d horiz;
|
vector3d horiz;
|
||||||
} port;
|
} port;
|
||||||
|
|
||||||
private:
|
|
||||||
bool allowDocking;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
12
src/view.h
12
src/view.h
@ -11,12 +11,16 @@
|
|||||||
*/
|
*/
|
||||||
class View : public Gui::Fixed {
|
class View : public Gui::Fixed {
|
||||||
public:
|
public:
|
||||||
View(void) : Gui::Fixed(0, 64, 640, 416) {
|
View(void) : Gui::Fixed(640, 416) {
|
||||||
m_rightButtonBar = new Gui::Fixed(512, 0, 128, 26);
|
Gui::Screen::AddBaseWidget(this, 0, 64);
|
||||||
m_rightButtonBar->SetBgColor(.65, .65, .65);
|
|
||||||
|
|
||||||
m_rightRegion2 = new Gui::Fixed(517, 26, 122, 17);
|
m_rightButtonBar = new Gui::Fixed(128, 26);
|
||||||
|
m_rightButtonBar->SetBgColor(.65, .65, .65);
|
||||||
|
Gui::Screen::AddBaseWidget(m_rightButtonBar, 512, 0);
|
||||||
|
|
||||||
|
m_rightRegion2 = new Gui::Fixed(122, 17);
|
||||||
m_rightRegion2->SetTransparency(true);
|
m_rightRegion2->SetTransparency(true);
|
||||||
|
Gui::Screen::AddBaseWidget(m_rightRegion2, 517, 26);
|
||||||
}
|
}
|
||||||
virtual ~View(void) { delete m_rightButtonBar; delete m_rightRegion2; }
|
virtual ~View(void) { delete m_rightButtonBar; delete m_rightRegion2; }
|
||||||
virtual void ShowAll(void) {
|
virtual void ShowAll(void) {
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#include "frame.h"
|
#include "frame.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "space.h"
|
#include "space.h"
|
||||||
|
#include "space_station.h"
|
||||||
|
#include "ship_cpanel.h"
|
||||||
|
|
||||||
static const float lightCol[] = { 1, 1, .9, 0 };
|
static const float lightCol[] = { 1, 1, .9, 0 };
|
||||||
const float WorldView::PICK_OBJECT_RECT_SIZE = 20.0f;
|
const float WorldView::PICK_OBJECT_RECT_SIZE = 20.0f;
|
||||||
@ -10,8 +12,15 @@ const float WorldView::PICK_OBJECT_RECT_SIZE = 20.0f;
|
|||||||
#define BG_STAR_MAX 5000
|
#define BG_STAR_MAX 5000
|
||||||
|
|
||||||
WorldView::WorldView(void): View() {
|
WorldView::WorldView(void): View() {
|
||||||
|
float size[2];
|
||||||
|
GetSize(size);
|
||||||
|
|
||||||
SetTransparency(true);
|
SetTransparency(true);
|
||||||
|
|
||||||
|
commsOptions = new Fixed(size[0], size[1]/2);
|
||||||
|
commsOptions->SetTransparency(true);
|
||||||
|
Add(commsOptions, 10, 20);
|
||||||
|
|
||||||
Gui::MultiStateImageButton* wheels_button = new Gui::MultiStateImageButton();
|
Gui::MultiStateImageButton* wheels_button = new Gui::MultiStateImageButton();
|
||||||
wheels_button->SetShortcut(SDLK_F7, KMOD_NONE);
|
wheels_button->SetShortcut(SDLK_F7, KMOD_NONE);
|
||||||
wheels_button->AddState(0, "icons/wheels_up.png");
|
wheels_button->AddState(0, "icons/wheels_up.png");
|
||||||
@ -114,22 +123,66 @@ void WorldView::Update(void) {
|
|||||||
/* Player control inputs. */
|
/* Player control inputs. */
|
||||||
if(L3D::player)
|
if(L3D::player)
|
||||||
L3D::player->PollControls();
|
L3D::player->PollControls();
|
||||||
|
|
||||||
|
Body* target = L3D::player->GetNavTarget();
|
||||||
|
if(target) {
|
||||||
|
commsOptions->ShowAll();
|
||||||
|
} else {
|
||||||
|
//commsOptions->HideAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldView::OnMouseDown(Gui::MouseButtonEvent* e) {
|
Gui::Button* WorldView::AddCommsOption(std::string msg, int ypos) {
|
||||||
|
Gui::Label* l = new Gui::Label(msg);
|
||||||
|
commsOptions->Add(l, 50, ypos);
|
||||||
|
|
||||||
|
Gui::TransparentButton* b = new Gui::TransparentButton();
|
||||||
|
commsOptions->Add(b, 16, ypos);
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void PlayerRequestDockingClearance(SpaceStation* s) {
|
||||||
|
s->GetDockingClearance(L3D::player);
|
||||||
|
L3D::cpan->SetTemporaryMessage(s, "Docking clearance granted.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorldView::UpdateCommsOptions(void) {
|
||||||
|
Body* const navtarget = L3D::player->GetNavTarget();
|
||||||
|
commsOptions->DeleteAllChildren();
|
||||||
|
|
||||||
|
float size[2];
|
||||||
|
commsOptions->GetSize(size);
|
||||||
|
int ypos = size[1]-16;
|
||||||
|
if(navtarget) {
|
||||||
|
if(navtarget->GetType() == Object::SPACESTATION) {
|
||||||
|
commsOptions->Add(new Gui::Label(navtarget->GetLabel()), 16, ypos);
|
||||||
|
ypos -= 32;
|
||||||
|
Gui::Button* b = AddCommsOption("Request docking clearance", ypos);
|
||||||
|
b->onClick.connect(sigc::bind(sigc::ptr_fun(&PlayerRequestDockingClearance), (SpaceStation*)navtarget));
|
||||||
|
ypos -= 32;
|
||||||
|
} else {
|
||||||
|
commsOptions->Add(new Gui::Label(navtarget->GetLabel()), 16, ypos);
|
||||||
|
ypos -= 32;
|
||||||
|
std::string msg = "Do something to "+navtarget->GetLabel();
|
||||||
|
Gui::Button* b = AddCommsOption(msg, ypos);
|
||||||
|
ypos -= 32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WorldView::OnMouseDown(Gui::MouseButtonEvent* e) {
|
||||||
|
/* If continuing to propagate mouse event, see if target is clicked on. */
|
||||||
|
if(Container::OnMouseDown(e)) {
|
||||||
if(1 == e->button && !L3D::MouseButtonState(3)) {
|
if(1 == e->button && !L3D::MouseButtonState(3)) {
|
||||||
/* Left click in view when RMB not pressed => Select target. */
|
/* Left click in view when RMB not pressed => Select target. */
|
||||||
float screenPos[2];
|
Body* const target = PickBody(e->screenX, e->screenY);
|
||||||
GetPosition(screenPos);
|
|
||||||
/* Put mouse coords into screen space. */
|
|
||||||
screenPos[0] += e->x;
|
|
||||||
screenPos[1] += e->y;
|
|
||||||
Body* const target = PickBody(screenPos[0], screenPos[1]);
|
|
||||||
if(L3D::player) {
|
if(L3D::player) {
|
||||||
/* TODO: If in nav mode, SetNavTarget(), else SetCombatTarget(). */
|
/* TODO: If in nav mode, SetNavTarget(), else SetCombatTarget(). */
|
||||||
L3D::player->SetNavTarget(target);
|
L3D::player->SetNavTarget(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Body* WorldView::PickBody(const float screenX, const float screenY) const {
|
Body* WorldView::PickBody(const float screenX, const float screenY) const {
|
||||||
|
@ -12,12 +12,15 @@ public:
|
|||||||
virtual void Draw3D(void);
|
virtual void Draw3D(void);
|
||||||
matrix4x4d viewingRotation;
|
matrix4x4d viewingRotation;
|
||||||
static const float PICK_OBJECT_RECT_SIZE;
|
static const float PICK_OBJECT_RECT_SIZE;
|
||||||
|
void UpdateCommsOptions(void);
|
||||||
private:
|
private:
|
||||||
|
Gui::Button* AddCommsOption(const std::string msg, int ypos);
|
||||||
void OnClickHyperspace(void);
|
void OnClickHyperspace(void);
|
||||||
void OnChangeWheelsState(Gui::MultiStateImageButton* b);
|
void OnChangeWheelsState(Gui::MultiStateImageButton* b);
|
||||||
virtual void OnMouseDown(Gui::MouseButtonEvent* e);
|
virtual bool OnMouseDown(Gui::MouseButtonEvent* e);
|
||||||
Body* PickBody(const float screenX, const float screenY) const;
|
Body* PickBody(const float screenX, const float screenY) const;
|
||||||
Gui::ImageButton* m_hyperspaceButton;
|
Gui::ImageButton* m_hyperspaceButton;
|
||||||
GLuint m_bgstarsDlist;
|
GLuint m_bgstarsDlist;
|
||||||
|
Gui::Fixed* commsOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user