]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/gui/guiFormSpecMenu.h
Formspecs: Introduce formspec_version to mods
[dragonfireclient.git] / src / gui / guiFormSpecMenu.h
index 9cd98f8068c97f495f96cc6dea5c66008624d228..46df0930cc1b9d0993f9e2f26ca8ef429f6e586c 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include <utility>
 #include <stack>
+#include <unordered_set>
 
 #include "irrlichttypes_extrabloated.h"
 #include "inventorymanager.h"
@@ -30,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "client/joystick_controller.h"
 #include "util/string.h"
 #include "util/enriched_string.h"
+#include "StyleSpec.h"
 
 class InventoryManager;
 class ISimpleTextureSource;
@@ -99,12 +101,14 @@ class GUIFormSpecMenu : public GUIModalMenu
 
                ListDrawSpec(const InventoryLocation &a_inventoryloc,
                                const std::string &a_listname,
-                               v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i):
+                               v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i,
+                               bool a_real_coordinates):
                        inventoryloc(a_inventoryloc),
                        listname(a_listname),
                        pos(a_pos),
                        geom(a_geom),
-                       start_item_i(a_start_item_i)
+                       start_item_i(a_start_item_i),
+                       real_coordinates(a_real_coordinates)
                {
                }
 
@@ -113,6 +117,7 @@ class GUIFormSpecMenu : public GUIModalMenu
                v2s32 pos;
                v2s32 geom;
                s32 start_item_i;
+               bool real_coordinates;
        };
 
        struct ListRingSpec
@@ -176,6 +181,18 @@ class GUIFormSpecMenu : public GUIModalMenu
                {
                }
 
+               ImageDrawSpec(const std::string &a_name,
+                               const v2s32 &a_pos, const v2s32 &a_geom, const core::rect<s32> &middle, bool clip=false):
+                               name(a_name),
+                               parent_button(NULL),
+                               pos(a_pos),
+                               geom(a_geom),
+                               middle(middle),
+                               scale(true),
+                               clip(clip)
+               {
+               }
+
                ImageDrawSpec(const std::string &a_name,
                                const v2s32 &a_pos):
                        name(a_name),
@@ -191,6 +208,7 @@ class GUIFormSpecMenu : public GUIModalMenu
                gui::IGUIButton *parent_button;
                v2s32 pos;
                v2s32 geom;
+               core::rect<s32> middle;
                bool scale;
                bool clip;
        };
@@ -223,7 +241,7 @@ class GUIFormSpecMenu : public GUIModalMenu
 
        struct BoxDrawSpec
        {
-               BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
+               BoxDrawSpec(v2s32 a_pos, v2s32 a_geom, irr::video::SColor a_color):
                        pos(a_pos),
                        geom(a_geom),
                        color(a_color)
@@ -287,12 +305,14 @@ class GUIFormSpecMenu : public GUIModalMenu
                        ISimpleTextureSource *tsrc,
                        IFormSource* fs_src,
                        TextDest* txt_dst,
+                       const std::string &formspecPrepend,
                        bool remap_dbl_click = true);
 
        ~GUIFormSpecMenu();
 
-       static void create(GUIFormSpecMenu **cur_formspec, Client *client,
-               JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest);
+       static void create(GUIFormSpecMenu *&cur_formspec, Client *client,
+               JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest,
+               const std::string &formspecPrepend);
 
        void setFormSpec(const std::string &formspec_string,
                        const InventoryLocation &current_inventory_location)
@@ -302,6 +322,16 @@ class GUIFormSpecMenu : public GUIModalMenu
                regenerateGui(m_screensize_old);
        }
 
+       const InventoryLocation &getFormspecLocation()
+       {
+               return m_current_inventory_location;
+       }
+
+       void setFormspecPrepend(const std::string &formspecPrepend)
+       {
+               m_formspec_prepend = formspecPrepend;
+       }
+
        // form_src is deleted by this GUIFormSpecMenu
        void setFormSource(IFormSource *form_src)
        {
@@ -341,7 +371,7 @@ class GUIFormSpecMenu : public GUIModalMenu
        void regenerateGui(v2u32 screensize);
 
        ItemSpec getItemAtPos(v2s32 p) const;
-       void drawList(const ListDrawSpec &s, int phase, bool &item_hovered);
+       void drawList(const ListDrawSpec &s, int layer, bool &item_hovered);
        void drawSelectedItem();
        void drawMenu();
        void updateSelectedItem();
@@ -365,19 +395,34 @@ class GUIFormSpecMenu : public GUIModalMenu
        {
                        return padding + offset + AbsoluteRect.UpperLeftCorner;
        }
+       std::wstring getLabelByID(s32 id);
+       std::string getNameByID(s32 id);
+       v2s32 getElementBasePos(bool absolute,
+                       const std::vector<std::string> *v_pos);
+       v2s32 getRealCoordinateBasePos(bool absolute,
+                       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_set<std::string> property_warned;
+
+       StyleSpec getStyleForElement(const std::string &type,
+                       const std::string &name="", const std::string &parent_type="");
 
        v2s32 padding;
-       v2s32 spacing;
+       v2f32 spacing;
        v2s32 imgsize;
        v2s32 offset;
-       v2s32 pos_offset;
-       std::stack<v2s32> container_stack;
+       v2f32 pos_offset;
+       std::stack<v2f32> container_stack;
 
        InventoryManager *m_invmgr;
        ISimpleTextureSource *m_tsrc;
        Client *m_client;
 
        std::string m_formspec_string;
+       std::string m_formspec_prepend;
        InventoryLocation m_current_inventory_location;
 
        std::vector<ListDrawSpec> m_inventorylists;
@@ -392,21 +437,15 @@ class GUIFormSpecMenu : public GUIModalMenu
        std::vector<std::pair<FieldSpec,GUITable*> > m_tables;
        std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
        std::map<std::string, TooltipSpec> m_tooltips;
+       std::vector<std::pair<irr::core::rect<s32>, TooltipSpec>> m_tooltip_rects;
        std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
        std::vector<std::pair<FieldSpec, std::vector<std::string> > > m_dropdowns;
 
        ItemSpec *m_selected_item = nullptr;
-       u32 m_selected_amount = 0;
+       u16 m_selected_amount = 0;
        bool m_selected_dragging = false;
+       ItemStack m_selected_swap;
 
-       // WARNING: BLACK MAGIC
-       // Used to guess and keep up with some special things the server can do.
-       // If name is "", no guess exists.
-       ItemStack m_selected_content_guess;
-       InventoryLocation m_selected_content_guess_inventory;
-
-       v2s32 m_pointer;
-       v2s32 m_old_pointer;  // Mouse position after previous mouse event
        gui::IGUIStaticText *m_tooltip_element = nullptr;
 
        u64 m_tooltip_show_delay;
@@ -433,12 +472,13 @@ class GUIFormSpecMenu : public GUIModalMenu
 private:
        IFormSource        *m_form_src;
        TextDest           *m_text_dst;
-       u32                 m_formspec_version = 0;
+       u16                 m_formspec_version = 1;
        std::string         m_focused_element = "";
        JoystickController *m_joystick;
 
        typedef struct {
                bool explicit_size;
+               bool real_coordinates;
                v2f invsize;
                v2s32 size;
                v2f32 offset;
@@ -484,6 +524,8 @@ class GUIFormSpecMenu : public GUIModalMenu
        void parseFieldCloseOnEnter(parserData *data, const std::string &element);
        void parsePwdField(parserData* data, const std::string &element);
        void parseField(parserData* data, const std::string &element, const std::string &type);
+       void createTextField(parserData *data, FieldSpec &spec,
+               core::rect<s32> &rect, bool is_multiline);
        void parseSimpleField(parserData* data,std::vector<std::string> &parts);
        void parseTextArea(parserData* data,std::vector<std::string>& parts,
                        const std::string &type);
@@ -504,6 +546,7 @@ class GUIFormSpecMenu : public GUIModalMenu
        void parsePosition(parserData *data, const std::string &element);
        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 tryClose();
 
@@ -527,13 +570,6 @@ class GUIFormSpecMenu : public GUIModalMenu
        int m_btn_height;
        gui::IGUIFont *m_font = nullptr;
 
-       std::wstring getLabelByID(s32 id);
-       std::string getNameByID(s32 id);
-#ifdef __ANDROID__
-       v2s32 m_down_pos;
-       std::string m_JavaDialogFieldName;
-#endif
-
        /* 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.
        *
@@ -541,7 +577,6 @@ class GUIFormSpecMenu : public GUIModalMenu
         * and the default value for the setting is true.
         */
        bool m_remap_dbl_click;
-
 };
 
 class FormspecFormSource: public IFormSource
@@ -556,7 +591,7 @@ class FormspecFormSource: public IFormSource
 
        void setForm(const std::string &formspec)
        {
-               m_formspec = FORMSPEC_VERSION_STRING + formspec;
+               m_formspec = formspec;
        }
 
        const std::string &getForm() const