Ich dachte mir ich Poste es nochmal Direkt, damit Leute nicht nur zufällig drauf stoßen die danach suchen:
Bitte melden Sie sich an, um dieses Bild zu sehen.
Python
- Replace:
- class TipBoard(ui.Bar):
- [...]
- with:
- class TipBoard(ui.Bar):
- SCROLL_WAIT_TIME = 3.0
- TIP_DURATION = 5.0
- FONT_HEIGHT = 15
- TEXT_POS_Y = 10
- LINE_HEIGHT = FONT_HEIGHT + 5
- STEP_HEIGHT = LINE_HEIGHT + 5
- LONG_TEXT_START_X = 300
- SCREEN_WIDTH = wndMgr.GetScreenWidth()
- def __init__(self):
- ui.Bar.__init__(self)
- self.AddFlag("not_pick")
- self.tipList = []
- self.curPos = 0
- self.dstPos = 0
- self.nextScrollTime = 0
- self.width = self.SCREEN_WIDTH
- self.SetPosition(0, 160)
- self.SetSize(self.SCREEN_WIDTH, 35)
- self.SetColor(grp.GenerateColor(0.0, 0.0, 0.0, 0.5))
- self.SetWindowHorizontalAlignCenter()
- self.__CreateTextBar()
- def __del__(self):
- ui.Bar.__del__(self)
- def __CreateTextBar(self):
- x, y = self.GetGlobalPosition()
- self.textBar = BigTextBar(self.SCREEN_WIDTH*2, 300, self.FONT_HEIGHT)
- self.textBar.SetParent(self)
- self.textBar.SetPosition(6, 8)
- self.textBar.SetTextColor(242, 231, 193)
- self.textBar.SetClipRect(0, y, self.SCREEN_WIDTH, y+8+self.STEP_HEIGHT)
- self.textBar.Show()
- def __CleanOldTip(self):
- leaveList = []
- for tip in self.tipList:
- madeTime = tip[0]
- if app.GetTime() - madeTime > self.TIP_DURATION:
- pass
- else:
- leaveList.append(tip)
- self.tipList = leaveList
- if not leaveList:
- self.textBar.ClearBar()
- self.Hide()
- return
- self.__RefreshBoard()
- def __RefreshBoard(self):
- self.textBar.ClearBar()
- index = 0
- for tip in self.tipList:
- text = tip[1]
- if text:
- (text_width, text_height) = self.textBar.GetTextExtent(text)
- if text_width>self.SCREEN_WIDTH:
- self.textBar.TextOut(0, index*self.STEP_HEIGHT, text)
- else:
- self.textBar.TextOut((wndMgr.GetScreenWidth()-text_width)/2, index*self.STEP_HEIGHT, text)
- index += 1
- def SetTip(self, text):
- if not app.IsVisibleNotice():
- return
- curTime = app.GetTime()
- self.tipList.append((curTime, text))
- self.__RefreshBoard()
- self.nextScrollTime = app.GetTime() + 1.0
- if not self.IsShow():
- self.curPos = -self.STEP_HEIGHT
- self.dstPos = -self.STEP_HEIGHT
- self.textBar.SetPosition(3, self.TEXT_POS_Y - self.curPos)
- self.Show()
- def OnUpdate(self):
- if not self.tipList:
- self.Hide()
- return
- if app.GetTime() > self.nextScrollTime:
- self.nextScrollTime = app.GetTime() + self.SCROLL_WAIT_TIME
- self.dstPos = self.curPos + self.STEP_HEIGHT
- if self.dstPos > self.curPos:
- self.curPos += 1
- self.textBar.SetPosition(3, self.TEXT_POS_Y - self.curPos)
- if self.curPos > len(self.tipList)*self.STEP_HEIGHT:
- self.curPos = -self.STEP_HEIGHT
- self.dstPos = -self.STEP_HEIGHT
- self.__CleanOldTip()