rework on graphics.cpp, implement some GFX with lua

This commit is contained in:
Eduardo Bart
2011-08-14 14:45:25 -03:00
parent 2abe962aa9
commit afc197f2dc
28 changed files with 250 additions and 128 deletions

View File

@@ -14,6 +14,7 @@ Module
require 'util'
require 'widget'
require 'messagebox'
require 'dispatcher'
rootWidget = getRootWidget()
return true

View 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

View File

@@ -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

View File

@@ -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

View File

@@ -1,5 +1,5 @@
Window < UIWindow
size: 200 100
size: 200 200
head:
height: 20
border-image:

26
modules/gfx/gfx.lua Normal file
View 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
View 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

View File

@@ -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

View File

@@ -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