Add ItemStack key-value meta storage
[oweals/minetest.git] / src / guiFormSpecMenu.h
index f04968aec465ac4b170cf54c347130fb665a80b3..2ab7db4f104334a3a464fbd30eaa8c4f57a58f28 100644 (file)
@@ -22,15 +22,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #define GUIINVENTORYMENU_HEADER
 
 #include <utility>
+#include <stack>
 
 #include "irrlichttypes_extrabloated.h"
-#include "inventory.h"
 #include "inventorymanager.h"
 #include "modalMenu.h"
 #include "guiTable.h"
 #include "network/networkprotocol.h"
+#include "client/joystick_controller.h"
+#include "util/string.h"
+#include "util/enriched_string.h"
 
-class IGameDef;
 class InventoryManager;
 class ISimpleTextureSource;
 class Client;
@@ -121,30 +123,80 @@ class GUIFormSpecMenu : public GUIModalMenu
                s32 start_item_i;
        };
 
-       struct ImageDrawSpec
+       struct ListRingSpec
        {
-               ImageDrawSpec()
+               ListRingSpec()
+               {
+               }
+               ListRingSpec(const InventoryLocation &a_inventoryloc,
+                               const std::string &a_listname):
+                       inventoryloc(a_inventoryloc),
+                       listname(a_listname)
                {
                }
+
+               InventoryLocation inventoryloc;
+               std::string listname;
+       };
+
+       struct ImageDrawSpec
+       {
+               ImageDrawSpec():
+                       parent_button(NULL),
+                       clip(false)
+               {}
+
                ImageDrawSpec(const std::string &a_name,
-                               v2s32 a_pos, v2s32 a_geom):
+                               const std::string &a_item_name,
+                               gui::IGUIButton *a_parent_button,
+                               const v2s32 &a_pos, const v2s32 &a_geom):
                        name(a_name),
+                       item_name(a_item_name),
+                       parent_button(a_parent_button),
                        pos(a_pos),
-                       geom(a_geom)
-               {
-                       scale = true;
-               }
+                       geom(a_geom),
+                       scale(true),
+                       clip(false)
+               {}
+
                ImageDrawSpec(const std::string &a_name,
-                               v2s32 a_pos):
+                               const std::string &a_item_name,
+                               const v2s32 &a_pos, const v2s32 &a_geom):
                        name(a_name),
-                       pos(a_pos)
-               {
-                       scale = false;
-               }
+                       item_name(a_item_name),
+                       parent_button(NULL),
+                       pos(a_pos),
+                       geom(a_geom),
+                       scale(true),
+                       clip(false)
+               {}
+
+               ImageDrawSpec(const std::string &a_name,
+                               const v2s32 &a_pos, const v2s32 &a_geom, bool clip=false):
+                       name(a_name),
+                       parent_button(NULL),
+                       pos(a_pos),
+                       geom(a_geom),
+                       scale(true),
+                       clip(clip)
+               {}
+
+               ImageDrawSpec(const std::string &a_name,
+                               const v2s32 &a_pos):
+                       name(a_name),
+                       parent_button(NULL),
+                       pos(a_pos),
+                       scale(false),
+                       clip(false)
+               {}
+
                std::string name;
+               std::string item_name;
+               gui::IGUIButton *parent_button;
                v2s32 pos;
                v2s32 geom;
                bool scale;
+               bool clip;
        };
 
        struct FieldSpec
@@ -153,15 +205,16 @@ class GUIFormSpecMenu : public GUIModalMenu
                {
                }
                FieldSpec(const std::string &name, const std::wstring &label,
-                               const std::wstring &fdeflt, int id) :
+                               const std::wstring &default_text, int id) :
                        fname(name),
                        flabel(label),
-                       fdefault(fdeflt),
-                       fid(id)
+                       fid(id),
+                       send(false),
+                       ftype(f_Unknown),
+                       is_exit(false)
                {
-                       send = false;
-                       ftype = f_Unknown;
-                       is_exit = false;
+                       //flabel = unescape_enriched(label);
+                       fdefault = unescape_enriched(default_text);
                }
                std::string fname;
                std::wstring flabel;
@@ -191,26 +244,53 @@ class GUIFormSpecMenu : public GUIModalMenu
                }
                TooltipSpec(std::string a_tooltip, irr::video::SColor a_bgcolor,
                                irr::video::SColor a_color):
-                       tooltip(a_tooltip),
                        bgcolor(a_bgcolor),
                        color(a_color)
                {
+                       //tooltip = unescape_enriched(utf8_to_wide(a_tooltip));
+                       tooltip = utf8_to_wide(a_tooltip);
                }
-               std::string tooltip;
+               std::wstring tooltip;
                irr::video::SColor bgcolor;
                irr::video::SColor color;
        };
 
+       struct StaticTextSpec {
+               StaticTextSpec():
+                       parent_button(NULL)
+               {
+               }
+               StaticTextSpec(const std::wstring &a_text,
+                               const core::rect<s32> &a_rect):
+                       rect(a_rect),
+                       parent_button(NULL)
+               {
+                       //text = unescape_enriched(a_text);
+                       text = a_text;
+               }
+               StaticTextSpec(const std::wstring &a_text,
+                               const core::rect<s32> &a_rect,
+                               gui::IGUIButton *a_parent_button):
+                       rect(a_rect),
+                       parent_button(a_parent_button)
+               {
+                       //text = unescape_enriched(a_text);
+                       text = a_text;
+               }
+               std::wstring text;
+               core::rect<s32> rect;
+               gui::IGUIButton *parent_button;
+       };
+
 public:
        GUIFormSpecMenu(irr::IrrlichtDevice* dev,
+                       JoystickController *joystick,
                        gui::IGUIElement* parent, s32 id,
                        IMenuManager *menumgr,
-                       InventoryManager *invmgr,
-                       IGameDef *gamedef,
+                       Client *client,
                        ISimpleTextureSource *tsrc,
                        IFormSource* fs_src,
                        TextDest* txt_dst,
-                       Client* client,
                        bool remap_dbl_click = true);
 
        ~GUIFormSpecMenu();
