]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/gui/guiFormSpecMenu.h
Formspecs: volume and key settings windows can now be closed by doubleclicking/tappin...
[dragonfireclient.git] / src / gui / guiFormSpecMenu.h
index 3a3a74c05ae4ad56357f231ab57c797ce5534954..613acaa043fb926656ae2555bbb19afa35e29485 100644 (file)
@@ -26,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "irrlichttypes_extrabloated.h"
 #include "inventorymanager.h"
 #include "modalMenu.h"
+#include "guiInventoryList.h"
+#include "guiScrollBar.h"
 #include "guiTable.h"
 #include "network/networkprotocol.h"
 #include "client/joystick_controller.h"
@@ -36,7 +38,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 class InventoryManager;
 class ISimpleTextureSource;
 class Client;
-class GUIScrollBar;
+class TexturePool;
+class GUIScrollContainer;
 
 typedef enum {
        f_Button,
@@ -47,6 +50,8 @@ typedef enum {
        f_ScrollBar,
        f_Box,
        f_ItemImage,
+       f_HyperText,
+       f_AnimatedImage,
        f_Unknown
 } FormspecFieldType;
 
@@ -78,51 +83,6 @@ class IFormSource
 
 class GUIFormSpecMenu : public GUIModalMenu
 {
-       struct ItemSpec
-       {
-               ItemSpec() = default;
-
-               ItemSpec(const InventoryLocation &a_inventoryloc,
-                               const std::string &a_listname,
-                               s32 a_i) :
-                       inventoryloc(a_inventoryloc),
-                       listname(a_listname),
-                       i(a_i)
-               {
-               }
-
-               bool isValid() const { return i != -1; }
-
-               InventoryLocation inventoryloc;
-               std::string listname;
-               s32 i = -1;
-       };
-
-       struct ListDrawSpec
-       {
-               ListDrawSpec() = default;
-
-               ListDrawSpec(const InventoryLocation &a_inventoryloc,
-                               const std::string &a_listname,
-                               IGUIElement *elem, v2s32 a_geom, s32 a_start_item_i,
-                               bool a_real_coordinates):
-                       inventoryloc(a_inventoryloc),
-                       listname(a_listname),
-                       e(elem),
-                       geom(a_geom),
-                       start_item_i(a_start_item_i),
-                       real_coordinates(a_real_coordinates)
-               {
-               }
-
-               InventoryLocation inventoryloc;
-               std::string listname;
-               IGUIElement *e;
-               v2s32 geom;
-               s32 start_item_i;
-               bool real_coordinates;
-       };
-
        struct ListRingSpec
        {
                ListRingSpec() = default;
@@ -143,7 +103,8 @@ class GUIFormSpecMenu : public GUIModalMenu
                FieldSpec() = default;
 
                FieldSpec(const std::string &name, const std::wstring &label,
-                               const std::wstring &default_text, s32 id, int priority = 0) :
+                               const std::wstring &default_text, s32 id, int priority = 0,
+                               gui::ECURSOR_ICON cursor_icon = ECI_NORMAL) :
                        fname(name),
                        flabel(label),
                        fdefault(unescape_enriched(translate_string(default_text))),
@@ -151,7 +112,8 @@ class GUIFormSpecMenu : public GUIModalMenu
                        send(false),
                        ftype(f_Unknown),
                        is_exit(false),
-                       priority(priority)
+                       priority(priority),
+                       fcursor_icon(cursor_icon)
                {
                }
 
@@ -165,6 +127,7 @@ class GUIFormSpecMenu : public GUIModalMenu
                // Draw priority for formspec version < 3
                int priority;
                core::rect<s32> rect;
+               gui::ECURSOR_ICON fcursor_icon;
        };
 
        struct TooltipSpec
@@ -183,35 +146,6 @@ class GUIFormSpecMenu : public GUIModalMenu
                irr::video::SColor color;
        };
 
