Changed: Use button lookup index in html_submit_form instead button name/value

--HG--
branch : develop
This commit is contained in:
Nimetu 2019-05-07 19:40:06 +03:00
parent bd5c03ebf0
commit 742092fd6b
3 changed files with 78 additions and 53 deletions

View file

@ -107,7 +107,7 @@ namespace NLGUI
void refresh(); void refresh();
// submit form // submit form
void submitForm (uint formId, const char *submitButtonType, const char *submitButtonName, const char *submitButtonValue, sint32 x, sint32 y); void submitForm(uint button, sint32 x, sint32 y);
// Browse error // Browse error
void browseError (const char *msg); void browseError (const char *msg);
@ -600,6 +600,9 @@ namespace NLGUI
sint InitialSelection; // initial selection for the combo box sint InitialSelection; // initial selection for the combo box
}; };
// <form> element "id" attribute
std::string id;
// The action the form has to perform // The action the form has to perform
std::string Action; std::string Action;
@ -607,6 +610,23 @@ namespace NLGUI
std::vector<CEntry> Entries; std::vector<CEntry> Entries;
}; };
std::vector<CForm> _Forms; std::vector<CForm> _Forms;
// submit buttons added to from
struct SFormSubmitButton
{
SFormSubmitButton(const std::string &form, const std::string &name, const std::string &value, const std::string &type)
: form(form), name(name), value(value), type(type)
{ }
std::string form; // form 'id'
std::string name; // submit button name
std::string value; // submit button value
std::string type; // button type, ie 'image'
};
// submit buttons added to form
std::vector<SFormSubmitButton> _FormSubmit;
std::vector<CInterfaceGroup *> _Groups; std::vector<CInterfaceGroup *> _Groups;
// Cells parameters // Cells parameters
@ -823,7 +843,7 @@ namespace NLGUI
const std::string &tooltip, const std::string &tooltip,
const std::string &src, const std::string &src,
const std::string &over, const std::string &over,
uint32 formId, const std::string &formId,
const std::string &formAction = "", const std::string &formAction = "",
uint32 minWidth = 0, uint32 minWidth = 0,
const std::string &templateName = ""); const std::string &templateName = "");
@ -831,7 +851,7 @@ namespace NLGUI
void insertFormTextButton(const std::string &name, void insertFormTextButton(const std::string &name,
const std::string &tooltip, const std::string &tooltip,
const std::string &value, const std::string &value,
uint32 formId, const std::string &formId,
const std::string &formAction = "", const std::string &formAction = "",
uint32 minWidth = 0, uint32 minWidth = 0,
const std::string &templateName = ""); const std::string &templateName = "");

View file

