00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "config.h"
00026 #include "Teddy/SpaceGame/UserInterface.h"
00027 #include "Teddy/SpaceGame/Cabin.h"
00028 #include "Teddy/SpaceGame/FrontCamera.h"
00029 #include "Teddy/SpaceGame/Hud.h"
00030 #include "Teddy/SpaceGame/Root.h"
00031 #include "Teddy/SpaceGame/Scanner.h"
00032 #include "Teddy/SpaceGame/Sight.h"
00033 #include "Teddy/SpaceGame/ShipCamera.h"
00034 #include "Teddy/Graphics/View.h"
00035 #include "Teddy/Graphics/Features.h"
00036 #include "Teddy/Materials/Material.h"
00037 #include "Teddy/PhysicalComponents/WindowManager.h"
00038 #include "Teddy/PhysicalComponents/LayoutConstraint.h"
00039 #include "Teddy/PhysicalComponents/Layer.h"
00040 #include "Teddy/PhysicalComponents/WindowManager.h"
00041 #include "Teddy/PhysicalComponents/Console.h"
00042 #include "Teddy/PhysicalComponents/HDock.h"
00043 #include "Teddy/SysSupport/Messages.h"
00044 using namespace Teddy::Graphics;
00045 using namespace Teddy::PhysicalComponents;
00046
00047
00048 namespace Teddy {
00049 namespace SpaceGame {
00050
00051
00052 UserInterface::UserInterface( Root *root ){
00053
00054 unsigned long view_flags = 0;
00055 if( root->isEnabled(RO_FULLSCREEN) == true ){
00056 view_flags |= VW_FULLSCREEN;
00057 }
00058
00059 view = new View(
00060 "Teddy Spacegame",
00061 root->getScreenWidth(),
00062 root->getScreenHeight(),
00063 view_flags
00064 );
00065
00066 window_manager = new WindowManager( view );
00067 view->setWindowManager( window_manager );
00068 Area::setDefaultWindowManager( window_manager );
00069
00070 layer = new Layer( "Test Layer", view );
00071
00072 this->root = root;
00073 }
00074
00075
00076 void UserInterface::enterRunLoop(){
00077 window_manager->inputLoop();
00078 }
00079
00080
00082 void UserInterface::addComponents(){
00083 LayoutConstraint *constraint_1 = new LayoutConstraint();
00084
00085 if( root->isEnabled(RO_MULTI_WINDOW) == true ){
00086 constraint_1->parent_x_fill_relative = 0.5;
00087 constraint_1->local_x_fill_pixels = -20;
00088 constraint_1->parent_y_fill_relative = 1;
00089 constraint_1->local_y_fill_pixels = -320;
00090 constraint_1->parent_x_offset_pixels = 10;
00091 constraint_1->parent_y_offset_pixels = 140;
00092 }else{
00093 constraint_1->parent_x_fill_relative = 1;
00094 constraint_1->parent_y_fill_relative = 1;
00095 this->view->setClear( false );
00096 }
00097
00098 LayoutConstraint *constraint_2 = new LayoutConstraint();
00099 constraint_2->parent_x_fill_relative = 0.5;
00100 constraint_2->local_x_fill_pixels = -20;
00101 constraint_2->parent_y_fill_relative = 1;
00102 constraint_2->local_y_fill_pixels = -320;
00103 constraint_2->parent_x_offset_relative = 1;
00104 constraint_2->parent_x_offset_pixels = -20;
00105 constraint_2->local_x_offset_relative = -1;
00106 constraint_2->parent_y_offset_pixels = 140;
00107
00108 Camera *camera = root->getObjectManager()->getCamera ();
00109 Camera *player_camera = root->getObjectManager()->getShipCamera();
00110
00111
00112 front_camera = new FrontCamera( "Camera 1", camera, root, constraint_1, root->isEnabled(RO_MULTI_WINDOW) == true );
00113
00114 if( root->isEnabled(RO_MULTI_WINDOW) == true ){
00115 front_camera2 = new FrontCamera( "Camera 2", player_camera, root, constraint_2, true );
00116 front_camera2->insert( new Sight() );
00117 layer->addProjection( front_camera2 );
00118 }else{
00119 front_camera->insert( new Sight() );
00120 }
00121
00122 hud = new Hud ( root );
00123 scanner = new Scanner( root );
00124
00125 camera ->setTitle( "Spectator View" );
00126 player_camera->setTitle( "Front View" );
00127
00128 hud->setTargetMatrix( &camera->debug_matrix );
00129
00130 window_manager->setFocus( dynamic_cast<EventListener*>(front_camera) );
00131 window_manager->insert ( layer );
00132
00133 if( root->isEnabled(RO_CABIN) == true ){
00134 layer->insert(
00135 new Cabin( "cabins/cabin5.lwo" )
00136 );
00137 }
00138
00139 if( root->isEnabled(RO_HUD) == true ){
00140 layer->insert( hud );
00141 }
00142 if( root->isEnabled(RO_SCANNER) == true ){
00143 layer->insert( scanner );
00144 }
00145
00146 layer->addProjection( front_camera );
00147 front_camera->focusActive( true );
00148
00149 layer->place ();
00150
00151
00152 front_camera->setClearColor( Color(0,0,0,1) );
00153 front_camera->getMaster()->setOptions ( RENDER_OPTION_ALL_M );
00154 front_camera->getMaster()->setMode ( RENDER_MODE_FILL );
00155 # if !defined( USE_TINY_GL )
00156 front_camera->getMaster()->setLighting( RENDER_LIGHTING_SIMPLE );
00157 # else
00158 front_camera->getMaster()->setLighting( RENDER_LIGHTING_COLOR );
00159 toggleCamera();
00160 # endif
00161
00162 if( root->isEnabled(RO_MULTI_WINDOW) == true ){
00163 front_camera2->setClearColor( Color(0.1f,0.3f,0.0f,1.0f) );
00164 front_camera2->disableSelect( RENDER_OPTION_DIFFUSE_M );
00165 front_camera2->disableSelect( RENDER_OPTION_BORDER_M );
00166 front_camera2->getMaster()->setMode ( RENDER_MODE_FILL_OUTLINE );
00167 front_camera2->getMaster()->setLighting ( RENDER_LIGHTING_COLOR );
00168 front_camera2->getMaster()->disableOptions( RENDER_OPTION_AMBIENT_M );
00169 front_camera2->getMaster()->disableOptions( RENDER_OPTION_SPECULAR_M );
00170 front_camera2->getMaster()->setDiffuse ( Color(0.0f,0.2f,0.0f,1.0f) );
00171 front_camera2->getMaster()->setBorder ( Color(0.6f,0.7f,0.5f,1.0f) );
00172 }
00173
00174 view ->display();
00175
00176 }
00177
00178
00180 void UserInterface::toggleCamera(){
00181 static int toggle = 0;
00182
00183 toggle = 1 - toggle;
00184
00185 if( toggle == 0 ){
00186 front_camera->setCamera( root->getObjectManager()->getCamera() );
00187 }else{
00188 front_camera->setCamera( root->getObjectManager()->getShipCamera() );
00189 }
00190 }
00191
00192
00193 View *UserInterface::getView(){
00194 return view;
00195 }
00196
00197
00198 Console *UserInterface::getConsole(){
00199 return this->console;
00200 }
00201
00202
00203 Scanner *UserInterface::getScanner(){
00204 return this->scanner;
00205 }
00206
00207
00208 Projection *UserInterface::getActiveProjection(){
00209 return this->front_camera;
00210 }
00211
00212
00213 };
00214 };
00215