fixed 3 major bugs (LineEdit backspace, input crashes, editor button press and editor actions)
parent
3e05c967ab
commit
a27ece921a
|
@ -10,7 +10,7 @@ engine/libraries/oglft/liboglft/OGLFT.h
|
||||||
|
|
||||||
start
|
start
|
||||||
runtests
|
runtests
|
||||||
run_asteroids
|
fysxasteroids
|
||||||
config.rc
|
config.rc
|
||||||
|
|
||||||
Debug/
|
Debug/
|
||||||
|
|
|
@ -229,7 +229,6 @@ void View::DrawStars() {
|
||||||
|
|
||||||
glEnd();
|
glEnd();
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void View::Draw() {
|
void View::Draw() {
|
||||||
|
@ -773,12 +772,14 @@ void View::DrawUiEditor() {
|
||||||
|
|
||||||
// The close button
|
// The close button
|
||||||
if (Engine::GUI::Button (1, "X", screen_right - 48, 20, 32, button_height)
|
if (Engine::GUI::Button (1, "X", screen_right - 48, 20, 32, button_height)
|
||||||
|| Engine::GUI::CheckKeyPress(SDLK_ESCAPE)) {
|
|| Engine::GUI::CheckKeyPressed(SDLK_ESCAPE)) {
|
||||||
|
|
||||||
if (mEditorState == EditorStateTest) {
|
if (mEditorState == EditorStateTest) {
|
||||||
mEditorState = EditorStateUnknown;
|
mEditorState = EditorStateUnknown;
|
||||||
|
|
||||||
GetModel()->DoLoadLevel("level_edit_temp.txt");
|
GetModel()->DoLoadLevel("level_edit_temp.txt");
|
||||||
GetModel()->SetGameState(GameStatePaused);
|
GetModel()->SetGameState(GameStatePaused);
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
PopViewState();
|
PopViewState();
|
||||||
}
|
}
|
||||||
|
@ -787,26 +788,38 @@ void View::DrawUiEditor() {
|
||||||
if (mEditorState != EditorStateTest) {
|
if (mEditorState != EditorStateTest) {
|
||||||
if (Engine::GUI::Button (2, "Add", 30, 20, 50, button_height)) {
|
if (Engine::GUI::Button (2, "Add", 30, 20, 50, button_height)) {
|
||||||
mEditorState = EditorStateAddEntity;
|
mEditorState = EditorStateAddEntity;
|
||||||
|
Engine::LogDebug ("Editor state now Add");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (3, "Del", 85, 20, 50, button_height)) {
|
if (Engine::GUI::Button (3, "Del", 85, 20, 50, button_height)) {
|
||||||
mEditorState = EditorStateDelEntity;
|
mEditorState = EditorStateDelEntity;
|
||||||
|
Engine::LogDebug ("Editor state now Del");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (4, "Move", 140, 20, 65, button_height)) {
|
if (Engine::GUI::Button (4, "Move", 140, 20, 65, button_height)) {
|
||||||
mEditorState = EditorStateMoveEntity;
|
mEditorState = EditorStateMoveEntity;
|
||||||
|
Engine::LogDebug ("Editor state now Move");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (5, "Spd", 210, 20, 50, button_height)) {
|
if (Engine::GUI::Button (5, "Spd", 210, 20, 50, button_height)) {
|
||||||
mEditorState = EditorStateEntityVelocity;
|
mEditorState = EditorStateEntityVelocity;
|
||||||
|
Engine::LogDebug ("Editor state now Add");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (6, "Save", 265, 20, 65, button_height)) {
|
if (Engine::GUI::Button (6, "Save", 265, 20, 65, button_height)) {
|
||||||
mEditorState = EditorStateSave;
|
mEditorState = EditorStateSave;
|
||||||
|
Engine::LogDebug ("Editor state now Save");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (7, "Load", 335, 20, 65, button_height)) {
|
if (Engine::GUI::Button (7, "Load", 335, 20, 65, button_height)) {
|
||||||
mEditorState = EditorStateLoad;
|
mEditorState = EditorStateLoad;
|
||||||
|
Engine::LogDebug ("Editor state now Load");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// we only show the Test button when there is actually something to play
|
// we only show the Test button when there is actually something to play
|
||||||
|
@ -833,7 +846,7 @@ void View::DrawUiEditor() {
|
||||||
SelectFont ("console.ttf size=12");
|
SelectFont ("console.ttf size=12");
|
||||||
Engine::GUI::Label (9999, "Adding", 128, 16);
|
Engine::GUI::Label (9999, "Adding", 128, 16);
|
||||||
|
|
||||||
if (Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
|
if (Engine::GUI::CheckKeyPressed(MouseButtonLeft)) {
|
||||||
// if there is no entity so far we create a player, otherwise we create
|
// if there is no entity so far we create a player, otherwise we create
|
||||||
// an asteroid
|
// an asteroid
|
||||||
|
|
||||||
|
@ -856,7 +869,7 @@ void View::DrawUiEditor() {
|
||||||
SelectFont ("console.ttf size=12");
|
SelectFont ("console.ttf size=12");
|
||||||
Engine::GUI::Label (9999, "Deleting", 128, 16);
|
Engine::GUI::Label (9999, "Deleting", 128, 16);
|
||||||
|
|
||||||
if (controller->GetButtonState(MouseButtonLeft)) {
|
if (Engine::GUI::CheckKeyPressed(MouseButtonLeft)) {
|
||||||
// Check if there is an entity near the given position
|
// Check if there is an entity near the given position
|
||||||
Engine::EntityBase* entity = Engine::GetEntityAt (mouse_world_pos);
|
Engine::EntityBase* entity = Engine::GetEntityAt (mouse_world_pos);
|
||||||
|
|
||||||
|
@ -871,7 +884,7 @@ void View::DrawUiEditor() {
|
||||||
SelectFont ("console.ttf size=12");
|
SelectFont ("console.ttf size=12");
|
||||||
Engine::GUI::Label (9999, "Moving", 128, 16);
|
Engine::GUI::Label (9999, "Moving", 128, 16);
|
||||||
|
|
||||||
if (controller->GetButtonState(MouseButtonLeft)) {
|
if (Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
|
||||||
// Check if there is an entity near the given position
|
// Check if there is an entity near the given position
|
||||||
Engine::EntityBase* asteroid = Engine::GetEntityAt (mouse_world_pos);
|
Engine::EntityBase* asteroid = Engine::GetEntityAt (mouse_world_pos);
|
||||||
if (asteroid) {
|
if (asteroid) {
|
||||||
|
@ -884,7 +897,7 @@ void View::DrawUiEditor() {
|
||||||
asteroid->mPhysicState->SetPosition (mouse_world_pos);
|
asteroid->mPhysicState->SetPosition (mouse_world_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!controller->GetButtonState(MouseButtonLeft)) {
|
if (!Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
|
||||||
if (mEditorEntityId != 0) {
|
if (mEditorEntityId != 0) {
|
||||||
mEditorEntityId = 0;
|
mEditorEntityId = 0;
|
||||||
}
|
}
|
||||||
|
@ -896,7 +909,7 @@ void View::DrawUiEditor() {
|
||||||
Engine::GUI::Label (9999, "Velocity", 128, 16);
|
Engine::GUI::Label (9999, "Velocity", 128, 16);
|
||||||
|
|
||||||
if (mEditorEntityId == 0) {
|
if (mEditorEntityId == 0) {
|
||||||
if (controller->GetButtonState(MouseButtonLeft)) {
|
if (Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
|
||||||
// Check if there is an entity near the given position
|
// Check if there is an entity near the given position
|
||||||
Engine::EntityBase* asteroid = Engine::GetEntityAt (mouse_world_pos);
|
Engine::EntityBase* asteroid = Engine::GetEntityAt (mouse_world_pos);
|
||||||
if (asteroid) {
|
if (asteroid) {
|
||||||
|
@ -912,7 +925,7 @@ void View::DrawUiEditor() {
|
||||||
new_velocity[1] = 0.;
|
new_velocity[1] = 0.;
|
||||||
asteroid->mPhysicState->SetVelocity (new_velocity);
|
asteroid->mPhysicState->SetVelocity (new_velocity);
|
||||||
|
|
||||||
if (!controller->GetButtonState(MouseButtonLeft)) {
|
if (!Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
|
||||||
if (mEditorEntityId != 0) {
|
if (mEditorEntityId != 0) {
|
||||||
mEditorEntityId = 0;
|
mEditorEntityId = 0;
|
||||||
}
|
}
|
||||||
|
@ -968,8 +981,8 @@ void View::DrawUiEditor() {
|
||||||
mEditorState = EditorStateUnknown;
|
mEditorState = EditorStateUnknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controller->GetButtonState(MouseButtonRight)
|
if (Engine::GUI::CheckKeyPressed(MouseButtonRight)
|
||||||
|| controller->GetButtonState(SDLK_ESCAPE) ) {
|
|| Engine::GUI::CheckKeyPressed(SDLK_ESCAPE) ) {
|
||||||
mEditorState = EditorStateUnknown;
|
mEditorState = EditorStateUnknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
set effects_volume 1
|
set effects_volume 1
|
||||||
set music_volume 0.585938
|
set music_volume 0.5625
|
||||||
|
|
|
@ -164,6 +164,7 @@ void ControllerBase::IMGUIFinish () {
|
||||||
// also reset the last keysym such that old values will not be reported
|
// also reset the last keysym such that old values will not be reported
|
||||||
uistate.last_keysym = SDLK_FIRST;
|
uistate.last_keysym = SDLK_FIRST;
|
||||||
uistate.last_key = SDLK_FIRST;
|
uistate.last_key = SDLK_FIRST;
|
||||||
|
uistate.keypressed_set.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Keyboard processing */
|
/** \brief Keyboard processing */
|
||||||
|
@ -175,6 +176,7 @@ bool ControllerBase::OnKeyDown (const SDL_keysym &keysym) {
|
||||||
// Only when Unicode processing is activated store the unicode value
|
// Only when Unicode processing is activated store the unicode value
|
||||||
if (SDL_EnableUNICODE(-1)) {
|
if (SDL_EnableUNICODE(-1)) {
|
||||||
uistate.last_unicode = keysym.unicode;
|
uistate.last_unicode = keysym.unicode;
|
||||||
|
// LogMessage ("Received key down of %s and unicode %d", convert_keycode(keysym.sym), keysym.unicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mView->mOverlayManager.SendKeyDown (keysym))
|
if (mView->mOverlayManager.SendKeyDown (keysym))
|
||||||
|
@ -191,6 +193,7 @@ bool ControllerBase::OnKeyDown (const SDL_keysym &keysym) {
|
||||||
/** \brief Keyboard processing */
|
/** \brief Keyboard processing */
|
||||||
bool ControllerBase::OnKeyUp (const SDL_keysym &keysym) {
|
bool ControllerBase::OnKeyUp (const SDL_keysym &keysym) {
|
||||||
mButtonStates.set(keysym.sym, false);
|
mButtonStates.set(keysym.sym, false);
|
||||||
|
uistate.keypressed_set.insert (keysym.sym);
|
||||||
|
|
||||||
if (mView->mOverlayManager.SendKeyUp (keysym))
|
if (mView->mOverlayManager.SendKeyUp (keysym))
|
||||||
return true;
|
return true;
|
||||||
|
@ -228,6 +231,7 @@ bool ControllerBase::OnMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos)
|
||||||
bool ControllerBase::OnMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos) {
|
bool ControllerBase::OnMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos) {
|
||||||
MouseButton mouse_button = convert_sdl_button (button);
|
MouseButton mouse_button = convert_sdl_button (button);
|
||||||
mButtonStates.set(mouse_button, false);
|
mButtonStates.set(mouse_button, false);
|
||||||
|
uistate.keypressed_set.insert (mouse_button);
|
||||||
|
|
||||||
if (mView->mOverlayManager.SendMouseButtonUp (button, xpos, ypos))
|
if (mView->mOverlayManager.SendMouseButtonUp (button, xpos, ypos))
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -21,6 +21,7 @@ struct IMGUIState {
|
||||||
SDLKey last_keysym;
|
SDLKey last_keysym;
|
||||||
Uint16 last_unicode;
|
Uint16 last_unicode;
|
||||||
int last_key;
|
int last_key;
|
||||||
|
std::set<int> keypressed_set;
|
||||||
|
|
||||||
int lastwidget;
|
int lastwidget;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <set>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
|
@ -322,6 +322,9 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
|
||||||
DrawBlock (x, y, w, h);
|
DrawBlock (x, y, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_EnableKeyRepeat(500, 50);
|
||||||
|
|
||||||
|
|
||||||
// Rendering of the current value
|
// Rendering of the current value
|
||||||
float width, height;
|
float width, height;
|
||||||
view = EngineGetView ();
|
view = EngineGetView ();
|
||||||
|
@ -383,6 +386,9 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
|
||||||
if (maxlength > 0 && text_value.size() < maxlength) {
|
if (maxlength > 0 && text_value.size() < maxlength) {
|
||||||
if (controller->uistate.last_unicode) {
|
if (controller->uistate.last_unicode) {
|
||||||
if ((controller->uistate.last_unicode & 0xFF80) == 0) {
|
if ((controller->uistate.last_unicode & 0xFF80) == 0) {
|
||||||
|
// we do not want to add special characters such as backspaces
|
||||||
|
// etc.
|
||||||
|
if ((controller->uistate.last_unicode & 0xFFFF) >= 0x20)
|
||||||
text_value += controller->uistate.last_unicode & 0x7F;
|
text_value += controller->uistate.last_unicode & 0x7F;
|
||||||
controller->uistate.last_unicode = 0;
|
controller->uistate.last_unicode = 0;
|
||||||
return true;
|
return true;
|
||||||
|
@ -508,11 +514,19 @@ float VerticalSlider (int id, int x, int y, int w, int h, float min_value, float
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckKeyPress (int keycode) {
|
bool CheckKeyPress (int keycode) {
|
||||||
if (controller->uistate.last_key == keycode)
|
if (controller->GetButtonState(keycode))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CheckKeyPressed (int keycode) {
|
||||||
|
if (controller->uistate.keypressed_set.find(keycode) != controller->uistate.keypressed_set.end())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,14 +38,19 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
|
||||||
|
|
||||||
float VerticalSlider (int id, int x, int y, int w, int h, float min_value, float max_value, float &value);
|
float VerticalSlider (int id, int x, int y, int w, int h, float min_value, float max_value, float &value);
|
||||||
|
|
||||||
/** \brief Checks whether a given key was pressed
|
/** \brief Checks whether a given key is currently pressed
|
||||||
*
|
*
|
||||||
* This function can be used to check whether a single key (e.g. ESC) was
|
* This function can be used to check whether a single key (e.g. ESC) is currently
|
||||||
* pressed. This is useful when one wants to abort an action or quit from the
|
* pressed. This is useful when one wants to abort an action or quit from the
|
||||||
* main screen by pressing a single key.
|
* main screen by pressing a single key.
|
||||||
*/
|
*/
|
||||||
bool CheckKeyPress (int keycode);
|
bool CheckKeyPress (int keycode);
|
||||||
|
|
||||||
|
/** \brief Checks whether a key press was completed for a given key
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool CheckKeyPressed (int keycode);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,6 +72,10 @@
|
||||||
* todos within the code have a look at the \ref todo.
|
* todos within the code have a look at the \ref todo.
|
||||||
*
|
*
|
||||||
* \todo [high] Create a simple racing or asteroids game
|
* \todo [high] Create a simple racing or asteroids game
|
||||||
|
* \todo [high] fix collisions that go over boundaries
|
||||||
|
*
|
||||||
|
* These are the (for now) postponed todos:
|
||||||
|
*
|
||||||
* \todo [med] Use shared_ptr instead of raw pointers for the Entities
|
* \todo [med] Use shared_ptr instead of raw pointers for the Entities
|
||||||
* \todo [med] Clear all references of EntityVisualState and EntityGameState
|
* \todo [med] Clear all references of EntityVisualState and EntityGameState
|
||||||
* \todo [med] Clarify functionalities of CreateEntity, KillEntity, RegisterEntity, UnregisterEntity (which frees memory, which does only change the state of the Model?)
|
* \todo [med] Clarify functionalities of CreateEntity, KillEntity, RegisterEntity, UnregisterEntity (which frees memory, which does only change the state of the Model?)
|
||||||
|
@ -87,6 +91,9 @@
|
||||||
* Engine::Module::Init()
|
* Engine::Module::Init()
|
||||||
*
|
*
|
||||||
* Done:
|
* Done:
|
||||||
|
* \todo [med] (30-01-2011) add Engine::GUI::CheckKeyPressed that checks for completed key presses
|
||||||
|
* \todo [med] (30-01-2011) fix LineEdit input which generates blanks when entering backspace for an empty edit
|
||||||
|
* \todo [high] (30-01-2011) fix random crashes for certain characters (has to do with boundary box computation in OGLFT) fix: disabled debug assertion for proper boundary box merging.
|
||||||
* \todo [high] (28-11-2010) Enable saving of music and effects volume
|
* \todo [high] (28-11-2010) Enable saving of music and effects volume
|
||||||
* \todo [high] (28-11-2010) Allow transitions when player dies
|
* \todo [high] (28-11-2010) Allow transitions when player dies
|
||||||
* \todo [high] (11-09-2010) Since introduction of the IMGUI pressing 'space' in the menu crashes the game
|
* \todo [high] (11-09-2010) Since introduction of the IMGUI pressing 'space' in the menu crashes the game
|
||||||
|
|
|
@ -440,9 +440,8 @@ namespace OGLFT {
|
||||||
<< " advance.dx: " << bbox.advance_.dx_
|
<< " advance.dx: " << bbox.advance_.dx_
|
||||||
|
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
*/
|
|
||||||
assert (bbox.y_max_ - bbox.y_min_ != 0.);
|
assert (bbox.y_max_ - bbox.y_min_ != 0.);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue