Donation.lua
4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
-- ToME - Tales of Maj'Eyal
-- Copyright (C) 2009 - 2017 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"
local Dialog = require "engine.ui.Dialog"
local Separator = require "engine.ui.Separator"
local List = require "engine.ui.List"
local Button = require "engine.ui.Button"
local Numberbox = require "engine.ui.Numberbox"
local Textzone = require "engine.ui.Textzone"
local Checkbox = require "engine.ui.Checkbox"
local Savefile = require "engine.Savefile"
local Map = require "engine.Map"
module(..., package.seeall, class.inherit(Dialog))
function _M:init(source)
self.donation_source = source or "ingame"
Dialog.init(self, "Donations", 500, 300)
local desc
local recur = false
if not profile.auth or not tonumber(profile.auth.donated) or tonumber(profile.auth.donated) <= 1 then
local donation_features = { "#GOLD#Custom character tiles#WHITE#", "#GOLD#Exploration mode (infinite lives)#WHITE#", "#GOLD#Item's appearance change (Shimmering)#WHITE#"}
self:triggerHook{"DonationDialog:features", list=donation_features}
-- First time donation
desc = Textzone.new{width=self.iw, auto_height=true, text=[[Hi, I am Nicolas (DarkGod), the maker of this game.
It is my dearest hope that you find my game enjoyable, and that you will continue to do so for many years to come!
ToME is free and open-source and will stay that way, but that does not mean I can live without money, so I have come to disturb you here and now to ask for your kindness.
If you feel that the (many) hours you have spent having fun were worth it, please consider making a donation for the future of the game.
Donators are also granted a few special features: ]]..table.concatNice(donation_features, ", ", " and ").."."}
else
-- Recurring donation
recur = true
desc = Textzone.new{width=self.iw, auto_height=true, text=[[Thank you for supporting ToME, your donation was greatly appreciated.
If you want to continue supporting ToME you are welcome to make a new donation or even a reccuring one which helps ensure the future of the game.
Thank you for your kindness!]]}
end
self.c_donate = Numberbox.new{title="Donation amount: ", number=10, max=1000, min=5, chars=5, fct=function() end}
local euro = Textzone.new{auto_width=true, auto_height=true, text=[[euro]]}
self.c_recur = Checkbox.new{title="Make it a recurring monthly donation", default=recur, fct=function() end}
local ok = require("engine.ui.Button").new{text="Accept", fct=function() self:ok() end}
local cancel = require("engine.ui.Button").new{text="Cancel", fct=function() self:cancel() end}
self:loadUI{
{left=0, top=0, ui=desc},
{left=5, bottom=5 + ok.h + self.c_recur.h, ui=self.c_donate},
{left=5+self.c_donate.w, bottom=10 + ok.h + self.c_recur.h, ui=euro},
{left=0, bottom=5 + ok.h, ui=self.c_recur},
{left=0, bottom=0, ui=ok},
{right=0, bottom=0, ui=cancel},
}
self:setFocus(self.c_donate)
self:setupUI(false, true)
end
function _M:cancel()
game:unregisterDialog(self)
end
function _M:ok()
if not tonumber(self.c_donate.number) or tonumber(self.c_donate.number) < 5 then return end
game:unregisterDialog(self)
local inside = jit and jit.os ~= "Linux" and core.webview and true or false
if not inside then self:simplePopup("Thank you", "Thank you, a paypal page should now open in your browser.") end
local url = ("https://te4.org/ingame-donate/%s/%s/%s/EUR/%s"):format(self.c_donate.number, self.c_recur.checked and "monthly" or "onetime", (profile.auth and profile.auth.drupid) and profile.auth.drupid or "0", self.donation_source)
if inside then util.browserOpenUrl(url, {is_external=true})
else util.browserOpenUrl(url, {webview=true, is_external=true}) end
end