[Add] More scrolling work and laying some additional groundwork for GUI.
This commit is contained in:
		
							parent
							
								
									c2ec30a048
								
							
						
					
					
						commit
						b1dac828d6
					
				
							
								
								
									
										80
									
								
								src/gui.cpp
									
									
									
									
									
								
							
							
						
						
									
										80
									
								
								src/gui.cpp
									
									
									
									
									
								
							| @ -3,9 +3,9 @@ | ||||
| 
 | ||||
| namespace Gui { | ||||
| namespace RawEvents { | ||||
|   sigc::signal<void, SDL_MouseMotionEvent*> onMouseMotion; | ||||
|   sigc::signal<void, SDL_MouseButtonEvent*> onMouseDown; | ||||
|   sigc::signal<void, SDL_MouseButtonEvent*> onMouseUp; | ||||
|   sigc::signal<void, MouseMotionEvent*> onMouseMotion; | ||||
|   sigc::signal<void, MouseButtonEvent*> onMouseDown; | ||||
|   sigc::signal<void, MouseButtonEvent*> onMouseUp; | ||||
|   sigc::signal<void, SDL_KeyboardEvent*>    onKeyDown; | ||||
|   sigc::signal<void, SDL_KeyboardEvent*>    onKeyUp; | ||||
| } | ||||
| @ -19,22 +19,18 @@ void HandleSDLEvent(SDL_Event* event) { | ||||
|   switch(event->type) { | ||||
|   case SDL_MOUSEBUTTONDOWN: | ||||
|     Screen::OnClick(&event->button); | ||||
|     RawEvents::onMouseDown.emit(&event->button); | ||||
|     break; | ||||
|   case SDL_MOUSEBUTTONUP: | ||||
|     Screen::OnClick(&event->button); | ||||
|     RawEvents::onMouseUp.emit(&event->button); | ||||
|     break; | ||||
|   case SDL_KEYDOWN: | ||||
|     Screen::OnKeyDown(&event->key.keysym); | ||||
|     RawEvents::onKeyDown.emit(&event->key); | ||||
|     break; | ||||
|   case SDL_KEYUP: | ||||
|     RawEvents::onKeyUp.emit(&event->key); | ||||
|     break; | ||||
|   case SDL_MOUSEMOTION: | ||||
|     Screen::OnMouseMotion(&event->motion); | ||||
|     RawEvents::onMouseMotion.emit(&event->motion); | ||||
|     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); | ||||
| } | ||||
| 
 | ||||
| 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); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										13
									
								
								src/gui.h
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/gui.h
									
									
									
									
									
								
							| @ -2,6 +2,13 @@ | ||||
| #include "libs.h" | ||||
| 
 | ||||