@@ -266,7 +346,7 @@ public:
        void regenerateGui(v2u32 screensize);
 
        ItemSpec getItemAtPos(v2s32 p) const;
-       void drawList(const ListDrawSpec &s, int phase);
+       void drawList(const ListDrawSpec &s, int phase, bool &item_hovered);
        void drawSelectedItem();
        void drawMenu();
        void updateSelectedItem();
@@ -279,6 +359,7 @@ public:
        bool pausesGame() { return doPause; }
 
        GUITable* getTable(const std::string &tablename);
+       std::vector<std::string>* getDropDownValues(const std::string &name);
 
 #ifdef __ANDROID__
        bool getAndroidUIInput();
@@ -294,10 +375,11 @@ protected:
        v2s32 spacing;
        v2s32 imgsize;
        v2s32 offset;
+       v2s32 pos_offset;
+       std::stack<v2s32> container_stack;
 
        irr::IrrlichtDevice* m_device;
        InventoryManager *m_invmgr;
-       IGameDef *m_gamedef;
        ISimpleTextureSource *m_tsrc;
        Client *m_client;
 
@@ -306,15 +388,19 @@ protected:
 
 
        std::vector<ListDrawSpec> m_inventorylists;
+       std::vector<ListRingSpec> m_inventory_rings;
        std::vector<ImageDrawSpec> m_backgrounds;
        std::vector<ImageDrawSpec> m_images;
        std::vector<ImageDrawSpec> m_itemimages;
        std::vector<BoxDrawSpec> m_boxes;
+       UNORDERED_MAP<std::string, bool> field_close_on_enter;
        std::vector<FieldSpec> m_fields;
+       std::vector<StaticTextSpec> m_static_texts;
        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<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
+       std::vector<std::pair<FieldSpec, std::vector<std::string> > > m_dropdowns;
 
        ItemSpec *m_selected_item;
        u32 m_selected_amount;
@@ -333,7 +419,7 @@ protected:
        u32 m_tooltip_show_delay;
        s32 m_hovered_time;
        s32 m_old_tooltip_id;
-       std::string m_old_tooltip;
+       std::wstring m_old_tooltip;
 
        bool m_rmouse_auto_place;
 
@@ -343,7 +429,6 @@ protected:
 
        bool m_bgfullscreen;
        bool m_slotborder;
-       bool m_clipbackground;
        video::SColor m_bgcolor;
        video::SColor m_slotbg_n;
        video::SColor m_slotbg_h;
@@ -352,10 +437,11 @@ protected:
        video::SColor m_default_tooltip_color;
 
 private:
-       IFormSource      *m_form_src;
-       TextDest         *m_text_dst;
-       unsigned int      m_formspec_version;
-       std::string       m_focused_element;
+       IFormSource        *m_form_src;
+       TextDest           *m_text_dst;
+       unsigned int        m_formspec_version;
+       std::string         m_focused_element;
+       JoystickController *m_joystick;
 
        typedef struct {
                bool explicit_size;
@@ -368,7 +454,7 @@ private:
                GUITable::TableOptions table_options;
                GUITable::TableColumns table_columns;
                // used to restore table selection/scroll/treeview state
-               std::map<std::string, GUITable::DynamicData> table_dyndata;
+               UNORDERED_MAP<std::string, GUITable::DynamicData> table_dyndata;
        } parserData;
 
        typedef struct {
@@ -379,13 +465,17 @@ private:
        } fs_key_pendig;
 
        fs_key_pendig current_keys_pending;
+       std::string current_field_enter_pending;
 
-       void parseElement(parserData* data,std::string element);
+       void parseElement(parserData* data, std::string element);
 
-       void parseSize(parserData* data,std::string element);
-       void parseList(parserData* data,std::string element);
-       void parseCheckbox(parserData* data,std::string element);
-       void parseImage(parserData* data,std::string element);
+       void parseSize(parserData* data, std::string element);
+       void parseContainer(parserData* data, std::string element);
+       void parseContainerEnd(parserData* data);
+       void parseList(parserData* data, std::string element);
+       void parseListRing(parserData* data, std::string element);
+       void parseCheckbox(parserData* data, std::string element);
+       void parseImage(parserData* data, std::string element);
        void parseItemImage(parserData* data,std::string element);
        void parseButton(parserData* data,std::string element,std::string typ);
        void parseBackground(parserData* data,std::string element);
@@ -394,6 +484,7 @@ private:
        void parseTable(parserData* data,std::string element);
        void parseTextList(parserData* data,std::string element);
        void parseDropDown(parserData* data,std::string element);
+       void parseFieldCloseOnEnter(parserData *data, const std::string &element);
        void parsePwdField(parserData* data,std::string element);
        void parseField(parserData* data,std::string element,std::string type);
        void parseSimpleField(parserData* data,std::vector<std::string> &parts);
@@ -412,6 +503,8 @@ private:
        bool parseSizeDirect(parserData* data, std::string element);
        void parseScrollBar(parserData* data, std::string element);
 
+       void tryClose();
+
        /**
         * check if event is part of a double click
         * @param event event to evaluate
@@ -470,4 +563,3 @@ public:
 };
 
 #endif
-