quick and dirty editor works for now
This commit is contained in:
@@ -60,6 +60,7 @@ int ControllerBase::OnInit (int argc, char* argv[]) {
|
||||
uistate.kbditem = 0;
|
||||
uistate.last_keysym = SDLK_CLEAR;
|
||||
uistate.last_unicode = 0;
|
||||
uistate.last_key = SDLK_CLEAR;
|
||||
|
||||
uistate.lastwidget = 0;
|
||||
|
||||
@@ -162,12 +163,14 @@ void ControllerBase::IMGUIFinish () {
|
||||
|
||||
// also reset the last keysym such that old values will not be reported
|
||||
uistate.last_keysym = SDLK_FIRST;
|
||||
uistate.last_key = SDLK_FIRST;
|
||||
}
|
||||
|
||||
/** \brief Keyboard processing */
|
||||
bool ControllerBase::OnKeyDown (const SDL_keysym &keysym) {
|
||||
mButtonStates.set(keysym.sym, true);
|
||||
uistate.last_keysym = keysym.sym;
|
||||
uistate.last_key = keysym.sym;
|
||||
|
||||
// Only when Unicode processing is activated store the unicode value
|
||||
if (SDL_EnableUNICODE(-1)) {
|
||||
@@ -208,6 +211,7 @@ bool ControllerBase::OnKeyUp (const SDL_keysym &keysym) {
|
||||
bool ControllerBase::OnMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos) {
|
||||
MouseButton mouse_button = convert_sdl_button (button);
|
||||
mButtonStates.set(mouse_button, true);
|
||||
uistate.last_key = mouse_button;
|
||||
|
||||
if (mView->mOverlayManager.SendMouseButtonDown (button, xpos, ypos))
|
||||
return true;
|
||||
|
||||
@@ -20,6 +20,7 @@ struct IMGUIState {
|
||||
int kbditem;
|
||||
SDLKey last_keysym;
|
||||
Uint16 last_unicode;
|
||||
int last_key;
|
||||
|
||||
int lastwidget;
|
||||
};
|
||||
@@ -59,6 +60,11 @@ class ControllerBase : public Module {
|
||||
pos_out[1] = mMouseWorldPosition[1];
|
||||
pos_out[2] = mMouseWorldPosition[2];
|
||||
}
|
||||
void GetMouseWorldPosition (vector3d &pos_out) {
|
||||
pos_out[0] = mMouseWorldPosition[0];
|
||||
pos_out[1] = mMouseWorldPosition[1];
|
||||
pos_out[2] = mMouseWorldPosition[2];
|
||||
}
|
||||
bool GetButtonState (unsigned int key) {
|
||||
assert (key < BINDING_KEYS_LAST);
|
||||
return mButtonStates.test(key);
|
||||
|
||||
@@ -224,7 +224,7 @@ void DrawVector(vector3d start, vector3d end) {
|
||||
float rad_delta = 2. * M_PI / (float) segments;
|
||||
double s,c;
|
||||
|
||||
glColor3f(0.2, 0.2, 0.5);
|
||||
glColor3f(0.2, 0.8, 0.2);
|
||||
glPointSize (10.);
|
||||
glBegin (GL_TRIANGLE_FAN);
|
||||
glVertex3f (end[0], end[1], end[2]);
|
||||
|
||||
+6
-4
@@ -70,10 +70,10 @@ struct EntityPhysicState {
|
||||
vector3d &GetOrientation ();
|
||||
float &GetAngleVelocity ();
|
||||
|
||||
void SetPosition (const vector3d &position);
|
||||
void SetVelocity (const vector3d &velocity);
|
||||
void SetOrientation (const vector3d &orientation);
|
||||
void SetAngleVelocity (const float &angle_velocity);
|
||||
void SetPosition (const vector3d &position) { mPosition = position; }
|
||||
void SetVelocity (const vector3d &velocity) { mVelocity = velocity; }
|
||||
void SetOrientation (const vector3d &orientation) { mOrientation = orientation; }
|
||||
void SetAngleVelocity (const float &angle_velocity) { mAngleVelocity = angle_velocity; }
|
||||
|
||||
/** \brief Transforms the given vector in local space to world coordinates */
|
||||
void Globalize (vector3d &vec);
|
||||
@@ -149,6 +149,8 @@ struct EntityBase {
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<unsigned int, EntityBase*>::iterator EntityBaseIter;
|
||||
|
||||
}
|
||||
|
||||
#endif // _ENTITYBASE_H
|
||||
|
||||
@@ -69,7 +69,7 @@ void DrawRoundedBlock (int x, int y, int w, int h) {
|
||||
assert (w > d);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
// lower part
|
||||
// lower part
|
||||
glVertex3f (x, y, 0.);
|
||||
glVertex3f (x, y + d, 0.);
|
||||
glVertex3f (x + w, y + d, 0.);
|
||||
@@ -127,7 +127,6 @@ void Label (int id, const char* caption, int x, int y) {
|
||||
view = EngineGetView ();
|
||||
assert (view);
|
||||
|
||||
glColor3f (1., 1., 1.);
|
||||
view->DrawGLStringMeasure(caption, &width, &height);
|
||||
view->DrawGLString(x , y + height * 0.5, caption);
|
||||
}
|
||||
@@ -148,6 +147,7 @@ void LabelCentered (int id, const char* caption, int x, int y) {
|
||||
view = EngineGetView ();
|
||||
assert (view);
|
||||
|
||||
SelectFont("console.ttf size=23");
|
||||
view->DrawGLStringMeasure(caption, &width, &height);
|
||||
view->DrawGLString(x - 0.5 * width, y + height * 0.5, caption);
|
||||
}
|
||||
@@ -334,6 +334,7 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
|
||||
if (controller->uistate.kbditem == id && SDL_GetTicks() >> 9 & 1)
|
||||
text_output += "_";
|
||||
|
||||
SelectFont("console.ttf size=23");
|
||||
view->DrawGLStringMeasure(text_value.c_str(), &width, &height);
|
||||
view->DrawGLString(textpos_x, textpos_y, text_output.c_str());
|
||||
|
||||
@@ -507,7 +508,7 @@ float VerticalSlider (int id, int x, int y, int w, int h, float min_value, float
|
||||
}
|
||||
|
||||
bool CheckKeyPress (int keycode) {
|
||||
if (controller->uistate.last_keysym == keycode)
|
||||
if (controller->uistate.last_key == keycode)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace GUI {
|
||||
/** \brief Checks whether the mouse is in the given rectangle */
|
||||
bool regionhit (int x, int y, int w, int h);
|
||||
|
||||
void DrawRoundedBlock (int x, int y, int w, int h);
|
||||
|
||||
/** \brief Draws a label at the given position with vertical center at y */
|
||||
void Label (int id, const char* caption, int x, int y);
|
||||
/** \brief Draws a label centered at the given position with vertical center at y */
|
||||
|
||||
+27
-1
@@ -175,6 +175,24 @@ EntityBase* ModelBase::GetEntity (const unsigned int id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EntityBase* ModelBase::GetEntityAt (const vector3d &pos) {
|
||||
std::map<unsigned int, EntityBase*>::iterator iter = mEntities.begin();
|
||||
|
||||
while (iter != mEntities.end ()) {
|
||||
EntityPhysicState* entity = iter->second->mPhysicState;
|
||||
/// \todo fix const casting!
|
||||
vector3d temp_pos (pos);
|
||||
|
||||
if ( (temp_pos - entity->GetPosition()).length() < entity->mRadius)
|
||||
return iter->second;
|
||||
|
||||
iter++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
unsigned int ModelBase::CreateEntityId () {
|
||||
if (mEntityIdCounter == NullEntityId - 1)
|
||||
LogError ("Could not create valid entity id, reached maximum value of %u", mEntityIdCounter);
|
||||
@@ -307,7 +325,7 @@ void KillEntity (unsigned int id) {
|
||||
ModelInstance->KillEntity (id);
|
||||
}
|
||||
|
||||
EntityBase * GetEntity (unsigned int id) {
|
||||
EntityBase* GetEntity (unsigned int id) {
|
||||
if (!ModelInstance) {
|
||||
LogError ("Couldn't execute GetEntity(): Model not initialized!");
|
||||
}
|
||||
@@ -315,6 +333,14 @@ EntityBase * GetEntity (unsigned int id) {
|
||||
return ModelInstance->GetEntity (id);
|
||||
}
|
||||
|
||||
EntityBase* GetEntityAt(const vector3d &pos) {
|
||||
if (!ModelInstance) {
|
||||
LogError ("Couldn't execute GetEntityAt(): Model not initialized!");
|
||||
}
|
||||
|
||||
return ModelInstance->GetEntityAt (pos);
|
||||
}
|
||||
|
||||
EntityPhysicState * GetEntityPhysicState (unsigned int id) {
|
||||
EntityBase *entity = GetEntity (id);
|
||||
|
||||
|
||||
@@ -68,6 +68,17 @@ class ModelBase : public Module {
|
||||
EntityBase* CreateEntity (int type);
|
||||
/** Returns the Entity with the given id */
|
||||
EntityBase* GetEntity (const unsigned int id);
|
||||
|
||||
/** Returns the Entity at the given world coordinates */
|
||||
EntityBase* GetEntityAt (const vector3d &pos);
|
||||
|
||||
EntityBaseIter GetEntityIterBegin () {
|
||||
return mEntities.begin();
|
||||
}
|
||||
EntityBaseIter GetEntityIterEnd() {
|
||||
return mEntities.end();
|
||||
}
|
||||
|
||||
/** Returns a unused id for an Entity */
|
||||
unsigned int CreateEntityId ();
|
||||
/** Removes all Entities */
|
||||
|
||||
@@ -2,9 +2,14 @@
|
||||
#define _MODELGLOBAL_H
|
||||
|
||||
namespace Engine {
|
||||
class EntityBase;
|
||||
|
||||
/** \brief Adds the function callback as command for the given name*/
|
||||
unsigned int GetPlayerEntityId ();
|
||||
|
||||
/** \brief Returns the entity at the given world coordinates or NULL */
|
||||
EntityBase* GetEntityAt(const vector3d &pos);
|
||||
|
||||
/** \brief Assigns the player to an Entity. All controls will be redirected to that player
|
||||
*
|
||||
* This can be used to disable the controls of of the player by assinging
|
||||
|
||||
@@ -53,22 +53,6 @@ float& EntityPhysicState::GetAngleVelocity () {
|
||||
return mAngleVelocity;
|
||||
}
|
||||
|
||||
void EntityPhysicState::SetPosition (const vector3d &position) {
|
||||
mPosition = position;
|
||||
}
|
||||
|
||||
void EntityPhysicState::SetVelocity (const vector3d &velocity) {
|
||||
mVelocity = velocity;
|
||||
}
|
||||
|
||||
void EntityPhysicState::SetOrientation (const vector3d &orientation) {
|
||||
mOrientation = orientation;
|
||||
}
|
||||
|
||||
void EntityPhysicState::SetAngleVelocity (const float &angle_velocity) {
|
||||
mAngleVelocity = angle_velocity;
|
||||
}
|
||||
|
||||
void EntityPhysicState::Globalize (vector3d &vec) {
|
||||
// make a copy of the local coordinates
|
||||
vector3d local (vec);
|
||||
|
||||
+2
-2
@@ -362,7 +362,8 @@ void ViewBase::DrawGrid () {
|
||||
xstep = 1.;
|
||||
zstep = 1.;
|
||||
|
||||
glColor3f (1., 1., 1.);
|
||||
glColor3f (0.8, 0.8, 0.8);
|
||||
glLineWidth(1.);
|
||||
glBegin (GL_LINES);
|
||||
for (i = 0; i <= count_x; i++) {
|
||||
glVertex3f (i * xstep + xmin, 0., zmin);
|
||||
@@ -373,7 +374,6 @@ void ViewBase::DrawGrid () {
|
||||
glVertex3f (xmax, 0, i * zstep + zmin);
|
||||
}
|
||||
glEnd ();
|
||||
|
||||
}
|
||||
|
||||
void ViewBase::DrawWorld () {
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ class ViewBase : public Module{
|
||||
bool SendMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos);
|
||||
bool SendMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos);
|
||||
*/
|
||||
|
||||
|
||||
private:
|
||||
protected:
|
||||
/** \brief Initializes the system */
|
||||
|
||||
Reference in New Issue
Block a user