editor: highlighting the current mode
parent
8daee27ed8
commit
ad528f0c6f
|
@ -410,8 +410,10 @@ void View::DrawUi () {
|
||||||
|
|
||||||
ViewState current_view_state = GetViewState();
|
ViewState current_view_state = GetViewState();
|
||||||
|
|
||||||
|
/*
|
||||||
SelectFont ("console.ttf size=12");
|
SelectFont ("console.ttf size=12");
|
||||||
Engine::GUI::Label (99999, GetStringViewState(current_view_state), 8, 16);
|
Engine::GUI::Label (99999, GetStringViewState(current_view_state), 8, 16);
|
||||||
|
*/
|
||||||
|
|
||||||
switch (current_view_state) {
|
switch (current_view_state) {
|
||||||
case ViewStateMainMenu:
|
case ViewStateMainMenu:
|
||||||
|
@ -673,7 +675,6 @@ void View::DrawUiHighscore() {
|
||||||
DrawPageTitle ("Highscores");
|
DrawPageTitle ("Highscores");
|
||||||
SelectFont ("console.ttf size=23");
|
SelectFont ("console.ttf size=23");
|
||||||
|
|
||||||
|
|
||||||
unsigned int entry_length = 32;
|
unsigned int entry_length = 32;
|
||||||
float char_width, height;
|
float char_width, height;
|
||||||
DrawGLStringMeasure ("M", &char_width, &height);
|
DrawGLStringMeasure ("M", &char_width, &height);
|
||||||
|
@ -785,25 +786,25 @@ void View::DrawUiEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mEditorState != EditorStateTest) {
|
if (mEditorState != EditorStateTest) {
|
||||||
if (Engine::GUI::Button (2, "Add", 30, 20, 50, button_height)) {
|
if (Engine::GUI::CheckButton (2, "Add", mEditorState == EditorStateAddEntity, 30, 20, 50, button_height)) {
|
||||||
mEditorState = EditorStateAddEntity;
|
mEditorState = EditorStateAddEntity;
|
||||||
Engine::LogDebug ("Editor state now Add");
|
Engine::LogDebug ("Editor state now Add");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (3, "Del", 85, 20, 50, button_height)) {
|
if (Engine::GUI::CheckButton (3, "Del", mEditorState == EditorStateDelEntity, 85, 20, 50, button_height)) {
|
||||||
mEditorState = EditorStateDelEntity;
|
mEditorState = EditorStateDelEntity;
|
||||||
Engine::LogDebug ("Editor state now Del");
|
Engine::LogDebug ("Editor state now Del");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (4, "Move", 140, 20, 65, button_height)) {
|
if (Engine::GUI::CheckButton (4, "Move", mEditorState == EditorStateMoveEntity, 140, 20, 65, button_height)) {
|
||||||
mEditorState = EditorStateMoveEntity;
|
mEditorState = EditorStateMoveEntity;
|
||||||
Engine::LogDebug ("Editor state now Move");
|
Engine::LogDebug ("Editor state now Move");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Engine::GUI::Button (5, "Spd", 210, 20, 50, button_height)) {
|
if (Engine::GUI::CheckButton (5, "Spd", mEditorState == EditorStateEntityVelocity, 210, 20, 50, button_height)) {
|
||||||
mEditorState = EditorStateEntityVelocity;
|
mEditorState = EditorStateEntityVelocity;
|
||||||
Engine::LogDebug ("Editor state now Add");
|
Engine::LogDebug ("Editor state now Add");
|
||||||
return;
|
return;
|
||||||
|
@ -843,7 +844,7 @@ void View::DrawUiEditor() {
|
||||||
|
|
||||||
if (mEditorState == EditorStateAddEntity) {
|
if (mEditorState == EditorStateAddEntity) {
|
||||||
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::CheckKeyPressed(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
|
||||||
|
@ -866,7 +867,7 @@ void View::DrawUiEditor() {
|
||||||
|
|
||||||
if (mEditorState == EditorStateDelEntity) {
|
if (mEditorState == EditorStateDelEntity) {
|
||||||
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 (Engine::GUI::CheckKeyPressed(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
|
||||||
|
@ -881,7 +882,7 @@ void View::DrawUiEditor() {
|
||||||
|
|
||||||
if (mEditorState == EditorStateMoveEntity) {
|
if (mEditorState == EditorStateMoveEntity) {
|
||||||
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 (Engine::GUI::CheckKeyPress(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
|
||||||
|
@ -905,7 +906,7 @@ void View::DrawUiEditor() {
|
||||||
|
|
||||||
if (mEditorState == EditorStateEntityVelocity) {
|
if (mEditorState == EditorStateEntityVelocity) {
|
||||||
SelectFont ("console.ttf size=12");
|
SelectFont ("console.ttf size=12");
|
||||||
Engine::GUI::Label (9999, "Velocity", 128, 16);
|
// Engine::GUI::Label (9999, "Velocity", 128, 16);
|
||||||
|
|
||||||
if (mEditorEntityId == 0) {
|
if (mEditorEntityId == 0) {
|
||||||
if (Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
|
if (Engine::GUI::CheckKeyPress(MouseButtonLeft)) {
|
||||||
|
@ -935,7 +936,7 @@ void View::DrawUiEditor() {
|
||||||
if (mEditorState == EditorStateSave) {
|
if (mEditorState == EditorStateSave) {
|
||||||
glColor3f (0.2, 0.2, 0.2);
|
glColor3f (0.2, 0.2, 0.2);
|
||||||
Engine::GUI::DrawRoundedBlock (140, 150, screen_right - 280, 200);
|
Engine::GUI::DrawRoundedBlock (140, 150, screen_right - 280, 200);
|
||||||
Engine::GUI::Label (9999, "Saving", 128, 16);
|
// Engine::GUI::Label (9999, "Saving", 128, 16);
|
||||||
SelectFont ("console.ttf size=23");
|
SelectFont ("console.ttf size=23");
|
||||||
|
|
||||||
Engine::GUI::Label(51, "Filename: ", 145, 180);
|
Engine::GUI::Label(51, "Filename: ", 145, 180);
|
||||||
|
@ -958,7 +959,7 @@ void View::DrawUiEditor() {
|
||||||
if (mEditorState == EditorStateLoad) {
|
if (mEditorState == EditorStateLoad) {
|
||||||
glColor3f (0.2, 0.2, 0.2);
|
glColor3f (0.2, 0.2, 0.2);
|
||||||
Engine::GUI::DrawRoundedBlock (140, 150, screen_right - 280, 200);
|
Engine::GUI::DrawRoundedBlock (140, 150, screen_right - 280, 200);
|
||||||
Engine::GUI::Label (9999, "Loading", 128, 16);
|
// Engine::GUI::Label (9999, "Loading", 128, 16);
|
||||||
SelectFont ("console.ttf size=23");
|
SelectFont ("console.ttf size=23");
|
||||||
|
|
||||||
Engine::GUI::Label(51, "Filename: ", 145, 180);
|
Engine::GUI::Label(51, "Filename: ", 145, 180);
|
||||||
|
|
|
@ -272,6 +272,121 @@ bool Button (int id, const char* caption, int x, int y, int w, int h) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CheckButton (int id, const char* caption, bool checked, int x, int y, int w, int h) {
|
||||||
|
controller = EngineGetController();
|
||||||
|
assert (controller);
|
||||||
|
|
||||||
|
// LogMessage ("id = %d hotitem = %d activeitem = %d kbditem = %d", id, controller->uistate.hotitem, controller->uistate.activeitem, controller->uistate.kbditem);
|
||||||
|
|
||||||
|
// Check for hotness
|
||||||
|
if (regionhit (x, y, w, h)) {
|
||||||
|
controller->uistate.hotitem = id;
|
||||||
|
if (controller->uistate.activeitem == 0
|
||||||
|
&& controller->GetButtonState(MouseButtonLeft))
|
||||||
|
controller->uistate.activeitem = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If nothing is selected
|
||||||
|
if (controller->uistate.hotitem != 0) {
|
||||||
|
controller->uistate.kbditem = controller->uistate.hotitem;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (controller->uistate.kbditem == 0) {
|
||||||
|
controller->uistate.hotitem = id;
|
||||||
|
controller->uistate.kbditem = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render
|
||||||
|
if (checked) {
|
||||||
|
glColor3f (0.91, 0.84, 0.);
|
||||||
|
DrawRoundedBlock (x - 2, y - 2, w + 4, h + 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
glColor3f (0.2, 0.2, 0.2);
|
||||||
|
|
||||||
|
if (controller->uistate.hotitem == id
|
||||||
|
|| controller->uistate.kbditem == id) {
|
||||||
|
if (controller->uistate.activeitem == id) {
|
||||||
|
glColor3f (0.8, 0.8, 0.8);
|
||||||
|
DrawRoundedBlock (x, y, w, h);
|
||||||
|
} else {
|
||||||
|
glColor3f (0.7, 0.7, 0.7);
|
||||||
|
DrawRoundedBlock (x, y, w, h);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
glColor3f (0.4, 0.4, 0.4);
|
||||||
|
DrawRoundedBlock (x, y, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Caption
|
||||||
|
if (caption != NULL) {
|
||||||
|
float width, height;
|
||||||
|
view = EngineGetView ();
|
||||||
|
assert (view);
|
||||||
|
|
||||||
|
// we have to load the font prior to measuring it
|
||||||
|
SelectFont("console.ttf size=23");
|
||||||
|
view->DrawGLStringMeasure(caption, &width, &height);
|
||||||
|
|
||||||
|
float xpos = x + w * 0.5 - width * 0.5;
|
||||||
|
float ypos = y + h * 0.5 - height * 0.5;
|
||||||
|
// LogDebug ("measure '%s' width = %f height = %f", caption, width, height);
|
||||||
|
|
||||||
|
if (controller->uistate.hotitem == id || controller->uistate.kbditem == id) {
|
||||||
|
SelectFont("console.ttf size=23 color=#666666");
|
||||||
|
view->DrawGLString( xpos - 2., ypos + 2., caption);
|
||||||
|
SelectFont("console.ttf size=23 color=#ffffff");
|
||||||
|
view->DrawGLString( xpos, ypos, caption);
|
||||||
|
} else {
|
||||||
|
SelectFont("console.ttf size=23 color=#4d4d4d");
|
||||||
|
view->DrawGLString( xpos - 2., ypos + 2., caption);
|
||||||
|
SelectFont("console.ttf size=23 color=#b3b3b3");
|
||||||
|
view->DrawGLString( xpos, ypos, caption);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mouse Logic
|
||||||
|
if (controller->GetButtonState(MouseButtonLeft) == false
|
||||||
|
&& controller->uistate.hotitem == id
|
||||||
|
&& controller->uistate.activeitem == id) {
|
||||||
|
controller->uistate.lastwidget = id;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keyboard Logic
|
||||||
|
if (controller->uistate.kbditem == id) {
|
||||||
|
// Any unicode keys that were sent get cleared
|
||||||
|
controller->uistate.last_unicode = 0;
|
||||||
|
|
||||||
|
// We have to make sure, that we always clear the uistate.last_keysym
|
||||||
|
// value, otherwise the same action might be repeated over and over.
|
||||||
|
switch (controller->uistate.last_keysym) {
|
||||||
|
case SDLK_DOWN:
|
||||||
|
controller->uistate.kbditem = 0;
|
||||||
|
controller->uistate.hotitem = 0;
|
||||||
|
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||||
|
break;
|
||||||
|
case SDLK_UP:
|
||||||
|
controller->uistate.kbditem = controller->uistate.lastwidget;
|
||||||
|
controller->uistate.hotitem = controller->uistate.lastwidget;
|
||||||
|
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||||
|
break;
|
||||||
|
case SDLK_RETURN:
|
||||||
|
controller->uistate.last_keysym = SDLK_CLEAR;
|
||||||
|
// As we (probably) exit the current set of widgets, we have to clear
|
||||||
|
// the uistate.kbditem value.
|
||||||
|
controller->uistate.kbditem = 0;
|
||||||
|
return true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
controller->uistate.lastwidget = id;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/** \brief An Edit widget that allows editing of a string consisting of one line
|
/** \brief An Edit widget that allows editing of a string consisting of one line
|
||||||
*
|
*
|
||||||
* \TODO [med] vertical alignment (especially of text) is a bit whacky
|
* \TODO [med] vertical alignment (especially of text) is a bit whacky
|
||||||
|
|
|
@ -34,6 +34,8 @@ void LabelCentered (int id, const char* caption, int x, int y);
|
||||||
*/
|
*/
|
||||||
bool Button (int id, const char* caption, int x, int y, int w, int h);
|
bool Button (int id, const char* caption, int x, int y, int w, int h);
|
||||||
|
|
||||||
|
bool CheckButton (int id, const char* caption, bool state, int x, int y, int w, int h);
|
||||||
|
|
||||||
bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxlength);
|
bool LineEdit (int id, int x, int y, std::string &text_value, const int &maxlength);
|
||||||
|
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue