diff options
Diffstat (limited to 'SidebarView.cpp')
-rw-r--r-- | SidebarView.cpp | 156 |
1 files changed, 124 insertions, 32 deletions
diff --git a/SidebarView.cpp b/SidebarView.cpp index 8e58967..cdf4a2e 100644 --- a/SidebarView.cpp +++ b/SidebarView.cpp @@ -1,11 +1,25 @@ #include "SidebarView.h" +#include "PlayerStart.h" -void SidebarView::spinButtonHeightChanged(GtkSpinButton *spinbutton, SidebarView *view) { - if(!view->editor->getActiveRoom()) +void SidebarView::spinButtonChanged(GtkWidget *spinbutton, SidebarView *view) { + if(!view->editor->getSelectedObject()) return; - view->editor->getActiveRoom()->setHeight(gtk_spin_button_get_value(spinbutton)); + if(view->editor->getSelectedObject()->isOfType("Room")) { + if(spinbutton == view->spinButtonHeight) + ((Room*)view->editor->getSelectedObject())->setHeight(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinbutton))); + } + else if(view->editor->getSelectedObject()->isOfType("PlayerStart")) { + if(spinbutton == view->spinButtonX) + ((PlayerStart*)view->editor->getSelectedObject())->setX(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinbutton))); + else if(spinbutton == view->spinButtonY) + ((PlayerStart*)view->editor->getSelectedObject())->setY(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinbutton))); + else if(spinbutton == view->spinButtonZ) + ((PlayerStart*)view->editor->getSelectedObject())->setZ(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spinbutton))); + } + + view->editor->update(); } SidebarView::SidebarView(EditManager *editor) { @@ -14,54 +28,114 @@ SidebarView::SidebarView(EditManager *editor) { sidebar = gtk_vbox_new(FALSE, 0); g_object_ref_sink(G_OBJECT(sidebar)); - GtkWidget *labelRoomInfo = gtk_label_new(NULL); - gtk_label_set_markup(GTK_LABEL(labelRoomInfo), "<b>Room info:</b>"); - gtk_misc_set_alignment(GTK_MISC(labelRoomInfo), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(sidebar), labelRoomInfo, FALSE, FALSE, 5); + labelType = gtk_label_new(NULL); + gtk_misc_set_alignment(GTK_MISC(labelType), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(sidebar), labelType, FALSE, FALSE, 5); gtk_box_pack_start(GTK_BOX(sidebar), gtk_hseparator_new(), FALSE, FALSE, 5); - GtkWidget *labelName = gtk_label_new("Name: "); + labelName = gtk_label_new("Name: "); gtk_misc_set_alignment(GTK_MISC(labelName), 0.0, 0.5); + gtk_widget_set_no_show_all(labelName, TRUE); gtk_box_pack_start(GTK_BOX(sidebar), labelName, FALSE, FALSE, 0); entryName = gtk_entry_new(); gtk_widget_set_size_request(entryName, 0, -1); //g_signal_connect(G_OBJECT(entryName), "focus-out-event", G_CALLBACK(sidebarNameFocusOutEvent), NULL); //gtk_widget_add_events(entryName, GDK_FOCUS_CHANGE_MASK); + gtk_widget_set_no_show_all(entryName, TRUE); gtk_box_pack_start(GTK_BOX(sidebar), entryName, FALSE, FALSE, 0); - GtkWidget *tableRoomData = gtk_table_new(2, 3, FALSE); + tableRoomData = gtk_table_new(2, 3, FALSE); gtk_table_set_row_spacings(GTK_TABLE(tableRoomData), 5); + gtk_widget_set_no_show_all(tableRoomData, TRUE); gtk_box_pack_start(GTK_BOX(sidebar), tableRoomData, FALSE, FALSE, 5); GtkWidget *labelAreaLabel = gtk_label_new("Room area: "); gtk_misc_set_alignment(GTK_MISC(labelAreaLabel), 0.0, 0.5); + gtk_widget_show(labelAreaLabel); gtk_table_attach(GTK_TABLE(tableRoomData), labelAreaLabel, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); labelArea = gtk_label_new(NULL); gtk_misc_set_alignment(GTK_MISC(labelArea), 1.0, 0.5); + gtk_widget_show(labelArea); gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelArea, 1, 2, 0, 1); GtkWidget *labelPerimeterLabel = gtk_label_new("Room perimeter: "); gtk_misc_set_alignment(GTK_MISC(labelPerimeterLabel), 0.0, 0.5); + gtk_widget_show(labelPerimeterLabel); gtk_table_attach(GTK_TABLE(tableRoomData), labelPerimeterLabel, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); labelPerimeter = gtk_label_new(NULL); gtk_misc_set_alignment(GTK_MISC(labelPerimeter), 1.0, 0.5); + gtk_widget_show(labelPerimeter); gtk_table_attach_defaults(GTK_TABLE(tableRoomData), labelPerimeter, 1, 2, 1, 2); GtkWidget *labelHeight = gtk_label_new("Height: "); gtk_misc_set_alignment(GTK_MISC(labelHeight), 0.0, 0.5); + gtk_widget_show(labelHeight); gtk_table_attach(GTK_TABLE(tableRoomData), labelHeight, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); spinButtonHeight = gtk_spin_button_new_with_range(0, 10000, 0.1f); gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonHeight), 2); gtk_entry_set_alignment(GTK_ENTRY(spinButtonHeight), 1.0); + gtk_widget_show(spinButtonHeight); gtk_table_attach(GTK_TABLE(tableRoomData), spinButtonHeight, 1, 2, 2, 3, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL), (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0); gtk_widget_set_size_request(spinButtonHeight, 0, -1); - g_signal_connect(G_OBJECT(spinButtonHeight), "value-changed", G_CALLBACK(spinButtonHeightChanged), this); + g_signal_connect(G_OBJECT(spinButtonHeight), "value-changed", G_CALLBACK(spinButtonChanged), this); + + tablePlayerStart = gtk_table_new(2, 4, FALSE); + gtk_table_set_row_spacings(GTK_TABLE(tablePlayerStart), 5); + gtk_widget_set_no_show_all(tablePlayerStart, TRUE); + gtk_box_pack_start(GTK_BOX(sidebar), tablePlayerStart, FALSE, FALSE, 5); + + GtkWidget *labelCoordinates = gtk_label_new("Coordinates:"); + gtk_misc_set_alignment(GTK_MISC(labelCoordinates), 0.0, 0.5); + gtk_widget_show(labelCoordinates); + gtk_table_attach(GTK_TABLE(tablePlayerStart), labelCoordinates, 0, 2, 0, 1, GTK_FILL, GTK_FILL, 0, 0); + + GtkWidget *labelX = gtk_label_new("X: "); + gtk_misc_set_alignment(GTK_MISC(labelX), 0.0, 0.5); + gtk_widget_show(labelX); + gtk_table_attach(GTK_TABLE(tablePlayerStart), labelX, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); + + spinButtonX = gtk_spin_button_new_with_range(-10000, 10000, 0.1f); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonX), 2); + gtk_entry_set_alignment(GTK_ENTRY(spinButtonX), 1.0); + gtk_widget_show(spinButtonX); + gtk_table_attach(GTK_TABLE(tablePlayerStart), spinButtonX, 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL), + (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0); + gtk_widget_set_size_request(spinButtonX, 0, -1); + g_signal_connect(G_OBJECT(spinButtonX), "value-changed", G_CALLBACK(spinButtonChanged), this); + + GtkWidget *labelY = gtk_label_new("Y: "); + gtk_misc_set_alignment(GTK_MISC(labelY), 0.0, 0.5); + gtk_widget_show(labelY); + gtk_table_attach(GTK_TABLE(tablePlayerStart), labelY, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); + + spinButtonY = gtk_spin_button_new_with_range(-10000, 10000, 0.1f); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonY), 2); + gtk_entry_set_alignment(GTK_ENTRY(spinButtonY), 1.0); + gtk_widget_show(spinButtonY); + gtk_table_attach(GTK_TABLE(tablePlayerStart), spinButtonY, 1, 2, 2, 3, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL), + (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0); + gtk_widget_set_size_request(spinButtonY, 0, -1); + g_signal_connect(G_OBJECT(spinButtonY), "value-changed", G_CALLBACK(spinButtonChanged), this); + + GtkWidget *labelZ = gtk_label_new("Z: "); + gtk_misc_set_alignment(GTK_MISC(labelZ), 0.0, 0.5); + gtk_widget_show(labelZ); + gtk_table_attach(GTK_TABLE(tablePlayerStart), labelZ, 0, 1, 3, 4, GTK_FILL, GTK_FILL, 0, 0); + + spinButtonZ = gtk_spin_button_new_with_range(-10000, 10000, 0.1f); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spinButtonZ), 2); + gtk_entry_set_alignment(GTK_ENTRY(spinButtonZ), 1.0); + gtk_widget_show(spinButtonZ); + gtk_table_attach(GTK_TABLE(tablePlayerStart), spinButtonZ, 1, 2, 3, 4, (GtkAttachOptions)(GTK_EXPAND|GTK_SHRINK|GTK_FILL), + (GtkAttachOptions)(GTK_EXPAND|GTK_FILL), 0, 0); + gtk_widget_set_size_request(spinButtonZ, 0, -1); + g_signal_connect(G_OBJECT(spinButtonZ), "value-changed", G_CALLBACK(spinButtonChanged), this); gtk_widget_show_all(sidebar); } @@ -75,29 +149,47 @@ GtkWidget* SidebarView::getWidget() { } void SidebarView::update() { - if(editor->getActiveRoom()) { - gtk_entry_set_text(GTK_ENTRY(entryName), editor->getActiveRoom()->getName().c_str()); - gtk_widget_set_sensitive(entryName, TRUE); - - gchar *string = g_strdup_printf("%.2f", editor->getActiveRoom()->area()); - gtk_label_set_text(GTK_LABEL(labelArea), string); - g_free(string); - - string = g_strdup_printf("%.2f", editor->getActiveRoom()->perimeter()); - gtk_label_set_text(GTK_LABEL(labelPerimeter), string); - g_free(string); - - gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonHeight), editor->getActiveRoom()->getHeight()); - gtk_widget_set_sensitive(spinButtonHeight, TRUE); + gtk_widget_hide(labelName); + gtk_widget_hide(entryName); + gtk_widget_hide(tableRoomData); + gtk_widget_hide(tablePlayerStart); + + if(editor->getSelectedObject()) { + if(editor->getSelectedObject()->isOfType("Room")) { + Room *room = (Room*)editor->getSelectedObject(); + + gtk_label_set_markup(GTK_LABEL(labelType), "<b>Room info:</b>"); + + gtk_widget_show(labelName); + + gtk_entry_set_text(GTK_ENTRY(entryName), room->getName().c_str()); + gtk_widget_show(entryName); + + gchar *string = g_strdup_printf("%.2f", room->area()); + gtk_label_set_text(GTK_LABEL(labelArea), string); + g_free(string); + + string = g_strdup_printf("%.2f", room->perimeter()); + gtk_label_set_text(GTK_LABEL(labelPerimeter), string); + g_free(string); + + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonHeight), room->getHeight()); + + gtk_widget_show(tableRoomData); + } + else if(editor->getSelectedObject()->isOfType("PlayerStart")) { + PlayerStart *playerStart = (PlayerStart*)editor->getSelectedObject(); + + gtk_label_set_markup(GTK_LABEL(labelType), "<b>Player start:</b>"); + + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonX), playerStart->getX()); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonY), playerStart->getY()); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonZ), playerStart->getZ()); + + gtk_widget_show(tablePlayerStart); + } } else { - gtk_entry_set_text(GTK_ENTRY(entryName), ""); - gtk_widget_set_sensitive(entryName, FALSE); - - gtk_label_set_text(GTK_LABEL(labelArea), NULL); - gtk_label_set_text(GTK_LABEL(labelPerimeter), NULL); - - gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinButtonHeight), 0.0); - gtk_widget_set_sensitive(spinButtonHeight, FALSE); + gtk_label_set_markup(GTK_LABEL(labelType), "<b>[Nothing selected]</b>"); } } |