-       struct StaticTextSpec
-       {
-               StaticTextSpec():
-                       parent_button(NULL)
-               {
-               }
-
-               StaticTextSpec(const std::wstring &a_text,
-                               const core::rect<s32> &a_rect):
-                       text(a_text),
-                       rect(a_rect),
-                       parent_button(NULL)
-               {
-               }
-
-               StaticTextSpec(const std::wstring &a_text,
-                               const core::rect<s32> &a_rect,
-                               gui::IGUIButton *a_parent_button):
-                       text(a_text),
-                       rect(a_rect),
-                       parent_button(a_parent_button)
-               {
-               }
-
-               std::wstring text;
-               core::rect<s32> rect;
-               gui::IGUIButton *parent_button;
-       };
-
 public:
        GUIFormSpecMenu(JoystickController *joystick,
                        gui::IGUIElement* parent, s32 id,
@@ -234,6 +168,7 @@ class GUIFormSpecMenu : public GUIModalMenu
        {
                m_formspec_string = formspec_string;
                m_current_inventory_location = current_inventory_location;
+               m_is_form_regenerated = false;
                regenerateGui(m_screensize_old);
        }
 
@@ -280,13 +215,37 @@ class GUIFormSpecMenu : public GUIModalMenu
                m_focused_element = elementname;
        }
 
+       Client *getClient() const
+       {
+               return m_client;
+       }
+
+       const GUIInventoryList::ItemSpec *getSelectedItem() const
+       {
+               return m_selected_item;
+       }
+
+       const u16 getSelectedAmount() const
+       {
+               return m_selected_amount;
+       }
+
+       bool doTooltipAppendItemname() const
+       {
+               return m_tooltip_append_itemname;
+       }
+
+       void addHoveredItemTooltip(const std::string &name)
+       {
+               m_hovered_item_tooltips.emplace_back(name);
+       }
+
        /*
                Remove and re-add (or reposition) stuff
        */
        void regenerateGui(v2u32 screensize);
 
-       ItemSpec getItemAtPos(v2s32 p) const;
-       void drawList(const ListDrawSpec &s, int layer, bool &item_hovered);
+       GUIInventoryList::ItemSpec getItemAtPos(v2s32 p) const;
        void drawSelectedItem();
        void drawMenu();
        void updateSelectedItem();
@@ -317,11 +276,13 @@ class GUIFormSpecMenu : public GUIModalMenu
        v2s32 getRealCoordinateBasePos(const std::vector<std::string> &v_pos);
        v2s32 getRealCoordinateGeometry(const std::vector<std::string> &v_geom);
 
-       std::unordered_map<std::string, StyleSpec> theme_by_type;
-       std::unordered_map<std::string, StyleSpec> theme_by_name;
+       std::unordered_map<std::string, std::vector<StyleSpec>> theme_by_type;
+       std::unordered_map<std::string, std::vector<StyleSpec>> theme_by_name;
        std::unordered_set<std::string> property_warned;
 
