Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Todo:
- - zeskalowanie aktywnych po zmianie rozdzielczosci
- - refaktoryzacja kodu
- */
- const NOTIFICATION_DISPLAY_TIME = 2500//ms
- const NOTIFICATION_ALPHA_EFFECT = 20//percent (długość chowania/pokazania, efekty alfy)
- const NOTIFICATION_DISPLAY_SIZE = 30//procent
- addEvent("onNotificationDestroyItem")
- local deltaTime = getTickCount()
- local lengthMoving = 0//px
- local endPosition = 0//px
- local sound = Sound("LEVER_LOCKED.WAV");
- sound.looping = false;
- sound.balance = 1.0;
- class GuiEditor.NotificationItem extends GUI.Draw//zrobić destruktor w klase GUI.Draw
- {
- #private:
- m_currMilisecond = 0
- m_isOutStart = true
- constructor(text, colorCoded = false)
- {
- base.constructor(0, 0, "")
- setText(text, colorCoded)
- }
- function setText(text, colorCoded = false)//musi być update pozycji (zmieia się szerokość, kontruktor nie uwzględnia bbcode)
- {
- base.setText(text, colorCoded)
- local res = getResolution()
- base.setPositionPx(res.x / 2 - base.getSizePx().width / 2, res.y / 2 - textHeightPx(text) / 2)
- }
- function getPercentFromNumber(value, percent)
- {
- return value.tofloat()/100.0 * percent
- }
- function getPercentFromRange(value, maxValue)
- {
- return value.tofloat() / maxValue.tofloat() * 100
- }
- function isOutStart()
- {
- return m_isOutStart
- }
- function effectRender()
- {
- local progress = getPercentFromRange(m_currMilisecond, NOTIFICATION_DISPLAY_TIME)
- local range = getPercentFromNumber(NOTIFICATION_DISPLAY_TIME, NOTIFICATION_ALPHA_EFFECT)
- if (progress < NOTIFICATION_ALPHA_EFFECT)
- {
- local speed = 255.0 / range.tofloat()
- base.setAlpha(speed * m_currMilisecond)
- }
- if (progress > 100 - NOTIFICATION_ALPHA_EFFECT)
- {
- local multiplier = m_currMilisecond - (NOTIFICATION_DISPLAY_TIME - range)
- local speed = 255.0 / range.tofloat()
- base.setAlpha((255 - speed * multiplier))
- }
- local pos = getPositionPx()
- base.setPositionPx(pos.x, (endPosition + lengthMoving - base.getLineSizePx()) - (lengthMoving / NOTIFICATION_DISPLAY_TIME * m_currMilisecond))
- if ((pos.y < endPosition + lengthMoving - 2 * getLineSizePx()) && m_isOutStart)
- m_isOutStart = false
- if(!base.getVisible())
- base.setVisible(true)
- }
- function render()
- {
- if (m_currMilisecond == NOTIFICATION_DISPLAY_TIME)
- callEvent("onNotificationDestroyItem", this)
- else
- {
- ++m_currMilisecond
- effectRender()
- }
- }
- }
- class GuiEditor.Notification
- {
- static m_queue = []
- static m_visibles = []
- static function init()//poprawić
- {
- local resolution = getResolution()
- lengthMoving = resolution.y.tofloat() / 100.0 * NOTIFICATION_DISPLAY_SIZE
- endPosition = resolution.y / 2 - lengthMoving / 2
- }
- static function add(message, colorCoded = false)
- {
- if (m_visibles.len() == 0)
- {
- m_visibles.push(GuiEditor.NotificationItem(message, colorCoded))
- sound.play()// :D
- return
- }
- if (m_visibles.len() < lengthMoving / textHeightPx(""))
- if (!m_visibles[m_visibles.len() - 1].isOutStart())
- m_visibles.push(GuiEditor.NotificationItem(message, colorCoded))
- else
- m_queue.push({message = message, colorCoded = colorCoded});
- sound.play()
- }
- static function onNotificationDestroyItem(item)
- {
- local visibles = GuiEditor.Notification.m_visibles
- for(local i = 0; i < visibles.len(); ++i)
- {
- if (item == visibles[i])
- {
- item.destroy()
- visibles.remove(i)
- return
- }
- }
- }
- static function onRender()
- {
- if (deltaTime <= getTickCount())
- {
- deltaTime = getTickCount() - deltaTime + 1;
- local visibles = GuiEditor.Notification.m_visibles
- local items = GuiEditor.Notification.m_queue
- foreach(object in visibles)
- object.render()
- if (visibles.len() > 0 && items.len() > 0)
- {
- if(!visibles[visibles.len() - 1].isOutStart())
- {
- visibles.push(GuiEditor.NotificationItem(items[0].message, items[0].colorCoded))
- items.remove(0)//usunięcie z kolejki
- }
- }
- }
- }
- }
- addEventHandler("onNotificationDestroyItem", GuiEditor.Notification.onNotificationDestroyItem)
- addEventHandler("onRender", GuiEditor.Notification.onRender)
- addEventHandler("onInit", GuiEditor.Notification.init)
- //test
- addEventHandler("onKey", function(key)
- {
- if (key == KEY_H)
- GuiEditor.Notification.add("[#FF7F00](GuiEditor) [#F60005]Włączono", true)
- if (key == KEY_G)
- GuiEditor.Notification.add("[#FF7F00](GuiEditor) [#32CD32]Wyłączono", true)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement