/* * dlogutil.h * BoE * * Created by Celtic Minstrel on 11/05/09. * */ #ifndef DIALOG_3CHOICE_H #define DIALOG_3CHOICE_H #include #include #include #include #include "dialogxml/keycodes.hpp" #include "dialogxml/dialogs/choicedlog.hpp" #include "dialogxml/widgets/button.hpp" #include "dialogxml/widgets/pictypes.hpp" #include "universe/universe.hpp" #include "scenario/special.hpp" /// Basic button type template struct bbtt { eBtnType type; ///< The type of the preset button. std::string label; ///< The preset button's label, if any. cKey defaultKey; ///< The preset button's default key shortcut, if any. std::string name; ///< (optional) A more descriptive name for the button. }; /// Represents a preset button for use with cThreeChoice. typedef boost::optional cBasicButtonType; namespace {cBasicButtonType null_btn = boost::none;} #ifndef BTNS_DEFINED extern bbtt basic_buttons[71]; #endif /// The signature of a record handler for cThreeChoice. typedef std::function record_callback_t; /// A choice dialog with several strings and up to three buttons. /// This is the class used for dialogs generated by special nodes. /// It generates the dialog dynamically from the given input. /// Note that the dialog is not limited to six strings. class cThreeChoice : public cChoiceDlog { cBasicButtonType btns[3]; unsigned short buttons_right, buttons_top; void init_strings(std::vector& strings, unsigned short left); void init_buttons(cBasicButtonType btn1, cBasicButtonType btn2, cBasicButtonType btn3); void init_pict(pic_num_t pic); const ePicType type; record_callback_t rec_f; bool hasRecord; bool onRecord(std::string id); public: /// Create a dialog with just one button. /// @param strings A list of the strings to place in the dialog. /// @param button The specification of the button. /// @param pic The icon to show at the top left. /// @param t The type of the icon. /// @param parent Optionally, a parent dialog. cThreeChoice(std::vector& strings, cBasicButtonType button, pic_num_t pic, ePicType t, cDialog* parent = nullptr); /// Create a dialog with up to three buttons. /// @param strings A list of the strings to place in the dialog. /// @param buttons A list of the button specifications. /// @param pic The icon to show at the top left. /// @param t The type of the icon. /// @param parent Optionally, a parent dialog. cThreeChoice(std::vector& strings, std::array& buttons, pic_num_t pic, ePicType t, cDialog* parent = nullptr); /// Create a dialog with up to three buttons. /// @param strings A list of the strings to place in the dialog. /// @param buttons A list of the index of the button; this is an index into available_btns which is in turn used to index basic_buttons. /// @param pic The icon to show at the top left. /// @param t The type of the icon. /// @param parent Optionally, a parent dialog. cThreeChoice(std::vector& strings, std::array& buttons, pic_num_t pic, ePicType t, cDialog* parent = nullptr); /// Set a record handler. /// @param rec The handler. /// @return This object, for method-call chaining. /// @note Only one record handler can be set at a time. To remove it, set it to null. /// @note The presence of the Record button is determined entirely by the presence of a record handler. /// /// A record handler should take one parameter, which is a reference to the dialog. /// (That's the cDialog, not the cThreeChoice.) It should return void. cThreeChoice& setRecordHandler(record_callback_t rec); /// @copydoc cChoiceDlog::show() /// @note The unique key in this case is the label specified in the button specification. std::string show(); }; short custom_choice_dialog(std::array& strs,short pic_num,ePicType pic_type,std::array& buttons, bool anim_pict = false, short anim_loops = -1, int anim_fps = -1, cUniverse* univ = nullptr, cDialog* parent = nullptr); short once_dialog(cUniverse& univ, cSpecial& spec, eSpecCtxType cur_type, cDialog* parent = nullptr); #endif