Skip to content
Snippets Groups Projects
Commit 396924b7 authored by dg's avatar dg
Browse files

Removed old unused NumberBox TextBox Button ButtonList classes

git-svn-id: http://svn.net-core.org/repos/t-engine4@2834 51575b47-30f0-44d4-a5cc-537603b46e54
parent 5df2f840
No related branches found
No related tags found
No related merge requests found
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
require "engine.Tiles"
require "engine.Mouse"
require "engine.KeyBind"
local ButtonList = require "engine.ButtonList"
--- Handles dialog windows
module(..., package.seeall, class.make)
function _M:init(name, text, x, y, w, height, owner, font, fct)
self.type = "Button"
self.owner = owner
self.name = name
self.fct = fct
self.font = font
self.x = x
self.y = y
self.btn = {
susel = ButtonList:makeButton(text, self.font, w, height, false),
sel = ButtonList:makeButton(text, self.font, 50, height, true),
h = height,
mouse_over= function(button)
if self.owner.state ~= self.name then self.owner:focusControl(self.name) end
if button == "left" then
self:fct()
end
self.owner.changed = true
end
}
self.owner.mouse:registerZone(owner.display_x + self.x, owner.display_y + self.y + height, w, height, self.btn.mouse_over)
end
function _M:drawControl(s)
if (self.owner.state == self.name) then
s:merge(self.btn.sel, self.x, self.y)
else
s:merge(self.btn.susel, self.x, self.y)
end
end
\ No newline at end of file
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
require "engine.Tiles"
require "engine.Mouse"
require "engine.KeyBind"
--- Handles dialog windows
module(..., package.seeall, class.make)
tiles = engine.Tiles.new(16, 16)
--- Create a buttons list
function _M:init(list, x, y, w, h, font, separator)
self.separator = separator or 20
self.w, self.h = math.floor(w), math.floor(h)
self.display_x = math.floor(x or (game.w - self.w) / 2)
self.display_y = math.floor(y or (game.h - self.h) / 2)
self.font = font
self.list = list
if not font then self.font = core.display.newFont("/data/font/VeraBd.ttf", 16) end
self.surface = core.display.newSurface(w, h)
self.texture = self.surface:glTexture()
self.surface:erase()
self.old_selected = 0
self.selected = 0
self:select(1)
for i, b in ipairs(self.list) do
assert(b.name, "no button name")
assert(b.fct, "no button function")
local bw, bh = (b.font or self.font):size(b.name)
b.w, b.h = w, h / (#list + 1)
b.susel = self:makeButton(b.name, b.font, b.w, b.h, false)
b.ssel = self:makeButton(b.name, b.font, b.w, b.h, true)
b.mouse_over = function(button)
self:select(i)
if button == "left" then
self:click(i)
end
end
end
self.changed = true
end
function _M:close()
if self.old_key then self.old_key:setCurrent() end
if self.old_mouse then self.old_mouse:setCurrent() end
end
function _M:setKeyHandling()
self.old_key = engine.KeyBind.current
self.key = engine.KeyBind.new()
self.key:setCurrent()
self.key:addBinds
{
MOVE_UP = function()
self:select(-1, true)
end,
MOVE_DOWN = function()
self:select(1, true)
end,
ACCEPT = function()
self:click()
end,
}
game.key = self.key
end
function _M:setMouseHandling()
self.old_mouse = engine.Mouse.current
self.mouse = engine.Mouse.new()
self.mouse:setCurrent()
for i, b in ipairs(self.list) do
self.mouse:registerZone(self.display_x, self.display_y + (i - 1) * (b.h + self.separator), b.w, b.h, b.mouse_over)
end
game.mouse = self.mouse
end
function _M:select(i, offset)
if offset then
self.selected = self.selected + i
else
self.selected = i
end
if self.selected > #self.list then self.selected = 1 self.old_selected = 0 end
if self.selected < 1 then self.selected = #self.list self.old_selected = #self.list + 1 end
if (not self.old_selected or self.old_selected ~= self.selected) and self.list[self.selected].onSelect then self.list[self.selected].onSelect() end
self.old_selected = self.selected
self.changed = true
end
function _M:skipSelected()
if self.old_selected < self.selected then self:select(1, true)
elseif self.old_selected > self.selected then self:select(-1, true) end
end
function _M:click(i)
self.list[i or self.selected].fct()
end
function _M:display()
end
function _M:toScreen(x,y)
for i, b in ipairs(self.list) do
if i == self.selected then
b.ssel:toScreen(x + 0, y + (i - 1) * (b.h + self.separator))
else
b.susel:toScreen(x + 0, y + (i - 1) * (b.h + self.separator))
end
end
end
function _M:makeButton(name, font, w, h, sel)
font = font or self.font
local s = core.display.newSurface(w, h)
if sel then
s:erase(143, 155, 85, 200)
else
s:erase(0,0,0,200)
end
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_7"..(sel and "_sel" or "")..".png"), 0, 0)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_9"..(sel and "_sel" or "")..".png"), w - 8, 0)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_1"..(sel and "_sel" or "")..".png"), 0, h - 8)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_3"..(sel and "_sel" or "")..".png"), w - 8, h - 8)
for i = 8, w - 9 do
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_8.png"), i, 0)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_8.png"), i, h - 3)
end
for i = 8, h - 9 do
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_4.png"), 0, i)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_4.png"), w - 3, i)
end
local sw, sh = font:size(name)
s:drawColorStringBlended(font, name, (w - sw) / 2, (h - sh) / 2)
return s
end
......@@ -238,56 +238,6 @@ function _M:toScreen(x, y, nb_keyframes)
end
end
function _M:addControl(control)
control.tabindex = self.tabindex
self.tabindex = self.tabindex + 1
self.controls[control.name] = control
table.sort(self.controls, function(a,b) return a.tabindex<b.tabindex end)
end
function _M:changeFocus(up)
local add = 1
if not up then add = -1 end
self.currenttabindex = self.currenttabindex + add
if (self.currenttabindex==self.tabindex) then self.currenttabindex = 0 end
if self.currenttabindex==-1 then self.currenttabindex=self.tabindex-1 end
local name = ""
for i, cntrl in pairs(self.controls) do
if cntrl.tabindex==self.currenttabindex then
if self.controls[self.state] and self.controls[self.state].unFocus then self.controls[self.state]:unFocus() end
cntrl.focused=true
name=i
end
end
return name
end
function _M:focusControl(focusOn)
if focusOn==self.state then return end
local oldstate = self.state
for i, cntrl in pairs(self.controls) do
if i==focusOn then cntrl.focused=true self.state=i self.currenttabindex=cntrl.tabindex end
if i==oldstate and cntrl.unFocus then cntrl:unFocus() end
end
end
function _M:databind()
local result = { }
for i, cntrl in pairs(self.controls or { }) do
if cntrl.type and (cntrl.type=="TextBox" or cntrl.type=="NumberBox") then
result[cntrl.name] = cntrl.text
end
end
return result
end
function _M:drawControls(s)
for i, cntrl in pairs(self.controls or { }) do
cntrl:drawControl(s)
end
end
function _M:drawDialog(s)
end
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
require "engine.Tiles"
require "engine.Mouse"
require "engine.KeyBind"
require "engine.interface.ControlCursorSupport"
--- Handles numberbox input control
module(..., package.seeall, class.inherit(engine.interface.ControlCursorSupport))
tiles = engine.Tiles.new(16, 16)
function _M:init(dialogdef, owner, font, mask, fct)
--name, title, min, max, x, y, w, height
self.type = "NumberBox"
self.name = dialogdef.name
self.title = dialogdef.title
self.min = dialogdef.min or 2
self.max = dialogdef.max or 25
self.h = dialogdef.h or 30
self.font = font
self.w = dialogdef.w or 200
self.x = dialogdef.x
self.y = dialogdef.y
self.private = dialogdef.private
self.text = dialogdef.default or 0
self.owner = owner
self.btn = {
h = dialogdef.h,
mouse_over= function(button)
if self.owner.state ~= self.name then self.focused=true self.owner:focusControl(self.name) end
if button == "right" then
self.text=0
end
self.owner.changed=true
end
}
self.owner.mouse:registerZone(self.owner.display_x + self.x, self.owner.display_y + self.y + self.h, self.w, self.h, self.btn.mouse_over)
self:startCursor()
self:moveRight(1, true)
end
function _M:backSpace()
--[[
if (self.cursorPosition==0) then return end
local temptext = self.text:sub(1, self.cursorPosition - 1)
if self.cursorPosition < self.maximumCursorPosition then temptext = temptext..self.text:sub(self.cursorPosition + 1, self.text:len()) end
self.text = temptext
self.maximumCursorPosition = self.maximumCursorPosition - 1
self.cursorPosition = self.cursorPosition - 1
]]
local b = tostring(self.text)
b = b:sub(1, b:len() - 1)
if b == '' then self.text = 0
else self.text = tonumber(b)
end
self.cursorPosition = b:len() + 1
end
function _M:textInput(c)
if not (c == '0' or c == '1' or c == '2' or c == '3' or c == '4' or c == '5' or c == '6' or c == '7' or c == '8' or c == '9') then return end
if self.text >= 10000000 then return end
local b = tostring(self.text)
if self.text == 0 then b = "" end
if self.first then
self.text = tonumber(c)
self.first = false
else
self.text = tonumber(b .. c)
end
self.cursorPosition = b:len() + 1
--[[
if self.text:len() < self.max then
local temp=nil
if self.cursorPosition < self.maximumCursorPosition then temp=self.text:sub(self.cursorPosition + 1, self.text:len()) end
self.text = self.text:sub(1,self.cursorPosition) .. c
if temp then self.text=self.text..temp end
self.owner.changed = true
self:moveRight(1, true)
end
]]
end
function _M:unFocus()
self.focused = false
end
function _M:drawControl(s)
local r, g, b
local w = self.w
local h = self.h
local tw, th = self.font:size(self.title)
tw = tw + 10
local title=self.title
if self.owner.state==self.name then
title = title.."*"
end
r, g, b = s:drawColorStringBlended(self.font, title, self.x, self.y + ((h - th) / 2), r, g, b)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_7"..(sel and "_sel" or "")..".png"), self.x + tw, self.y)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_9"..(sel and "_sel" or "")..".png"), w + self.x - 8, self.y)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_1"..(sel and "_sel" or "")..".png"), self.x + tw, self.y + h - 8)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_3"..(sel and "_sel" or "")..".png"), self.x + w - 8, self.y + h - 8)
for i = 8, w - tw - 9 do
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_8.png"), self.x + tw + i, self.y)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_8.png"), self.x + tw + i, self.y + h - 3)
end
for i = 8, h - 9 do
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_4.png"), self.x + tw, self.y + i)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_4.png"), self.x + w - 3, self.y + i)
end
local text = tostring(self.text)
if text=="" then text=self.mask or "" end
if self.private then text = text:gsub('.', '*') end
local sw, sh = self.font:size(text)
local baseX = self.x + tw + 10
s:drawColorStringBlended(self.font, text, baseX, self.y + h - sh - 8)
self:drawCursor(s, baseX, text)
end
-- TE4 - T-Engine 4
-- Copyright (C) 2009, 2010 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
require "engine.Tiles"
require "engine.Mouse"
require "engine.KeyBind"
require "engine.interface.ControlCursorSupport"
--- Handles textbox input control
module(..., package.seeall, class.inherit(engine.interface.ControlCursorSupport))
tiles = engine.Tiles.new(16, 16)
function _M:init(dialogdef, owner, font, mask, fct)
--name, title, min, max, x, y, w, height
self.type = "TextBox"
self.name = dialogdef.name
self.title = dialogdef.title
self.min = dialogdef.min or 2
self.max = dialogdef.max or 25
self.h = dialogdef.h or 30
self.font = font
self.w = dialogdef.w or 200
self.x = dialogdef.x
self.y = dialogdef.y
self.private = dialogdef.private
self.text = ""
self.owner = owner
self.btn = {
h = dialogdef.h,
mouse_over= function(button)
if self.owner.state ~= self.name then self.focused=true self.owner:focusControl(self.name) end
if button == "right" then
self.text=""
end
self.owner.changed=true
end
}
self.owner.mouse:registerZone(self.owner.display_x + self.x, self.owner.display_y + self.y + self.h, self.w, self.h, self.btn.mouse_over)
self:startCursor()
end
function _M:delete()
if (self.cursorPosition>=self.maximumCursorPosition) then return end
local temptext = self.text:sub(1, self.cursorPosition)
if self.cursorPosition < self.maximumCursorPosition - 1 then temptext = temptext..self.text:sub(self.cursorPosition + 2, self.text:len()) end
self.text = temptext
self.maximumCursorPosition = self.maximumCursorPosition - 1
end
function _M:backSpace()
if (self.cursorPosition==0) then return end
local temptext = self.text:sub(1, self.cursorPosition - 1)
if self.cursorPosition < self.maximumCursorPosition then temptext = temptext..self.text:sub(self.cursorPosition + 1, self.text:len()) end
self.text = temptext
self.maximumCursorPosition = self.maximumCursorPosition - 1
self.cursorPosition = self.cursorPosition - 1
end
function _M:textInput(c)
if self.text:len() < self.max then
local temp=nil
if self.cursorPosition < self.maximumCursorPosition then temp=self.text:sub(self.cursorPosition + 1, self.text:len()) end
self.text = self.text:sub(1,self.cursorPosition) .. c
if temp then self.text=self.text..temp end
self.owner.changed = true
self:moveRight(1, true)
end
end
function _M:unFocus()
self.focused = false
end
function _M:drawControl(s)
local r, g, b
local w = self.w
local h = self.h
local tw, th = self.font:size(self.title)
tw = tw + 10
local title=self.title
if self.owner.state==self.name then
title = title.."*"
end
r, g, b = s:drawColorStringBlended(self.font, title, self.x, self.y + ((h - th) / 2), r, g, b)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_7"..(sel and "_sel" or "")..".png"), self.x + tw, self.y)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_9"..(sel and "_sel" or "")..".png"), w + self.x - 8, self.y)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_1"..(sel and "_sel" or "")..".png"), self.x + tw, self.y + h - 8)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_3"..(sel and "_sel" or "")..".png"), self.x + w - 8, self.y + h - 8)
for i = 8, w - tw - 9 do
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_8.png"), self.x + tw + i, self.y)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_8.png"), self.x + tw + i, self.y + h - 3)
end
for i = 8, h - 9 do
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_4.png"), self.x + tw, self.y + i)
s:merge(tiles:get(nil, 0,0,0, 0,0,0, "border_4.png"), self.x + w - 3, self.y + i)
end
local text = self.text
if text=="" then text=self.mask or "" end
if self.private then text = text:gsub('.', '*') end
local sw, sh = self.font:size(text)
local baseX = self.x + tw + 10
s:drawColorStringBlended(self.font, text, baseX, self.y + h - sh - 8)
self:drawCursor(s, baseX, text)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment