TRIGRET_TYPE CClient::Dialog_OnButton( RESOURCE_ID_BASE rid, DWORD dwButtonID, CObjBase * pObj, CDialogResponseArgs * pArgs ) { ADDTOCALLSTACK("CClient::Dialog_OnButton"); // one of the gump dialog buttons was pressed. if ( !pObj ) // object is gone ? return TRIGRET_ENDIF; CResourceLock s; if ( !g_Cfg.ResourceLock(s, RESOURCE_ID(RES_DIALOG, rid.GetResIndex(), RES_DIALOG_BUTTON)) ) return TRIGRET_ENDIF; INT64 piCmd[3]; while ( s.ReadKeyParse()) { if ( ! s.IsKeyHead( "ON", 2 )) continue; size_t iArgs = Str_ParseCmds( s.GetArgStr(), piCmd, COUNTOF(piCmd) ); if ( iArgs == 0 ) continue; if ( iArgs == 1 ) { // single button value if ( (DWORD)piCmd[0] != dwButtonID ) continue; } else { // range of button values if ( dwButtonID < (DWORD)piCmd[0] || dwButtonID > (DWORD)piCmd[1] ) continue; } pArgs->m_iN1 = dwButtonID; return pObj->OnTriggerRunVal( s, TRIGRUN_SECTION_TRUE, m_pChar, pArgs ); } return( TRIGRET_ENDIF ); }
size_t CClient::Cmd_Skill_Menu_Build( RESOURCE_ID_BASE rid, int iSelect, CMenuItem *item, size_t iMaxSize, bool &fShowMenu, bool &fLimitReached ) { ADDTOCALLSTACK("CClient::Cmd_Skill_Menu_Build"); // Build the skill menu for the curent active skill. // Only list the things we have skill and ingrediants to make. // // ARGS: // m_Targ_UID = the object used to get us here. // rid = which menu ? // iSelect = -2 = Just a test of the whole menu., // iSelect = -1 = 1st setup. // iSelect = 0 = cancel // iSelect = x = execute the selection. // fShowMenu = whether or not menus can be shown // item = pointer to entries list // iMaxSize = maximum number of entries // // RETURN: number of entries in menu // m_tmMenu.m_Item = the menu entries. ASSERT(m_pChar); if ( rid.GetResType() != RES_SKILLMENU ) return 0; // Find section. CResourceLock s; if ( !g_Cfg.ResourceLock(s, rid) ) return 0; // Get title line if ( !s.ReadKey() ) return 0; if ( iSelect == 0 ) // cancelled { while ( s.ReadKeyParse() ) { if ( !s.IsKey("ON") || (*s.GetArgStr() != '@') ) continue; if ( strcmpi(s.GetArgStr(), "@Cancel") ) continue; if ( m_pChar->OnTriggerRunVal(s, TRIGRUN_SECTION_TRUE, m_pChar, NULL) == TRIGRET_RET_TRUE ) return 0; break; } return 1; } if ( iSelect < 0 ) { item[0].m_sText = s.GetKey(); if ( iSelect == -1 ) m_tmMenu.m_ResourceID = rid; } bool fSkip = false; // skip this if we lack resources or skill. int iOnCount = 0; size_t iShowCount = 0; CScriptTriggerArgs Args; while ( s.ReadKeyParse()) { if ( s.IsKeyHead("ON", 2) ) { if ( *s.GetArgStr() == '@' ) { fSkip = true; continue; } // a new option to look at. fSkip = false; iOnCount++; if ( iSelect < 0 ) // building up the list. { if ( iSelect < -1 && iShowCount >= 1 ) // just a test. so we are done. return 1; iShowCount++; if ( !item[iSelect == -2 ? 0 : iShowCount].ParseLine(s.GetArgRaw(), NULL, m_pChar) ) { // remove if the item is invalid. iShowCount--; fSkip = true; continue; } if ( iSelect == -1 ) m_tmMenu.m_Item[iShowCount] = iOnCount; if ( iShowCount >= (iMaxSize - 1) ) break; } else { if ( iOnCount > iSelect ) // we are done. break; } continue; } if ( fSkip ) // we have decided we cant do this option. continue; if ( iSelect > 0 && iOnCount != iSelect ) // only interested in the selected option continue; // Check for a skill / non-consumables required. if ( s.IsKey("TEST") ) { m_pChar->ParseText(s.GetArgRaw(), m_pChar); CResourceQtyArray skills(s.GetArgStr()); if ( !skills.IsResourceMatchAll(m_pChar) ) { iShowCount--; fSkip = true; } continue; } if ( s.IsKey("TESTIF") ) { m_pChar->ParseText(s.GetArgRaw(), m_pChar); if ( !s.GetArgVal() ) { iShowCount--; fSkip = true; } continue; } // select to execute any entries here ? if ( iOnCount == iSelect ) { // Execute command from script TRIGRET_TYPE tRet = m_pChar->OnTriggerRunVal(s, TRIGRUN_SINGLE_EXEC, m_pChar, &Args); if ( tRet != TRIGRET_RET_DEFAULT ) return tRet == TRIGRET_RET_TRUE ? 0 : 1; iShowCount++; // we are good. but continue til the end } else { ASSERT(iSelect < 0); if ( s.IsKey("SKILLMENU") ) { static int sm_iReentrant = 0; if ( sm_iReentrant > 1024 ) { if ( g_Cfg.m_wDebugFlags & DEBUGF_SCRIPTS ) g_Log.EventDebug("SCRIPT: Too many skill menus (circular menus?) to continue searching in menu '%s'\n", g_Cfg.ResourceGetDef(rid)->GetResourceName()); fLimitReached = true; } else { // Test if there is anything in this skillmenu we can do. ++sm_iReentrant; if ( !Cmd_Skill_Menu_Build(g_Cfg.ResourceGetIDType(RES_SKILLMENU, s.GetArgStr()), -2, *&item, iMaxSize, fShowMenu, fLimitReached) ) { iShowCount--; fSkip = true; } else fShowMenu = true; --sm_iReentrant; } continue; } if ( s.IsKey("MAKEITEM") ) { // test if i can make this item using m_Targ_UID. // There should ALWAYS be a valid id here. if ( !m_pChar->Skill_MakeItem(static_cast<ITEMID_TYPE>(g_Cfg.ResourceGetIndexType(RES_ITEMDEF, s.GetArgStr())), m_Targ_UID, SKTRIG_SELECT) ) { iShowCount--; fSkip = true; } continue; } } } return iShowCount; }
bool CWebPageDef::ServPagePost( CClient * pClient, LPCTSTR pszURLArgs, TCHAR * pContentData, int iContentLength ) { ADDTOCALLSTACK("CWebPageDef::ServPagePost"); UNREFERENCED_PARAMETER(pszURLArgs); // RETURN: true = this was the page of interest. ASSERT(pClient); if ( pContentData == NULL || iContentLength <= 0 ) return( false ); if ( ! HasTrigger(XTRIG_UNKNOWN)) // this form has no triggers. return( false ); // Parse the data. pContentData[iContentLength] = 0; TCHAR * ppArgs[64]; size_t iArgs = Str_ParseCmds(pContentData, ppArgs, COUNTOF(ppArgs), "&"); if (( iArgs <= 0 ) || ( iArgs >= 63 )) return false; // T or TXT or TEXT = the text fields. // B or BTN or BUTTON = the buttons // C or CHK or CHECK = the check boxes CDialogResponseArgs resp; DWORD dwButtonID = ULONG_MAX; for ( size_t i = 0; i < iArgs; i++ ) { TCHAR * pszNum = ppArgs[i]; while ( IsAlpha(*pszNum) ) pszNum++; int iNum = ATOI(pszNum); while ( *pszNum ) { if ( *pszNum == '=' ) { pszNum++; break; } pszNum++; } switch ( toupper(ppArgs[i][0]) ) { case 'B': dwButtonID = iNum; break; case 'C': if ( !iNum ) continue; if ( ATOI(pszNum) ) { resp.m_CheckArray.Add( iNum ); } break; case 'T': if ( iNum > 0 ) { TCHAR *pszData = Str_GetTemp(); HtmlDeCode( pszData, pszNum ); resp.AddText(static_cast<WORD>(iNum), pszData); } break; } } // Use the data in RES_WEBPAGE block. CResourceLock s; if ( !ResourceLock(s) ) return false; // Find the correct entry point. while ( s.ReadKeyParse()) { if ( !s.IsKeyHead("ON", 2) || ( (DWORD)s.GetArgVal() != dwButtonID )) continue; OnTriggerRunVal(s, TRIGRUN_SECTION_TRUE, pClient, &resp); return true; } // Put up some sort of failure page ? return( false ); }