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

  1.  
  2.  
  3.  
  4. import Scorer
  5. import Bladex
  6. import os
  7. import Interpolator
  8. import string
  9.  
  10.  
  11. Textos={}
  12. MapList = {}
  13. ComboNames = {
  14.               "Knight_N"   : {},
  15.               "Barbarian_N": {},
  16.               "Amazon_N"   : {},
  17.               "Dwarf_N"    : {},
  18.               "Default"    : {},
  19.              }
  20.              
  21. FADE_TIME=1.0
  22.  
  23. current_language=None
  24.  
  25. def SetLanguage(lang):
  26.   global current_language
  27.   global MapList
  28.   global ComboNames
  29.   if lang != current_language:
  30.     current_language= lang
  31.     print "Setting language",lang
  32.     l_path="../../Data/Text/"+lang
  33.     if not os.path.exists(l_path):
  34.       return
  35.  
  36.     files=os.listdir(l_path)    
  37.     for i in files:      
  38.       file=l_path+"/"+str(i)
  39.       if file[len(file)-3:]=='.py':
  40.         execfile(file)
  41.  
  42. def MapDescriptor(map):
  43.     if MapList.has_key(string.upper(map)):
  44.         return MapList[string.upper(map)]
  45.     else:
  46.         return map
  47.  
  48.  
  49. class FadeText(Interpolator.LinearInt):
  50.   def __init__(self,init_val,end_val):
  51.     Interpolator.LinearInt.__init__(self,init_val,end_val)
  52.     self.Interpolator=Interpolator.Interp("FadeText")
  53.     time=Bladex.GetTime()
  54.     self.Interpolator.AddAction(time,time+FADE_TIME,self)
  55.     self.end_val=end_val
  56.  
  57.  
  58.   def Execute(self,value):
  59.     ret=Interpolator.LinearInt.Execute(self,value)
  60.     Scorer.wGameText.SetAlpha(ret)
  61.  
  62.  
  63.   def EndExecute(self):
  64.     self.Interpolator.Kill()
  65.     Scorer.wGameText.SetAlpha(self.end_val)
  66.     if self.end_val==0:
  67.       Scorer.wGameText.SetText("")
  68.  
  69.  
  70.  
  71. def ClearText():
  72.   FadeText(1,0)
  73.  
  74.  
  75. def AbortText():
  76.   Bladex.RemoveScheduledFunc("ClearText")
  77.   Bladex.RemoveScheduledFunc("NextText")
  78.   Scorer.wGameText.SetAlpha(0)
  79.   Scorer.wGameText.SetText("")
  80.  
  81.  
  82.  
  83. def WriteTextAux(txt,duration,init_r,init_g,init_b,next_text):
  84.   Scorer.wGameText.SetColor(init_r,init_g,init_b)
  85.  
  86.   Scorer.wGameText.SetText(txt)
  87. ##  Scorer.wFrame.MoveWidgetTo("GameTextWidget",0.5,5);
  88.   Scorer.wFrame.RecalcLayout()
  89.  
  90.   FadeText(0,1)
  91.   now=Bladex.GetTime()
  92.  
  93.   if next_text==[]:
  94.     Bladex.AddScheduledFunc(now+duration,ClearText,(),"ClearText")
  95.   else:
  96.     Bladex.AddScheduledFunc(now+duration,ClearText,(),"ClearText")
  97.     Bladex.AddScheduledFunc(now+duration+FADE_TIME,WriteTextAux,(next_text[0],duration,init_r,init_g,init_b,next_text[1:]),"NextText")
  98.  
  99.  
  100.  
  101. def WriteText(txt_id):
  102.   
  103.   try:
  104.     _txt=Textos[txt_id]
  105.     txt=_txt[4]
  106.   except:
  107.     print "Error: can't print message",txt_id
  108.     return
  109.  
  110.   nLines=string.count(txt,"\n")+1
  111.   nParagraphs=(nLines/5)+1
  112.  
  113.   paragraphs=[]
  114.   if nParagraphs>1:
  115.     l=string.split(txt,"\n")
  116.     counter=0
  117.     t_str=""
  118.     for i in l:
  119.       t_str=t_str+i+"\n"
  120.       counter=counter+1
  121.       if counter==5:
  122.         paragraphs.append(t_str)
  123.         t_str=""
  124.         counter=0
  125.     if t_str!="":
  126.       paragraphs.append(t_str)
  127.  
  128.     WriteTextAux(paragraphs[0],_txt[0],_txt[1],_txt[2],_txt[3],paragraphs[1:])
  129.   else:
  130.     WriteTextAux(txt,_txt[0],_txt[1],_txt[2],_txt[3],[])
  131.  
  132.  
  133. def ShowMessage(message="",r=255,g=255,b=255):
  134.     Scorer.wGameText.SetText(message)
  135.     Scorer.wGameText.SetAlpha(1.0)
  136.     Scorer.wGameText.SetColor(r,g,b)
  137. ##    Scorer.wFrame.MoveWidgetTo("GameTextWidget",0.5,5)
  138.     Scorer.wFrame.RecalcLayout()
  139.  
  140. def HideMessage():
  141.     ShowMessage()
  142.  
  143. def GetComboName(EntityName,ComboId):
  144.     kindName = Bladex.GetEntity(EntityName).Kind
  145.     try:
  146.         return ComboNames[kindName][ComboId]
  147.     except:
  148.         try:
  149.             return ComboNames["Default"][ComboId]
  150.         except:
  151.             return None