|  namespace Gui { | ||||
| 
 | ||||
|   namespace Theme { | ||||
|     void DrawIndent(const float size[2]); | ||||
|     void DrawOutdent(const float size[2]); | ||||
|     void DrawHollowRect(const float size[2]); | ||||
|   } | ||||
| 
 | ||||
|   namespace Color { | ||||
|     extern const float bg[]; | ||||
|     extern const float bgShadow[]; | ||||
| @ -18,9 +25,9 @@ | ||||
| 
 | ||||
| namespace Gui { | ||||
|   namespace RawEvents { | ||||
|     extern sigc::signal<void, SDL_MouseMotionEvent*>  onMouseMotion; | ||||
|     extern sigc::signal<void, SDL_MouseButtonEvent*>  onMouseDown; | ||||
|     extern sigc::signal<void, SDL_MouseButtonEvent*>  onMouseUp; | ||||
|     extern sigc::signal<void, MouseMotionEvent*>  onMouseMotion; | ||||
|     extern sigc::signal<void, MouseButtonEvent*>  onMouseDown; | ||||
|     extern sigc::signal<void, MouseButtonEvent*>  onMouseUp; | ||||
|     extern sigc::signal<void, SDL_KeyboardEvent*>     onKeyDown; | ||||
|     extern sigc::signal<void, SDL_KeyboardEvent*>     onKeyUp; | ||||
|   } | ||||
|  | ||||
| @ -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) { | ||||
|     m_isPressed = false; | ||||
|     _m_release.disconnect(); | ||||
| @ -62,43 +62,19 @@ void TransparentButton::GetSizeRequested(float size[2]) { | ||||
| } | ||||
| 
 | ||||
| void SolidButton::Draw(void) { | ||||
|   glBegin(GL_QUADS); | ||||
|     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(); | ||||
|   float size[2]; | ||||
|   GetSize(size); | ||||
|   if(IsPressed()) { | ||||
|     Theme::DrawIndent(size); | ||||
|   } else { | ||||
|     Theme::DrawOutdent(size); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void TransparentButton::Draw(void) { | ||||
|   glColor3f(1, 1, 1); | ||||
|   glBegin(GL_LINE_LOOP); | ||||
|     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(); | ||||
| } | ||||
|   float size[2]; | ||||
|   GetSize(size); | ||||
| 
 | ||||
|   Theme::DrawHollowRect(size); | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -20,7 +20,7 @@ namespace Gui { | ||||
|     sigc::signal<void> onClick; | ||||
|     bool IsPressed(void) { return m_isPressed; } | ||||
|   private: | ||||
|     void OnRawMouseUp(SDL_MouseButtonEvent* e); | ||||
|     void OnRawMouseUp(MouseButtonEvent* e); | ||||
|     void OnRawKeyUp(SDL_KeyboardEvent* e); | ||||
| 
 | ||||
|     bool m_isPressed; | ||||
|  | ||||
| @ -12,7 +12,8 @@ Fixed::Fixed(float w, float h): Container() { | ||||
| } | ||||
| 
 | ||||
| void Fixed::GetSizeRequested(float size[2]) { | ||||
|   GetSize(size); | ||||
|   size[0] = m_w; | ||||
|   size[1] = m_h; | ||||
| } | ||||
| 
 | ||||
| Fixed::~Fixed(void) { | ||||
|  | ||||
| @ -97,6 +97,9 @@ void Screen::OnMouseMotion(SDL_MouseMotionEvent* e) { | ||||
|   ev.screenX = ev.x = x; | ||||
|   ev.screenY = ev.y = y; | ||||
|   baseContainer->OnMouseMotion(&ev); | ||||
|   ev.screenX = ev.x = x; | ||||
|   ev.screenY = ev.y = y; | ||||
|   RawEvents::onMouseMotion.emit(&ev); | ||||
| } | ||||
| 
 | ||||
| void Screen::OnClick(SDL_MouseButtonEvent* e) { | ||||
| @ -108,8 +111,13 @@ void Screen::OnClick(SDL_MouseButtonEvent* e) { | ||||
|   ev.screenX = ev.x = x; | ||||
|   ev.screenY = ev.y = y; | ||||
|   OnClickTestLabels(ev); | ||||
|   if(ev.isdown) baseContainer->OnMouseDown(&ev); | ||||
|   else baseContainer->OnMouseUp(&ev); | ||||
|   if(ev.isdown) { | ||||
|     baseContainer->OnMouseDown(&ev); | ||||
|     RawEvents::OnMouseDown.emit(&ev); | ||||
|   } else { | ||||
|     baseContainer->OnMouseUp(&ev); | ||||
|     RawEvents::onMouseUp.emit(&ev); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void Screen::OnClickTestLabels(const Gui::MouseButtonEvent& ev) { | ||||
|  | ||||
| @ -38,46 +38,13 @@ void ToggleButton::GetSizeRequested(float size[2]) { | ||||
| } | ||||
| 
 | ||||
| void ToggleButton::Draw(void) { | ||||
|   float size[2]; | ||||
|   GetSize(size); | ||||
| 
 | ||||
|   if(m_pressed) { | ||||
|     glBegin(GL_QUADS); | ||||
|       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(); | ||||
|     Theme::DrawIndent(size); | ||||
|   } else { | ||||
|     glBegin(GL_QUADS); | ||||
|       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(); | ||||
|     Theme::DrawOutdent(size); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -24,7 +24,7 @@ bool VScrollBar::OnMouseDown(MouseButtonEvent* e) { | ||||
|   return false; | ||||
| } | ||||
| 
 | ||||
| void VScrollBar::OnRawMouseUp(SDL_MouseButtonEvent* e) { | ||||
| void VScrollBar::OnRawMouseUp(MouseButtonEvent* e) { | ||||
|   if(e->button == 1) { | ||||
|     m_isPressed = false; | ||||
|     _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) { | ||||
|     float pos[2]; | ||||
|     GetAbsolutePosition(pos); | ||||
| @ -44,27 +44,8 @@ void VScrollBar::OnRawMouseMotion(SDL_MouseMotionEvent* e) { | ||||
| 
 | ||||
| void VScrollBar::Draw(void) { | ||||
|   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(); | ||||
|   glColor3f(1, 1, 1); | ||||
|   glBegin(GL_LINES); | ||||
|  | ||||
| @ -16,8 +16,8 @@ public: | ||||
|   } | ||||
| 
 | ||||
| private: | ||||
|   void OnRawMouseUp(SDL_MousebuttonEvent* e); | ||||
|   void OnRawMOuseMotion(SDL_MouseMotionEvent* e); | ||||
|   void OnRawMouseUp(MouseButtonEvent* e); | ||||
|   void OnRawMOuseMotion(MouseMotionEvent* e); | ||||
|   bool m_isPressed; | ||||
|   sigc::connection m_release, _m_motion; | ||||
|   Adjustment* m_sdjustment; | ||||
|  | ||||
| @ -38,6 +38,27 @@ void VScrollPortal::Remove(Widget* child) { | ||||
|   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) { | ||||
|   float size[2]; | ||||
|   GetSize(size); | ||||
|  | ||||
| @ -7,6 +7,9 @@ public: | ||||
|   VScrollPortal(float w, float h); | ||||
|   void Add(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 GetSizeRequested(float size[2]); | ||||
|   virtual void OnChildResizeRequest(Widget*); | ||||
| @ -14,6 +17,7 @@ public: | ||||
|   void SetBgColor(float r, float g, float b); | ||||
|   Adjustment vscrollAdjust; | ||||
| private: | ||||
|   float GetScrollPixels(); | ||||
|   void OnScroll(float); | ||||
|   float m_scrollY, m_childSizeY; | ||||
|   Widget* m_cild; | ||||
|  | ||||
| @ -55,27 +55,52 @@ const EquipType EquipType::types[] = { | ||||
|   { | ||||
|     "Interplanetary Drive", | ||||
|     Equip::SLOT_ENGINE, | ||||
|     1, 0 | ||||
|     4000, 1, 0 | ||||
|   }, | ||||
|   { | ||||
|     "Class 1 Hyperdrive", | ||||
|     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", | ||||
|     Equip::SLOT_LASER, | ||||
|     1, 1 | ||||
|     6000, 1, 1 | ||||
|   }, | ||||
|   { | ||||
|     "2MW beam laser", | ||||
|     Equip::SLOT_LASER, | ||||
|     1, 2 | ||||
|     10000, 1, 2 | ||||
|   }, | ||||
|   { | ||||
|     "4MW beam laser", | ||||
|     Equip::SLOT_LASER, | ||||
|     1, 4 | ||||
|     22000, 1, 4 | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -5,8 +5,9 @@ | ||||
| 
 | ||||
| namespace Equip { | ||||
|   enum Slot { SLOT_ENGINE, SLOT_LASER, SLOT_MISSILE, SLOT_MAX }; | ||||
|   enum Type { NONE, DRIVE_INTERPLANETARY, DRIVE_CLASS1, | ||||
|               LASER_1MW_BEAM, LASER_2MW_BEAM, LASER_4MW_BEAM }; | ||||
|   enum Type { NONE, DRIVE_INTERPLANETARY, DRIVE_CLASS1, DRIVE_CLASS2, | ||||
|               DRIVE_CLASS3, DRIVE_CLASS4, DRIVE_CLASS5, DRIVE_CLASS6, | ||||
|               LASER_1MW_BEAM, LASER_2MW_BEAM, LASER_4MW_BEAM, TYPE_MAX }; | ||||
| }; | ||||
| 
 | ||||
| struct ShipType { | ||||
| @ -58,6 +59,7 @@ private: | ||||
| struct EquipType { | ||||
|   const char* name; | ||||
|   Equip::Slot slot; | ||||
|   int         basePrice; | ||||
|   int         mass; | ||||
|   int         pval; /* Used for general 'power' attribute.. */ | ||||
|   static const EquipType types[]; | ||||
|  | ||||
| @ -4,6 +4,7 @@ | ||||
| #include "gameconsts.h" | ||||
| #include "star_system.h" | ||||
| #include "serializer.h" | ||||
| #include "l3d.h" | ||||
| 
 | ||||
| struct SpaceStationType { | ||||
|   Uint32 sbreModel; | ||||
| @ -19,6 +20,9 @@ void SpaceStation::Save(void) { | ||||
|   using namespace Serializer::Write; | ||||
|   ModelBody::Save(); | ||||
|   wr_int((int)m_type); | ||||
|   for(int i = 0; i < Equip::TYPE_MAX; i++) { | ||||
|     wr_int((int)m_equipmentStock[i]); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void SpaceStation::Load(void) { | ||||
| @ -26,6 +30,9 @@ void SpaceStation::Load(void) { | ||||
|   ModelBody::Load(); | ||||
|   m_type = (TYPE)rd_int(); | ||||
|   m_numPorts = 0; | ||||
|   for(int i = 0; i < Equip::TYPE_MAX; i++) { | ||||
|     m_equipmentStock[i] = static_cast<Equip::Type>(rd_int()); | ||||
|   } | ||||
|   Init(); | ||||
| } | ||||
| 
 | ||||
| @ -88,6 +95,9 @@ void SpaceStation::GetDockingSurface(CollMeshSet* mset, int midx) { | ||||
| SpaceStation::SpaceStation(TYPE type) : ModelBody() { | ||||
|   m_type = type; | ||||
|   m_numPorts = 0; | ||||
|   for(int i = 1; i < Equip::TYPE_MAX; i++) { | ||||
|     m_equipmentStock[i] = L3D::rng.Int32(0, 100); | ||||
|   } | ||||
|   Init(); | ||||
| } | ||||
| 
 | ||||
| @ -176,6 +186,10 @@ bool SpaceStation::GetDockingClearance(Ship* s) { | ||||
|   return true; | ||||
| } | ||||
| 
 | ||||
| int SpaceStation::GetEquipmentPrice(Equip::Type t) const { | ||||
|   return EquipType::types[t].basePrice; | ||||
| } | ||||
| 
 | ||||
| bool SpaceStation::OnCollision(Body* b, Uint32 flags) { | ||||
|   if(flags & 0x10) { | ||||
|     dockingport_t* dport = &port[flags & 0xf]; | ||||
|  | ||||
| @ -26,6 +26,8 @@ public: | ||||
|     vector3d normal; | ||||
|     vector3d horiz; | ||||
|   } port[MAX_DOCKING_PORTS]; | ||||
|   int GetEquipmentStock(Equip::TYPE t) const { return m_equipmentStock[t]; } | ||||
|   int GetEquipmentPrice(Equip::Type t) const; | ||||
| 
 | ||||
| protected: | ||||
|   virtual void Save(void); | ||||
| @ -35,5 +37,6 @@ private: | ||||
|   void Init(void); | ||||
|   TYPE m_type; | ||||
|   int m_numPorts; | ||||
|   int m_equipmentStock[Equip::TYPE_MAX]; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -31,13 +31,6 @@ private: | ||||
| StationFrontView::StationFrontView(SpaceStationView* parent): StationSubView(parent) { | ||||
|   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! " | ||||
|     "You may have noticed that the docking procedure was not entirely " | ||||
|     "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!"); | ||||
| 
 | ||||
| 
 | ||||
|   fbox->Add(box, 0, 0); | ||||
|   fbox->Add(scroll, 405, 0); | ||||
|   box->Add(l); | ||||
|   box->ShowAll(); | ||||
|   Gui::Fixed* fbox = new Gui::Fixed(720, 400); | ||||
|   fbox->Add(l, 0, 0); | ||||
|   Add(fbox, 40, 100); | ||||
|   fbox->ShowAll(); | ||||
| 
 | ||||
|   Gui::SolidButton* b = new Gui::SolidButton(); | ||||
| @ -73,12 +65,65 @@ class StationShipyardView: public StationSubView { | ||||
| public: | ||||
|   StationShipyardView(SpaceStationView* parent); | ||||
| private: | ||||
|    | ||||
|   virtual void ShowAll(void);   | ||||
| }; | ||||
| 
 | ||||
| StationShipyardView::StationShipyardView(SpaceStationView* parent): StationSubView(parent) { | ||||
|   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(); | ||||
| 
 | ||||
| } | ||||
| /**********************************************************/ | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Allanis
						Allanis