/planet/Objects.c4d/HUD.c4d/Elements.c4d/Bars.c4d/Script.c

https://bitbucket.org/randrian/openclonk2 · C · 72 lines · 44 code · 15 blank · 13 comment · 3 complexity · f0b9a9611e80d0c4ef7d3e4ae0e2579d MD5 · raw file

  1. #strict 2
  2. /*
  3. Progress-Bar element
  4. This object can show an unlimited amount of progress bars in different
  5. locations, sizes and colors. Using this basic funcionality, one could create
  6. floating health bars attached to clonks or include the bars as layers into
  7. (HUD) objects.
  8. */
  9. local offsx, offsy, layer, width, height;
  10. protected func Construction()
  11. {
  12. offsx = CreateArray();
  13. offsy = CreateArray();
  14. width = CreateArray();
  15. height = CreateArray();
  16. layer = CreateArray();
  17. }
  18. public func SetBarOffset(int x, int y, int num)
  19. {
  20. offsx[num] = x;
  21. offsy[num] = y;
  22. }
  23. public func RemoveBarLayers(int la)
  24. {
  25. // remove layers
  26. SetGraphics(nil,nil,nil,la);
  27. SetGraphics(nil,nil,nil,la+1);
  28. }
  29. public func SetBarLayers(int la, int num)
  30. {
  31. RemoveBarLayers(la);
  32. // new layers
  33. layer[num] = la;
  34. SetGraphics("Empty",BAR0,layer[num],GFXOV_MODE_Base);
  35. SetGraphics("Bar",BAR0,layer[num]+1,GFXOV_MODE_Base);
  36. }
  37. public func SetBarDimensions(int wdt, int hgt, int num)
  38. {
  39. width[num] = 1000 * wdt / BAR0->GetDefWidth();
  40. height[num] = 1000 * hgt / BAR0->GetDefHeight();
  41. }
  42. public func SetBarProgress(int promille, int num)
  43. {
  44. // not existing
  45. if(GetLength(layer) <= num) return false;
  46. // width/height not set == 1000
  47. if(!width[num]) width[num] = 1000;
  48. if(!height[num]) height[num] = 1000;
  49. var w = BAR0->GetDefWidth()/2;
  50. // the bar does not start on the left side of the graphics... correct this
  51. var graphicscorrect = 100;
  52. var baroffset = offsx[num]*1000 - width[num]*w * (1000-promille)/(1000+graphicscorrect);
  53. SetObjDrawTransform(width[num],0,offsx[num]*1000, 0, height[num], offsy[num]*1000, layer[num]);
  54. SetObjDrawTransform((promille * width[num])/1000,0, baroffset, 0, height[num], offsy[num]*1000, layer[num]+1);
  55. return true;
  56. }