mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 07:26:49 +01:00
rework on graphics.cpp, implement some GFX with lua
This commit is contained in:
@@ -14,6 +14,7 @@ Module
|
||||
require 'util'
|
||||
require 'widget'
|
||||
require 'messagebox'
|
||||
require 'dispatcher'
|
||||
|
||||
rootWidget = getRootWidget()
|
||||
return true
|
||||
|
||||
28
modules/core/dispatcher.lua
Normal file
28
modules/core/dispatcher.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
local eventId = 1
|
||||
local events = { }
|
||||
local orig = { scheduleEvent = scheduleEvent,
|
||||
addEvent = addEvent }
|
||||
|
||||
-- fix original scheduleEvent
|
||||
function scheduleEvent(func, delay)
|
||||
eventId = eventId + 1
|
||||
local id = eventId + 1
|
||||
local function proxyFunc()
|
||||
func()
|
||||
table[id] = nil
|
||||
end
|
||||
table[id] = proxyFunc
|
||||
orig.scheduleEvent(proxyFunc, delay)
|
||||
end
|
||||
|
||||
-- fix original addEvent
|
||||
function addEvent(func)
|
||||
eventId = eventId + 1
|
||||
local id = eventId + 1
|
||||
local function proxyFunc()
|
||||
func()
|
||||
table[id] = nil
|
||||
end
|
||||
table[id] = proxyFunc
|
||||
orig.addEvent(proxyFunc)
|
||||
end
|
||||
@@ -1,6 +1,6 @@
|
||||
Button < UIButton
|
||||
font: helvetica-11px-bold
|
||||
color: 240 173 77 255
|
||||
font-color: 240 173 77
|
||||
size: 106 24
|
||||
border-image:
|
||||
source: /core_ui/images/button.png
|
||||
|
||||
@@ -5,7 +5,8 @@ FlatPanel < Panel
|
||||
source: /core_ui/images/panel_flat.png
|
||||
border: 4
|
||||
|
||||
RoundedGridPanel < Panel
|
||||
RoundedPanel < Panel
|
||||
color: 255 255 255 192
|
||||
border-image:
|
||||
source: /core_ui/images/panel_rounded.png
|
||||
border: 4
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Window < UIWindow
|
||||
size: 200 100
|
||||
size: 200 200
|
||||
head:
|
||||
height: 20
|
||||
border-image:
|
||||
|
||||
26
modules/gfx/gfx.lua
Normal file
26
modules/gfx/gfx.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
GFX = { }
|
||||
|
||||
function GFX.fadeIn(widget, time, elapsed)
|
||||
if not elapsed then elapsed = 0 end
|
||||
if not time then time = 750 end
|
||||
widget.opacity = math.min((255*elapsed)/time, 255)
|
||||
if elapsed < time then
|
||||
scheduleEvent(function()
|
||||
GFX.fadeIn(widget, time, elapsed + 30)
|
||||
end, 30)
|
||||
end
|
||||
end
|
||||
|
||||
function GFX.fadeOut(widget, time, elapsed)
|
||||
if not elapsed then elapsed = 0 end
|
||||
if not time then time = 750 end
|
||||
widget.opacity = (255*(time - elapsed))/time
|
||||
if elapsed < time then
|
||||
scheduleEvent(function()
|
||||
GFX.fadeOut(widget, time, elapsed + 30)
|
||||
end, 30)
|
||||
else
|
||||
widget:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
15
modules/gfx/gfx.otmod
Normal file
15
modules/gfx/gfx.otmod
Normal file
@@ -0,0 +1,15 @@
|
||||
Module
|
||||
name: gfx
|
||||
description: Contains utilities for generating graphics effects
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
version: 0.2
|
||||
autoLoad: true
|
||||
dependencies:
|
||||
- core
|
||||
|
||||
onLoad: |
|
||||
require 'gfx'
|
||||
return true
|
||||
|
||||
|
||||
@@ -50,4 +50,4 @@ MainWindow
|
||||
anchors.bottom: parent.bottom
|
||||
margin.bottom: 16
|
||||
margin.right: 16
|
||||
onClick: function(self) self.parent:destroy() end
|
||||
onClick: function(self) GFX.fadeOut(self.parent) end
|
||||
|
||||
@@ -10,7 +10,7 @@ Panel
|
||||
smooth: true
|
||||
anchors.fill: parent
|
||||
|
||||
RoundedGridPanel
|
||||
RoundedPanel
|
||||
id: mainMenu
|
||||
size: 144 162
|
||||
anchors.left: parent.left
|
||||
@@ -23,7 +23,10 @@ Panel
|
||||
anchors.top: parent.top
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
margin.top: 18
|
||||
onClick: rootWidget:addChild(loadUI("/mainmenu/ui/entergamewindow.otui"))
|
||||
onClick: |
|
||||
local enterGameWindow = loadUI("/mainmenu/ui/entergamewindow.otui")
|
||||
rootWidget:addChild(enterGameWindow)
|
||||
GFX.fadeIn(enterGameWindow)
|
||||
|
||||
MenuButton
|
||||
text: Options
|
||||
|
||||
Reference in New Issue
Block a user