From: Laszlo T. <ave...@us...> - 2005-12-04 21:09:42
|
Update of /cvsroot/gemrb/gemrb/gemrb/plugins/GUIScript In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12632/plugins/GUIScript Modified Files: GUIScript.cpp Log Message: added code to handle formations better continued implementation of ActionsWindow Index: GUIScript.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/GUIScript/GUIScript.cpp,v retrieving revision 1.352 retrieving revision 1.353 diff -C2 -d -r1.352 -r1.353 *** GUIScript.cpp 3 Dec 2005 23:49:33 -0000 1.352 --- GUIScript.cpp 4 Dec 2005 21:09:32 -0000 1.353 *************** *** 76,79 **** --- 76,82 ---- static int ReputationIncrease[20]={0xcccccccc}; static int ReputationDonation[20]={0xcccccccc}; + //4 action button indices are packed on a single ieDword, there are 32 max. + static ieDword GUIAction[32]={0xcccccccc}; + static ieDword GUITooltip[32]; // Natural screen size of currently loaded winpack *************** *** 3178,3202 **** PyDoc_STRVAR( GemRB_GameGetFormation__doc, ! "GameGetFormation() => int\n\n" ! "Returns current party formation." ); ! static PyObject* GemRB_GameGetFormation(PyObject * /*self*/, PyObject* /*args*/) { ! int Formation = core->GetGame()->WhichFormation; return PyInt_FromLong( Formation ); } PyDoc_STRVAR( GemRB_GameSetFormation__doc, ! "GameSetFormation(Formation)\n\n" ! "Sets party formation." ); static PyObject* GemRB_GameSetFormation(PyObject * /*self*/, PyObject* args) { ! int Formation; ! if (!PyArg_ParseTuple( args, "i", &Formation )) { return AttributeError( GemRB_GameSetFormation__doc ); } ! core->GetGame()->WhichFormation = Formation; Py_INCREF( Py_None ); --- 3181,3225 ---- PyDoc_STRVAR( GemRB_GameGetFormation__doc, ! "GameGetFormation([Which]) => int\n\n" ! "Returns current party formation. If Which was supplied, it returns one of the preset formations." ); ! static PyObject* GemRB_GameGetFormation(PyObject * /*self*/, PyObject* args) { ! int Which = -1; ! int Formation; ! ! if (!PyArg_ParseTuple( args, "|i", &Which )) { ! return AttributeError( GemRB_GameGetFormation__doc ); ! } ! if (Which<0) { ! Formation = core->GetGame()->WhichFormation; ! } else { ! if (Which>4) { ! return AttributeError( GemRB_GameGetFormation__doc ); ! } ! Formation = core->GetGame()->Formations[Which]; ! } return PyInt_FromLong( Formation ); } PyDoc_STRVAR( GemRB_GameSetFormation__doc, ! "GameSetFormation(Formation[, Which])\n\n" ! "Sets party formation. If Which was supplied, it sets one of the preset formations." ); static PyObject* GemRB_GameSetFormation(PyObject * /*self*/, PyObject* args) { ! int Formation, Which=-1; ! if (!PyArg_ParseTuple( args, "i|i", &Formation, &Which )) { return AttributeError( GemRB_GameSetFormation__doc ); } ! if (Which<0) { ! core->GetGame()->WhichFormation = Formation; ! } else { ! if (Which>4) { ! return AttributeError( GemRB_GameSetFormation__doc ); ! } ! core->GetGame()->Formations[Which] = Formation; ! } Py_INCREF( Py_None ); *************** *** 5507,5510 **** --- 5530,5629 ---- return Py_None; } + + typedef union pack { + ieDword data; + ieByte bytes[4]; + } packtype; + + static void ReadActionButtons() + { + memset(GUIAction, -1, sizeof(GUIAction)); + memset(GUITooltip, -1, sizeof(GUITooltip)); + int table = core->LoadTable( "guibtact" ); + if (table<0) { + return; + } + TableMgr *tab = core->GetTable( table ); + for (int i = 0; i < 32; i++) { + packtype row; + + row.bytes[0] = (ieByte) atoi( tab->QueryField(i,0) ); + row.bytes[1] = (ieByte) atoi( tab->QueryField(i,1) ); + row.bytes[2] = (ieByte) atoi( tab->QueryField(i,2) ); + row.bytes[3] = (ieByte) atoi( tab->QueryField(i,3) ); + GUIAction[i] = row.data; + GUITooltip[i] = atoi( tab->QueryField(i,4) ); + } + core->DelTable( table ); + + } + + PyDoc_STRVAR( GemRB_SetActionIcon__doc, + "SetActionIcon(Window, Button, ActionIndex)\n\n" + "Sets up an action button. The ActionIndex should be less than 32." ); + + static PyObject* GemRB_SetActionIcon(PyObject * /*self*/, PyObject* args) + { + int WindowIndex, ControlIndex, Index; + + if (!PyArg_ParseTuple( args, "iii", &WindowIndex, &ControlIndex, &Index )) { + return AttributeError( GemRB_SetActionIcon__doc ); + } + + Button* btn = ( Button* ) GetControl(WindowIndex, ControlIndex, IE_GUI_BUTTON); + if (!btn) { + return NULL; + } + + if (Index<0) { + btn->SetImage( IE_GUI_BUTTON_UNPRESSED, 0 ); + btn->SetImage( IE_GUI_BUTTON_PRESSED, 0 ); + btn->SetImage( IE_GUI_BUTTON_SELECTED, 0 ); + btn->SetImage( IE_GUI_BUTTON_DISABLED, 0 ); + btn->SetFlags( IE_GUI_BUTTON_NO_IMAGE, BM_SET ); + core->SetTooltip( WindowIndex, ControlIndex, "" ); + Py_INCREF( Py_None ); + return Py_None; + } + + if (Index>32) { + return AttributeError( GemRB_SetActionIcon__doc ); + } + if (GUIAction[0]==0xcccccccc) { + ReadActionButtons(); + } + AnimationMgr* bam = ( AnimationMgr* ) + core->GetInterface( IE_BAM_CLASS_ID ); + //FIXME: this is a hardcoded resource (pst has no such one) + DataStream *str = core->GetResourceMgr()->GetResource( "GUIBTACT", IE_BAM_CLASS_ID ); + if (!bam->Open(str, true) ) { + return RuntimeError( "BAM not found" ); + } + packtype row; + + row.data = GUIAction[Index]; + Sprite2D *tspr = bam->GetFrameFromCycle( 0, row.bytes[0]); + btn->SetImage( IE_GUI_BUTTON_UNPRESSED, tspr ); + tspr = bam->GetFrameFromCycle( 0, row.bytes[1]); + btn->SetImage( IE_GUI_BUTTON_PRESSED, tspr ); + tspr = bam->GetFrameFromCycle( 0, row.bytes[2]); + btn->SetImage( IE_GUI_BUTTON_SELECTED, tspr ); + tspr = bam->GetFrameFromCycle( 0, row.bytes[3]); + btn->SetImage( IE_GUI_BUTTON_DISABLED, tspr ); + core->FreeInterface( bam ); + btn->SetFlags( IE_GUI_BUTTON_NORMAL, BM_SET ); + char *txt = core->GetString( GUITooltip[Index] ); + if (txt) { + char *txt2 = (char *) malloc(strlen(txt)+6); + sprintf(txt2,"F%1.1d - %s",ControlIndex+1,txt); + free(txt); + core->SetTooltip(WindowIndex, ControlIndex, txt2); + free (txt2); + } else { + core->SetTooltip(WindowIndex, ControlIndex, ""); + } + Py_INCREF( Py_None ); + return Py_None; + } static PyMethodDef GemRBMethods[] = { *************** *** 5533,5537 **** METHOD(GameGetPartyGold, METH_NOARGS), METHOD(GameSetPartyGold, METH_VARARGS), ! METHOD(GameGetFormation, METH_NOARGS), METHOD(GameSetFormation, METH_VARARGS), METHOD(GetJournalSize, METH_VARARGS), --- 5652,5656 ---- METHOD(GameGetPartyGold, METH_NOARGS), METHOD(GameSetPartyGold, METH_VARARGS), ! METHOD(GameGetFormation, METH_VARARGS), METHOD(GameSetFormation, METH_VARARGS), METHOD(GetJournalSize, METH_VARARGS), *************** *** 5687,5690 **** --- 5806,5810 ---- METHOD(GetAbilityBonus, METH_VARARGS), METHOD(LeaveParty, METH_VARARGS), + METHOD(SetActionIcon, METH_VARARGS), // terminating entry {NULL, NULL, 0, NULL} *************** *** 5693,5697 **** void initGemRB() { ! /*PyObject * m =*/ Py_InitModule( "GemRB", GemRBMethods ); } --- 5813,5817 ---- void initGemRB() { ! Py_InitModule( "GemRB", GemRBMethods ); } *************** *** 5716,5719 **** --- 5836,5842 ---- } StoreSpellsCount=-1; + ReputationIncrease[0]=0xcccccccc; + ReputationDonation[0]=0xcccccccc; + GUIAction[0]=0xcccccccc; } *************** *** 5792,5795 **** --- 5915,5919 ---- pMainDic = PyModule_GetDict( pMainMod ); /* pMainDic is a borrowed reference */ + return true; } |