fixed 3 major bugs (LineEdit backspace, input crashes, editor button press and editor actions)

main
Martin Felis (berta) 2011-01-30 21:43:04 +01:00
parent 3e05c967ab
commit a27ece921a
10 changed files with 62 additions and 18 deletions

View File

@ -10,7 +10,7 @@ engine/libraries/oglft/liboglft/OGLFT.h
start
runtests
run_asteroids
fysxasteroids
config.rc
Debug/

View File

@ -229,7 +229,6 @@ void View::DrawStars() {
glEnd();
glPopMatrix();
}
void View::Draw() {
@ -773,12 +772,14 @@ void View::DrawUiEditor() {
// The close button
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) {
mEditorState = EditorStateUnknown;
GetModel()->DoLoadLevel("level_edit_temp.txt");
GetModel()->SetGameState(GameStatePaused);
return;
} else {
PopViewState();
}
@ -787,26 +788,38 @@ void View::DrawUiEditor() {
if (mEditorState != EditorStateTest) {
if (Engine::GUI::Button (2, "Add", 30, 20, 50, button_height)) {
mEditorState = EditorStateAddEntity;
Engine::LogDebug ("Editor state now Add");
return;
}
if (Engine::GUI::Button (3, "Del", 85, 20, 50, button_height)) {
mEditorState = EditorStateDelEntity;
Engine::LogDebug ("Editor state now Del");
return;
}
if (Engine::GUI::Button (4, "Move", 140, 20, 65, button_height)) {
mEditorState = EditorStateMoveEntity;
Engine::LogDebug ("Editor state now Move");
return;
}
if (Engine::GUI::Button (5, "Spd", 210, 20, 50, button_height)) {
mEditorState = EditorStateEntityVelocity;
Engine::LogDebug ("Editor state now Add");
return;
}
if (Engine::GUI::Button (6, "Save", 265, 20, 65, button_height)) {
mEditorState = EditorStateSave;
Engine::LogDebug ("Editor state now Save");
return;
}
if (Engine::GUI::Button (7, "Load", 335, 20, 65, button_height)) {
mEditorState = EditorStateLoad;
Engine::LogDebug ("Editor state now Load");
return;
}
// 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");
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
// an asteroid
@ -856,7 +869,7 @@ void View::DrawUiEditor() {
SelectFont ("console.ttf size=12");
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
Engine::EntityBase* entity = Engine::GetEntityAt (mouse_world_pos);
@ -871,7 +884,7 @@ void View::DrawUiEditor() {
SelectFont ("console.ttf size=12");
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
Engine::EntityBase* asteroid = Engine::GetEntityAt (mouse_world_pos);
if (asteroid) {
@ -884,7 +897,7 @@ void View::DrawUiEditor() {
asteroid->mPhysicState->SetPosition (mouse_world_pos);
}
if (!controller->GetButtonState(MouseButtonLeft)) {
if (!Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
if (mEditorEntityId != 0) {
mEditorEntityId = 0;
}
@ -896,7 +909,7 @@ void View::DrawUiEditor() {
Engine::GUI::Label (9999, "Velocity", 128, 16);
if (mEditorEntityId == 0) {
if (controller->GetButtonState(MouseButtonLeft)) {
if (Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
// Check if there is an entity near the given position
Engine::EntityBase* asteroid = Engine::GetEntityAt (mouse_world_pos);
if (asteroid) {
@ -912,7 +925,7 @@ void View::DrawUiEditor() {
new_velocity[1] = 0.;
asteroid->mPhysicState->SetVelocity (new_velocity);
if (!controller->GetButtonState(MouseButtonLeft)) {
if (!Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
if (mEditorEntityId != 0) {
mEditorEntityId = 0;
}
@ -968,8 +981,8 @@ void View::DrawUiEditor() {
mEditorState = EditorStateUnknown;
}
if (controller->GetButtonState(MouseButtonRight)
|| controller->GetButtonState(SDLK_ESCAPE) ) {
if (Engine::GUI::CheckKeyPressed(MouseButtonRight)
|| Engine::GUI::CheckKeyPressed(SDLK_ESCAPE) ) {
mEditorState = EditorStateUnknown;
}
}

View File

@ -1,2 +1,2 @@
set effects_volume 1
set music_volume 0.585938
set music_volume 0.5625

View File

@ -164,6 +164,7 @@ 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;
uistate.keypressed_set.clear();
}
/** \brief Keyboard processing */
@ -175,6 +176,7 @@ bool ControllerBase::OnKeyDown (const SDL_keysym &keysym) {
// Only when Unicode processing is activated store the unicode value
if (SDL_EnableUNICODE(-1)) {
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))
@ -191,6 +193,7 @@ bool ControllerBase::OnKeyDown (const SDL_keysym &keysym) {
/** \brief Keyboard processing */
bool ControllerBase::OnKeyUp (const SDL_keysym &keysym) {
mButtonStates.set(keysym.sym, false);
uistate.keypressed_set.insert (keysym.sym);
if (mView->mOverlayManager.SendKeyUp (keysym))
return true;
@ -228,6 +231,7 @@ bool ControllerBase::OnMouseButtonDown (Uint8 button, Uint16 xpos, Uint16 ypos)
bool ControllerBase::OnMouseButtonUp (Uint8 button, Uint16 xpos, Uint16 ypos) {
MouseButton mouse_button = convert_sdl_button (button);
mButtonStates.set(mouse_button, false);
uistate.keypressed_set.insert (mouse_button);
if (mView->mOverlayManager.SendMouseButtonUp (button, xpos, ypos))
return true;

View File

@ -21,6 +21,7 @@ struct IMGUIState {
SDLKey last_keysym;
Uint16 last_unicode;
int last_key;
std::set<int> keypressed_set;
int lastwidget;
};

View File

@ -13,6 +13,7 @@
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>
#include <limits>

View File

@ -322,6 +322,9 @@ bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxleng
DrawBlock (x, y, w, h);
}
SDL_EnableKeyRepeat(500, 50);
// Rendering of the current value
float width, height;
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 (controller->uistate.last_unicode) {
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;
controller->uistate.last_unicode = 0;
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) {
if (controller->uistate.last_key == keycode)
if (controller->GetButtonState(keycode))
return true;
return false;
}
bool CheckKeyPressed (int keycode) {
if (controller->uistate.keypressed_set.find(keycode) != controller->uistate.keypressed_set.end())
return true;
return false;
}
};
};

View File

@ -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);
/** \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
* main screen by pressing a single key.
*/
bool CheckKeyPress (int keycode);
/** \brief Checks whether a key press was completed for a given key
*
*/
bool CheckKeyPressed (int keycode);
};
};

View File

@ -72,6 +72,10 @@
* todos within the code have a look at the \ref todo.
*
* \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] 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?)
@ -87,6 +91,9 @@
* Engine::Module::Init()
*
* 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) Allow transitions when player dies
* \todo [high] (11-09-2010) Since introduction of the IMGUI pressing 'space' in the menu crashes the game

View File

@ -440,9 +440,8 @@ namespace OGLFT {
<< " advance.dx: " << bbox.advance_.dx_
<< std::endl;
*/
assert (bbox.y_max_ - bbox.y_min_ != 0.);
*/
}
}