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

--HG--
branch : develop
feature/clean-deprecated
Nimetu 6 years ago
parent bd5c03ebf0
commit 742092fd6b

@ -107,7 +107,7 @@ namespace NLGUI
void refresh();
// 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
void browseError (const char *msg);
@ -600,6 +600,9 @@ namespace NLGUI
sint InitialSelection; // initial selection for the combo box
};
// <form> element "id" attribute
std::string id;
// The action the form has to perform
std::string Action;
@ -607,6 +610,23 @@ namespace NLGUI
std::vector<CEntry> Entries;
};
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;
// Cells parameters
@ -823,7 +843,7 @@ namespace NLGUI
const std::string &tooltip,
const std::string &src,
const std::string &over,
uint32 formId,
const std::string &formId,
const std::string &formAction = "",
uint32 minWidth = 0,
const std::string &templateName = "");
@ -831,7 +851,7 @@ namespace NLGUI
void insertFormTextButton(const std::string &name,
const std::string &tooltip,
const std::string &value,
uint32 formId,
const std::string &formId,
const std::string &formAction = "",
uint32 minWidth = 0,
const std::string &templateName = "");

@ -3118,6 +3118,7 @@ namespace NLGUI
_Cells.clear();
_TR.clear();
_Forms.clear();
_FormSubmit.clear();
_Groups.clear();
_Divs.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 (formId < _Forms.size())
if (button >= _FormSubmit.size())
return;
for(uint formId = 0; formId < _Forms.size(); formId++)
{
_PostNextTime = true;
_PostFormId = formId;
_PostFormSubmitType = submitButtonType;
_PostFormSubmitButton = submitButtonName;
_PostFormSubmitValue = submitButtonValue;
_PostFormSubmitX = x;
_PostFormSubmitY = y;
// case sensitive search (user id is lowecase, auto id is uppercase)
if (_Forms[formId].id == _FormSubmit[button].form)
{
_PostNextTime = true;
_PostFormId = formId;
_PostFormSubmitType = _FormSubmit[button].type;
_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"
std::string param = "name=" + getId() + "|form=" + toString(formId) + "|submit_button=" + name + "|submit_button_type=image";
_FormSubmit.push_back(SFormSubmitButton(formId, name, "", "image"));
// Action handler parameters
std::string param = "name=" + getId() + "|button=" + toString(_FormSubmit.size()-1);
// Add the ctrl button
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
string buttonTemplate(!templateName.empty() ? templateName : DefaultButtonGroup);
// 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;
}
_FormSubmit.push_back(SFormSubmitButton(formId, name, value, "submit"));
// Action handler parameters
string param = "name=" + getId() + "|button=" + toString(_FormSubmit.size()-1);
// Add the ctrl button
if (!_Paragraph)
@ -5096,12 +5098,12 @@ namespace NLGUI
paragraphChange ();
}
string buttonTemplate(!templateName.empty() ? templateName : DefaultButtonGroup);
typedef pair<string, string> TTmplParam;
vector<TTmplParam> tmplParams;
tmplParams.push_back(TTmplParam("id", name));
tmplParams.push_back(TTmplParam("onclick", "html_submit_form"));
tmplParams.push_back(TTmplParam("onclick_param", param));
//tmplParams.push_back(TTmplParam("text", text));
tmplParams.push_back(TTmplParam("active", "true"));
if (minWidth > 0) tmplParams.push_back(TTmplParam("wmin", toString(minWidth)));
CInterfaceGroup *buttonGroup = CWidgetManager::getInstance()->getParser()->createGroupInstance(buttonTemplate, _Paragraph->getId(), tmplParams);
@ -5474,6 +5476,12 @@ namespace NLGUI
{
// Build the 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
if (elm.hasNonEmptyAttribute("action"))
@ -5675,7 +5683,7 @@ namespace NLGUI
string src = elm.getAttribute("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")
{
@ -5683,7 +5691,7 @@ namespace NLGUI
string name = elm.getAttribute("name");
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")
{

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

Loading…
Cancel
Save