class NoticeBoxBoard(Window):
CORNER_WIDTH = 11
CORNER_HEIGHT = 11
LINE_WIDTH = 11
LINE_HEIGHT = 11
BOARD_COLOR = grp.GenerateColor(0.047, 0.047, 0.078, 0.6)
LT, LB, RT, RB = 0, 1, 2, 3
L, R, T, B = 0, 1, 2, 3
activeNotice = None
def __init__(self, msg, lifeTime=2.0, layer="UI"):
if NoticeBoxBoard.activeNotice and NoticeBoxBoard.activeNotice.IsShow():
NoticeBoxBoard.activeNotice.Close()
# set this instance as the new active one
NoticeBoxBoard.activeNotice = self
Window.__init__(self, layer)
CornerFileNames = [
"d:/ymir work/ui/pattern/notice_box/noti_box_left_top.dds",
"d:/ymir work/ui/pattern/notice_box/noti_box_left_bot.dds",
"d:/ymir work/ui/pattern/notice_box/noti_box_right_top.dds",
"d:/ymir work/ui/pattern/notice_box/noti_box_right_bot.dds"
]
LineFileNames = [
"d:/ymir work/ui/pattern/notice_box/noti_box_left.dds",
"d:/ymir work/ui/pattern/notice_box/noti_box_right.dds",
"d:/ymir work/ui/pattern/notice_box/noti_box_top.dds",
"d:/ymir work/ui/pattern/notice_box/noti_box_bot.dds"
]
self.Corners = []
for fn in CornerFileNames:
corner = ExpandedImageBox()
corner.AddFlag("attach")
corner.AddFlag("not_pick")
corner.LoadImage(fn)
corner.SetParent(self)
corner.Show()
self.Corners.append(corner)
self.Lines = []
for fn in LineFileNames:
line = ExpandedImageBox()
line.AddFlag("attach")
line.AddFlag("not_pick")
line.LoadImage(fn)
line.SetParent(self)
line.Show()
self.Lines.append(line)
# --FIX-- Bara centru # 1 #
self.Base = ExpandedImageBox()
self.Base.AddFlag("attach")
self.Base.AddFlag("not_pick")
self.Base.LoadImage("d:/ymir work/ui/pattern/notice_box/noti_box_center.dds")
self.Base.SetParent(self)
self.Base.Show()
self.SetSize(200, 32)
self.SetCenterPosition()
x, y = self.GetGlobalPosition()
self.SetPosition(x, y + 255)
self.AddFlag("float")
self.Show()
self.textLine = TextLine()
self.textLine.SetParent(self)
self.textLine.SetHorizontalAlignCenter()
self.textLine.SetVerticalAlignCenter()
self.textLine.SetPackedFontColor(0xFFF5F5DC)
self.textLine.Show()
self.lifeTime = lifeTime
self.startTime = app.GetTime()
self.SetText(msg)
def SetText(self, msg):
self.textLine.SetText(msg)
self.AdjustWidth()
def AdjustWidth(self):
textWidth = self.textLine.GetTextSize()[0]
padding = 50
minWidth = 200
width = max(textWidth + padding, minWidth)
height = 32
self.SetSize(width, height)
y = (self.GetHeight() - self.textLine.GetTextSize()[1]) / 2 + 4
self.textLine.SetPosition(self.GetWidth() / 2, y)
self.SetCenterPosition()
x, y = self.GetGlobalPosition()
self.SetPosition(x, y + 255)
def SetSize(self, width, height):
width = max(self.CORNER_WIDTH * 2, width)
height = max(self.CORNER_HEIGHT * 2, height)
Window.SetSize(self, width, height)
self.Corners[self.LB].SetPosition(0, height - self.CORNER_HEIGHT)
self.Corners[self.RT].SetPosition(width - self.CORNER_WIDTH, 0)
self.Corners[self.RB].SetPosition(width - self.CORNER_WIDTH, height - self.CORNER_HEIGHT)
self.Lines[self.L].SetPosition(0, self.CORNER_HEIGHT)
self.Lines[self.R].SetPosition(width - self.CORNER_WIDTH, self.CORNER_HEIGHT)
self.Lines[self.T].SetPosition(self.CORNER_WIDTH, 0)
self.Lines[self.B].SetPosition(self.CORNER_WIDTH, height - self.CORNER_HEIGHT)
verticalShowingPercentage = float((height - self.CORNER_HEIGHT * 2) - self.LINE_HEIGHT) / self.LINE_HEIGHT
horizontalShowingPercentage = float((width - self.CORNER_WIDTH * 2) - self.LINE_WIDTH) / self.LINE_WIDTH
self.Lines[self.L].SetRenderingRect(0, 0, 0, verticalShowingPercentage)
self.Lines[self.R].SetRenderingRect(0, 0, 0, verticalShowingPercentage)
self.Lines[self.T].SetRenderingRect(0, 0, horizontalShowingPercentage, 0)
self.Lines[self.B].SetRenderingRect(0, 0, horizontalShowingPercentage, 0)
# --FIX-- Bara centru # 2 #
baseWidth = width - self.CORNER_WIDTH * 2
baseHeight = height - self.CORNER_HEIGHT * 2
self.Base.SetPosition(self.CORNER_WIDTH, self.CORNER_HEIGHT)
# --FIX-- Bara centru # 3 #
horizontalScale = float(baseWidth - self.LINE_WIDTH) / self.LINE_WIDTH
verticalScale = float(baseHeight - self.LINE_HEIGHT) / self.LINE_HEIGHT
self.Base.SetRenderingRect(0, 0, horizontalScale, verticalScale)
def OnUpdate(self):
if self.lifeTime > 0 and (app.GetTime() - self.startTime > self.lifeTime):
self.Close()
def Close(self):
self.Hide()
self.textLine = None
self.Base = None
self.Corners = []
self.Lines = []
if NoticeBoxBoard.activeNotice is self:
NoticeBoxBoard.activeNotice = None