Advertisement
expired6978

HUD

Mar 30th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. void __stdcall InstallHudComponents(HUDMenu * menu)
  2. {
  3.     BSTArrayFunctor<HUDObject*> alloc(&menu->hudComponents);
  4.  
  5.     GFxValue hudComponent;
  6.  
  7.     GFxValue args[2];
  8.     args[0].SetString("hudExtension");
  9.     args[1].SetNumber(-1);
  10.  
  11.     menu->view->Invoke("_root.createEmptyMovieClip", &hudComponent, args, 2);
  12.     args[0].SetString("hud_extension.swf");
  13.     hudComponent.Invoke("loadMovie", NULL, &args[0], 1);
  14.  
  15.     HUDEnemyHealthbars * healthBars = new HUDEnemyHealthbars(menu->view);
  16.     healthBars->object = hudComponent;
  17.     alloc.Push((HUDObject*&)healthBars);
  18. }
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. void HUDEnemyHealthbars::Update()
  27. {
  28.     for(UInt32 i = 0; i < (*g_thePlayer)->hostileHandles.count; i++) {
  29.         UInt32 handle = 0;
  30.         (*g_thePlayer)->hostileHandles.GetNthItem(i, handle);
  31.         EnemyHealthbar dummy;
  32.         dummy.handle = handle;
  33.         std::pair<EnemySet::iterator,bool> ret = components.insert(dummy);
  34.         if(ret.second == false) {
  35.             // AttachMovie, new handle added
  36.             GFxValue meterComponent;
  37.             GFxValue arg;
  38.             arg.SetNumber(handle);
  39.             view->Invoke("_root.hudExtension.loadMeter", &meterComponent, &arg, 1);
  40.             (*ret.first).object = meterComponent;
  41.         }
  42.     }
  43.  
  44.     EnemySet::iterator it = components.begin();
  45.     while(it != components.end())
  46.     {
  47.         UInt32 handle = (*it).handle;
  48.         TESObjectREFR * refr = NULL;
  49.         LookupREFRByHandle(&handle, &refr);
  50.         if(!refr) { // Handle lookup failed, delete it
  51.             components.erase(it++);
  52.             continue;
  53.         }
  54.         if(refr) {
  55.             Actor * actor = DYNAMIC_CAST(refr, TESObjectREFR, Actor);
  56.             if(actor) {
  57.                 if(actor->actorValueOwner.GetCurrent(24) < 0.0) { // Actor died
  58.                     components.erase(it++);
  59.                     continue;
  60.                 }
  61.  
  62.                 NiPoint3 markerPos;
  63.                 refr->GetMarkerPosition(&markerPos);
  64.  
  65.                 float x_out = 0.0;
  66.                 float y_out = 0.0;
  67.                 float z_out = 0.0;
  68.  
  69.                 GRectF rect = view->GetVisibleFrameRect();
  70.  
  71.                 WorldPtToScreenPt3_Internal(g_worldToCamMatrix, g_viewPort, &markerPos, &x_out, &y_out, &z_out, 1e-5);
  72.  
  73.                 // Move component, update component stats
  74.                 y_out = 1.0 - y_out;
  75.                 y_out = rect.top + (rect.bottom - rect.top) * y_out;
  76.                 x_out = rect.bottom + (rect.right - rect.left) * x_out;
  77.                
  78.                 if(it->object.IsDisplayObject()) {
  79.                     GFxValue::DisplayInfo dInfo;
  80.                     it->object.GetDisplayInfo(&dInfo);
  81.                     dInfo.x = x_out;
  82.                     dInfo.y = y_out;
  83.                     it->object.SetDisplayInfo(&dInfo);
  84.                 }
  85.             }
  86.         }
  87.         it++;
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement