home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / NetScorer.py < prev    next >
Encoding:
Python Source  |  2000-10-27  |  10.2 KB  |  295 lines

  1. import netgame
  2. import BUIx
  3. import CharStats
  4. import Netval
  5. import Bladex
  6. import ScorerWidgets
  7. import WidgetsExtra
  8. from Reference import ENERGY_LOW_LEVEL
  9.  
  10. VISIBLE=1
  11.  
  12. CURRENT_STRENGTH_R=251
  13. CURRENT_STRENGTH_G=241
  14. CURRENT_STRENGTH_B=2
  15.  
  16.  
  17. __wNULL=BUIx.CreateNULLWidget()
  18. wFrame=BUIx.B_FrameWidget(__wNULL,"MainFrame",640,480)
  19.  
  20. # life and level
  21. wLeftFrame=BUIx.B_FrameWidget(wFrame,"BarsFrame",195,65)
  22.  
  23. wDownFrame=BUIx.B_FrameWidget(wFrame,"DownFrame",195,73)
  24. wChatFrame=BUIx.B_FrameWidget(wFrame,"ChatFrame",195,65)
  25.  
  26. wFragFrame=BUIx.B_FrameWidget(wFrame,"FragFrame",200,200)
  27.  
  28.  
  29. Bladex.ReadBitMap("..\\..\\Data\\Bar.bmp","BitmapBarra")
  30. wLifeBar1=BUIx.B_BarWidget(wLeftFrame,"LifeBar1",180,12)
  31. wLifeBar1.SetColor(110,0,5)
  32. wLifeBar1.SetBackgroundAlpha(0.4)
  33. wLifeBar1.SetAlpha(1.0)
  34. wLifeBar1.SetBitmap("BitmapBarra")
  35.  
  36. wLifeBar2=BUIx.B_BarWidget(wLeftFrame,"LifeBar2",180,12)
  37. wLifeBar2.SetColor(163,28,0)
  38. wLifeBar2.SetBackgroundAlpha(0.0)
  39. wLifeBar2.SetAlpha(1.0)
  40. wLifeBar2.SetBitmap("BitmapBarra")
  41.  
  42. wLifeBar=BUIx.B_StackBarWidget(wLeftFrame,"LifeBar",180,12)
  43. wLifeBar.AddBar(wLifeBar1)
  44. wLifeBar.AddBar(wLifeBar2)
  45. wLeftFrame.AddWidget(wLifeBar,8,14)
  46.  
  47.  
  48. wLifeLabel=BUIx.B_TextWidget(wLifeBar,"LifeLabel","100/100",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  49. wLifeLabel.SetColor(170,170,170)
  50. wLifeLabel.SetAlpha(0.5)
  51. wLifeBar.AddLabel(wLifeLabel,0,2,
  52.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_Bottom,
  53.                   BUIx.B_Widget.B_FR_AbsoluteRight,BUIx.B_Widget.B_FR_Right,
  54.                   BUIx.B_Widget.B_FR_AbsoluteTop,BUIx.B_Widget.B_FR_Top
  55.                   )
  56.                   
  57.  
  58. wCurrentLevelLabel=BUIx.B_TextWidget(wLifeBar,"CurrentLevelLabel","Level 5",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  59. wCurrentLevelLabel.SetColor(0,159,220)
  60. wCurrentLevelLabel.SetAlpha(0.5)
  61. wLifeBar.AddLabel(wCurrentLevelLabel,0,2,
  62.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_Bottom,
  63.                   BUIx.B_Widget.B_FR_AbsoluteLeft,BUIx.B_Widget.B_FR_Left,
  64.                   BUIx.B_Widget.B_FR_AbsoluteTop,BUIx.B_Widget.B_FR_Top
  65.                   )
  66.  
  67. # Frags
  68. wPlayersFrags=BUIx.B_TextWidget(wLifeBar,"FragsLabel","",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  69. wPlayersFrags.SetColor(220,220,220)
  70. wPlayersFrags.SetAlpha(0.8)
  71. wLifeBar.AddLabel(wPlayersFrags,0,2,
  72.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_Bottom,
  73.                   BUIx.B_Widget.B_FR_AbsoluteLeft,BUIx.B_Widget.B_FR_Left,
  74.                   BUIx.B_Widget.B_FR_AbsoluteTop,BUIx.B_Widget.B_FR_Top
  75.                   )
  76.  
  77.  
  78. # versus value
  79. wPlayersVS=BUIx.B_TextWidget(wLifeBar,"VersusLabel","Waiting for a combat...",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  80. wPlayersVS.SetColor(220,220,220)
  81. wPlayersVS.SetAlpha(0.7)
  82. wDownFrame.AddWidget(wPlayersVS,0,0)
  83.  
  84. # Status of the client
  85. wStatusGame=BUIx.B_TextWidget(wLifeBar,"VersusLabel","",ScorerWidgets.font_server,"..\\..\\Data\\letras menu peq.BMP")
  86. wStatusGame.SetColor(0,128,255)
  87. wStatusGame.SetAlpha(0.8)
  88. wDownFrame.AddWidget(wStatusGame,0,16)
  89.  
  90.  
  91. # Barra de energy  -------------------------------------------------------------------------------------------
  92.  
  93. Bladex.ReadBitMap("..\\..\\Data\\agotamiento.bmp","BitmapRGBar")
  94. wEnergyBar=ScorerWidgets.B_SmoothBarWidget(wLeftFrame,"EnergyBar",180,8)
  95. wEnergyBar.SetColor(255,255,255)
  96. wEnergyBar.SetAlpha(0.2)
  97. wEnergyBar.SetBackgroundAlpha(0.05)
  98. wEnergyBar.SetBackgroundColor(64,64,64)
  99. wEnergyBar.SetVisible(0)
  100. wEnergyBar.SetBitmap("BitmapRGBar")
  101.  
  102. wDangerLabel=WidgetsExtra.B_FlashTextWidget(wEnergyBar,"DangerLabel","LOW ENERGY",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  103. wDangerLabel.SetColor(238,191,0)
  104. wDangerLabel.SetAlpha(1.0)
  105. wDangerLabel.SetVisible(0)
  106. wEnergyBar.AddLabel(wDangerLabel,0.5,0.5,
  107.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_VCenter,
  108.                   BUIx.B_Widget.B_FR_HRelative, BUIx.B_Widget.B_FR_HCenter,
  109.                   BUIx.B_Widget.B_FR_VRelative, BUIx.B_Widget.B_FR_VCenter
  110.                   )
  111.  
  112. wDownFrame.AddWidget(wEnergyBar,0,32)
  113.  
  114.  
  115. # Barra de strength  -------------------------------------------------------------------------------------------
  116. wStrengthBar=ScorerWidgets.B_SmoothBarWidget(wLeftFrame,"StrengthBar",180,8)
  117. wStrengthBar.SetColor(CURRENT_STRENGTH_R,CURRENT_STRENGTH_G,CURRENT_STRENGTH_B)
  118. wStrengthBar.SetAlpha(0.3)
  119. wStrengthBar.SetBackgroundAlpha(0.1)
  120. wStrengthBar.SetBackgroundColor(CURRENT_STRENGTH_R,CURRENT_STRENGTH_G,CURRENT_STRENGTH_B)
  121. wStrengthBar.SetVisible(0)
  122.  
  123. wMaxPowerLabel=WidgetsExtra.B_FlashTextWidget(wStrengthBar,"MaxPowerLabel","MAXIMUM POWER",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  124. wMaxPowerLabel.SetColor(255,255,255)
  125. wMaxPowerLabel.SetAlpha(1.0)
  126. wMaxPowerLabel.SetVisible(0)
  127. wStrengthBar.AddLabel(wMaxPowerLabel,0.5,0.5,
  128.                   BUIx.B_Widget.B_LAB_HCenter,BUIx.B_Widget.B_LAB_VCenter,
  129.                   BUIx.B_Widget.B_FR_HRelative, BUIx.B_Widget.B_FR_HCenter,
  130.                   BUIx.B_Widget.B_FR_VRelative, BUIx.B_Widget.B_FR_VCenter
  131.                   )
  132.  
  133. wStrengthLabel=WidgetsExtra.B_FlashTextWidget(wStrengthBar,"StrengthLabel","LAUNCH",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  134. wStrengthLabel.SetColor(99,210,251)
  135. wStrengthLabel.SetAlpha(1.0)
  136. wStrengthLabel.SetFlash(0.0)
  137. wStrengthBar.AddLabel(wStrengthLabel,6,0.5,
  138.                   BUIx.B_Widget.B_LAB_Left,BUIx.B_Widget.B_LAB_VCenter,
  139.                   BUIx.B_Widget.B_FR_AbsoluteRight,BUIx.B_Widget.B_FR_Right,
  140.                   BUIx.B_Widget.B_FR_VRelative, BUIx.B_Widget.B_FR_VCenter
  141.                   )                 
  142.  
  143. wDownFrame.AddWidget(wStrengthBar,0,32)
  144.                   
  145. wChatLines = ["","","",""]
  146.  
  147. for i in range(len(wChatLines)):
  148.     wChatLines[i]=BUIx.B_TextWidget(wLifeBar,"VersusLabel","",ScorerWidgets.font_server,"..\\..\\Data\\Mapa de letras.bmp")
  149.     wChatLines[i].SetColor(220,220,220)
  150.     wChatLines[i].SetAlpha((i+1.0)/(len(wChatLines)))
  151.     wChatFrame.AddWidget(wChatLines[i],0,i*14)
  152.  
  153. # FragLimit
  154. wFragLimit=BUIx.B_TextWidget(wLifeBar,"FragLimimit","THE CARNAGE IS OVER",ScorerWidgets.font_server,"..\\..\\Data\\letras menu med.BMP")
  155. wFragLimit.SetColor(255,0,0)
  156. wFragLimit.SetAlpha(0.8)
  157. wFragFrame.AddWidget(wFragLimit,0,5)
  158.  
  159. wFragList=BUIx.B_TextWidget(wLifeBar,"FragLimimit","",ScorerWidgets.font_server,"..\\..\\Data\\letras menu med.BMP")
  160. wFragList.SetColor(220,220,220)
  161. wFragList.SetAlpha(0.8)
  162. wFragFrame.AddWidget(wFragList,0,25)
  163.  
  164.  
  165. ##############################################################################################
  166. wFrame.SetVisible(1)
  167. wLeftFrame.SetVisible(1)
  168. wDownFrame.SetVisible(1)
  169. wFragFrame.SetVisible(0)
  170.  
  171. # muestra la lista grande de frags
  172. def ShowFragLimit(val):
  173.     wLeftFrame.SetVisible(val)
  174.     wDownFrame.SetVisible(val)
  175.     wChatFrame.SetVisible(val)
  176.     wFragFrame.SetVisible(val==0)
  177.  
  178.  
  179. wFrame.AddWidget(wLeftFrame,0,0)
  180. wFrame.AddWidget(wDownFrame,0.5,20,BUIx.B_FrameWidget.B_FR_HRelative,BUIx.B_FrameWidget.B_FR_HCenter,
  181.                               BUIx.B_FrameWidget.B_FR_AbsoluteBottom,BUIx.B_FrameWidget.B_FR_VCenter)
  182.  
  183. wFrame.AddWidget(wChatFrame,20,20,BUIx.B_FrameWidget.B_FR_AbsoluteRight,BUIx.B_FrameWidget.B_FR_Right,
  184.                               BUIx.B_FrameWidget.B_FR_AbsoluteTop,BUIx.B_FrameWidget.B_FR_Top)
  185.  
  186. wFrame.AddWidget(wFragFrame,0.5,0.5,BUIx.B_FrameWidget.B_FR_HRelative,BUIx.B_FrameWidget.B_FR_HCenter,
  187.                               BUIx.B_FrameWidget.B_FR_AbsoluteTop)
  188.  
  189. Bladex.SetRootWidget(wFrame.GetPointer())
  190.  
  191. ScrollLimit = 0
  192.  
  193. def SetStrengthBarValue(v):
  194.   wEnergyBar.SetVisible(0)  
  195.   if VISIBLE:
  196.       wStrengthBar.SetVisible(1)
  197.   old_pos= wStrengthBar.GetPositionPercentage()
  198.   wStrengthBar.SetPositionPercentage(v)  
  199.   
  200.   if v>=1.0:
  201.       if old_pos<1.0:
  202.           wMaxPowerLabel.SetFlash(14)
  203.           wStrengthLabel.SetFlash(14)          
  204.           wMaxPowerLabel.SetVisible(1)
  205.   else:
  206.       wMaxPowerLabel.SetVisible(0)
  207.       wStrengthLabel.SetFlash(0.0)
  208.       
  209. def SetEnergyBarValue(v, max_v):
  210.   wStrengthBar.SetVisible(0)
  211.   if VISIBLE:
  212.       wEnergyBar.SetVisible(1)
  213.   pos= min(max(v/max_v, 0),1.0)
  214.   wEnergyBar.SetPositionPercentage(pos)
  215.   if pos<=ENERGY_LOW_LEVEL:            
  216.       wDangerLabel.SetFlash(14)      
  217.       wDangerLabel.SetVisible(1)
  218.   else:
  219.       wDangerLabel.SetVisible(0)  
  220.  
  221. def ScrollChatConsole():
  222.     global ScrollLimit
  223.     for i in range(len(wChatLines)-1):
  224.         wChatLines[i].SetText(wChatLines[i+1].GetTextData())
  225.     wChatLines[len(wChatLines)-1].SetText("")
  226.     ScrollLimit = Bladex.GetTime()+3.0
  227.     
  228.  
  229. def ChatClientString(cad):
  230.     ScrollChatConsole()
  231.     wChatLines[len(wChatLines)-1].SetText(cad)
  232.     
  233.     
  234. def AddChatString(cad):
  235.     if netgame.GetNetState() != 2:
  236.         ScrollChatConsole()
  237.         wChatLines[len(wChatLines)-1].SetText(cad)
  238.     netgame.SendUserString(Netval.NET_GAME_CHAT_STRING,cad)
  239.  
  240. NetPlayer = "Player1"
  241.  
  242. def SetNetPlayerScorer(s):
  243.     global NetPlayer
  244.     NetPlayer = s
  245.  
  246. LastFragViewerTime = 0
  247.  
  248. def SwitchFragViewer():
  249.     global LastFragViewerTime
  250.     
  251.     LastFragViewerTime = Bladex.GetTime()+4.0
  252.     wPlayersFrags.SetVisible(1)
  253.     
  254. ViewStats = 0
  255.  
  256. def NetScorerAfterFrameFunc(time):
  257.     import Actions
  258.     global ScrollLimit
  259.     global NetPlayer
  260.     global LastFragViewerTime
  261.     
  262.     pj=Bladex.GetEntity(NetPlayer)
  263.     if "NetLife" in dir(pj.Data):
  264.         if "NetLevel" in dir(pj.Data):
  265.             info = netgame.GetPlayerData(NetPlayer)    
  266.  
  267.  
  268.             throw_pressed = Bladex.GetTimeActionHeld ("Throw")
  269.             if throw_pressed:
  270.                 SetStrengthBarValue(Actions.ThrowTime2ThrowForce(throw_pressed))
  271.             else:                
  272.                 max_energy= CharStats.GetCharMaxEnergy(pj.Kind, 29)
  273.                 wStrengthBar.SetVisible(0)
  274.                 if info[0] < max_energy:
  275.                     SetEnergyBarValue(info[0]*1.0, max_energy*1.0)                    
  276.                 else:
  277.                     wStrengthBar.SetVisible(0)
  278.                     
  279.                     wEnergyBar.SetVisible(0)
  280.             
  281.             wLifeBar.SetPosition(info[1])
  282.             wLifeLabel.SetText(str(info[1])+"/"+str(int(pj.Data.NetLife)))
  283.             wCurrentLevelLabel.SetText("Level "+str(int(pj.Data.NetLevel)))
  284.             if ScrollLimit<time :
  285.                 ScrollChatConsole()
  286.             if LastFragViewerTime<time:
  287.                 wPlayersFrags.SetVisible(0)
  288.             if ViewStats:
  289.                 wStatusGame.SetText(netgame.ServerInfoBlock())
  290.     
  291. Bladex.SetAfterFrameFunc("DefaultSelectionData",NetScorerAfterFrameFunc)
  292.  
  293. def ActivateScorer():
  294.     Bladex.SetRootWidget(wFrame.GetPointer())
  295.