-       StyleSpec getStyleForElement(const std::string &type,
+       StyleSpec getDefaultStyleForElement(const std::string &type,
+                       const std::string &name="", const std::string &parent_type="");
+       std::array<StyleSpec, StyleSpec::NUM_STATES> getStyleForElement(const std::string &type,
                        const std::string &name="", const std::string &parent_type="");
 
        v2s32 padding;
@@ -339,10 +300,15 @@ class GUIFormSpecMenu : public GUIModalMenu
        std::string m_formspec_prepend;
        InventoryLocation m_current_inventory_location;
 
-       std::vector<ListDrawSpec> m_inventorylists;
+       // Default true because we can't control regeneration on resizing, but
+       // we can control cases when the formspec is shown intentionally.
+       bool m_is_form_regenerated = true;
+
+       std::vector<GUIInventoryList *> m_inventorylists;
        std::vector<ListRingSpec> m_inventory_rings;
        std::vector<gui::IGUIElement *> m_backgrounds;
        std::unordered_map<std::string, bool> field_close_on_enter;
+       std::unordered_map<std::string, bool> m_dropdown_index_event;
        std::vector<FieldSpec> m_fields;
        std::vector<std::pair<FieldSpec, GUITable *>> m_tables;
        std::vector<std::pair<FieldSpec, gui::IGUICheckBox *>> m_checkboxes;
@@ -350,8 +316,10 @@ class GUIFormSpecMenu : public GUIModalMenu
        std::vector<std::pair<gui::IGUIElement *, TooltipSpec>> m_tooltip_rects;
        std::vector<std::pair<FieldSpec, GUIScrollBar *>> m_scrollbars;
        std::vector<std::pair<FieldSpec, std::vector<std::string>>> m_dropdowns;
+       std::vector<gui::IGUIElement *> m_clickthrough_elements;
+       std::vector<std::pair<std::string, GUIScrollContainer *>> m_scroll_containers;
 
-       ItemSpec *m_selected_item = nullptr;
+       GUIInventoryList::ItemSpec *m_selected_item = nullptr;
        u16 m_selected_amount = 0;
        bool m_selected_dragging = false;
        ItemStack m_selected_swap;
@@ -369,23 +337,21 @@ class GUIFormSpecMenu : public GUIModalMenu
        bool m_lock = false;
        v2u32 m_lockscreensize;
 
+       bool m_bgnonfullscreen;
        bool m_bgfullscreen;
-       bool m_slotborder;
        video::SColor m_bgcolor;
        video::SColor m_fullscreen_bgcolor;
-       video::SColor m_slotbg_n;
-       video::SColor m_slotbg_h;
-       video::SColor m_slotbordercolor;
        video::SColor m_default_tooltip_bgcolor;
        video::SColor m_default_tooltip_color;
 
-
 private:
        IFormSource        *m_form_src;
        TextDest           *m_text_dst;
+       std::string         m_last_formname;
        u16                 m_formspec_version = 1;
        std::string         m_focused_element = "";
        JoystickController *m_joystick;
+       bool m_show_debug = false;
 
        typedef struct {
                bool explicit_size;
@@ -398,9 +364,11 @@ class GUIFormSpecMenu : public GUIModalMenu
                core::rect<s32> rect;
                v2s32 basepos;
                v2u32 screensize;
-               std::string focused_fieldname;
                GUITable::TableOptions table_options;
                GUITable::TableColumns table_columns;
+               gui::IGUIElement *current_parent = nullptr;
+
+               GUIInventoryList::Options inventorylist_options;
 
                struct {
                        s32 max = 1000;
@@ -424,16 +392,20 @@ class GUIFormSpecMenu : public GUIModalMenu
 
        fs_key_pendig current_keys_pending;
        std::string current_field_enter_pending = "";
+       std::vector<std::string> m_hovered_item_tooltips;
 
        void parseElement(parserData* data, const std::string &element);
 
        void parseSize(parserData* data, const std::string &element);
        void parseContainer(parserData* data, const std::string &element);
        void parseContainerEnd(parserData* data);
+       void parseScrollContainer(parserData *data, const std::string &element);
+       void parseScrollContainerEnd(parserData *data);
        void parseList(parserData* data, const std::string &element);
        void parseListRing(parserData* data, const std::string &element);
        void parseCheckbox(parserData* data, const std::string &element);
        void parseImage(parserData* data, const std::string &element);
+       void parseAnimatedImage(parserData *data, const std::string &element);
        void parseItemImage(parserData* data, const std::string &element);
        void parseButton(parserData* data, const std::string &element,
                        const std::string &typ);
@@ -471,6 +443,7 @@ class GUIFormSpecMenu : public GUIModalMenu
        bool parseAnchorDirect(parserData *data, const std::string &element);
        void parseAnchor(parserData *data, const std::string &element);
        bool parseStyle(parserData *data, const std::string &element, bool style_type);
+       void parseSetFocus(const std::string &element);
 
        void tryClose();
 
@@ -484,30 +457,8 @@ class GUIFormSpecMenu : public GUIModalMenu
         */
        void legacySortElements(core::list<IGUIElement *>::Iterator from);
 
-       /**
-        * check if event is part of a double click
-        * @param event event to evaluate
-        * @return true/false if a doubleclick was detected
-        */
-       bool DoubleClickDetection(const SEvent event);
-
-       struct clickpos
-       {
-               v2s32 pos;
-               s64 time;
-       };
-       clickpos m_doubleclickdetect[2];
-
        int m_btn_height;
        gui::IGUIFont *m_font = nullptr;
-
-       /* If true, remap a double-click (or double-tap) action to ESC. This is so
-        * that, for example, Android users can double-tap to close a formspec.
-       *
-        * This value can (currently) only be set by the class constructor
-        * and the default value for the setting is true.
-        */
-       bool m_remap_dbl_click;
 };
 
 class FormspecFormSource: public IFormSource