]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/guiFormSpecMenu.h
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.git] / src / guiFormSpecMenu.h
index 17b202b187e5ab30c2bd39ae49283236e86ce172..84124afc3fa60272a1752855a3594725e3584539 100644 (file)
@@ -21,6 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifndef GUIINVENTORYMENU_HEADER
 #define GUIINVENTORYMENU_HEADER
 
+#include <utility>
+
 #include "irrlichttypes_extrabloated.h"
 #include "inventory.h"
 #include "inventorymanager.h"
@@ -29,6 +31,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 class IGameDef;
 class InventoryManager;
 
+typedef enum {
+       f_Button,
+       f_ListBox,
+       f_TabHeader,
+       f_CheckBox,
+       f_DropDown,
+       f_Unknown
+} FormspecFieldType;
+
 struct TextDest
 {
        virtual ~TextDest() {};
@@ -46,13 +57,6 @@ class IFormSource
        virtual std::string resolveText(std::string str){ return str; }
 };
 
-void drawItemStack(video::IVideoDriver *driver,
-               gui::IGUIFont *font,
-               const ItemStack &item,
-               const core::rect<s32> &rect,
-               const core::rect<s32> *clip,
-               IGameDef *gamedef);
-
 class GUIFormSpecMenu : public GUIModalMenu
 {
        struct ItemSpec
@@ -113,10 +117,19 @@ class GUIFormSpecMenu : public GUIModalMenu
                        pos(a_pos),
                        geom(a_geom)
                {
+                       scale = true;
+               }
+               ImageDrawSpec(const std::string &a_name,
+                               v2s32 a_pos):
+                       name(a_name),
+                       pos(a_pos)
+               {
+                       scale = false;
                }
                std::string name;
                v2s32 pos;
                v2s32 geom;
+               bool scale;
        };
        
        struct FieldSpec
@@ -131,7 +144,7 @@ class GUIFormSpecMenu : public GUIModalMenu
                        fid(id)
                {
                        send = false;
-                       is_button = false;
+                       ftype = f_Unknown;
                        is_exit = false;
                        tooltip="";
                }
@@ -140,12 +153,24 @@ class GUIFormSpecMenu : public GUIModalMenu
                std::wstring fdefault;
                int fid;
                bool send;
-               bool is_button;
+               FormspecFieldType ftype;
                bool is_exit;
                core::rect<s32> rect;
                std::string tooltip;
        };
 
+       struct BoxDrawSpec {
+               BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
+                       pos(a_pos),
+                       geom(a_geom),
+                       color(a_color)
+               {
+               }
+               v2s32 pos;
+               v2s32 geom;
+               irr::video::SColor color;
+       };
+
 public:
        GUIFormSpecMenu(irr::IrrlichtDevice* dev,
                        gui::IGUIElement* parent, s32 id,
@@ -153,6 +178,7 @@ class GUIFormSpecMenu : public GUIModalMenu
                        InventoryManager *invmgr,
                        IGameDef *gamedef
                        );
+
        ~GUIFormSpecMenu();
 
        void setFormSpec(const std::string &formspec_string,
@@ -175,6 +201,20 @@ class GUIFormSpecMenu : public GUIModalMenu
                m_text_dst = text_dst;
        }
 
+       void allowClose(bool value)
+       {
+               m_allowclose = value;
+       }
+
+       void useGettext(bool value) {
+               m_use_gettext = true;
+       }
+
+       void lockSize(bool lock,v2u32 basescreensize=v2u32(0,0)) {
+               m_lock = lock;
+               m_lockscreensize = basescreensize;
+       }
+
        void removeChildren();
        /*
                Remove and re-add (or reposition) stuff
@@ -186,19 +226,23 @@ class GUIFormSpecMenu : public GUIModalMenu
        void drawSelectedItem();
        void drawMenu();
        void updateSelectedItem();
+       ItemStack verifySelectedItem();
 
-       void acceptInput();
+       void acceptInput(int evttype=-1);
        bool OnEvent(const SEvent& event);
        
+       int getListboxIndex(std::string listboxname);
+
 protected:
        v2s32 getBasePos() const
        {
-               return padding + AbsoluteRect.UpperLeftCorner;
+                       return padding + offset + AbsoluteRect.UpperLeftCorner;
        }
 
        v2s32 padding;
        v2s32 spacing;
        v2s32 imgsize;
+       v2s32 offset;
        
        irr::IrrlichtDevice* m_device;
        InventoryManager *m_invmgr;
@@ -213,7 +257,10 @@ class GUIFormSpecMenu : public GUIModalMenu
        std::vector<ImageDrawSpec> m_backgrounds;
        std::vector<ImageDrawSpec> m_images;
        std::vector<ImageDrawSpec> m_itemimages;
+       std::vector<BoxDrawSpec> m_boxes;
        std::vector<FieldSpec> m_fields;
+       std::vector<std::pair<FieldSpec,gui::IGUIListBox*> > m_listboxes;
+       std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
 
        ItemSpec *m_selected_item;
        u32 m_selected_amount;
@@ -227,6 +274,83 @@ class GUIFormSpecMenu : public GUIModalMenu
 
        v2s32 m_pointer;
        gui::IGUIStaticText *m_tooltip_element;
+
+       bool m_allowclose;
+       bool m_use_gettext;
+       bool m_lock;
+       v2u32 m_lockscreensize;
+private:
+       typedef struct {
+               v2s32 size;
+               s32 helptext_h;
+               core::rect<s32> rect;
+               v2s32 basepos;
+               int bp_set;
+               v2u32 screensize;
+               std::map<std::wstring,int> listbox_selections;
+       } parserData;
+
+       typedef struct {
+               bool key_up;
+               bool key_down;
+               bool key_enter;
+               bool key_escape;
+       } fs_key_pendig;
+
+       std::vector<video::ITexture *> m_Textures;
+
+       fs_key_pendig current_keys_pending;
+
+       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 parseItemImage(parserData* data,std::string element);
+       void parseButton(parserData* data,std::string element,std::string typ);
+       void parseBackground(parserData* data,std::string element);
+       void parseTextList(parserData* data,std::string element);
+       void parseDropDown(parserData* data,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);
+       void parseTextArea(parserData* data,std::vector<std::string>& parts,std::string type);
+       void parseLabel(parserData* data,std::string element);
+       void parseVertLabel(parserData* data,std::string element);
+       void parseImageButton(parserData* data,std::string element,std::string type);
+       void parseItemImageButton(parserData* data,std::string element);
+       void parseTabHeader(parserData* data,std::string element);
+       void parseBox(parserData* data,std::string element);
+
+       bool parseColor(std::string color, irr::video::SColor& outcolor); 
+};
+
+class FormspecFormSource: public IFormSource
+{
+public:
+       FormspecFormSource(std::string formspec,FormspecFormSource** game_formspec)
+       {
+               m_formspec = formspec;
+               m_game_formspec = game_formspec;
+       }
+
+       ~FormspecFormSource()
+       {
+               *m_game_formspec = 0;
+       }
+
+       void setForm(std::string formspec) {
+               m_formspec = formspec;
+       }
+
+       std::string getForm()
+       {
+               return m_formspec;
+       }
+
+       std::string m_formspec;
+       FormspecFormSource** m_game_formspec;
 };
 
 #endif