@@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
24
24
#include < limits>
25
25
#include < sstream>
26
26
#include " guiFormSpecMenu.h"
27
+ #include " guiScrollBar.h"
28
+ #include " guiTable.h"
27
29
#include " constants.h"
28
30
#include " gamedef.h"
29
31
#include " client/keycode.h"
@@ -123,24 +125,18 @@ GUIFormSpecMenu::~GUIFormSpecMenu()
123
125
{
124
126
removeChildren ();
125
127
126
- for (auto &table_it : m_tables) {
128
+ for (auto &table_it : m_tables)
127
129
table_it.second ->drop ();
128
- }
129
- for (auto &inventorylist_it : m_inventorylists) {
130
+ for (auto &inventorylist_it : m_inventorylists)
130
131
inventorylist_it.e ->drop ();
131
- }
132
- for (auto &checkbox_it : m_checkboxes) {
132
+ for (auto &checkbox_it : m_checkboxes)
133
133
checkbox_it.second ->drop ();
134
- }
135
- for (auto &scrollbar_it : m_scrollbars) {
134
+ for (auto &scrollbar_it : m_scrollbars)
136
135
scrollbar_it.second ->drop ();
137
- }
138
- for (auto &background_it : m_backgrounds) {
136
+ for (auto &background_it : m_backgrounds)
139
137
background_it->drop ();
140
- }
141
- for (auto &tooltip_rect_it : m_tooltip_rects) {
138
+ for (auto &tooltip_rect_it : m_tooltip_rects)
142
139
tooltip_rect_it.first ->drop ();
143
- }
144
140
145
141
delete m_selected_item;
146
142
delete m_form_src;
@@ -614,22 +610,86 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen
614
610
spec.ftype = f_ScrollBar;
615
611
spec.send = true ;
616
612
GUIScrollBar *e = new GUIScrollBar (Environment, this , spec.fid , rect,
617
- is_horizontal, false );
613
+ is_horizontal, true );
618
614
619
615
auto style = getStyleForElement (" scrollbar" , name);
620
616
e->setNotClipped (style.getBool (StyleSpec::NOCLIP, false ));
617
+ e->setArrowsVisible (data->scrollbar_options .arrow_visiblity );
618
+
619
+ s32 max = data->scrollbar_options .max ;
620
+ s32 min = data->scrollbar_options .min ;
621
+
622
+ e->setMax (max);
623
+ e->setMin (min);
621
624
622
- e->setMax (1000 );
623
- e->setMin (0 );
624
625
e->setPos (stoi (parts[4 ]));
625
- e->setSmallStep (10 );
626
- e->setLargeStep (100 );
626
+
627
+ e->setSmallStep (data->scrollbar_options .small_step );
628
+ e->setLargeStep (data->scrollbar_options .large_step );
629
+
630
+ s32 scrollbar_size = is_horizontal ? dim.X : dim.Y ;
631
+
632
+ e->setPageSize (scrollbar_size * (max - min + 1 ) / data->scrollbar_options .thumb_size );
627
633
628
634
m_scrollbars.emplace_back (spec,e);
629
635
m_fields.push_back (spec);
630
636
return ;
631
637
}
632
- errorstream<< " Invalid scrollbar element(" << parts.size () << " ): '" << element << " '" << std::endl;
638
+ errorstream << " Invalid scrollbar element(" << parts.size () << " ): '" << element
639
+ << " '" << std::endl;
640
+ }
641
+
642
+ void GUIFormSpecMenu::parseScrollBarOptions (parserData* data, const std::string &element)
643
+ {
644
+ std::vector<std::string> parts = split (element, ' ;' );
645
+
646
+ if (parts.size () == 0 ) {
647
+ warningstream << " Invalid scrollbaroptions element(" << parts.size () << " ): '" <<
648
+ element << " '" << std::endl;
649
+ return ;
650
+ }
651
+
652
+ for (const std::string &i : parts) {
653
+ std::vector<std::string> options = split (i, ' =' );
654
+
655
+ if (options.size () != 2 ) {
656
+ warningstream << " Invalid scrollbaroptions option syntax: '" <<
657
+ element << " '" << std::endl;
658
+ continue ; // Go to next option
659
+ }
660
+
661
+ if (options[0 ] == " max" ) {
662
+ data->scrollbar_options .max = stoi (options[1 ]);
663
+ continue ;
664
+ } else if (options[0 ] == " min" ) {
665
+ data->scrollbar_options .min = stoi (options[1 ]);
666
+ continue ;
667
+ } else if (options[0 ] == " smallstep" ) {
668
+ int value = stoi (options[1 ]);
669
+ data->scrollbar_options .small_step = value < 0 ? 10 : value;
670
+ continue ;
671
+ } else if (options[0 ] == " largestep" ) {
672
+ int value = stoi (options[1 ]);
673
+ data->scrollbar_options .large_step = value < 0 ? 100 : value;
674
+ continue ;
675
+ } else if (options[0 ] == " thumbsize" ) {
676
+ int value = stoi (options[1 ]);
677
+ data->scrollbar_options .thumb_size = value <= 0 ? 1 : value;
678
+ continue ;
679
+ } else if (options[0 ] == " arrows" ) {
680
+ std::string value = trim (options[1 ]);
681
+ if (value == " hide" )
682
+ data->scrollbar_options .arrow_visiblity = GUIScrollBar::HIDE;
683
+ else if (value == " show" )
684
+ data->scrollbar_options .arrow_visiblity = GUIScrollBar::SHOW;
685
+ else // Auto hide/show
686
+ data->scrollbar_options .arrow_visiblity = GUIScrollBar::DEFAULT;
687
+ continue ;
688
+ }
689
+
690
+ warningstream << " Invalid scrollbaroptions option(" << options[0 ] <<
691
+ " ): '" << element << " '" << std::endl;
692
+ }
633
693
}
634
694
635
695
void GUIFormSpecMenu::parseImage (parserData* data, const std::string &element)
@@ -2591,6 +2651,11 @@ void GUIFormSpecMenu::parseElement(parserData* data, const std::string &element)
2591
2651
return ;
2592
2652
}
2593
2653
2654
+ if (type == " scrollbaroptions" ) {
2655
+ parseScrollBarOptions (data, description);
2656
+ return ;
2657
+ }
2658
+
2594
2659
// Ignore others
2595
2660
infostream << " Unknown DrawSpec: type=" << type << " , data=\" " << description << " \" "
2596
2661
<< std::endl;
@@ -2633,24 +2698,18 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
2633
2698
// Remove children
2634
2699
removeChildren ();
2635
2700
2636
- for (auto &table_it : m_tables) {
2701
+ for (auto &table_it : m_tables)
2637
2702
table_it.second ->drop ();
2638
- }
2639
- for (auto &inventorylist_it : m_inventorylists) {
2703
+ for (auto &inventorylist_it : m_inventorylists)
2640
2704
inventorylist_it.e ->drop ();
2641
- }
2642
- for (auto &checkbox_it : m_checkboxes) {
2705
+ for (auto &checkbox_it : m_checkboxes)
2643
2706
checkbox_it.second ->drop ();
2644
- }
2645
- for (auto &scrollbar_it : m_scrollbars) {
2707
+ for (auto &scrollbar_it : m_scrollbars)
2646
2708
scrollbar_it.second ->drop ();
2647
- }
2648
- for (auto &background_it : m_backgrounds) {
2709
+ for (auto &background_it : m_backgrounds)
2649
2710
background_it->drop ();
2650
- }
2651
- for (auto &tooltip_rect_it : m_tooltip_rects) {
2711
+ for (auto &tooltip_rect_it : m_tooltip_rects)
2652
2712
tooltip_rect_it.first ->drop ();
2653
- }
2654
2713
2655
2714
mydata.size = v2s32 (100 ,100 );
2656
2715
mydata.screensize = screensize;
0 commit comments