33#include " components/database.h"
44#include " components/rendering.h"
55#include " ecs/query.h"
6+ #include " playerInfo.h"
67
78#include " gui/gui2_listbox.h"
89#include " gui/gui2_image.h"
@@ -17,19 +18,33 @@ DatabaseViewComponent::DatabaseViewComponent(GuiContainer* owner)
1718{
1819 setAttribute (" layout" , " horizontal" );
1920
20- // Setup the navigation bar
21- GuiElement* navigation_element = new GuiElement (this , " NAVIGATION_BAR" );
22- navigation_element->setAttribute (" layout" , " vertical" );
23- navigation_element->setMargins (20 , 20 , 20 , 120 )->setSize (navigation_width, GuiElement::GuiSizeMax);
24- back_button = new GuiButton (navigation_element," BACK_BUTTON" , " Back" , [this ](){
25- selected_entry = sp::ecs::Entity::fromString (back_entry);
26- display ();
27- });
28- back_button->setSize (GuiElement::GuiSizeMax, 50 )->hide ()->setMargins (0 , 0 , 0 , 20 );
29- item_list = new GuiListbox (navigation_element, " DATABASE_ITEM_LIST" , [this ](int index, string value) {
30- selected_entry = sp::ecs::Entity::fromString (value);
31- display ();
32- });
21+ // Setup the navigation bar.
22+ navigation_element = new GuiElement (this , " DB_NAV_BAR" );
23+ navigation_element
24+ ->setSize (navigation_width, GuiElement::GuiSizeMax)
25+ ->setAttribute (" layout" , " vertical" );
26+ navigation_element
27+ ->setAttribute (" margin" , " 0, 20, 0, 0" );
28+
29+ back_button = new GuiButton (navigation_element, " DB_BACK_BUTTON" , tr (" databaseView" , " Back" ),
30+ [this ]()
31+ {
32+ selected_entry = sp::ecs::Entity::fromString (back_entry);
33+ display ();
34+ }
35+ );
36+ back_button
37+ ->setSize (GuiElement::GuiSizeMax, 50 .0f )
38+ ->hide ()
39+ ->setAttribute (" margin" , " 0, 0, 0, 20" );
40+
41+ item_list = new GuiListbox (navigation_element, " DB_ITEM_LIST" ,
42+ [this ](int index, string value)
43+ {
44+ selected_entry = sp::ecs::Entity::fromString (value);
45+ display ();
46+ }
47+ );
3348 item_list->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
3449 display ();
3550}
@@ -48,6 +63,18 @@ bool DatabaseViewComponent::findAndDisplayEntry(string name)
4863 return false ;
4964}
5065
66+ DatabaseViewComponent* DatabaseViewComponent::setDetailsPadding (int padding)
67+ {
68+ details_padding = std::max (0 , padding);
69+ return this ;
70+ }
71+
72+ DatabaseViewComponent* DatabaseViewComponent::setItemsPadding (int padding)
73+ {
74+ items_padding = std::max (0 , padding);
75+ return this ;
76+ }
77+
5178void DatabaseViewComponent::fillListBox ()
5279{
5380 item_list->setOptions ({});
@@ -115,58 +142,77 @@ void DatabaseViewComponent::fillListBox()
115142
116143void DatabaseViewComponent::display ()
117144{
118- if (keyvalue_container)
119- keyvalue_container->destroy ();
120- if (details_container)
121- details_container->destroy ();
122-
123- keyvalue_container = new GuiElement (this , " KEY_VALUE_CONTAINER" );
124- keyvalue_container->setMargins (20 )->setSize (400 , GuiElement::GuiSizeMax)->setAttribute (" layout" , " vertical" );
125-
126- details_container = new GuiElement (this , " DETAILS_CONTAINER" );
127- details_container->setMargins (20 )->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax)->setAttribute (" layout" , " vertical" );
128- details_container->layout .padding .top = 50 ;
145+ if (keyvalue_container) keyvalue_container->destroy ();
146+ if (details_container) details_container->destroy ();
147+
148+ keyvalue_container = new GuiElement (this , " DB_KV_CONTAINER" );
149+ keyvalue_container
150+ ->setSize (400 .0f , GuiElement::GuiSizeMax)
151+ ->setAttribute (" layout" , " vertical" );
152+
153+ details_container = new GuiElement (this , " DB_DETAILS_CONTAINER" );
154+ details_container
155+ ->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax)
156+ ->setAttribute (" layout" , " vertical" );
157+ details_container
158+ ->setAttribute (" margin" , " 20, 0, 0, 0" );
159+ // Set conditional padding on details and item lists.
160+ details_container
161+ ->setAttribute (" padding" , " 0, 0, " + static_cast <string>(details_padding) + " , 0" );
162+
163+ navigation_element
164+ ->setAttribute (" padding" , " 0, 0, 0, " + static_cast <string>(items_padding));
129165
130166 fillListBox ();
131167
132168 auto database = selected_entry.getComponent <Database>();
133- if (!database)
134- return ;
135- auto mrc = selected_entry.getComponent <MeshRenderComponent>();
169+ if (!database) return ;
136170
171+ auto mrc = selected_entry.getComponent <MeshRenderComponent>();
137172 bool has_key_values = database->key_values .size () > 0 ;
138173 bool has_image_or_model = mrc || database->image != " " ;
139174 bool has_text = database->description .length () > 0 ;
140175
141176 if (has_image_or_model)
142177 {
143- GuiElement* visual = (new GuiElement (details_container, " DATABASE_VISUAL_ELEMENT" ))->setMargins (0 , 0 , 0 , 40 )->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
178+ GuiElement* visual = (new GuiElement (details_container, " DB_VISUAL_ELEMENT" ))
179+ ->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
144180
145181 if (mrc)
146182 {
147- (new GuiRotatingModelView (visual, " DATABASE_MODEL_VIEW " , selected_entry))
183+ (new GuiRotatingModelView (visual, " DB_MODEL_VIEW " , selected_entry))
148184 ->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
149- if (database->image != " " )
185+
186+ if (database->image != " " )
150187 {
151- (new GuiImage (visual, " DATABASE_IMAGE" , database->image ))->setMargins (0 )->setSize (32 , 32 );
188+ (new GuiImage (visual, " DB_IMAGE" , database->image ))
189+ ->setSize (32 .0f , 32 .0f );
152190 }
153191 }
154192 else if (database->image != " " )
155193 {
156- auto image = new GuiImage (visual, " DATABASE_IMAGE " , database->image );
157- image ->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
194+ ( new GuiImage (visual, " DB_IMAGE " , database->image ))
195+ ->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
158196 }
159197 }
198+
160199 if (has_text)
161200 {
162- (new GuiScrollFormattedText (details_container, " DATABASE_LONG_DESCRIPTION" , database->description ))->setTextSize (24 )->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
201+ (new GuiScrollFormattedText (details_container, " DB_LONG_DESCRIPTION" , database->description ))
202+ ->setTextSize (24 .0f )
203+ ->setSize (GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
163204 }
164205
165206 if (has_key_values)
166207 {
167- for (auto & kv : database->key_values )
168- (new GuiKeyValueDisplay (keyvalue_container, " " , 0.37 , kv.key , kv.value ))->setSize (GuiElement::GuiSizeMax, 40 );
169- } else {
208+ for (auto & kv : database->key_values )
209+ {
210+ (new GuiKeyValueDisplay (keyvalue_container, " " , 0 .37f , kv.key , kv.value ))
211+ ->setSize (GuiElement::GuiSizeMax, 40 .0f );
212+ }
213+ }
214+ else
215+ {
170216 keyvalue_container->destroy ();
171217 keyvalue_container = nullptr ;
172218 }
0 commit comments