@ -3118,6 +3118,7 @@ namespace NLGUI
_Cells.clear(); _Cells.clear();
_TR.clear(); _TR.clear();
_Forms.clear(); _Forms.clear();
_FormSubmit.clear();
_Groups.clear(); _Groups.clear();
_Divs.clear(); _Divs.clear();
_Anchors.clear(); _Anchors.clear();
@ -3328,19 +3329,29 @@ namespace NLGUI
// *************************************************************************** // ***************************************************************************
void CGroupHTML::submitForm (uint formId, const char *submitButtonType, const char *submitButtonName, const char *submitButtonValue, sint32 x, sint32 y) void CGroupHTML::submitForm(uint button, sint32 x, sint32 y)
{ {
// Form id valid ? if (button >= _FormSubmit.size())
if (formId < _Forms.size()) return;
for(uint formId = 0; formId < _Forms.size(); formId++)
{ {
_PostNextTime = true; // case sensitive search (user id is lowecase, auto id is uppercase)
_PostFormId = formId; if (_Forms[formId].id == _FormSubmit[button].form)
_PostFormSubmitType = submitButtonType; {
_PostFormSubmitButton = submitButtonName; _PostNextTime = true;
_PostFormSubmitValue = submitButtonValue; _PostFormId = formId;
_PostFormSubmitX = x; _PostFormSubmitType = _FormSubmit[button].type;
_PostFormSubmitY = y; _PostFormSubmitButton = _FormSubmit[button].name;
_PostFormSubmitValue = _FormSubmit[button].value;
_PostFormSubmitX = x;
_PostFormSubmitY = y;
return;
}
} }
nlwarning("Unable to find form '%s' to submit (button '%s')", _FormSubmit[button].form.c_str(), _FormSubmit[button].name.c_str());
} }
// *************************************************************************** // ***************************************************************************
@ -5063,31 +5074,22 @@ namespace NLGUI
} }
// *************************************************************************** // ***************************************************************************
void CGroupHTML::insertFormImageButton(const std::string &name, const std::string &tooltip, const std::string &src, const std::string &over, uint32 formId, const std::string &action, uint32 minWidth, const std::string &templateName) void CGroupHTML::insertFormImageButton(const std::string &name, const std::string &tooltip, const std::string &src, const std::string &over, const std::string &formId, const std::string &action, uint32 minWidth, const std::string &templateName)
{ {
// Action handler parameters : "name=group_html_id|form=id_of_the_form|submit_button=button_name" _FormSubmit.push_back(SFormSubmitButton(formId, name, "", "image"));
std::string param = "name=" + getId() + "|form=" + toString(formId) + "|submit_button=" + name + "|submit_button_type=image"; // Action handler parameters
std::string param = "name=" + getId() + "|button=" + toString(_FormSubmit.size()-1);
// Add the ctrl button // Add the ctrl button
addButton (CCtrlButton::PushButton, name, src, src, over, "html_submit_form", param.c_str(), tooltip.c_str(), _Style.Current); addButton (CCtrlButton::PushButton, name, src, src, over, "html_submit_form", param.c_str(), tooltip.c_str(), _Style.Current);
} }
// *************************************************************************** // ***************************************************************************
void CGroupHTML::insertFormTextButton(const std::string &name, const std::string &tooltip, const std::string &value, uint32 formId, const std::string &formAction, uint32 minWidth, const std::string &templateName) void CGroupHTML::insertFormTextButton(const std::string &name, const std::string &tooltip, const std::string &value, const std::string &formId, const std::string &formAction, uint32 minWidth, const std::string &templateName)
{ {
// The submit button _FormSubmit.push_back(SFormSubmitButton(formId, name, value, "submit"));
string buttonTemplate(!templateName.empty() ? templateName : DefaultButtonGroup); // Action handler parameters
string param = "name=" + getId() + "|button=" + toString(_FormSubmit.size()-1);
// Action handler parameters : "name=group_html_id|form=id_of_the_form|submit_button=button_name"
string param = "name=" + getId() + "|form=" + toString(formId) + "|submit_button=" + name + "|submit_button_type=submit";
if (!value.empty())
{
// escape AH param separator
string tmp = value;
while(NLMISC::strFindReplace(tmp, "|", "&#124;"))
;
param = param + "|submit_button_value=" + tmp;
}
// Add the ctrl button // Add the ctrl button
if (!_Paragraph) if (!_Paragraph)
@ -5096,12 +5098,12 @@ namespace NLGUI
paragraphChange (); paragraphChange ();
} }
string buttonTemplate(!templateName.empty() ? templateName : DefaultButtonGroup);
typedef pair<string, string> TTmplParam; typedef pair<string, string> TTmplParam;
vector<TTmplParam> tmplParams; vector<TTmplParam> tmplParams;
tmplParams.push_back(TTmplParam("id", name)); tmplParams.push_back(TTmplParam("id", name));
tmplParams.push_back(TTmplParam("onclick", "html_submit_form")); tmplParams.push_back(TTmplParam("onclick", "html_submit_form"));
tmplParams.push_back(TTmplParam("onclick_param", param)); tmplParams.push_back(TTmplParam("onclick_param", param));
//tmplParams.push_back(TTmplParam("text", text));
tmplParams.push_back(TTmplParam("active", "true")); tmplParams.push_back(TTmplParam("active", "true"));
if (minWidth > 0) tmplParams.push_back(TTmplParam("wmin", toString(minWidth))); if (minWidth > 0) tmplParams.push_back(TTmplParam("wmin", toString(minWidth)));
CInterfaceGroup *buttonGroup = CWidgetManager::getInstance()->getParser()->createGroupInstance(buttonTemplate, _Paragraph->getId(), tmplParams); CInterfaceGroup *buttonGroup = CWidgetManager::getInstance()->getParser()->createGroupInstance(buttonTemplate, _Paragraph->getId(), tmplParams);
@ -5474,6 +5476,12 @@ namespace NLGUI
{ {
// Build the form // Build the form
CGroupHTML::CForm form; CGroupHTML::CForm form;
// id check is case sensitive and auto id's are uppercase
form.id = toLower(trim(elm.getAttribute("id")));
if (form.id.empty())
{
form.id = toString("FORM%d", _Forms.size());
}
// Get the action name // Get the action name
if (elm.hasNonEmptyAttribute("action")) if (elm.hasNonEmptyAttribute("action"))
@ -5675,7 +5683,7 @@ namespace NLGUI
string src = elm.getAttribute("src"); string src = elm.getAttribute("src");
string over = elm.getAttribute("data-over-src"); string over = elm.getAttribute("data-over-src");
insertFormImageButton(name, tooltip, src, over, _Forms.size()-1, "", minWidth, templateName); insertFormImageButton(name, tooltip, src, over, _Forms.back().id, "", minWidth, templateName);
} }
else if (type == "button" || type == "submit") else if (type == "button" || type == "submit")
{ {
@ -5683,7 +5691,7 @@ namespace NLGUI
string name = elm.getAttribute("name"); string name = elm.getAttribute("name");
string value = elm.getAttribute("value"); string value = elm.getAttribute("value");
insertFormTextButton(name, tooltip, value, _Forms.size()-1, "", minWidth, templateName); insertFormTextButton(name, tooltip, value, _Forms.back().id, "", minWidth, templateName);
} }
else if (type == "text") else if (type == "text")
{ {

View file

@ -1103,20 +1103,18 @@ REGISTER_ACTION_HANDLER( CHandlerBrowseRefresh, "browse_refresh");
// *************************************************************************** // ***************************************************************************
/** Build the help window for a pact/item/brick and open it.
*/
class CHandlerHTMLSubmitForm : public IActionHandler class CHandlerHTMLSubmitForm : public IActionHandler
{ {
void execute (CCtrlBase *pCaller, const std::string &sParams) void execute (CCtrlBase *pCaller, const std::string &sParams)
{ {
string container = getParam (sParams, "name"); string container = getParam (sParams, "name");
uint form; uint button;
fromString(getParam (sParams, "form"), form); if (!fromString(getParam(sParams, "button"), button))
{
string submit_button = getParam (sParams, "submit_button"); nlwarning("Invalid button index: '%s', expected integer", getParam(sParams, "button").c_str());
string type = getParam (sParams, "submit_button_type"); return;
string value = getParam (sParams, "submit_button_value"); }
sint32 x = pCaller->getEventX(); sint32 x = pCaller->getEventX();
sint32 y = pCaller->getEventY(); sint32 y = pCaller->getEventY();
@ -1127,8 +1125,7 @@ class CHandlerHTMLSubmitForm : public IActionHandler
CGroupHTML *groupHtml = dynamic_cast<CGroupHTML*>(element); CGroupHTML *groupHtml = dynamic_cast<CGroupHTML*>(element);
if (groupHtml) if (groupHtml)
{ {
// Submit the form the url groupHtml->submitForm(button, x, y);
groupHtml->submitForm (form, type.c_str(), submit_button.c_str(), value.c_str(), x, y);
} }
} }
} }
@ -2339,11 +2336,11 @@ void setupCosmetic(CSheetHelpSetup &setup, CItemSheet *pIS)
void setupItemPreview(CSheetHelpSetup &setup, CItemSheet *pIS) void setupItemPreview(CSheetHelpSetup &setup, CItemSheet *pIS)
{ {
nlassert(pIS); nlassert(pIS);
CInterfaceManager *pIM = CInterfaceManager::getInstance(); CInterfaceManager *pIM = CInterfaceManager::getInstance();
CCDBNodeBranch *dbBranch = NLGUI::CDBManager::getInstance()->getDbBranch( setup.SrcSheet->getSheet() ); CCDBNodeBranch *dbBranch = NLGUI::CDBManager::getInstance()->getDbBranch( setup.SrcSheet->getSheet() );
CInterfaceElement *elt = setup.HelpWindow->getElement(setup.HelpWindow->getId()+setup.PrefixForExtra+INFO_ITEM_PREVIEW); CInterfaceElement *elt = setup.HelpWindow->getElement(setup.HelpWindow->getId()+setup.PrefixForExtra+INFO_ITEM_PREVIEW);
if (elt == NULL) if (elt == NULL)
return; return;
@ -2357,12 +2354,12 @@ void setupItemPreview(CSheetHelpSetup &setup, CItemSheet *pIS)
static sint32 helpWidth = setup.HelpWindow->getW(); static sint32 helpWidth = setup.HelpWindow->getW();
bool scene_inactive = ! NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:SHOW_3D_ITEM_PREVIEW")->getValueBool(); bool scene_inactive = ! NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:SHOW_3D_ITEM_PREVIEW")->getValueBool();
if (scene_inactive || if (scene_inactive ||
(pIS->Family != ITEMFAMILY::ARMOR && (pIS->Family != ITEMFAMILY::ARMOR &&
pIS->Family != ITEMFAMILY::MELEE_WEAPON && pIS->Family != ITEMFAMILY::MELEE_WEAPON &&
pIS->Family != ITEMFAMILY::RANGE_WEAPON && pIS->Family != ITEMFAMILY::RANGE_WEAPON &&
pIS->Family != ITEMFAMILY::SHIELD)) pIS->Family != ITEMFAMILY::SHIELD))
{ {
setup.HelpWindow->setW(helpWidth); setup.HelpWindow->setW(helpWidth);
ig->setActive(false); ig->setActive(false);
return; return;
@ -2372,7 +2369,7 @@ void setupItemPreview(CSheetHelpSetup &setup, CItemSheet *pIS)
setup.HelpWindow->setW(helpWidth + ITEM_PREVIEW_WIDTH); setup.HelpWindow->setW(helpWidth + ITEM_PREVIEW_WIDTH);
ig->setActive(true); ig->setActive(true);
} }
CInterface3DScene *sceneI = dynamic_cast<CInterface3DScene *>(ig->getGroup("scene_item_preview")); CInterface3DScene *sceneI = dynamic_cast<CInterface3DScene *>(ig->getGroup("scene_item_preview"));
if (!sceneI) if (!sceneI)
{ {
@ -2458,7 +2455,7 @@ void setupItemPreview(CSheetHelpSetup &setup, CItemSheet *pIS)
cs.VisualPropA.PropertySubData.HatColor = color->getValue32(); cs.VisualPropA.PropertySubData.HatColor = color->getValue32();
SCharacter3DSetup::setupDBFromCharacterSummary("UI:TEMP:CHAR3D", cs); SCharacter3DSetup::setupDBFromCharacterSummary("UI:TEMP:CHAR3D", cs);
camHeight = -0.35f; camHeight = -0.35f;
} }
} }
else if (pIS->Family == ITEMFAMILY::SHIELD) else if (pIS->Family == ITEMFAMILY::SHIELD)
{ {