| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150 |
- #include "..\..\..\common_h/mission/Mission.h"
- #include "csProgressBar.h"
- #include "..\Utils\InterfaceUtils.h"
- static const char TOP_LEFT [] = "Top-left";
- static const char TOP_RIGHT [] = "Top-right";
- static const char BOTTOM_LEFT [] = "Bottom-left";
- static const char BOTTOM_RIGHT[] = "Bottom-right";
- /*
- const float MaxAddDecEffectTime = 1.0f;
- const float MaxShowEffectTime = 0.8f;
- */
- csProgressBar::csProgressBar()
- {
- m_restart = false;
- m_fValue = 0.0f;
- m_fPrevValue = 0.0f;
- m_fPercent = 0.5f;
- m_pHPObject.Reset();
- MaxAddDecEffectTime = 1.0f;
- MaxShowEffectTime = 0.8f;
- m_fValue = 0.0f;
- m_showAddDecEffect = false;
- m_showEffectTime = 0.0f;
- pRS = (IRender*)api->GetService("DX9Render");
- Assert(pRS)
- barTexture = pRS->GetTechniqueGlobalVariable("interfaceTexture",_FL_);
- texture = NULL;
- drawLevel = ML_GUI2;
- }
- csProgressBar::~csProgressBar()
- {
- if( texture )
- {
- texture->Release();
- texture = null;
- }
- barTexture = null;
- }
- void csProgressBar::Restart()
- {
- m_restart = true;
- ReCreate();
- }
- // Вызывается в режиме игры после создания всех объектов
- void csProgressBar::PostCreate()
- {
- if( !m_pHPObject.Ptr() && !m_params.HPObject.IsEmpty())
- {
- FindObject(m_params.HPObject,m_pHPObject);
- if( m_pHPObject.Ptr())
- {
- m_fPrevValue = m_fValue = m_pHPObject.Ptr()->GetHP();
- }
- }
- m_pHPObject.Validate();
- }
- //Создание объекта
- bool csProgressBar::Create (MOPReader & reader)
- {
- if( !m_restart )
- {
- Render().GetShaderId("interfaceQuad",GUI_Quad_id);
- }
- EditMode_Update(reader);
- return true;
- }
- //Обновление параметров
- bool csProgressBar::EditMode_Update(MOPReader & reader)
- {
- ////////////////////////////////////////////////
- // BaseGUIElement::EditMode_Update(reader); //
- ////////////////////////////////////////////////
- if( !m_restart )
- {
- // m_aspect = InterfaceUtils::AspectRatio(Render());
- InitAspect();
- }
- Layout layout;
- switch( reader.Enum().c_str()[0] )
- {
- case 'C':
- layout = OnCenter;
- break;
- case 'L':
- layout = OnLeft;
- break;
- case 'R':
- layout = OnRight;
- break;
- };
- if( !Restricted(preserveLayout))
- m_layout = layout;
- m_natLay = layout;
- back_t = reader.String().c_str();
- fron_t = reader.String().c_str();
- if( !m_restart )
- {
- if( texture )
- texture->Release();
- // texture = (ITexture *)pRS->CreateTexture(_FL_,fron_t);
- texture = (ITexture *)pRS->CreateTextureFullQuality(_FL_,fron_t);
- m_backRender.SetTexture(back_t);
- m_frontRender.SetTexture(fron_t);
- }
- // m_params.fX = reader.Float();
- // m_params.fY = reader.Float();
- float x = reader.Float();
- float y = reader.Float();
- if( !Restricted(preservePos))
- MoveTo(x,y);
- m_natPos.x = x;
- m_natPos.y = y;
- // m_params.fWidth = reader.Float();
- // m_params.fHeight = reader.Float();
- float w = reader.Float();
- float h = reader.Float();
- if( !Restricted(preserveSize))
- SizeTo(w,h);
- m_natSize.w = w;
- m_natSize.h = h;
- m_fValue = m_params.fMaxValue = (float)reader.Long();
- m_fPrevValue = 0.0f;
- m_params.HPObject = reader.String();
- fMinBorder = reader.Float() * 0.01f;
- fMaxBorder = reader.Float() * 0.01f;
- m_params.fStartBar = reader.Float() * 0.01f;
- m_params.fEndBar = reader.Float() * 0.01f;
- m_params.drawPriority = reader.Long();
- m_res = reader.Enum().c_str();
- m_params.doShowEffect = reader.Bool();
- // Show(reader.Bool());
- nativeShow = reader.Bool();
- MaxAddDecEffectTime = reader.Float();
- MaxShowEffectTime = reader.Float();
- circular = reader.Bool();
- reverse = reader.Bool();
- vertical = reader.Bool();
- inverse = reader.Bool();
- // MoveTo(m_params.fX ,m_params.fY);
- // SizeTo(m_params.fWidth,m_params.fHeight);
- SetAlpha (reader.Float());
- SetParent(reader.String());
- // SetUpdate(&csProgressBar::InitFunc,ML_FIRST);
- SetUpdate(&csProgressBar::InitFunc,ML_FIRST + 2);
- return true;
- }
- void csProgressBar::OnParentNotify(Notification event)
- {
- BaseGUIElement::OnParentNotify(event);
- if( event == ParentChanged )
- Update();
- }
- // извращенный расчет ректа
- void csProgressBar::GetRect(Rect &rect, bool useOffset)// const
- {
- float x = m_X;
- float y = m_Y;
- float w = GetWidth ()*m_aspect;
- float h = GetHeight();
- if( w >= 0.0f )
- {
- rect.l = x;
- rect.t = y;
- rect.r = x + w;
- rect.b = y + h;
- }
- else
- {
- rect.l = x + w;
- rect.t = y;
- rect.r = x;
- rect.b = y + h;
- }
- }
- void _cdecl csProgressBar::InitFunc(float, long)
- {
- DelUpdate(&csProgressBar::InitFunc);
- if( m_restart )
- {
- m_restart = false;
- }
- else
- {
- BaseGUIElement *parent = GetParent();
- if( BaseGUIElement *newParent = FindParent())
- {
- newParent->Register(this);
- }
- else
- {
- if( parent )
- parent->UnRegister(this);
- }
- }
- Update();
- Show(nativeShow);
- }
- /*
- void csProgressBar::Update()
- {
- FindParent();
- Rect r; GetParentRect(r);
-
- parent_bottom = r.b;
- float x,y; GetNativePos (x,y);
- float w,h; GetNativeSize(w,h);
- x *= m_aspect;
- if( w < 0.0f )
- w = -w;
- if( string::IsEqual(m_res,TOP_LEFT))
- {
- m_X = x + r.l;
- m_Y = y + r.t;
- m_bottom = false;
- }
- if( string::IsEqual(m_res,BOTTOM_LEFT))
- {
- m_X = x + r.l;
- m_Y = r.b - h - y;
- m_bottom = true;
- }
- if( string::IsEqual(m_res,TOP_RIGHT))
- {
- m_X = r.r - x;
- m_Y = y + r.t;
- w = -w;
- m_bottom = false;
- }
- if( string::IsEqual(m_res,BOTTOM_RIGHT))
- {
- m_X = r.r - x;
- m_Y = r.b - h - y;
- w = -w;
- m_bottom = true;
- }
- SizeTo(w,h);
- }
- */
- void csProgressBar::Update()
- {
- FindParent();
- Rect r; GetParentRect(r);
-
- parent_bottom = r.b;
- float x,y; GetNativePos (x,y);
- float w,h; GetNativeSize(w,h);
- x *= m_aspect;
- if( w < 0.0f )
- w = -w;
- if( string::IsEqual(m_res,"Top"))
- {
- switch( m_layout )
- {
- case OnLeft:
- m_X = x + r.l;
- m_Y = y + r.t;
- break;
- case OnCenter:
- m_X = (r.l + r.r)*0.5f + x - w*m_aspect*0.5f;
- m_Y = y + r.t;
- break;
- case OnRight:
- m_X = r.r - x;
- m_Y = y + r.t; w = -w;
- break;
- }
- m_bottom = false;
- }
- else
- {
- switch( m_layout )
- {
- case OnLeft:
- m_X = x + r.l;
- m_Y = r.b - h - y;
- break;
- case OnCenter:
- m_X = (r.l + r.r)*0.5f + x - w*m_aspect*0.5f;
- m_Y = r.b - h - y;
- break;
- case OnRight:
- m_X = r.r - x;
- m_Y = r.b - h - y; w = -w;
- }
- m_bottom = true;
- }
- SizeTo(w,h);
- }
- static const float R1 = PI/4;
- static const float R2 = -R1;
- static const float R3 = -R1*3;
- static const float R4 = -R1*5;
- void csProgressBar::Calculate(float x, float y, float w, float h, Vertex &v, float ang, float a, float wk)
- {
- float s = sin(ang);
- float c = cos(ang);
- float xk = c/fabsf(s);
- float yk = s/fabsf(c);
- if( ang > R1 || ang <= R4 )
- {
- v.x = x + w*xk;
- v.y = y - h;
- v.a = a;
- v.u = 0.5f + 0.5f*xk*wk;
- v.v = 0.0f;
- }
- else
- if( ang > R2 )
- {
- v.x = x + w;
- v.y = y - h*yk;
- v.a = a;
- v.u = wk < 0.0f ? 0.0f : 1.0f;
- v.v = 0.5f - 0.5f*yk;
- }
- else
- if( ang > R3 )
- {
- v.x = x + w*xk;
- v.y = y + h;
- v.a = a;
- v.u = 0.5f + 0.5f*xk*wk;
- v.v = 1.0f;
- }
- else
- if( ang > R4 )
- {
- v.x = x - w;
- v.y = y - h*yk;
- v.a = a;
- v.u = wk < 0.0f ? 1.0f : 0.0f;
- v.v = 0.5f - 0.5f*yk;
- }
- }
- void csProgressBar::DrawBar(float wk, float x, float y, float w, float h, float beg, float end, float alpha, float xs, float ys)
- {
- if( reverse )
- {
- beg = 1.0f - beg;
- end = 1.0f - end;
- }
- if( end <= beg )
- // return;
- {
- float t = end;
- end = beg;
- beg = t;
- }
- x -= (w*xs - w)*0.5f;
- y -= (h*ys - h)*0.5f;
- w *= xs;
- h *= ys;
- w *= 0.5*0.01f;
- h *= 0.5*0.01f;
- x *= 0.01f;
- y *= 0.01f;
- x += w;
- y += h;
- beg = PI*0.5f - 2*PI*beg;
- end = PI*0.5f - 2*PI*end;
- Vertex b[7]; long n = 0;
- b[n].x = x;
- b[n].y = y;
- b[n].a = alpha;
- b[n].u = 0.5f;
- b[n].v = 0.5f;
- n++;
- float pos = PI/4; float step = PI/2;
- while( beg < pos )
- {
- // Calculate(x,y,w,h,b[n++],pos,alpha);
- pos -= step;
- }
- Calculate(x,y,w,h,b[n++],beg,alpha,wk);
- while( end < pos )
- {
- Calculate(x,y,w,h,b[n++],pos,alpha,wk);
- pos -= step;
- }
- Calculate(x,y,w,h,b[n++],end,alpha,wk);
- if( inverse )
- {
- for( int i = 0 ; i < n ; i++ )
- {
- b[i].x = b[i].x*2.0f - 1.0f;
- b[i].y = 1.0f - (y - (b[i].y - y))*2.0f;
- b[i].z = 1.0f;
- b[i].v = 1.0f - b[i].v;
- }
- }
- else
- {
- for( int i = 0 ; i < n ; i++ )
- {
- b[i].x = b[i].x*2.0f - 1.0f;
- b[i].y = 1.0f - b[i].y*2.0f;
- b[i].z = 1.0f;
- }
- }
- if( barTexture && texture )
- barTexture->SetTexture(texture);
- pRS->DrawPrimitiveUP(GUI_Quad_id, PT_TRIANGLEFAN,n - 2,b,6*sizeof(float));
- }
- void csProgressBar::Draw(float wScale, float hScale, float fMaximalVal, float globalAlpha)
- {
- bool edit_mode = EditMode_IsOn();
- float y = m_Y;
- float w = GetWidth ();
- float h = GetHeight();
- if( !Restricted(preserveSize))
- w *= m_aspect;
- if( m_bottom )
- y = parent_bottom - h - GetNativeY();
- float wk;
- float xx;
-
- if( circular && reverse )
- {
- wk = -1.0f;
- xx = GetWidth();
- }
- else
- {
- wk = 1.0f;
- xx = 0.0f;
- }
- if( edit_mode || back_t[0] )
- {
- float al = 1.0f;
- if( edit_mode && !back_t[0] )
- al = 0.5f;
- m_backRender.DrawQuad(
- m_X + xx,y,w*wk,h,0,0,1.0,1.0,10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
- }
- if( !edit_mode && !fron_t[0] )
- return;
- float al = 1.0f;
- if( edit_mode && !fron_t[0] )
- al = 0.5f;
- // рисуем спецэффект добавления/убавления жизней
- if( m_fPrevValue != m_fValue && !edit_mode )
- {
- m_showAddDecEffect = true;
- m_addDecEffectTime = MaxAddDecEffectTime;
- if( m_fPrevValue < m_fValue) m_effects |= AddHP;
- if( m_fPrevValue > m_fValue) m_effects |= DecHP;
-
- m_addDecEffectStartU = ScaleToBorder(m_fValue/fMaximalVal)*(m_params.fEndBar - m_params.fStartBar);
- m_addDecEffectEndU = ScaleToBorder(m_fPrevValue/fMaximalVal)*(m_params.fEndBar - m_params.fStartBar);
- }
- float off = 0.0f;
- if( m_showAddDecEffect && m_effects&AddHP )
- {
- float k = m_addDecEffectTime/MaxAddDecEffectTime;
- off = k*(m_addDecEffectEndU - m_addDecEffectStartU);
- }
- if( circular )
- {
- DrawBar(wk,m_X,y,w,h,
- m_params.fStartBar,
- // m_params.fStartBar + m_fPercent*(m_params.fEndBar - m_params.fStartBar),
- m_params.fStartBar + m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,
- 10.0f + 1.0f*globalAlpha*al,wScale,hScale);
- }
- else
- {
- if( vertical )
- {
- if( reverse )
- {
- m_frontRender.DrawQuad(
- // m_X,y + m_params.fStartBar*h,
- m_X,y + h - (1.0f - m_params.fEndBar)*h - (m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*h,
- w,(m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*h,
- // m_params.fStartBar,0,
- // m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,1.0f,
- // 0,m_params.fStartBar,
- 0,1.0f - (1.0f - m_params.fEndBar + m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off),
- 1.0f,m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,
- 10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
- }
- else
- {
- m_frontRender.DrawQuad(
- m_X,y + m_params.fStartBar*h,
- w,(m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*h,
- // m_params.fStartBar,0,
- // m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,1.0f,
- 0,m_params.fStartBar,
- 1.0f,m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,
- 10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
- }
- }
- else
- {
- if( reverse )
- {
- m_frontRender.DrawQuad(
- // m_X + m_params.fStartBar*w,y,
- m_X + w - (1.0f - m_params.fEndBar)*w - (m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*w,y,
- (m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*w,h,
- // m_params.fStartBar,0,
- 1.0f - (1.0f - m_params.fEndBar + m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off),0,
- m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,1.0f,
- 10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
- }
- else
- {
- m_frontRender.DrawQuad(
- m_X + m_params.fStartBar*w,y,
- (m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off)*w,h,
- m_params.fStartBar,0,
- m_fPercent*(m_params.fEndBar - m_params.fStartBar) + off,1.0f,
- 10.0f + 1.0f*globalAlpha*al,wScale,hScale,vertical,true);
- }
- }
- }
- if( m_showAddDecEffect )
- {
- float Bright = 10.0f;
- // if( m_effects&AddHP )
- if( m_effects&AddHP && circular )
- {
- // Bright *= 2.0f;
- }
- if( m_addDecEffectTime <= 0.0f )
- {
- m_addDecEffectTime = 0.0f;
- m_showAddDecEffect = false;
- m_effects &= ~AddHP;
- m_effects &= ~DecHP;
- }
- if( circular )
- {
- float k = m_addDecEffectTime/MaxAddDecEffectTime;
- if( m_effects&AddHP ) k = 1.0f - k;
- DrawBar(wk,m_X,y,w,h,
- m_params.fStartBar + m_addDecEffectStartU,
- m_params.fStartBar + m_addDecEffectStartU + m_addDecEffectTime*(m_addDecEffectEndU - m_addDecEffectStartU),
- Bright + globalAlpha*k*al,wScale,hScale);
- }
- else
- {
- float k = m_addDecEffectTime/MaxAddDecEffectTime;
- float delta = k*(m_addDecEffectEndU - m_addDecEffectStartU);
- if( m_effects&AddHP )
- k = 1.0f - k;
- if( vertical )
- {
- if( reverse )
- {
- m_frontRender.DrawQuad(
- // m_X,y + (m_params.fStartBar + m_addDecEffectStartU)*h + (h*hScale - h)*0.5f*0.5f,
- m_X,y + h - (1.0f - m_params.fEndBar + m_addDecEffectStartU)*h - (h*hScale - h)*0.5f*0.5f - delta*h,
- w,delta*h,
- // m_params.fStartBar + m_addDecEffectStartU,0,
- // delta,1.0f,
- // 0,m_params.fStartBar + m_addDecEffectStartU,
- 0,1.0f - (1.0f - m_params.fEndBar + m_addDecEffectStartU + delta),
- 1.0f,delta,
- Bright + globalAlpha*k*al,wScale,hScale,vertical,true);
- }
- else
- {
- m_frontRender.DrawQuad(
- m_X,y + (m_params.fStartBar + m_addDecEffectStartU)*h + (h*hScale - h)*0.5f*0.5f,
- w,delta*h,
- // m_params.fStartBar + m_addDecEffectStartU,0,
- // delta,1.0f,
- 0,m_params.fStartBar + m_addDecEffectStartU,
- 1.0f,delta,
- Bright + globalAlpha*k*al,wScale,hScale,vertical,true);
- }
- }
- else
- {
- if( reverse )
- {
- m_frontRender.DrawQuad(
- m_X + w - (1.0f - m_params.fEndBar + m_addDecEffectStartU)*w - (w*wScale - w)*0.5f*0.5f - delta*w,y,
- delta*w,h,
- // m_params.fStartBar + m_addDecEffectStartU,0,
- 1.0f - (1.0f - m_params.fEndBar + m_addDecEffectStartU + delta),0,
- delta,1.0f,
- Bright + globalAlpha*k*al,wScale,hScale,vertical,true);
- }
- else
- {
- m_frontRender.DrawQuad(
- m_X + (m_params.fStartBar + m_addDecEffectStartU)*w + (w*wScale - w)*0.5f*0.5f,y,
- delta*w,h,
- m_params.fStartBar + m_addDecEffectStartU,0,
- delta,1.0f,
- Bright + globalAlpha*k*al,wScale,hScale,vertical,true);
- }
- }
- }
- }
- }
- void _cdecl csProgressBar::Work(float dltTime, long level)
- {
- if( EditMode_IsOn() && !EditMode_IsVisible())
- return;
- Draw();
- Update(dltTime);
- }
- void csProgressBar::Update(float dltTime)
- {
- if(!EditMode_IsOn())
- {
- if( !m_pHPObject.Validate())
- {
- FindObject(m_params.HPObject,m_pHPObject);
- if( m_pHPObject.Ptr())
- {
- m_fPrevValue = m_fValue = m_pHPObject.Ptr()->GetHP();
- }
- }
- }
- if( m_showAddDecEffect )
- m_addDecEffectTime -= dltTime;
- if( m_effects&ShowBar )
- {
- m_showEffectTime -= dltTime;
- if( m_showEffectTime <= 0.0f )
- {
- m_showEffectTime = 0.0f;
- m_effects &= ~ShowBar;
- }
- }
- m_fPrevValue = m_fValue;
- }
- void csProgressBar::Draw()
- {
- if( InterfaceUtils::IsHide())
- return;
- float fMaximalVal = m_params.fMaxValue;
- if( m_pHPObject.Ptr())
- {
- float maxHP = m_pHPObject.Ptr()->GetMaxHP();
- if( maxHP > 0.0f )
- {
- fMaximalVal = maxHP;
- m_fValue = m_pHPObject.Ptr()->GetHP();
- }
- }
- m_fPercent = ScaleToBorder(m_fValue/fMaximalVal);
-
- // FIX ME!!!!
- if( m_fPercent > 1.0f )
- m_fPercent = 1.0f;
- // Draw(1.0f,1.0f,fMaximalVal,1.0f);
- Draw(1.0f,1.0f,fMaximalVal,GetAlpha());
- if( m_effects&ShowBar )
- {
- if( m_showEffectTime > 0.0f )
- {
- float FinalScales[] = {0.1f,0.2f,0.4f};
- for( dword k = 0 ; k < sizeof(FinalScales)/sizeof(FinalScales[0]) ; k++ )
- {
- Draw(1.0f + FinalScales[k]*(1.0f - m_showEffectTime/MaxShowEffectTime),
- 1.0f + FinalScales[k]*(1.0f - m_showEffectTime/MaxShowEffectTime),
- // fMaximalVal,m_showEffectTime/MaxShowEffectTime);
- fMaximalVal,m_showEffectTime/MaxShowEffectTime*GetAlpha());
- }
- }
- }
- }
- void csProgressBar::Show(bool isShow)
- {
- // MissionObject ::Show(isShow);
- BaseGUIElement::Show(isShow);
- BaseGUIElement *parent = GetParent();
- long level = drawLevel;
- /* if( parent )
- level = parent->GetDrawLevel() + 100;*/
- DelUpdate(&csProgressBar::Work);
- if( IsShow())
- {
- if( GetAlpha() > 0.0f )
- {
- SetUpdate(&csProgressBar::Work,level + m_params.drawPriority);
- }
- if( m_params.doShowEffect && !EditMode_IsOn())
- {
- m_effects |= ShowBar;
- m_showEffectTime = MaxShowEffectTime;
- }
- }
- }
- void csProgressBar::SetMax(float val)
- {
- if( m_params.fMaxValue == val )
- return;
- m_params.fMaxValue = val;
- //LogicDebug("Change progress bar max to %3.2f", m_params.fMaxValue);
- if( m_fValue > m_params.fMaxValue )
- m_fValue = m_params.fMaxValue;
- m_fPrevValue = m_fValue;
- }
- void csProgressBar::SetPos(float val)
- {
- if( m_fValue == val )
- return;
- m_fValue = val;
- if( m_fValue < 0.0f )
- m_fValue = 0.0f;
- if( m_fValue > m_params.fMaxValue )
- m_fValue = m_params.fMaxValue;
- }
- //Обработчик команд для объекта
- void csProgressBar::Command(const char *id, dword numParams, const char **params)
- {
- m_fPrevValue = m_fValue;
- if( string::IsEmpty(id))
- return;
-
- if( string::IsEqual(id,"Set"))
- {
- if( numParams > 0 )
- {
- float fVal = (float)atoi(params[0]);
- SetPos(fVal);
- }
- return;
- }
- if( string::IsEqual(id,"Inc"))
- {
- if( numParams > 0 )
- {
- float fInc = (float)atoi(params[0]);
- m_fValue += fInc;
- }
- else
- {
- m_fValue += 1.0f;
- }
- if( m_fValue > m_params.fMaxValue )
- m_fValue = m_params.fMaxValue;
- return;
- }
- if( string::IsEqual(id,"Dec"))
- {
- if( numParams > 0 )
- {
- float fDec = (float)atoi(params[0]);
- m_fValue -= fDec;
- }
- else
- {
- m_fValue -= 1.0f;
- }
- if( m_fValue < 0.0f )
- m_fValue = 0.0f;
- return;
- }
- if( string::IsEqual(id,"Zero"))
- {
- LogicDebug("Zero progress bar");
- m_fValue = 0;
- return;
- }
- if( string::IsEqual(id,"Full"))
- {
- LogicDebug("Full progress bar");
- float fMaximalVal = m_params.fMaxValue;
- if( m_pHPObject.Ptr())
- {
- float maxHP = m_pHPObject.Ptr()->GetMaxHP();
- if( maxHP > 0.0f )
- {
- fMaximalVal = maxHP;
- m_fValue = m_pHPObject.Ptr()->GetHP();
- }
- }
- m_fValue = fMaximalVal;
- return;
- }
- if( string::IsEqual(id,"SetMax"))
- {
- if( numParams > 0 )
- {
- float fVal = (float)atoi(params[0]);
-
- SetMax(fVal);
- }
- return;
- }
- if( string::IsEqual(id,"SetHP"))
- {
- if( numParams > 0 )
- {
- m_fValue = (float)atoi(params[0]);
- //LogicDebug("Change progress bar HP to %3.2f", m_fValue);
- if( m_fValue > m_params.fMaxValue )
- m_fValue = m_params.fMaxValue;
- if( m_fValue < 0 )
- m_fValue = 0;
- }
- return;
- }
- if( string::IsEqual(id,"SetMO"))
- {
- if( numParams > 0 )
- {
- m_pHPObject.Reset();
- m_params.HPObjectStr = params[0];
- m_params.HPObject.Set(m_params.HPObjectStr.c_str());
- }
- return;
- }
- BaseGUIElement::Command(id,numParams,params);
- }
- float csProgressBar::ScaleToBorder(float hp)
- {
- static float out_hp = 1.0f;
-
- if (hp<=fMinBorder)
- {
- out_hp = 0.0f;
- }
- else
- if (hp>=fMaxBorder)
- {
- out_hp = 1.0f;
- }
- else
- {
- out_hp = (hp - fMinBorder)/(fMaxBorder - fMinBorder);
- }
- return out_hp;
- }
- static const char *g_comment =
- "Object for some events at some count\n"
- " \n"
- "Commands list:\n"
- "----------------------------------------\n"
- " Increase progress value\n"
- "----------------------------------------\n"
- " command: inc\n"
- " parm: number value (without param number = 1)\n"
- " \n"
- "----------------------------------------\n"
- " Decrease progress value\n"
- "----------------------------------------\n"
- " command: dec\n"
- " parm: number value (without param number = 1)\n"
- " \n"
- "----------------------------------------\n"
- " Zero progress value\n"
- "----------------------------------------\n"
- " command: zero\n"
- " \n"
- "----------------------------------------\n"
- " Full progress value\n"
- "----------------------------------------\n"
- " command: full\n"
- " \n"
- "----------------------------------------\n"
- " Set progress maximum\n"
- "----------------------------------------\n"
- " command: SetMax\n"
- " parm: number value\n"
- " \n"
- " ";
- MOP_BEGINLISTCG(csProgressBar, "ProgressBar", '1.00', /*100*/50, g_comment, "Interface")
- MOP_ENUMBEG("Layout")
- MOP_ENUMELEMENT("Left")
- MOP_ENUMELEMENT("Center")
- MOP_ENUMELEMENT("Right")
- MOP_ENUMEND
- MOP_ENUM("Layout", "Layout")
- MOP_STRING("Background Texture", "")
- MOP_STRING("Progress Texture", "")
- MOP_FLOATEX("X", 0.0f, -50.0f, 100.0f);
- MOP_FLOATEX("Y", 0.0f, -50.0f, 100.0f);
- MOP_FLOATEX("Width" , 50.0f, 0.1f, 100.0f);
- MOP_FLOATEX("Height", 25.0f, 0.1f, 100.0f);
- MOP_LONGEX("Max value", 10000, 0, 10000000000);
- MOP_STRING("Show HP from", "")
- MOP_FLOATEX("Min HP Border", 0, 0, 100);
- MOP_FLOATEX("Max HP Border", 100, 0, 100);
- MOP_FLOATEX("Start Bar", 25.0f, 0.0f, 100.0f);
- MOP_FLOATEX("End Bar", 85.0f, 0.0f, 100.0f);
- MOP_LONG("Draw priority", 0)
- MOP_ENUMBEG("ControlAlign")
- /* MOP_ENUMELEMENT(TOP_LEFT)
- MOP_ENUMELEMENT(BOTTOM_LEFT)
- MOP_ENUMELEMENT(TOP_RIGHT)
- MOP_ENUMELEMENT(BOTTOM_RIGHT)*/
- MOP_ENUMELEMENT("Top")
- MOP_ENUMELEMENT("Bottom")
- MOP_ENUMEND
- MOP_ENUM("ControlAlign", "Align")
- MOP_BOOL("Do show effect", true)
- MOP_BOOL("Show", true)
- MOP_FLOAT("AddDecEffectTime", 1.0f)
- MOP_FLOAT("ShowEffectTime" , 0.8f)
- MOP_BOOL("Circular", false)
- // MOP_BOOLC("Reverse" , false, "инвертирует направление указателя в круговом режиме")
- MOP_BOOLC("Reverse" , false, "инвертирует направление индикатора")
- MOP_BOOL("Vertical", false)
- MOP_BOOLC("Inverse", false, "зеркалит по вертикали индикатор в круговом режиме")
- MOP_FLOAT ("Alpha", 1.0f)
- MOP_STRING("Parent id", "")
- MOP_ENDLIST(csProgressBar)
|