From: <ave...@us...> - 2007-05-20 11:51:41
|
Revision: 4658 http://gemrb.svn.sourceforge.net/gemrb/?rev=4658&view=rev Author: avenger_teambg Date: 2007-05-20 04:51:39 -0700 (Sun, 20 May 2007) Log Message: ----------- implemented portrait change event (hp bar, state, portrait icons, etc) pst: implemented changing portraits based on state SetAnimation guiscript command will now accept an optional cycle parameter Modified Paths: -------------- gemrb/trunk/gemrb/GUIScripts/ie_stats.py gemrb/trunk/gemrb/GUIScripts/pst/GUICommonWindows.py gemrb/trunk/gemrb/plugins/Core/Actor.cpp gemrb/trunk/gemrb/plugins/Core/ControlAnimation.cpp gemrb/trunk/gemrb/plugins/Core/ControlAnimation.h gemrb/trunk/gemrb/plugins/Core/Game.cpp gemrb/trunk/gemrb/plugins/Core/Interface.cpp gemrb/trunk/gemrb/plugins/Core/Interface.h gemrb/trunk/gemrb/plugins/GUIScript/GUIScript.cpp Modified: gemrb/trunk/gemrb/GUIScripts/ie_stats.py =================================================================== --- gemrb/trunk/gemrb/GUIScripts/ie_stats.py 2007-05-12 18:32:35 UTC (rev 4657) +++ gemrb/trunk/gemrb/GUIScripts/ie_stats.py 2007-05-20 11:51:39 UTC (rev 4658) @@ -42,7 +42,11 @@ ENEMY = 255 # state bits (IE_STATE) +STATE_PANIC = 4 +STATE_HELPLESS = 1+ 8 + 32 +STATE_PETRIFIED = 64 + 128 STATE_DEAD = 2048 +STATE_POISONED = 0x4000 MC_FALLEN_PALADIN = 0x200 MC_FALLEN_RANGER = 0x400 Modified: gemrb/trunk/gemrb/GUIScripts/pst/GUICommonWindows.py =================================================================== --- gemrb/trunk/gemrb/GUIScripts/pst/GUICommonWindows.py 2007-05-12 18:32:35 UTC (rev 4657) +++ gemrb/trunk/gemrb/GUIScripts/pst/GUICommonWindows.py 2007-05-20 11:51:39 UTC (rev 4658) @@ -305,19 +305,40 @@ GemRB.SetButtonFlags (Window, ButtonHP, IE_GUI_BUTTON_NO_IMAGE, OP_SET) continue - #sel = GemRB.GameIsPCSelected (i+1) sel = GemRB.GameGetSelectedPCSingle () == i + 1 GemRB.SetButtonBAM (Window, Button, pic, 0, 0, -1) - GemRB.SetAnimation (Window, Button, pic) + + state = GemRB.GetPlayerStat (i+1, IE_STATE_ID) + hp = GemRB.GetPlayerStat (i+1, IE_HITPOINTS) + hp_max = GemRB.GetPlayerStat (i+1, IE_MAXHITPOINTS) + + if state & STATE_DEAD: + cycle = 9 + elif state & STATE_HELPLESS: + cycle = 8 + elif state & STATE_PETRIFIED: + cycle = 7 + elif state & STATE_PANIC: + cycle = 6 + elif state & STATE_POISONED: + cycle = 2 + elif hp<hp_max/5: + cycle = 4 + else: + cycle = 0 + + print "HP:",hp, ", ", hp_max + print "State:", state, "Cycle: ", cycle + + GemRB.SetAnimation (Window, Button, pic, cycle) - GemRB.SetButtonFlags(Window, Button, IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_ANIMATED | IE_GUI_BUTTON_PLAYRANDOM, OP_SET) - #GemRB.SetButtonFlags(Window, Button, IE_GUI_BUTTON_ANIMATED, OP_SET) + if cycle<6: + GemRB.SetButtonFlags(Window, Button, IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_ANIMATED | IE_GUI_BUTTON_PLAYRANDOM, OP_SET) + else: + GemRB.SetButtonFlags(Window, Button, IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_ANIMATED, OP_SET) GemRB.SetButtonFlags(Window, ButtonHP, IE_GUI_BUTTON_PICTURE, OP_SET) - hp = GemRB.GetPlayerStat (i+1, IE_HITPOINTS) - hp_max = GemRB.GetPlayerStat (i+1, IE_MAXHITPOINTS) - ratio = (hp + 0.0) / hp_max if ratio > 1.0: ratio = 1.0 r = int (255 * (1.0 - ratio)) Modified: gemrb/trunk/gemrb/plugins/Core/Actor.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/Core/Actor.cpp 2007-05-12 18:32:35 UTC (rev 4657) +++ gemrb/trunk/gemrb/plugins/Core/Actor.cpp 2007-05-20 11:51:39 UTC (rev 4658) @@ -576,6 +576,9 @@ void pcf_state(Actor *actor, ieDword Value) { + if (actor->InParty) { + core->SetEventFlag(EF_PORTRAIT); + } if (Value & STATE_PETRIFIED) { SetLockedPalette( actor, fullstone); return; @@ -599,6 +602,9 @@ actor->Die(NULL); } actor->Modified[IE_MINHITPOINTS]=Value; + if (actor->InParty) { + core->SetEventFlag(EF_PORTRAIT); + } } void pcf_maxhitpoint(Actor *actor, ieDword Value) @@ -607,6 +613,9 @@ actor->Modified[IE_HITPOINTS]=Value; pcf_hitpoint(actor,Value); } + if (actor->InParty) { + core->SetEventFlag(EF_PORTRAIT); + } } void pcf_minhitpoint(Actor *actor, ieDword Value) @@ -630,6 +639,9 @@ if ((signed) Value<=0) { actor->Die(NULL); } + if (actor->InParty) { + core->SetEventFlag(EF_PORTRAIT); + } } void pcf_gold(Actor *actor, ieDword /*Value*/) Modified: gemrb/trunk/gemrb/plugins/Core/ControlAnimation.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/Core/ControlAnimation.cpp 2007-05-12 18:32:35 UTC (rev 4657) +++ gemrb/trunk/gemrb/plugins/Core/ControlAnimation.cpp 2007-05-20 11:51:39 UTC (rev 4658) @@ -27,11 +27,11 @@ #include "Button.h" -ControlAnimation::ControlAnimation(Control* ctl, ieResRef ResRef) +ControlAnimation::ControlAnimation(Control* ctl, ieResRef ResRef, int Cycle) { control = NULL; bam = NULL; - cycle = 0; + cycle = Cycle; frame = 0; anim_phase = 0; @@ -55,19 +55,37 @@ bam = NULL; } +bool ControlAnimation::SameResource(ieResRef ResRef, int Cycle) +{ + if (!control ) return false; + if (!bam) return false; + if (memcmp(ResRef, bam->ResRef, sizeof(ieResRef) )) return false; + int c = cycle; + if (control->Flags&IE_GUI_BUTTON_PLAYRANDOM) { + c&=~1; + } + if (Cycle!=c) return false; + return true; +} + void ControlAnimation::UpdateAnimation(void) { unsigned long time; + int Cycle = cycle; if (control->Flags & IE_GUI_BUTTON_PLAYRANDOM) { // simple Finite-State Machine if (anim_phase == 0) { - cycle = 0; frame = 0; anim_phase = 1; time = 500 + 500 * (rand() % 20); + cycle&=~1; + Cycle=cycle; } else if (anim_phase == 1) { - if (rand() % 30 == 0) cycle = 1; + if (rand() % 30 == 0) { + cycle|=1; + Cycle=cycle; + } anim_phase = 2; time = 100; } else { @@ -79,7 +97,7 @@ time = 15; } - Sprite2D* pic = bam->GetFrame( (unsigned short) frame, (unsigned char) cycle ); + Sprite2D* pic = bam->GetFrame( (unsigned short) frame, (unsigned char) Cycle ); if (pic == NULL) { //stopping at end frame Modified: gemrb/trunk/gemrb/plugins/Core/ControlAnimation.h =================================================================== --- gemrb/trunk/gemrb/plugins/Core/ControlAnimation.h 2007-05-12 18:32:35 UTC (rev 4657) +++ gemrb/trunk/gemrb/plugins/Core/ControlAnimation.h 2007-05-20 11:51:39 UTC (rev 4658) @@ -54,9 +54,11 @@ unsigned int frame; unsigned int anim_phase; public: - ControlAnimation(Control* ctl, ieResRef ResRef); + ControlAnimation(Control* ctl, ieResRef ResRef, int Cycle = 0); ~ControlAnimation(void); void UpdateAnimation(); + //report if the current resource is the same as descripted by the params + bool SameResource(ieResRef ResRef, int Cycle); }; #endif Modified: gemrb/trunk/gemrb/plugins/Core/Game.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/Core/Game.cpp 2007-05-12 18:32:35 UTC (rev 4657) +++ gemrb/trunk/gemrb/plugins/Core/Game.cpp 2007-05-20 11:51:39 UTC (rev 4658) @@ -941,7 +941,7 @@ case BM_AND: ControlStatus&=value; break; case BM_XOR: ControlStatus^=value; break; } - core->EventFlag|=EF_CONTROL; + core->SetEventFlag(EF_CONTROL); } void Game::AddGold(ieDword add) Modified: gemrb/trunk/gemrb/plugins/Core/Interface.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/Core/Interface.cpp 2007-05-12 18:32:35 UTC (rev 4657) +++ gemrb/trunk/gemrb/plugins/Core/Interface.cpp 2007-05-20 11:51:39 UTC (rev 4658) @@ -542,6 +542,15 @@ return; } + if (EventFlag&EF_PORTRAIT) { + ieDword tmp = (ieDword) ~0; + vars->Lookup( "PortraitWindow", tmp ); + if (tmp != (ieDword) ~0) { + EventFlag&=~EF_PORTRAIT; + guiscript->RunFunction( "UpdatePortraitWindow" ); + } + } + if (EventFlag&EF_CONTROL) { EventFlag&=~EF_CONTROL; guiscript->RunFunction( "UpdateControlStatus" ); Modified: gemrb/trunk/gemrb/plugins/Core/Interface.h =================================================================== --- gemrb/trunk/gemrb/plugins/Core/Interface.h 2007-05-12 18:32:35 UTC (rev 4657) +++ gemrb/trunk/gemrb/plugins/Core/Interface.h 2007-05-20 11:51:39 UTC (rev 4658) @@ -156,6 +156,7 @@ //they wait until the condition is right #define EF_CONTROL 1 #define EF_SHOWMAP 2 +#define EF_PORTRAIT 4 //autopause #define AP_UNUSABLE 0 @@ -677,16 +678,21 @@ /** Sends a termination signal to the Video Driver */ bool Quit(void); /** CheatKey support */ - void EnableCheatKeys(int Flag) + inline void EnableCheatKeys(int Flag) { CheatFlag=(Flag > 0); } - bool CheatEnabled() + inline bool CheatEnabled() { return CheatFlag; } + inline void SetEventFlag(int Flag) + { + EventFlag|=Flag; + } + /** Next Script Name */ char NextScript[64]; /** Console is on Screen */ Modified: gemrb/trunk/gemrb/plugins/GUIScript/GUIScript.cpp =================================================================== --- gemrb/trunk/gemrb/plugins/GUIScript/GUIScript.cpp 2007-05-12 18:32:35 UTC (rev 4657) +++ gemrb/trunk/gemrb/plugins/GUIScript/GUIScript.cpp 2007-05-20 11:51:39 UTC (rev 4658) @@ -1406,7 +1406,7 @@ return NULL; } if (!WindowIndex) { - core->EventFlag|=EF_CONTROL; + core->SetEventFlag(EF_CONTROL); } Py_INCREF( Py_None ); @@ -2870,15 +2870,16 @@ } PyDoc_STRVAR( GemRB_SetAnimation__doc, -"SetAnimation(WindowIndex, ControlIndex, BAMResRef)\n\n" -"Sets the animation of a Button Control from a BAM file."); +"SetAnimation(WindowIndex, ControlIndex, BAMResRef[, Cycle])\n\n" +"Sets the animation of a Control (usually a Button) from a BAM file. Optionally an animation cycle could be set too."); static PyObject* GemRB_SetAnimation(PyObject * /*self*/, PyObject* args) { int wi, ci; char* ResRef; + int Cycle = 0; - if (!PyArg_ParseTuple( args, "iis", &wi, &ci, &ResRef )) { + if (!PyArg_ParseTuple( args, "iis|i", &wi, &ci, &ResRef, &Cycle )) { return AttributeError( GemRB_SetAnimation__doc ); } @@ -2887,8 +2888,14 @@ return NULL; } - //who knows, there might have been lurking an active animation + //who knows, there might have been an active animation lurking if (ctl->animation) { + //if this control says the resource is the same + //we are just setting now don't reset it + if(ctl->animation->SameResource(ResRef, Cycle)) { + Py_INCREF( Py_None ); + return Py_None; + } delete ctl->animation; ctl->animation = NULL; } @@ -2899,7 +2906,7 @@ return Py_None; } - ControlAnimation* anim = new ControlAnimation( ctl, ResRef ); + ControlAnimation* anim = new ControlAnimation( ctl, ResRef, Cycle ); anim->UpdateAnimation(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |