mirror of
https://github.com/rayaman/multi.git
synced 2026-09-05 07:27:35 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b9fe6070b | ||
|
|
7601fc636d | ||
|
|
e7d82d5681 | ||
|
|
38f8234d20 | ||
|
|
1635a1633c | ||
|
|
561a5466e0 | ||
|
|
4761475845 | ||
|
|
fd39b09dd3 | ||
|
|
699744e16b | ||
|
|
1b9972d1b7 | ||
|
|
34853f7fb6 | ||
|
|
361012b23b | ||
|
|
bf5078f0bc | ||
|
|
cf22651949 | ||
|
|
f34b200979 | ||
|
|
ca1d05899e | ||
|
|
817c419930 | ||
|
|
97cbc628a9 | ||
|
|
66b96cf567 | ||
|
|
f1c32efb8b | ||
|
|
5209ef20a7 | ||
|
|
04528ef56c | ||
|
|
2116ed34e5 | ||
|
|
4cbb4b0982 | ||
|
|
bb3c814325 | ||
|
|
74cc5ffde8 | ||
|
|
de4de84d2e | ||
|
|
0f7b5fc6af | ||
|
|
6b980b52a5 | ||
|
|
8cf45ac5dd | ||
|
|
81a88e5b89 | ||
|
|
5b95dbec38 | ||
|
|
0968219926 | ||
|
|
11cdb91702 | ||
|
|
0356875f3c | ||
|
|
34ec6b25f9 |
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017 Ryan Ward
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
+1522
File diff suppressed because one or more lines are too long
@@ -1,100 +1,47 @@
|
|||||||
# multi Version: 1.7.0 (Taking multi-tasking to the next level)
|
# multi Version: 1.8.0 (How much thread could a thread thread if a thread could thread thread?)
|
||||||
Updated from 1.6.0 to 1.7.0
|
**Note: The changes section has information on how to use the new features as they come out. Why put the infomation twice on the readme?**</br>
|
||||||
Modified: multi.intergration.lanesManager.lua
|
|
||||||
It is now in a stable and simple state Works with the latest lanes version! Tested with version 3.11 I cannot promise that everything will work with eariler versions. Future versions are good though.
|
|
||||||
Example Usage:
|
|
||||||
```lua
|
|
||||||
local GLOBAL,lthread=require("multi.intergration.lanesManager").init()
|
|
||||||
require("multi.alarm")
|
|
||||||
require("multi.threading")
|
|
||||||
multi:newAlarm(2):OnRing(function(self)
|
|
||||||
GLOBAL["NumOfCores"]=lthread.getCores()
|
|
||||||
end)
|
|
||||||
multi:newAlarm(7):OnRing(function(self)
|
|
||||||
GLOBAL["AnotherTest"]=true
|
|
||||||
end)
|
|
||||||
multi:newAlarm(13):OnRing(function(self)
|
|
||||||
GLOBAL["FinalTest"]=true
|
|
||||||
end)
|
|
||||||
multi:newSystemThread("test",function() -- spawns a thread in another lua process
|
|
||||||
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
|
||||||
print("Waiting for variable: NumOfCores")
|
|
||||||
print("Got it: ",lthread.waitFor("NumOfCores"))
|
|
||||||
lthread.hold(function()
|
|
||||||
return GLOBAL["AnotherTest"] -- note this would hold the entire systemthread. Spawn a coroutine thread using multi:newThread() or multi:newThreaded...
|
|
||||||
end)
|
|
||||||
print("Holding works!")
|
|
||||||
multi:newThread("tests",function()
|
|
||||||
thread.hold(function()
|
|
||||||
return GLOBAL["FinalTest"] -- note this will not hold the entire systemthread. As seen with the TLoop constantly going!
|
|
||||||
end)
|
|
||||||
print("Final test works!")
|
|
||||||
os.exit()
|
|
||||||
end)
|
|
||||||
local a=0
|
|
||||||
multi:newTLoop(function()
|
|
||||||
a=a+1
|
|
||||||
print(a)
|
|
||||||
end,.5)
|
|
||||||
multi:mainloop()
|
|
||||||
end)
|
|
||||||
multi:mainloop()
|
|
||||||
```
|
|
||||||
Onec I am happy with the intergration and feel it is ready I will document it better
|
|
||||||
|
|
||||||
|
|
||||||
Updated from 1.5.0 to 1.6.0
|
|
||||||
Changed: steps and loops
|
|
||||||
```lua
|
|
||||||
-- Was
|
|
||||||
step:OnStep(function(pos,self) -- same goes for tsteps as well
|
|
||||||
print(pos)
|
|
||||||
end)
|
|
||||||
multi:newLoop(function(dt,self)
|
|
||||||
print(dt)
|
|
||||||
end)
|
|
||||||
-- Is now
|
|
||||||
step:OnStep(function(self,pos) -- same goes for tsteps as well
|
|
||||||
print(pos)
|
|
||||||
end)
|
|
||||||
multi:newLoop(function(self,dt)
|
|
||||||
print(dt)
|
|
||||||
end)
|
|
||||||
```
|
|
||||||
Reasoning I wanted to keep objects consistant, but a lot of my older libraries use the old way of doing things. Therefore I added a backwards module
|
|
||||||
```lua
|
|
||||||
require("multi.all")
|
|
||||||
require("multi.compat.backwards[1,5,0]") -- allows for the use of features that were scrapped/changed in 1.6.0+
|
|
||||||
```
|
|
||||||
Updated from 1.4.1 to 1.5.0
|
|
||||||
Added:
|
|
||||||
- An easy way to manage timeouts
|
|
||||||
- Small bug fixes
|
|
||||||
|
|
||||||
1.4.1 - First Public release of the library
|
|
||||||
|
|
||||||
IMPORTANT:
|
|
||||||
Every update I make aims to make things simpler more efficent and just better, but a lot of old code, which can be really big, uses a lot of older features. I know the pain of having to rewrite everything. My promise to my library users is that I will always have backwards support for older features! New ways may exist that are quicker and eaiser, but the old features/methods will be supported.
|
|
||||||
|
|
||||||
Example at end of the readme
|
|
||||||
|
|
||||||
My multitasking library for lua</br>
|
My multitasking library for lua</br>
|
||||||
To install copy the multi folder into your enviroment and you are good to go</br>
|
To install copy the multi folder into your enviroment and you are good to go</br>
|
||||||
|
|
||||||
It is a pure lua binding if you ingore the intergrations (Stable!)</br>
|
It is a pure lua binding if you ingore the intergrations and the love2d compat</br>
|
||||||
|
|
||||||
If you find any bugs or have any issues please let me know :)
|
If you find any bugs or have any issues please let me know :)
|
||||||
|
|
||||||
Also I will eventually add an example folder with a lot of examples for how you can use this library. Don't konw when that will be though :P
|
~~Also I will eventually add an example folder with a lot of examples for how you can use this library. Don't konw when that will be though :P~~ Added!
|
||||||
|
|
||||||
# Discord
|
|
||||||
|
[TOC]
|
||||||
|
|
||||||
|
Discord
|
||||||
|
-------
|
||||||
For real-time assistance with my libraries! A place where you can ask questions and get help with any of my libraries</br>
|
For real-time assistance with my libraries! A place where you can ask questions and get help with any of my libraries</br>
|
||||||
https://discord.gg/U8UspuA</br>
|
https://discord.gg/U8UspuA</br>
|
||||||
|
|
||||||
|
Planned features/TODO
|
||||||
|
---------------------
|
||||||
|
- [x] ~~Add system threads for love2d that works like the lanesManager (loveManager, slight differences).~~
|
||||||
|
- [ ] Improve performance of the library -- It has increased a bit, but I feel I can get a little more out of it
|
||||||
|
- [x] ~~Add more features to support module creators~~
|
||||||
|
- [x] ~~Make a framework for eaiser thread task distributing~~
|
||||||
|
- [x] ~~Fix Error handling on threaded multi objects~~ Non threaded multiobjs will crash your program if they error though! Use multi:newThread() of multi:newSystemThread() if your code can error! Unless you use multi:protect() this however lowers performance!
|
||||||
|
- [x] ~~Add multi:OnError(function(obj,err))~~
|
||||||
|
- [ ] sThread.wrapper(obj) **May or may not be completed**
|
||||||
|
- [ ] SystemThreaded Actors -- After some tests i figured out a way to make this work... It will work slightly different though. This is due to the actor needing to be splittable...
|
||||||
|
- [ ] LoadBalancing for system threads (Once SystemThreaded Actors are done)
|
||||||
|
- [ ] Add more intergrations
|
||||||
|
- [ ] Finish the wiki stuff. (11% done)
|
||||||
|
- [ ] Test for unknown bugs
|
||||||
|
|
||||||
|
Known Bugs/Issues
|
||||||
|
-----------------
|
||||||
|
In regards to intergrations, thread cancellation works slightly different for love2d and lanes. Within love2d I was unable to (To lazy to...) not use the multi library within the thread. A fix for this is to call `multi:Stop()` when you are done with your threaded code! This may change however if I find a way to work around this. In love2d in order to mimic the GLOBAL table I needed the library to constantly sync tha data... You can use the sThread.waitFor(varname), or sThread.hold(func) methods to sync the globals, to get the value instead of using GLOBAL and this could work. If you want to go this route I suggest setting multi.isRunning=true to prevent the auto runner from doing its thing! This will make the multi manager no longer function, but thats the point :P
|
||||||
|
|
||||||
Usage:</br>
|
Usage:</br>
|
||||||
|
-----
|
||||||
```lua
|
```lua
|
||||||
--Basic usage
|
-- Basic usage Alarms: Have been moved to the core of the library require("multi") would work as well
|
||||||
require("multi.all") -- gets the entire library
|
require("multi") -- gets the entire library
|
||||||
alarm=multi:newAlarm(3) -- in seconds can go to .001 uses the built in os.clock()
|
alarm=multi:newAlarm(3) -- in seconds can go to .001 uses the built in os.clock()
|
||||||
alarm:OnRing(function(a)
|
alarm:OnRing(function(a)
|
||||||
print("3 Seconds have passed!")
|
print("3 Seconds have passed!")
|
||||||
@@ -120,25 +67,26 @@ Check out the wiki for detailed usage, but here are the objects:</br>
|
|||||||
- Timer</br>
|
- Timer</br>
|
||||||
- Updater</br>
|
- Updater</br>
|
||||||
- Thread*</br>
|
- Thread*</br>
|
||||||
- Trigger**</br>
|
- Trigger</br>
|
||||||
- Task</br>
|
- Task</br>
|
||||||
- Job</br>
|
- Job</br>
|
||||||
- Function</br>
|
- Function</br>
|
||||||
- Watcher***</br>
|
- Watcher</br>
|
||||||
#Both a process and queue act like the multi namespace, but allows for some cool things. Because they use the other objects an example on them will be done last</br>
|
Note: *Both a process and queue act like the multi namespace, but allows for some cool things. Because they use the other objects an example on them will be done last*</br>
|
||||||
*Uses the built in coroutine features of lua, these have an interesting interaction with the other means of multi-tasking</br>
|
*Uses the built in coroutine features of lua, these have an interesting interaction with the other means of multi-tasking</br>
|
||||||
**Triggers are kind of useless after the creation of the Connection</br>
|
Triggers are kind of useless after the creation of the Connection</br>
|
||||||
***Watchers have no real purpose as well I made it just because.</br>
|
Watchers have no real purpose as well I made it just because.</br>
|
||||||
|
|
||||||
# Examples of each object being used</br>
|
# Examples of each object being used</br>
|
||||||
We already showed alarms in action so lets move on to a Loop object
|
We already showed alarms in action so lets move on to a Loop object
|
||||||
|
|
||||||
Throughout these examples I am going to do some strange things in order to show other features of the library!
|
Throughout these examples I am going to do some strange things in order to show other features of the library!
|
||||||
|
|
||||||
# LOOPS
|
LOOPS
|
||||||
|
-----
|
||||||
```lua
|
```lua
|
||||||
-- Loops
|
-- Loops: Have been moved to the core of the library require("multi") would work as well
|
||||||
require("multi.all") -- gets the entire library
|
require("multi") -- gets the entire library
|
||||||
count=0
|
count=0
|
||||||
loop=multi:newLoop(function(self,dt) -- dt is delta time and self is a reference to itself
|
loop=multi:newLoop(function(self,dt) -- dt is delta time and self is a reference to itself
|
||||||
count=count+1
|
count=count+1
|
||||||
@@ -173,11 +121,12 @@ With loops out of the way lets go down the line
|
|||||||
|
|
||||||
This library aims to be Async like. In reality everything is still on one thread *unless you are using the lanes intergration module WIP* (More on that later)
|
This library aims to be Async like. In reality everything is still on one thread *unless you are using the lanes intergration module WIP* (More on that later)
|
||||||
|
|
||||||
# EVENTS
|
EVENTS
|
||||||
|
------
|
||||||
```lua
|
```lua
|
||||||
-- Events, these were the first objects introduced into the library. I seldomly use them in their pure form though, but later on you'll see their advance uses!
|
-- Events, these were the first objects introduced into the library. I seldomly use them in their pure form though, but later on you'll see their advance uses!
|
||||||
-- Events on there own don't really do much... We are going to need 2 objects at least to get something going
|
-- Events on there own don't really do much... We are going to need 2 objects at least to get something going
|
||||||
require("multi.all") -- gets the entire library
|
require("multi") -- gets the entire library
|
||||||
count=0
|
count=0
|
||||||
-- lets use the loop again to add to count!
|
-- lets use the loop again to add to count!
|
||||||
loop=multi:newLoop(function(self,dt)
|
loop=multi:newLoop(function(self,dt)
|
||||||
@@ -193,9 +142,10 @@ multi:mainloop()
|
|||||||
# Output
|
# Output
|
||||||
Stopped that loop!
|
Stopped that loop!
|
||||||
|
|
||||||
# STEPS
|
STEPS
|
||||||
|
-----
|
||||||
```lua
|
```lua
|
||||||
require("multi.all")
|
require("multi")
|
||||||
-- Steps, are like for loops but non blocking... You can run a loop to infintity and everything will still run I will combine Steps with Ranges in this example.
|
-- Steps, are like for loops but non blocking... You can run a loop to infintity and everything will still run I will combine Steps with Ranges in this example.
|
||||||
step1=multi:newStep(1,10,1,0) -- Some explaining is due. Argument 1 is the Start # Argument 2 is the ResetAt # (inclusive) Argument 3 is the count # (in our case we are counting by +1, this can be -1 but you need to adjust your start and resetAt numbers)
|
step1=multi:newStep(1,10,1,0) -- Some explaining is due. Argument 1 is the Start # Argument 2 is the ResetAt # (inclusive) Argument 3 is the count # (in our case we are counting by +1, this can be -1 but you need to adjust your start and resetAt numbers)
|
||||||
-- The 4th Argument is for skipping. This is useful for timing and for basic priority management. A priority management system is included!
|
-- The 4th Argument is for skipping. This is useful for timing and for basic priority management. A priority management system is included!
|
||||||
@@ -254,9 +204,10 @@ Stepping... 3</br>
|
|||||||
Ok 9.5!</br>
|
Ok 9.5!</br>
|
||||||
Ok 10!</br>
|
Ok 10!</br>
|
||||||
|
|
||||||
# TLOOPS
|
TLOOPS
|
||||||
|
------
|
||||||
```lua
|
```lua
|
||||||
require("multi.all")
|
require("multi")
|
||||||
-- TLoops are loops that run ever n second. We will also look at condition objects as well
|
-- TLoops are loops that run ever n second. We will also look at condition objects as well
|
||||||
-- Here we are going to modify the old loop to be a little different
|
-- Here we are going to modify the old loop to be a little different
|
||||||
count=0
|
count=0
|
||||||
@@ -274,11 +225,12 @@ multi:mainloop()
|
|||||||
# Output
|
# Output
|
||||||
Count is 101!
|
Count is 101!
|
||||||
|
|
||||||
# Connections
|
Connections
|
||||||
|
-----------
|
||||||
These are my favorite objects and you'll see why. They are very useful objects for ASync connections!
|
These are my favorite objects and you'll see why. They are very useful objects for ASync connections!
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
require("multi.all")
|
require("multi")
|
||||||
-- Lets create the events
|
-- Lets create the events
|
||||||
yawn={} -- ill just leave that there
|
yawn={} -- ill just leave that there
|
||||||
OnCustomSafeEvent=multi:newConnection(true) -- lets pcall the calls incase something goes wrong defualt
|
OnCustomSafeEvent=multi:newConnection(true) -- lets pcall the calls incase something goes wrong defualt
|
||||||
@@ -327,16 +279,16 @@ CSE2 1 100 Hello!</br>
|
|||||||
CSE1 1 100 Hi Ya Folks!!!</br>
|
CSE1 1 100 Hi Ya Folks!!!</br>
|
||||||
CSE2 1 100 Hi Ya Folks!!!</br>
|
CSE2 1 100 Hi Ya Folks!!!</br>
|
||||||
CSE3 1 100 Hi Ya Folks!!!</br>
|
CSE3 1 100 Hi Ya Folks!!!</br>
|
||||||
------</br>
|
|
||||||
CSE2 1 100 Hi Ya Folks!!!</br>
|
CSE2 1 100 Hi Ya Folks!!!</br>
|
||||||
CSE3 1 100 Hi Ya Folks!!!</br>
|
CSE3 1 100 Hi Ya Folks!!!</br>
|
||||||
------</br>
|
</br>
|
||||||
|
|
||||||
You may think timers should be bundled with alarms, but they are a bit different and have cool features</br>
|
You may think timers should be bundled with alarms, but they are a bit different and have cool features</br>
|
||||||
# TIMERS
|
TIMERS
|
||||||
|
------
|
||||||
```lua
|
```lua
|
||||||
-- You see the thing is that all time based objects use timers eg. Alarms, TSteps, and Loops. Timers are more low level!
|
-- You see the thing is that all time based objects use timers eg. Alarms, TSteps, and Loops. Timers are more low level!
|
||||||
require("multi.all")
|
require("multi")
|
||||||
local clock = os.clock
|
local clock = os.clock
|
||||||
function sleep(n) -- seconds
|
function sleep(n) -- seconds
|
||||||
local t0 = clock()
|
local t0 = clock()
|
||||||
@@ -379,9 +331,11 @@ Note: This will make more sense when you run it for your self</br>
|
|||||||
4.002</br>
|
4.002</br>
|
||||||
5.003</br>
|
5.003</br>
|
||||||
|
|
||||||
# UPDATER
|
UPDATER
|
||||||
|
-------
|
||||||
```lua
|
```lua
|
||||||
require("multi.all")
|
-- Updaters: Have been moved to the core of the library require("multi") would work as well
|
||||||
|
require("multi")
|
||||||
updater=multi:newUpdater(5) -- really simple, think of a look with the skip feature of a step
|
updater=multi:newUpdater(5) -- really simple, think of a look with the skip feature of a step
|
||||||
updater:OnUpdate(function(self)
|
updater:OnUpdate(function(self)
|
||||||
--print("updating...")
|
--print("updating...")
|
||||||
@@ -431,7 +385,6 @@ multi:mainloop() -- Notice how the past few examples did not need this, well onl
|
|||||||
Note: These numbers will vary drastically depending on your compiler and cpu power</br>
|
Note: These numbers will vary drastically depending on your compiler and cpu power</br>
|
||||||
Regular Bench: 2094137 Steps in 3 second(s)!</br>
|
Regular Bench: 2094137 Steps in 3 second(s)!</br>
|
||||||
P1</br>
|
P1</br>
|
||||||
---------------</br>
|
|
||||||
Below_Normal: 236022 Steps in 3 second(s)!</br>
|
Below_Normal: 236022 Steps in 3 second(s)!</br>
|
||||||
Normal: 314697 Steps in 3 second(s)!</br>
|
Normal: 314697 Steps in 3 second(s)!</br>
|
||||||
Above_Normal: 393372 Steps in 3 second(s)!</br>
|
Above_Normal: 393372 Steps in 3 second(s)!</br>
|
||||||
@@ -440,7 +393,6 @@ Core: 550722 Steps in 3 second(s)!</br>
|
|||||||
Low: 157348 Steps in 3 second(s)!</br>
|
Low: 157348 Steps in 3 second(s)!</br>
|
||||||
Idle: 78674 Steps in 3 second(s)!</br>
|
Idle: 78674 Steps in 3 second(s)!</br>
|
||||||
P2</br>
|
P2</br>
|
||||||
---------------</br>
|
|
||||||
Core: 994664 Steps in 3 second(s)!</br>
|
Core: 994664 Steps in 3 second(s)!</br>
|
||||||
High: 248666 Steps in 3 second(s)!</br>
|
High: 248666 Steps in 3 second(s)!</br>
|
||||||
Above_Normal: 62166 Steps in 3 second(s)!</br>
|
Above_Normal: 62166 Steps in 3 second(s)!</br>
|
||||||
@@ -451,10 +403,11 @@ Low: 971 Steps in 3 second(s)!</br>
|
|||||||
|
|
||||||
Notice: Even though I started each bench at the same time the order that they finished differed the order is likely to vary on your machine as well!</br>
|
Notice: Even though I started each bench at the same time the order that they finished differed the order is likely to vary on your machine as well!</br>
|
||||||
|
|
||||||
# Processes
|
Processes
|
||||||
|
---------
|
||||||
A process allows you to group the Actor objects within a controlable interface
|
A process allows you to group the Actor objects within a controlable interface
|
||||||
```lua
|
```lua
|
||||||
require("multi.all")
|
require("multi")
|
||||||
proc=multi:newProcess() -- takes an optional file as an argument, but for this example we aren't going to use that
|
proc=multi:newProcess() -- takes an optional file as an argument, but for this example we aren't going to use that
|
||||||
-- a process works just like the multi object!
|
-- a process works just like the multi object!
|
||||||
b=0
|
b=0
|
||||||
@@ -528,9 +481,11 @@ function multi:hold(task)
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
# Queuer (WIP)
|
Queuer (WIP)
|
||||||
|
------------
|
||||||
A queuer works just like a process however objects are processed in order that they were created...
|
A queuer works just like a process however objects are processed in order that they were created...
|
||||||
```lua
|
```lua
|
||||||
|
require("multi")
|
||||||
queue = multi:newQueuer()
|
queue = multi:newQueuer()
|
||||||
queue:newAlarm(3):OnRing(function()
|
queue:newAlarm(3):OnRing(function()
|
||||||
print("Ring ring!!!")
|
print("Ring ring!!!")
|
||||||
@@ -575,7 +530,8 @@ Done</br>
|
|||||||
10</br>
|
10</br>
|
||||||
Ring ring!!!</br>
|
Ring ring!!!</br>
|
||||||
|
|
||||||
# Threads
|
Threads
|
||||||
|
-------
|
||||||
These fix the hold problem that you get with regular objects, and they work exactly the same! They even have some extra features that make them really useful.</br>
|
These fix the hold problem that you get with regular objects, and they work exactly the same! They even have some extra features that make them really useful.</br>
|
||||||
```lua
|
```lua
|
||||||
_require=require -- lets play with the require method a bit
|
_require=require -- lets play with the require method a bit
|
||||||
@@ -584,6 +540,7 @@ function require(path)
|
|||||||
_require(path)
|
_require(path)
|
||||||
end
|
end
|
||||||
require("multi.*") -- now I can use that lovely * symbol to require everything
|
require("multi.*") -- now I can use that lovely * symbol to require everything
|
||||||
|
-- Pointless I know I... Don't look at me like that :P
|
||||||
test=multi:newThreadedProcess("main") -- you can thread processors and all Actors see note for a list of actors you can thread!
|
test=multi:newThreadedProcess("main") -- you can thread processors and all Actors see note for a list of actors you can thread!
|
||||||
test2=multi:newThreadedProcess("main2")
|
test2=multi:newThreadedProcess("main2")
|
||||||
count=0
|
count=0
|
||||||
@@ -636,18 +593,20 @@ step 3</br>
|
|||||||
Hello!</br>
|
Hello!</br>
|
||||||
Ring</br>
|
Ring</br>
|
||||||
Count is 100</br>
|
Count is 100</br>
|
||||||
# Threadable Actors
|
Threadable Actors
|
||||||
|
-----------------
|
||||||
- Alarms
|
- Alarms
|
||||||
- Events
|
- Events
|
||||||
- Loop/TLoop
|
- Loop/TLoop
|
||||||
- Process
|
- Process
|
||||||
- Step/TStep
|
- Step/TStep
|
||||||
|
|
||||||
# Functions
|
Functions
|
||||||
|
---------
|
||||||
If you ever wanted to pause a function then great now you can
|
If you ever wanted to pause a function then great now you can
|
||||||
The uses of the Function object allows one to have a method that can run free in a sense
|
The uses of the Function object allows one to have a method that can run free in a sense
|
||||||
```lua
|
```lua
|
||||||
require("multi.all")
|
require("multi")
|
||||||
func=multi:newFunction(function(self,arg1,arg2,...)
|
func=multi:newFunction(function(self,arg1,arg2,...)
|
||||||
self:Pause()
|
self:Pause()
|
||||||
return arg1
|
return arg1
|
||||||
@@ -662,11 +621,12 @@ Hello</br>
|
|||||||
PAUSED</br>
|
PAUSED</br>
|
||||||
Hello3</br>
|
Hello3</br>
|
||||||
|
|
||||||
# ThreadedUpdater
|
ThreadedUpdater
|
||||||
|
---------------
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
-- Works the same as a regular updater!
|
-- Works the same as a regular updater!
|
||||||
require("multi.all")
|
require("multi")
|
||||||
multi:newThreadedUpdater("Test",10000):OnUpdate(function(self)
|
multi:newThreadedUpdater("Test",10000):OnUpdate(function(self)
|
||||||
print(self.pos)
|
print(self.pos)
|
||||||
end)
|
end)
|
||||||
@@ -678,11 +638,12 @@ multi:mainloop()
|
|||||||
...</br>
|
...</br>
|
||||||
.inf</br>
|
.inf</br>
|
||||||
|
|
||||||
# Triggers
|
Triggers
|
||||||
|
--------
|
||||||
Triggers were what I used before connections became a thing, also Function objects are a lot like triggers and can be paused as well, while triggers cannot...</br>
|
Triggers were what I used before connections became a thing, also Function objects are a lot like triggers and can be paused as well, while triggers cannot...</br>
|
||||||
They are simple to use, but in most cases you are better off using a connection</br>
|
They are simple to use, but in most cases you are better off using a connection</br>
|
||||||
```lua
|
```lua
|
||||||
require("multi.trigger")
|
require("multi")
|
||||||
-- They work like connections but can only have one event binded to them
|
-- They work like connections but can only have one event binded to them
|
||||||
trig=multi:newTrigger(function(self,a,b,c,...)
|
trig=multi:newTrigger(function(self,a,b,c,...)
|
||||||
print(a,b,c,...)
|
print(a,b,c,...)
|
||||||
@@ -695,11 +656,11 @@ trig:Fire(1,2,3,"Hello",true)
|
|||||||
1 2 3</br>
|
1 2 3</br>
|
||||||
1 2 3 Hello true</br>
|
1 2 3 Hello true</br>
|
||||||
|
|
||||||
# Tasks
|
Tasks
|
||||||
|
-----
|
||||||
Tasks allow you to run a block of code before the multi mainloops does it thing. Tasks still have a use, but depending on how you program they aren't needed.</br>
|
Tasks allow you to run a block of code before the multi mainloops does it thing. Tasks still have a use, but depending on how you program they aren't needed.</br>
|
||||||
```lua
|
```lua
|
||||||
require("multi.loop")
|
require("multi")
|
||||||
require("multi.task")
|
|
||||||
multi:newTask(function()
|
multi:newTask(function()
|
||||||
print("Hi!")
|
print("Hi!")
|
||||||
end)
|
end)
|
||||||
@@ -719,10 +680,11 @@ Which came first the task or the loop?</br>
|
|||||||
|
|
||||||
As seen in the example above the tasks were done before anything else in the mainloop! This is useful when making libraries around the multitasking features and you need things to happen in a certain order!</br>
|
As seen in the example above the tasks were done before anything else in the mainloop! This is useful when making libraries around the multitasking features and you need things to happen in a certain order!</br>
|
||||||
|
|
||||||
# Jobs
|
Jobs
|
||||||
|
----
|
||||||
Jobs were a strange feature that was created for throttling connections! When I was building a irc bot around this library I couldn't have messages posting too fast due to restrictions. Jobs allowed functions to be added to a queue that were executed after a certain amount of time has passed
|
Jobs were a strange feature that was created for throttling connections! When I was building a irc bot around this library I couldn't have messages posting too fast due to restrictions. Jobs allowed functions to be added to a queue that were executed after a certain amount of time has passed
|
||||||
```lua
|
```lua
|
||||||
require("multi.alarm") -- jobs use alarms I am pondering if alarms should be added to the core or if jobs should use timers instead...
|
require("multi") -- jobs use alarms I am pondering if alarms should be added to the core or if jobs should use timers instead...
|
||||||
-- jobs are built into the core of the library so no need to require them
|
-- jobs are built into the core of the library so no need to require them
|
||||||
print(multi:hasJobs())
|
print(multi:hasJobs())
|
||||||
multi:setJobSpeed(1) -- set job speed to 1 second
|
multi:setJobSpeed(1) -- set job speed to 1 second
|
||||||
@@ -753,11 +715,11 @@ There are 4 jobs in the queue!</br>
|
|||||||
A job!</br></br>
|
A job!</br></br>
|
||||||
Another job!</br>
|
Another job!</br>
|
||||||
|
|
||||||
# Watchers
|
Watchers
|
||||||
|
--------
|
||||||
Watchers allow you to monitor a variable and trigger an event when the variable has changed!
|
Watchers allow you to monitor a variable and trigger an event when the variable has changed!
|
||||||
```lua
|
```lua
|
||||||
require("multi.watcher")
|
require("multi")
|
||||||
require("multi.tloop")
|
|
||||||
a=0
|
a=0
|
||||||
watcher=multi:newWatcher(_G,"a") -- watch a in the global enviroment
|
watcher=multi:newWatcher(_G,"a") -- watch a in the global enviroment
|
||||||
watcher:OnValueChanged(function(self,old,new)
|
watcher:OnValueChanged(function(self,old,new)
|
||||||
@@ -776,9 +738,10 @@ multi:mainloop()
|
|||||||
.inf-1 inf</br>
|
.inf-1 inf</br>
|
||||||
|
|
||||||
Timeout management
|
Timeout management
|
||||||
|
------------------
|
||||||
```lua
|
```lua
|
||||||
-- Note: I used a tloop so I could control the output of the program a bit.
|
-- Note: I used a tloop so I could control the output of the program a bit.
|
||||||
require("multi.tloop")
|
require("multi")
|
||||||
a=0
|
a=0
|
||||||
inc=1 -- change to 0 to see it not met at all, 1 if you want to see the first condition not met but the second and 2 if you want to see it meet the condition on the first go.
|
inc=1 -- change to 0 to see it not met at all, 1 if you want to see the first condition not met but the second and 2 if you want to see it meet the condition on the first go.
|
||||||
loop=multi:newTLoop(function(self)
|
loop=multi:newTLoop(function(self)
|
||||||
@@ -823,6 +786,328 @@ Looping...</br>
|
|||||||
Looping...</br>
|
Looping...</br>
|
||||||
We did it! 1 2 3</br>
|
We did it! 1 2 3</br>
|
||||||
|
|
||||||
# TODO (In order of importance)
|
Changes
|
||||||
- Finish the wiki stuff. (10% done)</br>
|
-------
|
||||||
- Test for unknown bugs</br>
|
Updated from 1.7.6 to 1.8.0</br>
|
||||||
|
Added:</br>
|
||||||
|
- multi:newSystemThreadedQueue()
|
||||||
|
- multi:systemThreadedBenchmark()
|
||||||
|
- More example files
|
||||||
|
- multi:canSystemThread() -- true if an intergration was added false otherwise (For module creation)
|
||||||
|
- Fixed a few bugs in the loveManager
|
||||||
|
|
||||||
|
# Using multi:systemThreadedBenchmark()
|
||||||
|
```lua
|
||||||
|
package.path="?/init.lua;"..package.path
|
||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
||||||
|
multi:systemThreadedBenchmark(3):OnBench(function(self,count)
|
||||||
|
print("First Bench: "..count)
|
||||||
|
multi:systemThreadedBenchmark(3,"All Threads: ")
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
|
```
|
||||||
|
|
||||||
|
# Using multi:newSystemThreadedQueue()
|
||||||
|
```lua
|
||||||
|
-- in love2d, this file will be in the same example folder as before, but is named main2.lua
|
||||||
|
require("core.Library")
|
||||||
|
GLOBAL,sThread=require("multi.intergration.loveManager").init() -- load the love2d version of the lanesManager and requires the entire multi library
|
||||||
|
--IMPORTANT
|
||||||
|
-- Do not make the above local, this is the one difference that the lanesManager does not have
|
||||||
|
-- If these are local the functions will have the upvalues put into them that do not exist on the threaded side
|
||||||
|
-- You will need to ensure that the function does not refer to any upvalues in its code. It will print an error if it does though
|
||||||
|
-- Also each thread has a .1 second delay! This is used to generate a random values for each thread!
|
||||||
|
require("core.GuiManager")
|
||||||
|
gui.ff.Color=Color.Black
|
||||||
|
function multi:newSystemThreadedQueue(name) -- in love2d this will spawn a channel on both ends
|
||||||
|
local c={}
|
||||||
|
c.name=name
|
||||||
|
if love then
|
||||||
|
if love.thread then
|
||||||
|
function c:init()
|
||||||
|
self.chan=love.thread.getChannel(self.name)
|
||||||
|
function self:push(v)
|
||||||
|
self.chan:push(v)
|
||||||
|
end
|
||||||
|
function self:pop()
|
||||||
|
return self.chan:pop()
|
||||||
|
end
|
||||||
|
GLOBAL[self.name]=self
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
else
|
||||||
|
error("Make sure you required the love.thread module!")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
c.linda=lanes.linda()
|
||||||
|
function c:push(v)
|
||||||
|
self.linda:send("Q",v)
|
||||||
|
end
|
||||||
|
function c:pop()
|
||||||
|
return ({self.linda:receive(0,"Q")})[2]
|
||||||
|
end
|
||||||
|
function c:init()
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
GLOBAL[name]=c
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
|
queue=multi:newSystemThreadedQueue("QUEUE"):init()
|
||||||
|
queue:push("This is a test")
|
||||||
|
queue:push("This is a test2")
|
||||||
|
queue:push("This is a test3")
|
||||||
|
queue:push("This is a test4")
|
||||||
|
multi:newSystemThread("test2",function()
|
||||||
|
queue=sThread.waitFor("QUEUE"):init()
|
||||||
|
data=queue:pop()
|
||||||
|
while data do
|
||||||
|
print(data)
|
||||||
|
data=queue:pop()
|
||||||
|
end
|
||||||
|
queue:push("DONE!")
|
||||||
|
end)
|
||||||
|
multi:newThread("test!",function()
|
||||||
|
thread.hold(function() return queue:pop() end)
|
||||||
|
t.text="Done!"
|
||||||
|
end)
|
||||||
|
t=gui:newTextLabel("no done yet!",0,0,300,100)
|
||||||
|
t:centerX()
|
||||||
|
t:centerY()
|
||||||
|
```
|
||||||
|
# In Lanes
|
||||||
|
```lua
|
||||||
|
-- The code is compatible with each other, I just wanted to show different things you can do in both examples
|
||||||
|
-- This file can be found in the examples folder as lanesintergrationtest4.lua
|
||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
||||||
|
queue=multi:newSystemThreadedQueue("QUEUE"):init()
|
||||||
|
queue:push("This is a test")
|
||||||
|
queue:push("This is a test2")
|
||||||
|
queue:push("This is a test3")
|
||||||
|
queue:push("This is a test4")
|
||||||
|
multi:newSystemThread("test2",function()
|
||||||
|
queue=sThread.waitFor("QUEUE"):init()
|
||||||
|
data=queue:pop()
|
||||||
|
while data do
|
||||||
|
print(data)
|
||||||
|
data=queue:pop()
|
||||||
|
end
|
||||||
|
queue:push("This is a test5")
|
||||||
|
queue:push("This is a test6")
|
||||||
|
queue:push("This is a test7")
|
||||||
|
queue:push("This is a test8")
|
||||||
|
end)
|
||||||
|
multi:newThread("test!",function() -- this is a lua thread
|
||||||
|
thread.sleep(.1)
|
||||||
|
data=queue:pop()
|
||||||
|
while data do
|
||||||
|
print(data)
|
||||||
|
data=queue:pop()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
|
```
|
||||||
|
Updated from 1.7.5 to 1.7.6</br>
|
||||||
|
Fixed:
|
||||||
|
Typos like always
|
||||||
|
Added:</br>
|
||||||
|
multi:getPlatform() -- returns "love2d" if using the love2d platform or returns "lanes" if using lanes for threading</br>
|
||||||
|
examples files</br>
|
||||||
|
In Events added method setTask(func)</br>
|
||||||
|
The old way still works and is more convient to be honest, but I felt a method to do this was ok.</br>
|
||||||
|
|
||||||
|
Updated:
|
||||||
|
some example files to reflect changes to the core. Changes allow for less typing</br>
|
||||||
|
loveManager to require the compat if used so you don't need 2 require line to retrieve the library</br>
|
||||||
|
Updated from 1.7.4 to 1.7.5</br>
|
||||||
|
Fixed some typos in the readme... (I am sure there are more there are always more)</br>
|
||||||
|
Added more features for module support</br>
|
||||||
|
TODO:</br>
|
||||||
|
Work on performance of the library... I see 3 places where I can make this thing run quicker</br>
|
||||||
|
|
||||||
|
I'll show case some old versions of the multitasking library eventually so you can see its changes in days past!</br>
|
||||||
|
|
||||||
|
Updated from 1.7.3 to 1.7.4</br>
|
||||||
|
Added: the example folder which will be populated with more examples in the near future!</br>
|
||||||
|
The loveManager intergration that mimics the lanesManager intergration almost exactly to keep coding in both enviroments as close to possible. This is done mostly for library creation support!</br>
|
||||||
|
An example of the loveManager in action using almost the same code as the lanesintergreationtest2.lua</br>
|
||||||
|
NOTE: This code has only been tested to work on love2d version 1.10.2 thoough it should work version 0.9.0
|
||||||
|
```lua
|
||||||
|
require("core.Library") -- Didn't add this to a repo yet! Will do eventually... Allows for injections and other cool things
|
||||||
|
require("multi.compat.love2d") -- allows for multitasking and binds my libraies to the love2d engine that i am using
|
||||||
|
GLOBAL,sThread=require("multi.intergration.loveManager").init() -- load the love2d version of the lanesManager
|
||||||
|
--IMPORTANT
|
||||||
|
-- Do not make the above local, this is the one difference that the lanesManager does not have
|
||||||
|
-- If these are local the functions will have the upvalues put into them that do not exist on the threaded side
|
||||||
|
-- You will need to ensure that the function does not refer to any upvalues in its code. It will print an error if it does though
|
||||||
|
-- Also each thread has a .1 second delay! This is used to generate a random values for each thread!
|
||||||
|
require("core.GuiManager") -- allows the use of graphics in the program.
|
||||||
|
gui.ff.Color=Color.Black
|
||||||
|
function comma_value(amount)
|
||||||
|
local formatted = amount
|
||||||
|
while true do
|
||||||
|
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
|
||||||
|
if (k==0) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return formatted
|
||||||
|
end
|
||||||
|
multi:newSystemThread("test1",function() -- Another difference is that the multi library is already loaded in the threaded enviroment as well as a call to multi:mainloop()
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 1"):OnBench(function(self,c) GLOBAL["T1"]=c multi:Stop() end)
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test2",function() -- spawns a thread in another lua process
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 2"):OnBench(function(self,c) GLOBAL["T2"]=c multi:Stop() end)
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test3",function() -- spawns a thread in another lua process
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 3"):OnBench(function(self,c) GLOBAL["T3"]=c multi:Stop() end)
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test4",function() -- spawns a thread in another lua process
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 4"):OnBench(function(self,c) GLOBAL["T4"]=c multi:Stop() end)
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test5",function() -- spawns a thread in another lua process
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 5"):OnBench(function(self,c) GLOBAL["T5"]=c multi:Stop() end)
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test6",function() -- spawns a thread in another lua process
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 6"):OnBench(function(self,c) GLOBAL["T6"]=c multi:Stop() end)
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("Combiner",function() -- spawns a thread in another lua process
|
||||||
|
function comma_value(amount)
|
||||||
|
local formatted = amount
|
||||||
|
while true do
|
||||||
|
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
|
||||||
|
if (k==0) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return formatted
|
||||||
|
end
|
||||||
|
local b=comma_value(tostring(sThread.waitFor("T1")+sThread.waitFor("T2")+sThread.waitFor("T3")+sThread.waitFor("T4")+sThread.waitFor("T5")+sThread.waitFor("T6")))
|
||||||
|
GLOBAL["DONE"]=b
|
||||||
|
end)
|
||||||
|
multi:newThread("test0",function()
|
||||||
|
-- sThread.waitFor("DONE") -- lets hold the main thread completely so we don't eat up cpu
|
||||||
|
-- os.exit()
|
||||||
|
-- when the main thread is holding there is a chance that error handling on the system threads may not work!
|
||||||
|
-- instead we can do this
|
||||||
|
while true do
|
||||||
|
thread.skip(1) -- allow error handling to take place... Otherwise lets keep the main thread running on the low
|
||||||
|
-- Before we held just because we could... But this is a game and we need to have logic continue
|
||||||
|
--sThreadM.sleep(.001) -- Sleeping for .001 is a greeat way to keep cpu usage down. Make sure if you aren't doing work to rest. Abuse the hell out of GLOBAL if you need to :P
|
||||||
|
if GLOBAL["DONE"] then
|
||||||
|
t.text="Bench: "..GLOBAL["DONE"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
GLOBAL["Bench"]=3
|
||||||
|
t=gui:newTextLabel("no done yet!",0,0,300,100)
|
||||||
|
t:centerX()
|
||||||
|
t:centerY()
|
||||||
|
```
|
||||||
|
Updated from 1.7.2 to 1.7.3</br>
|
||||||
|
Changed how requiring the library works!
|
||||||
|
`require("multi.all")` Will still work as expected; however, with the exception of threading, compat, and intergrations everything else has been moved into the core of the library.
|
||||||
|
```lua
|
||||||
|
-- This means that these are no longer required and will cause an error if done so
|
||||||
|
require("multi.loop")
|
||||||
|
require("multi.alarm")
|
||||||
|
require("multi.updater")
|
||||||
|
require("multi.tloop")
|
||||||
|
require("multi.watcher")
|
||||||
|
require("multi.tstep")
|
||||||
|
require("multi.step")
|
||||||
|
require("multi.task")
|
||||||
|
-- ^ they are all part of the core now
|
||||||
|
```
|
||||||
|
|
||||||
|
Updated from 1.7.1 to 1.7.2</br>
|
||||||
|
Moved updaters, loops, and alarms into the init.lua file. I consider them core features and they are referenced in the init.lua file so they need to exist there. Threaded versions are still separate though. Added another example file
|
||||||
|
|
||||||
|
Updated from 1.7.0 to 1.7.1 Bug fixes only
|
||||||
|
|
||||||
|
Updated from 1.6.0 to 1.7.0</br>
|
||||||
|
Modified: multi.intergration.lanesManager.lua
|
||||||
|
It is now in a stable and simple state Works with the latest lanes version! Tested with version 3.11 I cannot promise that everything will work with eariler versions. Future versions are good though.</br>
|
||||||
|
Example Usage:</br>
|
||||||
|
sThread is a handle to a global interface for system threads to interact with themself</br>
|
||||||
|
thread is the interface for multithreads as seen in the threading section</br>
|
||||||
|
|
||||||
|
GLOBAL a table that can be used throughout each and every thread
|
||||||
|
|
||||||
|
sThreads have a few methods</br>
|
||||||
|
sThread.set(name,val) -- you can use the GLOBAL table instead modifies the same table anyway</br>
|
||||||
|
sThread.get(name) -- you can use the GLOBAL table instead modifies the same table anyway</br>
|
||||||
|
sThread.waitFor(name) -- waits until a value exists, if it does it returns it</br>
|
||||||
|
sThread.getCores() -- returns the number of cores on your cpu</br>
|
||||||
|
sThread.sleep(n) -- sleeps for a bit stopping the entire thread from running</br>
|
||||||
|
sThread.hold(n) -- sleeps until a condition is met</br>
|
||||||
|
```lua
|
||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
||||||
|
require("multi.all")
|
||||||
|
multi:newAlarm(2):OnRing(function(self)
|
||||||
|
GLOBAL["NumOfCores"]=sThread.getCores()
|
||||||
|
end)
|
||||||
|
multi:newAlarm(7):OnRing(function(self)
|
||||||
|
GLOBAL["AnotherTest"]=true
|
||||||
|
end)
|
||||||
|
multi:newAlarm(13):OnRing(function(self)
|
||||||
|
GLOBAL["FinalTest"]=true
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test",function() -- spawns a thread in another lua process
|
||||||
|
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
||||||
|
print("Waiting for variable: NumOfCores")
|
||||||
|
print("Got it: ",sThread.waitFor("NumOfCores"))
|
||||||
|
sThread.hold(function()
|
||||||
|
return GLOBAL["AnotherTest"] -- note this would hold the entire systemthread. Spawn a coroutine thread using multi:newThread() or multi:newThreaded...
|
||||||
|
end)
|
||||||
|
print("Holding works!")
|
||||||
|
multi:newThread("tests",function()
|
||||||
|
thread.hold(function()
|
||||||
|
return GLOBAL["FinalTest"] -- note this will not hold the entire systemthread. As seen with the TLoop constantly going!
|
||||||
|
end)
|
||||||
|
print("Final test works!")
|
||||||
|
os.exit()
|
||||||
|
end)
|
||||||
|
local a=0
|
||||||
|
multi:newTLoop(function()
|
||||||
|
a=a+1
|
||||||
|
print(a)
|
||||||
|
end,.5)
|
||||||
|
multi:mainloop()
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
|
```
|
||||||
|
|
||||||
|
Updated from 1.5.0 to 1.6.0</br>
|
||||||
|
Changed: steps and loops
|
||||||
|
```lua
|
||||||
|
-- Was
|
||||||
|
step:OnStep(function(pos,self) -- same goes for tsteps as well
|
||||||
|
print(pos)
|
||||||
|
end)
|
||||||
|
multi:newLoop(function(dt,self)
|
||||||
|
print(dt)
|
||||||
|
end)
|
||||||
|
-- Is now
|
||||||
|
step:OnStep(function(self,pos) -- same goes for tsteps as well
|
||||||
|
print(pos)
|
||||||
|
end)
|
||||||
|
multi:newLoop(function(self,dt)
|
||||||
|
print(dt)
|
||||||
|
end)
|
||||||
|
```
|
||||||
|
Reasoning I wanted to keep objects consistant, but a lot of my older libraries use the old way of doing things. Therefore I added a backwards module
|
||||||
|
```lua
|
||||||
|
require("multi.all")
|
||||||
|
require("multi.compat.backwards[1,5,0]") -- allows for the use of features that were scrapped/changed in 1.6.0+
|
||||||
|
```
|
||||||
|
Updated from 1.4.1 to 1.5.0
|
||||||
|
Added:
|
||||||
|
- An easy way to manage timeouts
|
||||||
|
- Small bug fixes
|
||||||
|
|
||||||
|
1.4.1 - First Public release of the library
|
||||||
|
|
||||||
|
IMPORTANT:</br>
|
||||||
|
Every update I make aims to make things simpler more efficent and just better, but a lot of old code, which can be really big, uses a lot of older features. I know the pain of having to rewrite everything. My promise to my library users is that I will always have backwards support for older features! New ways may exist that are quicker and eaiser, but the old features/methods will be supported.</br>
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
-- Tick Tock Example
|
||||||
|
require("multi")
|
||||||
|
alarm=multi:newAlarm(1)
|
||||||
|
alarm.state=-1 -- set the state to -1
|
||||||
|
alarm.sounds={[-1]="Tick",[1]="Tock"} -- this makes changing between states easy and fast
|
||||||
|
alarm:OnRing(function(self)
|
||||||
|
print(self.sounds[self.state])
|
||||||
|
self.state=self.state*-1 -- change the state in one line
|
||||||
|
self:Reset() -- Reset the alarm so it runs again
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
package.path="?/init.lua;"..package.path
|
package.path="?/init.lua;"..package.path
|
||||||
require("multi.all")
|
require("multi")
|
||||||
require("multi.compat.backwards[1,5,0]")
|
require("multi.compat.backwards[1,5,0]")
|
||||||
multi:newLoop(function(dt,self)
|
multi:newLoop(function(dt,self)
|
||||||
print(dt)
|
print(dt)
|
||||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,32 @@
|
|||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
||||||
|
require("proAudioRt") -- an audio library
|
||||||
|
-- The hosting site with precompiled binaries is down, but here is a link to a archive
|
||||||
|
-- https://web.archive.org/web/20160907180559/http://viremo.eludi.net:80/proteaAudio/proteaaudiolua.html documentation and downloads are availiable... I also have saved copies just in case :D
|
||||||
|
-- Music by: myuuji
|
||||||
|
-- His youtube channel can be found here: https://www.youtube.com/channel/UCiSKnkKCKAQVxMUWpZQobuQ
|
||||||
|
proAudio.create()
|
||||||
|
multi:newThread("test",function()
|
||||||
|
-- simple playlist
|
||||||
|
sThread.waitFor("song")
|
||||||
|
print("Playing song 1!")
|
||||||
|
proAudio.soundPlay(GLOBAL["song"])
|
||||||
|
sThread.waitFor("song2")
|
||||||
|
thread.hold(function() sThread.sleep(.001) return proAudio.soundActive()==0 end)
|
||||||
|
print("Playing song 2!")
|
||||||
|
proAudio.soundPlay(GLOBAL["song2"])
|
||||||
|
sThread.waitFor("song3")
|
||||||
|
thread.hold(function() sThread.sleep(.001) return proAudio.soundActive()==0 end)
|
||||||
|
print("Playing song 3!")
|
||||||
|
proAudio.soundPlay(GLOBAL["song3"])
|
||||||
|
end)
|
||||||
|
-- loading the audio in another thread is way faster! So lets do that
|
||||||
|
multi:newSystemThread("test1",function() -- spawns a thread in another lua process
|
||||||
|
require("proAudioRt")
|
||||||
|
GLOBAL["song"]=proAudio.sampleFromFile("test.ogg",1,1)
|
||||||
|
print("Loaded song 1!")
|
||||||
|
GLOBAL["song2"]=proAudio.sampleFromFile("test2.ogg",1,1)
|
||||||
|
print("Loaded song 2!")
|
||||||
|
GLOBAL["song3"]=proAudio.sampleFromFile("test3.ogg",1,1)
|
||||||
|
print("Loaded song 3!")
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,10 +1,7 @@
|
|||||||
package.path="?/init.lua;?.lua;"..package.path
|
package.path="?/init.lua;?.lua;"..package.path
|
||||||
local GLOBAL,lthread=require("multi.intergration.lanesManager").init()
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
||||||
require("multi.alarm")
|
|
||||||
require("multi.threading")
|
|
||||||
for i,v in pairs(lanes.ABOUT) do print(i,v) end
|
|
||||||
multi:newAlarm(2):OnRing(function(self)
|
multi:newAlarm(2):OnRing(function(self)
|
||||||
GLOBAL["NumOfCores"]=lthread.getCores()
|
GLOBAL["NumOfCores"]=sThread.getCores()
|
||||||
end)
|
end)
|
||||||
multi:newAlarm(7):OnRing(function(self)
|
multi:newAlarm(7):OnRing(function(self)
|
||||||
GLOBAL["AnotherTest"]=true
|
GLOBAL["AnotherTest"]=true
|
||||||
@@ -15,8 +12,8 @@ end)
|
|||||||
multi:newSystemThread("test",function() -- spawns a thread in another lua process
|
multi:newSystemThread("test",function() -- spawns a thread in another lua process
|
||||||
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
||||||
print("Waiting for variable: NumOfCores")
|
print("Waiting for variable: NumOfCores")
|
||||||
print("Got it: ",lthread.waitFor("NumOfCores"))
|
print("Got it: ",sThread.waitFor("NumOfCores"))
|
||||||
lthread.hold(function()
|
sThread.hold(function()
|
||||||
return GLOBAL["AnotherTest"] -- note this would hold the entire systemthread. Spawn a coroutine thread using multi:newThread() or multi:newThreaded...
|
return GLOBAL["AnotherTest"] -- note this would hold the entire systemthread. Spawn a coroutine thread using multi:newThread() or multi:newThreaded...
|
||||||
end)
|
end)
|
||||||
print("Holding works!")
|
print("Holding works!")
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package.path="?/init.lua;?.lua;"..package.path
|
||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init() -- loads the lanesManager and includes the entire multi library
|
||||||
|
local function comma_value(amount)
|
||||||
|
local formatted = amount
|
||||||
|
while true do
|
||||||
|
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
|
||||||
|
if (k==0) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return formatted
|
||||||
|
end
|
||||||
|
multi:newSystemThread("test1",function() -- spawns a thread in another lua process
|
||||||
|
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 1"):OnBench(function(self,c) GLOBAL["T1"]=c multi:Stop() end)
|
||||||
|
multi:mainloop()
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test2",function() -- spawns a thread in another lua process
|
||||||
|
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 2"):OnBench(function(self,c) GLOBAL["T2"]=c multi:Stop() end)
|
||||||
|
multi:mainloop()
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test3",function() -- spawns a thread in another lua process
|
||||||
|
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 3"):OnBench(function(self,c) GLOBAL["T3"]=c multi:Stop() end)
|
||||||
|
multi:mainloop()
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test4",function() -- spawns a thread in another lua process
|
||||||
|
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 4"):OnBench(function(self,c) GLOBAL["T4"]=c multi:Stop() end)
|
||||||
|
multi:mainloop()
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test5",function() -- spawns a thread in another lua process
|
||||||
|
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 5"):OnBench(function(self,c) GLOBAL["T5"]=c multi:Stop() end)
|
||||||
|
multi:mainloop()
|
||||||
|
end)
|
||||||
|
multi:newSystemThread("test6",function() -- spawns a thread in another lua process
|
||||||
|
require("multi.all") -- now you can do all of your coding with the multi library! You could even spawn more threads from here with the intergration. You would need to require the interaction again though
|
||||||
|
multi:benchMark(sThread.waitFor("Bench"),nil,"Thread 6"):OnBench(function(self,c) GLOBAL["T6"]=c multi:Stop() end)
|
||||||
|
multi:mainloop()
|
||||||
|
print("Bench: ",comma_value(tostring(sThread.waitFor("T1")+sThread.waitFor("T2")+sThread.waitFor("T3")+sThread.waitFor("T4")+sThread.waitFor("T5")+sThread.waitFor("T6"))))
|
||||||
|
GLOBAL["DONE"]=true
|
||||||
|
end)
|
||||||
|
multi:newThread("test0",function()
|
||||||
|
-- sThread.waitFor("DONE") -- lets hold the main thread completely so we don't eat up cpu
|
||||||
|
-- os.exit()
|
||||||
|
-- when the main thread is holding there is a chance that error handling on the system threads may not work!
|
||||||
|
-- instead we can do this
|
||||||
|
while true do
|
||||||
|
thread.skip(1) -- allow error handling to take place... Otherwise lets keep the main thread running on the low
|
||||||
|
sThread.sleep(.001) -- Sleeping for .001 is a greeat way to keep cpu usage down. Make sure if you aren't doing work to rest. Abuse the hell out of GLOBAL if you need to :P
|
||||||
|
if GLOBAL["DONE"] then
|
||||||
|
os.exit()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
GLOBAL["Bench"]=60
|
||||||
|
multi:mainloop()
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package.path="?/init.lua;?.lua;"..package.path -- Spawing threads using 1 method and the sThread.getCores() function!
|
||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init() -- loads the lanesManager and includes the entire multi library
|
||||||
|
local function comma_value(amount)
|
||||||
|
local formatted = amount
|
||||||
|
while true do
|
||||||
|
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
|
||||||
|
if (k==0) then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return formatted
|
||||||
|
end
|
||||||
|
GLOBAL["BENCHCOUNT"],GLOBAL["CNUM"],GLOBAL["DONE"]=0,0,0
|
||||||
|
cores=sThread.getCores()
|
||||||
|
function benchmark() -- our single function that will be used across a bunch of threads
|
||||||
|
require("multi.all") -- get the library
|
||||||
|
local n=GLOBAL["CNUM"]; GLOBAL["CNUM"]=n+1 -- do some math so we can identify which thread is which
|
||||||
|
multi:benchMark(sThread.waitFor("BENCH"),nil,"Thread "..n+1):OnBench(function(self,c) GLOBAL["BENCHCOUNT"]=GLOBAL["BENCHCOUNT"]+c; GLOBAL["DONE"]=GLOBAL["DONE"]+1; multi:Stop() end)
|
||||||
|
-- ^ do the bench mark and add to the BENCHCOUNT GLOBAL value, then increment the DONE Value
|
||||||
|
multi:mainloop()
|
||||||
|
end
|
||||||
|
for i=1,cores do -- loop based on the number of cores you have
|
||||||
|
multi:newSystemThread("test"..i,benchmark) -- create a system thread based on the benchmark
|
||||||
|
end
|
||||||
|
multi:newThread("test0",function()
|
||||||
|
while true do
|
||||||
|
thread.skip(1)
|
||||||
|
sThread.sleep(.001)
|
||||||
|
if GLOBAL["DONE"]==cores then
|
||||||
|
print(comma_value(tostring(GLOBAL["BENCHCOUNT"])))
|
||||||
|
os.exit()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
GLOBAL["BENCH"]=10
|
||||||
|
print("Platform is: ",multi:getPlatform()) -- returns love2d or lanes depending on which platform you are using... If I add more intergrations then this method will be updated! corona sdk may see this library in the future...
|
||||||
|
multi:mainloop()
|
||||||
|
--[[ Output on my machine! I am using luajit and have 6 cores on my computer. Your numbers will vary, but it should look something like this
|
||||||
|
Intergrated Lanes!
|
||||||
|
Platform is: lanes
|
||||||
|
Thread 1 62442125 Steps in 10 second(s)!
|
||||||
|
Thread 2 61379095 Steps in 10 second(s)!
|
||||||
|
Thread 3 62772502 Steps in 10 second(s)!
|
||||||
|
Thread 4 62740684 Steps in 10 second(s)!
|
||||||
|
Thread 5 60926715 Steps in 10 second(s)!
|
||||||
|
Thread 6 61793175 Steps in 10 second(s)!
|
||||||
|
372,054,296
|
||||||
|
]]
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
||||||
|
queue=multi:newSystemThreadedQueue("QUEUE"):init()
|
||||||
|
queue:push("This is a test")
|
||||||
|
queue:push("This is a test2")
|
||||||
|
queue:push("This is a test3")
|
||||||
|
queue:push("This is a test4")
|
||||||
|
multi:newSystemThread("test2",function()
|
||||||
|
queue=sThread.waitFor("QUEUE"):init()
|
||||||
|
data=queue:pop()
|
||||||
|
while data do
|
||||||
|
print(data)
|
||||||
|
data=queue:pop()
|
||||||
|
end
|
||||||
|
queue:push("This is a test5")
|
||||||
|
queue:push("This is a test6")
|
||||||
|
queue:push("This is a test7")
|
||||||
|
queue:push("This is a test8")
|
||||||
|
end)
|
||||||
|
multi:newThread("test!",function() -- this is a lua thread
|
||||||
|
thread.sleep(.1)
|
||||||
|
data=queue:pop()
|
||||||
|
while data do
|
||||||
|
print(data)
|
||||||
|
data=queue:pop()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package.path="?/init.lua;"..package.path -- slightly different usage of the code
|
||||||
|
local GLOBAL,sThread=require("multi.intergration.lanesManager").init()
|
||||||
|
queue=multi:newSystemThreadedQueue("QUEUE")
|
||||||
|
queue:push(1)
|
||||||
|
queue:push(2)
|
||||||
|
queue:push(3)
|
||||||
|
queue:push(4)
|
||||||
|
queue:push(5)
|
||||||
|
queue:push(6)
|
||||||
|
multi:newSystemThread("STHREAD_1",function()
|
||||||
|
queue=sThread.waitFor("QUEUE"):init()
|
||||||
|
GLOBAL["QUEUE"]=nil
|
||||||
|
data=queue:pop()
|
||||||
|
while data do
|
||||||
|
print(data)
|
||||||
|
data=queue:pop()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
multi:newThread("THREAD_1",function()
|
||||||
|
while true do
|
||||||
|
if GLOBAL["QUEUE"]==nil then
|
||||||
|
print("Deleted a Global!")
|
||||||
|
break
|
||||||
|
end
|
||||||
|
thread.skip(1)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
-- like the while loop (kinda)
|
||||||
|
require("multi")
|
||||||
|
loop=multi:newLoop(function(self,dt)
|
||||||
|
if dt>10 then
|
||||||
|
print("Enough time has passed!")
|
||||||
|
self:Break() -- lets break this thing
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
multi:mainloop()
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
function gui:Clickable()
|
||||||
|
local x,y,w,h=love.graphics.getScissor()
|
||||||
|
local mx=love.mouse.getX()
|
||||||
|
local my=love.mouse.getY()
|
||||||
|
if _GuiPro.HasStencel then
|
||||||
|
local obj=_GuiPro.StencelHolder
|
||||||
|
if self:isDescendant(obj) then
|
||||||
|
return math.sqrt((mx-obj.x)^2+(my-obj.y)^2)<=(obj.offset.size.x or 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not(x) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return not(mx>x+w or mx<x or my>y+h or my<y)
|
||||||
|
end
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
|||||||
|
function DrawThings(items)
|
||||||
|
for i=1,#items do
|
||||||
|
items[i]:draw()
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
function gui:OnClicked(func)
|
||||||
|
table.insert(self.funcs,func)
|
||||||
|
end
|
||||||
|
function gui:OnReleased(func)
|
||||||
|
table.insert(self.funcs2,func)
|
||||||
|
end
|
||||||
|
function gui:OnEnter(func)
|
||||||
|
table.insert(self.funcs3,func)
|
||||||
|
end
|
||||||
|
function gui:OnExit(func)
|
||||||
|
table.insert(self.funcs4,func)
|
||||||
|
end
|
||||||
|
function gui:OnUpdate(func)
|
||||||
|
table.insert(self.funcs5,func)
|
||||||
|
end
|
||||||
|
function gui:OnDragStart(func)
|
||||||
|
table.insert(self.func8,func)
|
||||||
|
end
|
||||||
|
function gui:OnDragging(func)
|
||||||
|
table.insert(self.func6,func)
|
||||||
|
end
|
||||||
|
function gui:OnDragEnd(func)
|
||||||
|
table.insert(self.func7,func)
|
||||||
|
end
|
||||||
|
function gui:WhileHovering(func)
|
||||||
|
table.insert(self.func9,func)
|
||||||
|
end
|
||||||
|
function gui:OnMouseMoved(func)
|
||||||
|
table.insert(self.func10,func)
|
||||||
|
end
|
||||||
|
function gui:getChildren()
|
||||||
|
return self.Children
|
||||||
|
end
|
||||||
|
function gui:LClicked()
|
||||||
|
return self.lclicked
|
||||||
|
end
|
||||||
|
function gui:RClicked()
|
||||||
|
return self.rclicked
|
||||||
|
end
|
||||||
|
function gui:MClicked()
|
||||||
|
return self.mclicked
|
||||||
|
end
|
||||||
|
function gui:Clicked()
|
||||||
|
return (self.lclicked or self.rclicked)
|
||||||
|
end
|
||||||
|
function gui:Hovering()
|
||||||
|
return self.hovering
|
||||||
|
end
|
||||||
|
function gui:FreeConnections()
|
||||||
|
self.funcs={function(b,self) if b=="l" then self.LRE=true end end,function(b,self) if b=="r" then self.RRE=true end end,function(b,self) if b=="m" then self.MRE=true end end}
|
||||||
|
self.funcs2={function(b,self) if b=="l" then self.LRE=false end end,function(b,self) if b=="r" then self.RRE=false end end,function(b,self) if b=="m" then self.MRE=false end end}
|
||||||
|
self.funcs3={function(self) self.HE=true end}
|
||||||
|
self.funcs4={function(self) self.HE=false end}
|
||||||
|
self.funcs5={function(self) self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y end}
|
||||||
|
end
|
||||||
|
function gui:LClick()
|
||||||
|
for i=1,#self.funcs do
|
||||||
|
self.funcs[i]("l",self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function gui:RClick()
|
||||||
|
for i=1,#self.funcs do
|
||||||
|
self.funcs[i]("r",self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function gui:MClick()
|
||||||
|
for i=1,#self.funcs do
|
||||||
|
self.funcs[i]("m",self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function gui:LRelease()
|
||||||
|
for i=1,#self.funcs2 do
|
||||||
|
self.funcs2[i]("l",self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function gui:RRelease()
|
||||||
|
for i=1,#self.funcs2 do
|
||||||
|
self.funcs2[i]("r",self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function gui:MRelease()
|
||||||
|
for i=1,#self.funcs2 do
|
||||||
|
self.funcs2[i]("m",self)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
function UpdateThings(items)
|
||||||
|
for i=#items,1,-1 do
|
||||||
|
if items[i]:LClicked() then
|
||||||
|
for g=1,#items[i].funcs do
|
||||||
|
items[i].funcs[g]("l",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||||
|
end
|
||||||
|
elseif items[i]:RClicked() then
|
||||||
|
for g=1,#items[i].funcs do
|
||||||
|
items[i].funcs[g]("r",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||||
|
end
|
||||||
|
elseif items[i]:MClicked() then
|
||||||
|
for g=1,#items[i].funcs do
|
||||||
|
items[i].funcs[g]("m",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not(items[i]:LClicked()) and items[i].LRE then
|
||||||
|
for g=1,#items[i].funcs2 do
|
||||||
|
items[i].funcs2[g]("l",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||||
|
end
|
||||||
|
elseif not(items[i]:RClicked()) and items[i].RRE then
|
||||||
|
for g=1,#items[i].funcs2 do
|
||||||
|
items[i].funcs2[g]("r",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||||
|
end
|
||||||
|
elseif not(items[i]:MClicked()) and items[i].MRE then
|
||||||
|
for g=1,#items[i].funcs2 do
|
||||||
|
items[i].funcs2[g]("m",items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if items[i]:Hovering() and items[i].HE==false then
|
||||||
|
for g=1,#items[i].funcs3 do
|
||||||
|
items[i].funcs3[g](items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||||
|
end
|
||||||
|
elseif not(items[i]:Hovering()) and items[i].HE==true then
|
||||||
|
for g=1,#items[i].funcs4 do
|
||||||
|
items[i].funcs4[g](items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||||
|
end
|
||||||
|
elseif items[i]:Hovering() then
|
||||||
|
for g=1,#items[i].func9 do
|
||||||
|
items[i].func9[g](items[i],love.mouse.getX()-items[i].x,love.mouse.getY()-items[i].y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for g=1,#items[i].funcs5 do
|
||||||
|
items[i].funcs5[g](items[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
function GetAllChildren(Object)
|
||||||
|
local Stuff = {}
|
||||||
|
function Seek(Items)
|
||||||
|
for i=1,#Items do
|
||||||
|
if Items[i].Visible==true then
|
||||||
|
table.insert(Stuff,Items[i])
|
||||||
|
local NItems = Items[i]:getChildren()
|
||||||
|
if NItems ~= nil then
|
||||||
|
Seek(NItems)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local Objs = Object:getChildren()
|
||||||
|
for i=1,#Objs do
|
||||||
|
if Objs[i].Visible==true then
|
||||||
|
table.insert(Stuff,Objs[i])
|
||||||
|
local Items = Objs[i]:getChildren()
|
||||||
|
if Items ~= nil then
|
||||||
|
Seek(Items)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return Stuff
|
||||||
|
end
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
function GetAllChildren2(Object)
|
||||||
|
local Stuff = {}
|
||||||
|
function Seek(Items)
|
||||||
|
for i=1,#Items do
|
||||||
|
table.insert(Stuff,Items[i])
|
||||||
|
local NItems = Items[i]:getChildren()
|
||||||
|
if NItems ~= nil then
|
||||||
|
Seek(NItems)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local Objs = Object:getChildren()
|
||||||
|
for i=1,#Objs do
|
||||||
|
table.insert(Stuff,Objs[i])
|
||||||
|
local Items = Objs[i]:getChildren()
|
||||||
|
if Items ~= nil then
|
||||||
|
Seek(Items)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return Stuff
|
||||||
|
end
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
function gui:eventable()
|
||||||
|
if self.important then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if _GuiPro.Hierarchy then
|
||||||
|
if _GuiPro.TopHovered~=nil then
|
||||||
|
return self:isDescendant(_GuiPro.TopHovered) or _GuiPro.TopHovered==self
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:full()
|
||||||
|
self:SetDualDim(nil,nil,nil,nil,nil,nil,1,1)
|
||||||
|
end
|
||||||
@@ -0,0 +1,238 @@
|
|||||||
|
function gui.enableAutoWindowScaling(b)
|
||||||
|
_GuiPro.DPI_ENABLED=b or true
|
||||||
|
_defaultfont=love.graphics.newFont(12*love.window.getPixelScale())
|
||||||
|
end
|
||||||
|
function filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
if type(name)~="string" then
|
||||||
|
sh=sw
|
||||||
|
sw=sy
|
||||||
|
sy=sx
|
||||||
|
sx=h
|
||||||
|
h=w
|
||||||
|
w=y
|
||||||
|
y=x
|
||||||
|
x=name
|
||||||
|
end
|
||||||
|
return x,y,w,h,sx,sy,sw,sh
|
||||||
|
end
|
||||||
|
function gui:newBase(tp,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
_GuiPro.count=_GuiPro.count+1
|
||||||
|
local c = {}
|
||||||
|
setmetatable(c, gui)
|
||||||
|
if self==gui then
|
||||||
|
c.Parent=_GuiPro
|
||||||
|
else
|
||||||
|
c.Parent=self
|
||||||
|
end
|
||||||
|
c.segments=nil
|
||||||
|
c.ry=nil
|
||||||
|
c.rx=nil
|
||||||
|
c.DPI=1
|
||||||
|
if _GuiPro.DPI_ENABLED then
|
||||||
|
c.DPI=love.window.getPixelScale()
|
||||||
|
x, y, w, h=c.DPI*x,c.DPI*y,c.DPI*w,c.DPI*h
|
||||||
|
end
|
||||||
|
c.centerFontY=true
|
||||||
|
c.FormFactor="rectangle"
|
||||||
|
c.Type=tp
|
||||||
|
c.Active=true
|
||||||
|
c.form="rectangle"
|
||||||
|
c.Draggable=false
|
||||||
|
c.Name=name or "Gui"..tp
|
||||||
|
c:SetName(name)
|
||||||
|
c.BorderSize=1
|
||||||
|
c.BorderColor={0,0,0}
|
||||||
|
c.BorderVisibility=1
|
||||||
|
c.VIS=true
|
||||||
|
c.Visible=true
|
||||||
|
c.oV=true
|
||||||
|
c.Children={}
|
||||||
|
c.hovering=false
|
||||||
|
c.rclicked=false
|
||||||
|
c.lclicked=false
|
||||||
|
c.mclicked=false
|
||||||
|
c.clicked=false
|
||||||
|
c.Visibility=1
|
||||||
|
c.ClipDescendants=false
|
||||||
|
c.TextWrap=true
|
||||||
|
c.scale={}
|
||||||
|
c.scale.size={}
|
||||||
|
c.scale.size.x=sw or 0
|
||||||
|
c.scale.size.y=sh or 0
|
||||||
|
c.offset={}
|
||||||
|
c.offset.size={}
|
||||||
|
c.offset.size.x=w or 0
|
||||||
|
c.offset.size.y=h or 0
|
||||||
|
c.scale.pos={}
|
||||||
|
c.scale.pos.x=sx or 0
|
||||||
|
c.scale.pos.y=sy or 0
|
||||||
|
c.offset.pos={}
|
||||||
|
c.offset.pos.x=x or 0
|
||||||
|
c.offset.pos.y=y or 0
|
||||||
|
c.width = 0
|
||||||
|
c.height = 0
|
||||||
|
c.LRE=false
|
||||||
|
c.RRE=false
|
||||||
|
c.MRE=false
|
||||||
|
c.Color = {255, 255, 255}
|
||||||
|
function c:setRoundness(rx,ry,segments)
|
||||||
|
self.segments=segments
|
||||||
|
self.ry=ry
|
||||||
|
self.rx=rx
|
||||||
|
end
|
||||||
|
function c.stfunc()
|
||||||
|
love.graphics.rectangle("fill", c.x, c.y, c.width, c.height,c.rx,c.ry,c.segments)
|
||||||
|
end
|
||||||
|
function c:hasRoundness()
|
||||||
|
return (self.ry or self.rx)
|
||||||
|
end
|
||||||
|
c.funcs={function(b,self)
|
||||||
|
if b=="l" then
|
||||||
|
self.LRE=true
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
function(b,self)
|
||||||
|
if b=="r" then
|
||||||
|
self.RRE=true
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
function(b,self)
|
||||||
|
if b=="m" then
|
||||||
|
self.MRE=true
|
||||||
|
end
|
||||||
|
end}
|
||||||
|
c.funcs2={function(b,self)
|
||||||
|
if b=="l" then
|
||||||
|
self.LRE=false
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
function(b,self)
|
||||||
|
if b=="r" then
|
||||||
|
self.RRE=false
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
function(b,self)
|
||||||
|
if b=="m" then
|
||||||
|
self.MRE=false
|
||||||
|
end
|
||||||
|
end}
|
||||||
|
c.HE=false
|
||||||
|
c.funcs3={function(self)
|
||||||
|
self.HE=true
|
||||||
|
end}
|
||||||
|
c.funcs4={function(self)
|
||||||
|
self.HE=false
|
||||||
|
end}
|
||||||
|
c.funcs5={}
|
||||||
|
c.tid={}
|
||||||
|
c.touchcount=0
|
||||||
|
c.x=(c.Parent.width*c.scale.pos.x)+c.offset.pos.x+c.Parent.x
|
||||||
|
c.y=(c.Parent.height*c.scale.pos.y)+c.offset.pos.y+c.Parent.y
|
||||||
|
c.width=(c.Parent.width*c.scale.size.x)+c.offset.size.x
|
||||||
|
c.height=(c.Parent.height*c.scale.size.y)+c.offset.size.y
|
||||||
|
c.func6={}
|
||||||
|
c.func7={function() _GuiPro.DragItem={} end}
|
||||||
|
c.func8={function(self) _GuiPro.DragItem=self end}
|
||||||
|
c.func9={}
|
||||||
|
c.func10={}
|
||||||
|
function c:ImageRule()
|
||||||
|
if self.Image then
|
||||||
|
local sx=self.width/self.ImageWidth
|
||||||
|
local sy=self.height/self.ImageHeigth
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.ImageVisibility*255)
|
||||||
|
if self.width~=self.ImageWidth and self.height~=self.ImageHeigth then
|
||||||
|
love.graphics.draw(self.Image,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||||
|
else
|
||||||
|
love.graphics.draw(self.Image,self.Quad,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function c:VideoRule()
|
||||||
|
if self.Video then
|
||||||
|
local sx=self.width/self.VideoWidth
|
||||||
|
local sy=self.height/self.VideoHeigth
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.VideoVisibility*255)
|
||||||
|
if self.width~=self.VideoWidth and self.height~=self.VideoHeigth then
|
||||||
|
love.graphics.draw(self.Video,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||||
|
else
|
||||||
|
love.graphics.draw(self.Video,self.Quad,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function c:repeatImage(b,b2)
|
||||||
|
if b then
|
||||||
|
self.Image:setWrap(b,b2 or "repeat")
|
||||||
|
function self:ImageRule()
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.ImageVisibility*255)
|
||||||
|
love.graphics.draw(self.Image,self.Quad,self.x,self.y,math.rad(self.rotation))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
sx=self.width/self.ImageWidth
|
||||||
|
sy=self.height/self.ImageHeigth
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.ImageVisibility*255)
|
||||||
|
love.graphics.draw(self.Image,self.Quad,self.x,self.y,math.rad(self.rotation),sx,sy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function c:Mutate(t)
|
||||||
|
for i,v in pairs(t) do
|
||||||
|
_GuiPro.self=self
|
||||||
|
if type(i)=="number" then
|
||||||
|
loadstring("_GuiPro.self:"..v)()
|
||||||
|
else
|
||||||
|
self[i]=v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
c:WhileHovering(function(self)
|
||||||
|
self.omx=self.nmx
|
||||||
|
self.omy=self.nmy
|
||||||
|
self.nmx=love.mouse.getX()
|
||||||
|
self.nmy=love.mouse.getY()
|
||||||
|
if self.omx~=self.nmx or self.omy~=self.nmy then
|
||||||
|
for i=1,#self.func10 do
|
||||||
|
if self and self.nmx and self.nmy and self.omx and self.omy then
|
||||||
|
self.func10[i](self,self.nmx,self.nmy,self.omx,self.omy)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if self.WasBeingDragged==true and love.mouse.isDown(self.dragbut or "m")==false and self.Type~="TextImageButtonFrameDrag" then
|
||||||
|
for i=1,#self.func7 do
|
||||||
|
self.func7[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if _GuiPro.hasDrag==false and love.mouse.isDown(self.dragbut or "m") then
|
||||||
|
for i=1,#self.func8 do
|
||||||
|
self.func8[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if self.IsBeingDragged==true then
|
||||||
|
_GuiPro.hasDrag=true
|
||||||
|
self.WasBeingDragged=true
|
||||||
|
elseif self.WasBeingDragged==true and self.IsBeingDragged==false then
|
||||||
|
self.WasBeingDragged=false
|
||||||
|
_GuiPro.hasDrag=false
|
||||||
|
end
|
||||||
|
if self.Draggable==true and love.mouse.isDown(self.dragbut or "m") and _GuiPro.hasDrag==false then
|
||||||
|
for i=1,#self.func6 do
|
||||||
|
self.func6[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||||
|
end
|
||||||
|
_GuiPro.hasDrag=true
|
||||||
|
if self.FormFactor:lower()=="circle" or self.FormFactor:lower()=="c" or self.FormFactor:lower()=="cir" then
|
||||||
|
self.IsBeingDragged=true
|
||||||
|
x=(love.mouse.getX()-self.x)
|
||||||
|
y=(love.mouse.getY()-self.y)
|
||||||
|
self:Move(x,y)
|
||||||
|
elseif self.FormFactor:lower()=="rectangle" or self.FormFactor:lower()=="r" or self.FormFactor:lower()=="rect" then
|
||||||
|
self.IsBeingDragged=true
|
||||||
|
x=(love.mouse.getX()-self.x)-self.width/2
|
||||||
|
y=(love.mouse.getY()-self.y)-self.height/2
|
||||||
|
self:Move(x,y)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
self.IsBeingDragged=false
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
table.insert(c.Parent.Children,c)
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
_GuiPro.mousedownfunc=love.mouse.isDown
|
||||||
|
function love.mouse.isDown(b)
|
||||||
|
if not(b) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return _GuiPro.mousedownfunc(({["l"]=1,["r"]=2,["m"]=3})[b] or b)
|
||||||
|
end
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
--[[WORKING ON
|
||||||
|
doubleTap - UnFinished!
|
||||||
|
touchRendering - Broken
|
||||||
|
]]
|
||||||
|
function gui:TClickable(mx,my)
|
||||||
|
local x,y,w,h=love.graphics.getScissor()
|
||||||
|
if _GuiPro.HasStencel then
|
||||||
|
local obj=_GuiPro.StencelHolder
|
||||||
|
if self:isDescendant(obj) then
|
||||||
|
return math.sqrt((mx-obj.x)^2+(my-obj.y)^2)<=(obj.offset.size.x or 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not(x) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return not(mx>x+w or mx<x or my>y+h or my<y)
|
||||||
|
end
|
||||||
|
function gui:touchable(t)
|
||||||
|
local touches = love.touch.getTouches()
|
||||||
|
local x,y=0,0
|
||||||
|
for i, id in ipairs(touches) do
|
||||||
|
if self.id==id then
|
||||||
|
x, y = love.touch.getPosition(id)
|
||||||
|
return (x > self.x and x < self.x+self.width and y > self.y and y < self.y+self.height and self:TClickable(x,y) and self:eventable())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.id=-1
|
||||||
|
end
|
||||||
|
multi:newTask(function() -- A bit of post-loading haha
|
||||||
|
gui.touchpressed=multi:newConnection()
|
||||||
|
gui.touchreleased=multi:newConnection()
|
||||||
|
gui.touchmoved=multi:newConnection()
|
||||||
|
love.touchpressed=Library.convert(love.touchpressed or function() end)
|
||||||
|
love.touchreleased=Library.convert(love.touchreleased or function() end)
|
||||||
|
love.touchmoved=Library.convert(love.touchmoved or function() end)
|
||||||
|
love.touchpressed:inject(function(id, x, y, dx, dy, pressure) gui.touchpressed:Fire(id, x, y, dx, dy, pressure) return {id, x, y, dx, dy, pressure} end,1)
|
||||||
|
love.touchreleased:inject(function(id, x, y, dx, dy, pressure) gui.touchreleased:Fire(id, x, y, dx, dy, pressure) return {id, x, y, dx, dy, pressure} end,1)
|
||||||
|
love.touchmoved:inject(function(id, x, y, dx, dy, pressure) gui.touchmoved:Fire(id, x, y, dx, dy, pressure) return {id, x, y, dx, dy, pressure} end,1)
|
||||||
|
_GuiPro.TouchReady=true
|
||||||
|
_GuiPro.TouchRegister={}
|
||||||
|
gui.touchpressed:connect(function(id, x, y, dx, dy, pressure)
|
||||||
|
for i,v in pairs(_GuiPro.TouchRegister) do
|
||||||
|
if #v.tid==0 then
|
||||||
|
if (x > v.x and x < v.x+v.width and y > v.y and y < v.y+v.height and v:TClickable(x,y) and v:eventable()) then
|
||||||
|
v:addTID(id)
|
||||||
|
v.touchcount=1
|
||||||
|
for i=1,#v.ToFuncP do
|
||||||
|
v.ToFuncP[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif not(v:hasTID(id)) then
|
||||||
|
if (x > v.x and x < v.x+v.width and y > v.y and y < v.y+v.height and v:TClickable(x,y) and v:eventable()) then
|
||||||
|
v:addTID(id)
|
||||||
|
v.touchcount=v.touchcount+1
|
||||||
|
for i=1,#v.ToFuncP do
|
||||||
|
v.ToFuncP[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
gui.touchreleased:connect(function(id, x, y, dx, dy, pressure)
|
||||||
|
for i,v in pairs(_GuiPro.TouchRegister) do
|
||||||
|
if v:hasTID(id) then
|
||||||
|
v:removeTID(id)
|
||||||
|
for i=1,#v.ToFuncR do
|
||||||
|
v.ToFuncR[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
gui.touchmoved:connect(function(id, x, y, dx, dy, pressure)
|
||||||
|
for i,v in pairs(_GuiPro.TouchRegister) do
|
||||||
|
if v:hasTID(id) and (x > v.x and x < v.x+v.width and y > v.y and y < v.y+v.height and v:TClickable(x,y) and v:eventable()) then
|
||||||
|
for i=1,#v.ToFuncM do
|
||||||
|
v.ToFuncM[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||||
|
end
|
||||||
|
elseif v:hasTID(id) and not((x > v.x and x < v.x+v.width and y > v.y and y < v.y+v.height and v:TClickable(x,y) and v:eventable())) then
|
||||||
|
v:removeTID(id)
|
||||||
|
for i=1,#v.ToFuncR do
|
||||||
|
v.ToFuncR[i](v,id, x-v.x, y-v.y, dx, dy or 0, pressure or 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
-- now that that is done lets set up some more post loading checks
|
||||||
|
_GuiPro.int=multi:newProcess()
|
||||||
|
_GuiPro.int:Start()
|
||||||
|
_GuiPro.int:setJobSpeed(.001)
|
||||||
|
_GuiPro.EXACT=0
|
||||||
|
_GuiPro.LAX=.01
|
||||||
|
_GuiPro.LAZY=.05
|
||||||
|
-- now lets define the reg function
|
||||||
|
function gui.Compare(a,b,v,tp)
|
||||||
|
if tp==">" then
|
||||||
|
if (a+v>b or a-v>b) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elseif tp=="<" then
|
||||||
|
if (a+v<b or a-v<b) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elseif tp=="<=" then
|
||||||
|
if (a+v<=b or a-v<=b) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elseif tp==">=" then
|
||||||
|
if (a+v>=b or a-v>=b) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
elseif tp=="==" then -- this one is gonna be tricky
|
||||||
|
if (a>=b-v and a<=b+v) or (b>=a-v and b<=a+v) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
function gui:regesterTouch()
|
||||||
|
local obj=self
|
||||||
|
obj.ToFuncP={}
|
||||||
|
obj.ToFuncM={}
|
||||||
|
obj.ToFuncR={}
|
||||||
|
obj.To2Func={}
|
||||||
|
obj.ToDTFunc={}
|
||||||
|
obj.touchRendering =_GuiPro.EXACT -- exact(0), lax(), #
|
||||||
|
function obj:removeTID(id)
|
||||||
|
for i=1,#self.tid do
|
||||||
|
if self.tid[i]==id then
|
||||||
|
table.remove(self.tid,i)
|
||||||
|
self.touchcount=self.touchcount-1
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function obj:hasTID(id)
|
||||||
|
for i=1,#self.tid do
|
||||||
|
if self.tid[i]==id then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
obj.txl1=0
|
||||||
|
obj.tyl1=0
|
||||||
|
obj.txl2=0
|
||||||
|
obj.tyl2=0
|
||||||
|
obj.LS=0
|
||||||
|
obj:OnUpdate(function(self)
|
||||||
|
if self.touchcount==2 then
|
||||||
|
local x1,y1=love.touch.getPosition( self.tid[1] )
|
||||||
|
local x2,y2=love.touch.getPosition( self.tid[2] )
|
||||||
|
local CS=math.sqrt((x2-x1)^2+(y2-y1)^2)
|
||||||
|
if gui.Compare(CS,self.LS,self.touchRendering,">") then
|
||||||
|
for i=1,#self.To2Func do
|
||||||
|
self.To2Func[i](self,CS,x1-self.x,y1-self.y,x2-self.x,y2-self.y)
|
||||||
|
end
|
||||||
|
elseif gui.Compare(CS,self.LS,self.touchRendering,"<") then
|
||||||
|
for i=1,#self.To2Func do
|
||||||
|
self.To2Func[i](self,-CS,x1-self.x,y1-self.y,x2-self.x,y2-self.y)
|
||||||
|
end
|
||||||
|
elseif gui.Compare(CS,self.LS,self.touchRendering,"==") then
|
||||||
|
for i=1,#self.To2Func do
|
||||||
|
self.To2Func[i](self,0,x1-self.x,y1-self.y,x2-self.x,y2-self.y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- if self.txl1~=x1 or self.txl2~=x2 or self.tyl1~=y1 or self.tyl2~=y2 then
|
||||||
|
-- for i=1,#self.To2Func do
|
||||||
|
-- self.To2Func[i](self,0,x1-self.x,y1-self.y,x2-self.x,y2-self.y)
|
||||||
|
-- end
|
||||||
|
-- end
|
||||||
|
self.LS=CS
|
||||||
|
self.txl1=x1
|
||||||
|
self.txl2=x2
|
||||||
|
self.tyl1=y1
|
||||||
|
self.tyl2=y2
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
function obj:OnDoubleTap(func)
|
||||||
|
table.insert(self.ToDTFunc,func)
|
||||||
|
end
|
||||||
|
function obj:On2TouchMoved(func)
|
||||||
|
table.insert(self.To2Func,func)
|
||||||
|
end
|
||||||
|
function obj:addTID(id)
|
||||||
|
table.insert(self.tid,id)
|
||||||
|
end
|
||||||
|
function obj:OnTouchPressed(func)
|
||||||
|
table.insert(self.ToFuncP,func) -- event for touches
|
||||||
|
end
|
||||||
|
function obj:OnTouchReleased(func) -- event for touches
|
||||||
|
table.insert(self.ToFuncR,func)
|
||||||
|
end
|
||||||
|
function obj:OnTouchMoved(func) -- event for touches
|
||||||
|
table.insert(self.ToFuncM,func)
|
||||||
|
end
|
||||||
|
if _GuiPro.TouchReady then -- my sneaky test
|
||||||
|
print("Registred: "..tostring(obj))
|
||||||
|
table.insert(_GuiPro.TouchRegister,obj)
|
||||||
|
else
|
||||||
|
print("Attempting to register: "..tostring(obj))
|
||||||
|
_GuiPro.int:newJob(function() table.insert(_GuiPro.TouchRegister,obj) end) -- a sneaky way to ensure that your object gets registered eventually, even if you call the method before the touch patch was activated.
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
function gui:AddDrawRuleB(rule)
|
||||||
|
if not(self.DrawRulesB) then self.DrawRulesB={} end
|
||||||
|
table.insert(self.DrawRulesB,rule)
|
||||||
|
end
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
function gui:AddDrawRuleE(rule)
|
||||||
|
if not(self.DrawRulesE) then self.DrawRulesE={} end
|
||||||
|
table.insert(self.DrawRulesE,rule)
|
||||||
|
end
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
function gui:draw()
|
||||||
|
if _GuiPro.rotate~=0 then
|
||||||
|
love.graphics.rotate(math.rad(_GuiPro.rotate))
|
||||||
|
end
|
||||||
|
if self.FormFactor:lower()=="rectangle" then
|
||||||
|
self:drawR()
|
||||||
|
elseif self.FormFactor:lower()=="circle" then
|
||||||
|
self:drawC()
|
||||||
|
else
|
||||||
|
error("Unsupported FormFactor: "..self.FormFactor.."!")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
function gui:drawC()
|
||||||
|
if love.mouse.isDown("l")==false and love.mouse.isDown("m")==false and love.mouse.isDown("r")==false then
|
||||||
|
_GuiPro.DragItem={}
|
||||||
|
_GuiPro.hasDrag=false
|
||||||
|
end
|
||||||
|
if self.Visible==true and self.VIS==true then
|
||||||
|
local b=true
|
||||||
|
for i,v in pairs(_GuiPro.Clips) do
|
||||||
|
if self:isDescendant(v)==true then
|
||||||
|
b=false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if b then
|
||||||
|
love.graphics.setStencilTest( )
|
||||||
|
_GuiPro.HasStencel=false
|
||||||
|
_GuiPro.StencelHolder=nil
|
||||||
|
end
|
||||||
|
local x,y,r,s=(self.offset.pos.x or 0)+self.Parent.x,(self.offset.pos.y or 0)+self.Parent.y,self.offset.size.x or 0,self.offset.size.y or 360
|
||||||
|
if self.CC then
|
||||||
|
x,y=x+r,y+r
|
||||||
|
end
|
||||||
|
self.x,self.y=x,y
|
||||||
|
_GuiPro.circleStencilFunction = function()
|
||||||
|
love.graphics.circle("fill",x,y,r,s)
|
||||||
|
end
|
||||||
|
if math.sqrt((love.mouse.getX()-x)^2+(love.mouse.getY()-y)^2)<=r and self:eventable() and self:Clickable() and self.Active==true then
|
||||||
|
self.hovering=true
|
||||||
|
if love.mouse.isDown("l") and _GuiPro.hasDrag==false then
|
||||||
|
if string.find(self.Type, "Button") then
|
||||||
|
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
end
|
||||||
|
self.lclicked=true
|
||||||
|
elseif love.mouse.isDown("r") and _GuiPro.hasDrag==false then
|
||||||
|
if string.find(self.Type, "Button") then
|
||||||
|
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
end
|
||||||
|
self.rclicked=true
|
||||||
|
elseif love.mouse.isDown("m") and _GuiPro.hasDrag==false then
|
||||||
|
if string.find(self.Type, "Button") then
|
||||||
|
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
end
|
||||||
|
self.mclicked=true
|
||||||
|
else
|
||||||
|
if string.find(self.Type, "Button") and _GuiPro.hasDrag==false then
|
||||||
|
love.graphics.setColor(self.Color[1]-5, self.Color[2]-5, self.Color[3]-5,self.Visibility*254)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
end
|
||||||
|
self.rclicked=false
|
||||||
|
self.lclicked=false
|
||||||
|
self.mclicked=false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
self.hovering=false
|
||||||
|
self.rclicked=false
|
||||||
|
self.lclicked=false
|
||||||
|
self.mclicked=false
|
||||||
|
end
|
||||||
|
if self.ClipDescendants==true then
|
||||||
|
_GuiPro.Clips[tostring(self)]=self
|
||||||
|
_GuiPro.HasStencel=true
|
||||||
|
_GuiPro.StencelHolder=self
|
||||||
|
love.graphics.stencil(_GuiPro.circleStencilFunction)
|
||||||
|
love.graphics.setStencilTest("notequal",0)
|
||||||
|
end
|
||||||
|
love.graphics.circle("fill",x,y,r,s)
|
||||||
|
love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],self.BorderVisibility*254)
|
||||||
|
for b=0,self.BorderSize-1 do
|
||||||
|
love.graphics.circle("line",x,y,r+b,s)
|
||||||
|
end
|
||||||
|
if string.find(self.Type, "Text") then
|
||||||
|
if self.text~=nil then
|
||||||
|
if self.AutoScaleText then
|
||||||
|
self.FontSize=math.floor(self.height/1.45833)
|
||||||
|
end
|
||||||
|
love.graphics.setColor(self.TextColor[1],self.TextColor[2],self.TextColor[3],self.TextVisibility*254)
|
||||||
|
love.graphics.setFont(self.Font)
|
||||||
|
love.graphics.printf(self.text, x-(r/2)+(self.XTween), y-(r/2)+self.Tween, r, self.TextFormat)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
function gui:drawR()
|
||||||
|
if love.mouse.isDown("l")==false and love.mouse.isDown("m")==false and love.mouse.isDown("r")==false then
|
||||||
|
_GuiPro.DragItem={}
|
||||||
|
_GuiPro.hasDrag=false
|
||||||
|
end
|
||||||
|
if self.Visible==true and self.VIS==true then
|
||||||
|
local b=true
|
||||||
|
for i,v in pairs(_GuiPro.Clips) do
|
||||||
|
if self:isDescendant(v)==true then
|
||||||
|
b=false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if b==true then
|
||||||
|
love.graphics.setStencilTest()
|
||||||
|
love.graphics.setScissor()
|
||||||
|
end
|
||||||
|
self.x=(self.Parent.width*self.scale.pos.x)+self.offset.pos.x+self.Parent.x
|
||||||
|
self.y=(self.Parent.height*self.scale.pos.y)+self.offset.pos.y+self.Parent.y
|
||||||
|
self.width=(self.Parent.width*self.scale.size.x)+self.offset.size.x
|
||||||
|
self.height=(self.Parent.height*self.scale.size.y)+self.offset.size.y
|
||||||
|
if self.DrawRulesB then
|
||||||
|
for dr=1,#self.DrawRulesB do
|
||||||
|
self.DrawRulesB[dr](self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (love.mouse.getX() > self.x and love.mouse.getX() < self.x+self.width and love.mouse.getY() > self.y and love.mouse.getY() < self.y+self.height and self:Clickable() and self:eventable()) or self:touchable("r") and self.Active==true then
|
||||||
|
self.hovering=true
|
||||||
|
if love.mouse.isDown("l") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||||
|
if string.find(self.Type, "Button") then
|
||||||
|
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
end
|
||||||
|
self.lclicked=true
|
||||||
|
elseif love.mouse.isDown("r") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||||
|
if string.find(self.Type, "Button") then
|
||||||
|
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
end
|
||||||
|
self.rclicked=true
|
||||||
|
elseif love.mouse.isDown("m") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||||
|
if string.find(self.Type, "Button") then
|
||||||
|
love.graphics.setColor(self.Color[1]-10, self.Color[2]-10, self.Color[3]-10,self.Visibility*254)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
end
|
||||||
|
self.mclicked=true
|
||||||
|
else
|
||||||
|
if string.find(self.Type, "Button") or self:touchable("r") and _GuiPro.hasDrag==false then
|
||||||
|
love.graphics.setColor(self.Color[1]-5, self.Color[2]-5, self.Color[3]-5,self.Visibility*254)
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
end
|
||||||
|
self.rclicked=false
|
||||||
|
self.lclicked=false
|
||||||
|
self.mclicked=false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
love.graphics.setColor(self.Color[1],self.Color[2],self.Color[3],self.Visibility*254)
|
||||||
|
self.hovering=false
|
||||||
|
self.rclicked=false
|
||||||
|
self.lclicked=false
|
||||||
|
self.mclicked=false
|
||||||
|
end
|
||||||
|
if self.ClipDescendants==true then
|
||||||
|
_GuiPro.Clips[tostring(self)]=self
|
||||||
|
love.graphics.setScissor(self.x, self.y, self.width, self.height)
|
||||||
|
end
|
||||||
|
if self:hasRoundness() then
|
||||||
|
love.graphics.stencil(self.stfunc, "replace", 1)
|
||||||
|
love.graphics.setStencilTest("greater", 0)
|
||||||
|
end
|
||||||
|
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI)
|
||||||
|
if string.find(self.Type, "Image") then
|
||||||
|
self:ImageRule()
|
||||||
|
end
|
||||||
|
if self.Type=="Video" then
|
||||||
|
self:VideoRule()
|
||||||
|
end
|
||||||
|
if self:hasRoundness() then
|
||||||
|
love.graphics.setStencilTest()
|
||||||
|
end
|
||||||
|
love.graphics.setColor(self.BorderColor[1], self.BorderColor[2], self.BorderColor[3],self.BorderVisibility*254)
|
||||||
|
for b=0,self.BorderSize-1 do
|
||||||
|
love.graphics.rectangle("line", self.x-(b/2), self.y-(b/2), self.width+b, self.height+b,(self.rx or 1)*self.DPI,(self.ry or 1)*self.DPI,(self.segments or 1)*self.DPI)
|
||||||
|
end
|
||||||
|
if string.find(self.Type, "Text") then
|
||||||
|
if self.text~=nil then
|
||||||
|
if self.AutoScaleText then
|
||||||
|
self.FontSize=math.floor(self.height/1.45833)
|
||||||
|
end
|
||||||
|
love.graphics.setColor(self.TextColor[1],self.TextColor[2],self.TextColor[3],self.TextVisibility*254)
|
||||||
|
if self.Font==_defaultfont then
|
||||||
|
love.graphics.setFont(self.Font)
|
||||||
|
love.graphics.printf(self.text, self.x+2+(self.XTween*self.DPI)+((self.marginL or 0)*self.DPI or self.XTween*self.DPI), self.y+(self.FontHeight/2)+self.Tween*self.DPI, self.width+(0 or (self.marginR or 0)*self.DPI), self.TextFormat)
|
||||||
|
else
|
||||||
|
if type(self.Font)=="string" then
|
||||||
|
self.Font=love.graphics.newFont(self.Font,self.FontSize)
|
||||||
|
self.FontHeight=self.Font:getHeight()
|
||||||
|
else
|
||||||
|
love.graphics.setFont(self.Font)
|
||||||
|
end
|
||||||
|
if type(self.FontSize)=="string" then
|
||||||
|
self.FontSize=tonumber(self.FontSize)
|
||||||
|
love.graphics.setNewFont(self.FontSize)
|
||||||
|
end
|
||||||
|
love.graphics.printf(self.text, self.x+2+((self.marginL or 0)*self.DPI or self.XTween*self.DPI), self.y+math.floor((self.FontHeight-self.FontSize)/2)+self.Tween*self.DPI, self.width+(0 or (self.marginR or 0)*self.DPI), self.TextFormat)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if self.DrawRulesE then
|
||||||
|
for dr=1,#self.DrawRulesE do
|
||||||
|
self.DrawRulesE[dr](self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
function gui:newDropFrame(name,x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("DropFrame",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
c.WasBeingDragged=false
|
||||||
|
c.IsBeingDragged=false
|
||||||
|
c.Draggable=false
|
||||||
|
c.funcD={}
|
||||||
|
function c:GetDroppedItems()
|
||||||
|
local t=self:getChildren()
|
||||||
|
local tab={}
|
||||||
|
for i=1,#t do
|
||||||
|
if t[i].Type=="TextImageButtonFrameDrag" then
|
||||||
|
table.insert(tab,t[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tab
|
||||||
|
end
|
||||||
|
function c:OnDropped(func)
|
||||||
|
table.insert(self.funcD,func)
|
||||||
|
end
|
||||||
|
c:OnUpdate(function(self)
|
||||||
|
if _GuiPro.DragItem then
|
||||||
|
if _GuiPro.DragItem.Type=="TextImageButtonFrameDrag" and love.mouse.isDown(_GuiPro.DragItem.dragbut or "m")==false and self:IsHovering() then
|
||||||
|
local t=_GuiPro.DragItem
|
||||||
|
_GuiPro.DragItem={}
|
||||||
|
for i=1,#t.funcD do
|
||||||
|
t.funcD[i](self,t)
|
||||||
|
end
|
||||||
|
for i=1,#self.funcD do
|
||||||
|
self.funcD[i](self,t)
|
||||||
|
end
|
||||||
|
_GuiPro.hasDrag=false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
function gui:newFrame(name,x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("Frame",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
c.WasBeingDragged=false
|
||||||
|
c.IsBeingDragged=false
|
||||||
|
c.Draggable=false
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
function gui:newFullFrame(name)
|
||||||
|
name=name or ""
|
||||||
|
return self:newFrame(name,0,0,0,0,0,0,1,1)
|
||||||
|
end
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
function gui:newTabFrame(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=gui:newFrame(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
c.tabheight=20
|
||||||
|
c.Holder=c:newFrame("Holder",0,c.tabheight,0,0,0,0,1,1)
|
||||||
|
c.TabHolder=c:newFrame("TabHolder",0,0,0,c.tabheight,0,0,1)
|
||||||
|
function c:setTabHeight(n)
|
||||||
|
self.tabheight=n
|
||||||
|
self.Holder:SetDualDim(0,-self.tabheight,0,0,0,0,1,1)
|
||||||
|
end
|
||||||
|
function c:addTab(name,colorT,colorH)
|
||||||
|
if colorT and not(colorH) then
|
||||||
|
colorH=colorT
|
||||||
|
end
|
||||||
|
local tab=self.TabHolder:newTextButton(name,name,0,0,0,0,0,0,0,1)
|
||||||
|
tab.Tween=-3
|
||||||
|
if colorT then
|
||||||
|
tab.Color=colorT
|
||||||
|
end
|
||||||
|
local holder=self.Holder:newFrame(name,0,0,0,0,0,0,1,1)
|
||||||
|
if colorH then
|
||||||
|
holder.Color=colorH
|
||||||
|
end
|
||||||
|
tab.frame=holder
|
||||||
|
tab:OnReleased(function(b,self)
|
||||||
|
if b=="l" then
|
||||||
|
local tt=self.Parent:getChildren()
|
||||||
|
local th=self.Parent.Parent.Holder:getChildren()
|
||||||
|
for i=1,#th do
|
||||||
|
th[i].Visible=false
|
||||||
|
end
|
||||||
|
for i=1,#tt do
|
||||||
|
tt[i].frame.Visible=false
|
||||||
|
tt[i].BorderSize=1
|
||||||
|
end
|
||||||
|
self.BorderSize=0
|
||||||
|
self.frame.Visible=true
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
local tt=self.TabHolder:getChildren()
|
||||||
|
for i=1,#tt do
|
||||||
|
tt[i].frame.Visible=false
|
||||||
|
tt[i].BorderSize=1
|
||||||
|
end
|
||||||
|
tab.frame.Visible=true
|
||||||
|
tab.BorderSize=0
|
||||||
|
return tab,holder
|
||||||
|
end
|
||||||
|
c:OnUpdate(function(self)
|
||||||
|
local th=self.TabHolder:getChildren()
|
||||||
|
local l=self.width/#th
|
||||||
|
for i=1,#th do
|
||||||
|
th[i]:SetDualDim(l*(i-1),0,l)
|
||||||
|
end
|
||||||
|
if #th==0 then
|
||||||
|
self:Destroy()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
function gui:SetImage(i)
|
||||||
|
if type(i)=="string" then
|
||||||
|
self.Image=love.graphics.newImage(i)
|
||||||
|
else
|
||||||
|
self.Image=i
|
||||||
|
end
|
||||||
|
if self.Image~=nil then
|
||||||
|
self.ImageHeigth=self.Image:getHeight()
|
||||||
|
self.ImageWidth=self.Image:getWidth()
|
||||||
|
self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth)
|
||||||
|
end
|
||||||
|
return self.ImageWidth,self.ImageHeigth
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
function gui:UpdateImage()
|
||||||
|
self.ImageHeigth=self.Image:getHeight()
|
||||||
|
self.ImageWidth=self.Image:getWidth()
|
||||||
|
self.Quad=love.graphics.newQuad(0,0,self.width,self.height,self.ImageWidth,self.ImageHeigth)
|
||||||
|
end
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
function gui:getTile(i,x,y,w,h)-- returns imagedata
|
||||||
|
if type(i)=="string" then
|
||||||
|
i=love.graphics.newImage(i)
|
||||||
|
elseif type(i)=="userdata" then
|
||||||
|
-- do nothing
|
||||||
|
elseif string.find(self.Type,"Image",1,true) then
|
||||||
|
local i,x,y,w,h=self.Image,i,x,y,w
|
||||||
|
else
|
||||||
|
error("getTile invalid args!!! Usage: ImageElement:getTile(x,y,w,h) or gui:getTile(imagedata,x,y,w,h)")
|
||||||
|
end
|
||||||
|
local iw,ih=i:getDimensions()
|
||||||
|
local id,_id=i:getData(),love.image.newImageData(w,h)
|
||||||
|
for _x=x,w+x-1 do
|
||||||
|
for _y=y,h+y-1 do
|
||||||
|
--
|
||||||
|
_id:setPixel(_x-x,_y-y,id:getPixel(_x,_y))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return love.graphics.newImage(_id)
|
||||||
|
end
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
function gui:newAnim(file,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local x,y,w,h,sx,sy,sw,sh=filter(file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("ImageAnimation",file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
c.Visibility=0
|
||||||
|
c.ImageVisibility=1
|
||||||
|
c.delay=delay or .05
|
||||||
|
c.files={}
|
||||||
|
c.AnimStart={}
|
||||||
|
c.AnimEnd={}
|
||||||
|
local _files=alphanumsort(love.filesystem.getDirectoryItems(file))
|
||||||
|
for i=1,#_files do
|
||||||
|
if string.sub(_files[i],-1,-1)~="b" then
|
||||||
|
table.insert(c.files,love.graphics.newImage(file.."/".._files[i]))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
c.step=multi:newTStep(1,#c.files,1,c.delay)
|
||||||
|
c.step.parent=c
|
||||||
|
c.rotation=0
|
||||||
|
c.step:OnStart(function(step)
|
||||||
|
for i=1,#step.parent.AnimStart do
|
||||||
|
step.parent.AnimStart[i](step.parent)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
c.step:OnStep(function(pos,step)
|
||||||
|
step.parent:SetImage(step.parent.files[pos])
|
||||||
|
end)
|
||||||
|
c.step:OnEnd(function(step)
|
||||||
|
for i=1,#step.parent.AnimEnd do
|
||||||
|
step.parent.AnimEnd[i](step.parent)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
function c:OnAnimStart(func)
|
||||||
|
table.insert(self.AnimStart,func)
|
||||||
|
end
|
||||||
|
function c:OnAnimEnd(func)
|
||||||
|
table.insert(self.AnimEnd,func)
|
||||||
|
end
|
||||||
|
function c:Pause()
|
||||||
|
self.step:Pause()
|
||||||
|
end
|
||||||
|
function c:Resume()
|
||||||
|
self.step:Resume()
|
||||||
|
end
|
||||||
|
function c:Reset()
|
||||||
|
self.step.pos=1
|
||||||
|
end
|
||||||
|
function c:getFrames()
|
||||||
|
return #self.files
|
||||||
|
end
|
||||||
|
function c:getFrame()
|
||||||
|
return self.step.pos
|
||||||
|
end
|
||||||
|
function c:setFrame(n)
|
||||||
|
return self:SetImage(self.files[n])
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
function gui:newAnimFromData(data,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("ImageAnimation","FromFile", x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
c.Visibility=0
|
||||||
|
c.ImageVisibility=1
|
||||||
|
c.delay=delay or .05
|
||||||
|
c.files=data
|
||||||
|
c.AnimStart={}
|
||||||
|
c.AnimEnd={}
|
||||||
|
c:SetImage(c.files[1])
|
||||||
|
c.step=multi:newTStep(1,#c.files,1,c.delay)
|
||||||
|
c.step.parent=c
|
||||||
|
c.rotation=0
|
||||||
|
c.step:OnStart(function(step)
|
||||||
|
for i=1,#step.parent.AnimStart do
|
||||||
|
step.parent.AnimStart[i](step.parent)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
c.step:OnStep(function(pos,step)
|
||||||
|
step.parent:SetImage(step.parent.files[pos])
|
||||||
|
end)
|
||||||
|
c.step:OnEnd(function(step)
|
||||||
|
for i=1,#step.parent.AnimEnd do
|
||||||
|
step.parent.AnimEnd[i](step.parent)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
function c:OnAnimStart(func)
|
||||||
|
table.insert(self.AnimStart,func)
|
||||||
|
end
|
||||||
|
function c:OnAnimEnd(func)
|
||||||
|
table.insert(self.AnimEnd,func)
|
||||||
|
end
|
||||||
|
function c:Pause()
|
||||||
|
self.step:Pause()
|
||||||
|
end
|
||||||
|
function c:Resume()
|
||||||
|
self.step:Resume()
|
||||||
|
end
|
||||||
|
function c:Reset()
|
||||||
|
self.step.pos=1
|
||||||
|
end
|
||||||
|
function c:getFrames()
|
||||||
|
return #self.files
|
||||||
|
end
|
||||||
|
function c:getFrame()
|
||||||
|
return self.step.pos
|
||||||
|
end
|
||||||
|
function c:setFrame(n)
|
||||||
|
return self:SetImage(self.files[n])
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
function gui:newAnimFromTiles(file,xd,yd,delay, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("ImageAnimation",file, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local im=love.graphics.newImage(file)
|
||||||
|
local _x,_y=im:getDimensions()
|
||||||
|
c.Visibility=0
|
||||||
|
c.ImageVisibility=1
|
||||||
|
c.delay=delay or .05
|
||||||
|
c.files={}
|
||||||
|
c.AnimStart={}
|
||||||
|
c.AnimEnd={}
|
||||||
|
for i=0,_y/yd-1 do
|
||||||
|
for j=0,_x/xd-1 do
|
||||||
|
table.insert(c.files,gui:getTile(im,j*xd,i*yd,xd,yd))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
c:SetImage(c.files[1])
|
||||||
|
c.step=multi:newTStep(1,#c.files,1,c.delay)
|
||||||
|
c.step.parent=c
|
||||||
|
c.rotation=0
|
||||||
|
c.step:OnStart(function(step)
|
||||||
|
for i=1,#step.parent.AnimStart do
|
||||||
|
step.parent.AnimStart[i](step.parent)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
c.step:OnStep(function(pos,step)
|
||||||
|
step.parent:SetImage(step.parent.files[pos])
|
||||||
|
end)
|
||||||
|
c.step:OnEnd(function(step)
|
||||||
|
for i=1,#step.parent.AnimEnd do
|
||||||
|
step.parent.AnimEnd[i](step.parent)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
function c:OnAnimStart(func)
|
||||||
|
table.insert(self.AnimStart,func)
|
||||||
|
end
|
||||||
|
function c:OnAnimEnd(func)
|
||||||
|
table.insert(self.AnimEnd,func)
|
||||||
|
end
|
||||||
|
function c:Pause()
|
||||||
|
self.step:Pause()
|
||||||
|
end
|
||||||
|
function c:Resume()
|
||||||
|
self.step:Resume()
|
||||||
|
end
|
||||||
|
function c:Reset()
|
||||||
|
self.step.pos=1
|
||||||
|
end
|
||||||
|
function c:getFrames()
|
||||||
|
return #self.files
|
||||||
|
end
|
||||||
|
function c:getFrame()
|
||||||
|
return self.step.pos
|
||||||
|
end
|
||||||
|
function c:setFrame(n)
|
||||||
|
return self:SetImage(self.files[n])
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:newFullImageLabel(i,name)
|
||||||
|
return self:newImageLabel(i,name,0,0,0,0,0,0,1,1)
|
||||||
|
end
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
function gui:newImageButton(i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("ImageButton",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
if type(i)=="string" then
|
||||||
|
c.Image=love.graphics.newImage(i)
|
||||||
|
else
|
||||||
|
c.Image=i
|
||||||
|
end
|
||||||
|
c.Visibility=0
|
||||||
|
c.ImageVisibility=1
|
||||||
|
c.rotation=0
|
||||||
|
if c.Image~=nil then
|
||||||
|
c.ImageHeigth=c.Image:getHeight()
|
||||||
|
c.ImageHeight=c.Image:getHeight()
|
||||||
|
c.ImageWidth=c.Image:getWidth()
|
||||||
|
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||||
|
end
|
||||||
|
c:OnEnter(function()
|
||||||
|
love.mouse.setCursor(_GuiPro.CursorH)
|
||||||
|
end)
|
||||||
|
c:OnExit(function()
|
||||||
|
love.mouse.setCursor(_GuiPro.CursorN)
|
||||||
|
end)
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
function gui:newImageLabel(i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("ImageLabel",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
if type(i)=="string" then
|
||||||
|
c.Image=love.graphics.newImage(i)
|
||||||
|
else
|
||||||
|
c.Image=i
|
||||||
|
end
|
||||||
|
c.Visibility=0
|
||||||
|
c.ImageVisibility=1
|
||||||
|
c.rotation=0
|
||||||
|
if c.Image~=nil then
|
||||||
|
c.ImageHeigth=c.Image:getHeight()
|
||||||
|
c.ImageWidth=c.Image:getWidth()
|
||||||
|
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
function gui:newVideo(name,i,x,y,w,h,sx,sy,sw,sh)
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("Video",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
if type(i)=="string" then
|
||||||
|
c.Video=love.graphics.newVideo(i)
|
||||||
|
else
|
||||||
|
c.Video=i
|
||||||
|
end
|
||||||
|
c.Visibility=0
|
||||||
|
c.VideoVisibility=1
|
||||||
|
c.rotation=0
|
||||||
|
if c.Video~=nil then
|
||||||
|
c.VideoHeigth=c.Video:getHeight()
|
||||||
|
c.VideoWidth=c.Video:getWidth()
|
||||||
|
c.Quad=love.graphics.newQuad(0,0,w,h,c.VideoWidth,c.VideoHeigth)
|
||||||
|
end
|
||||||
|
c.funcV={}
|
||||||
|
function c:Play()
|
||||||
|
self.handStart=true
|
||||||
|
self.Video:play()
|
||||||
|
end
|
||||||
|
function c:Pause()
|
||||||
|
self.Video:pause()
|
||||||
|
end
|
||||||
|
c.Resume=c.Play
|
||||||
|
function c:Stop()
|
||||||
|
self.handStart=false
|
||||||
|
self:Pause()
|
||||||
|
self:Rewind()
|
||||||
|
for i=1,# self.funcV do
|
||||||
|
self.funcV[i](self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function c:OnVideoStopped(func)
|
||||||
|
table.insert(self.funcV,func)
|
||||||
|
end
|
||||||
|
function c:Rewind()
|
||||||
|
self.Video:rewind()
|
||||||
|
end
|
||||||
|
function c:Restart()
|
||||||
|
self:Rewind()
|
||||||
|
self:Play()
|
||||||
|
end
|
||||||
|
function c:Seek(o)
|
||||||
|
self.Video:seek(o)
|
||||||
|
end
|
||||||
|
function c:Tell()
|
||||||
|
self.Video:tell()
|
||||||
|
end
|
||||||
|
function c:SetFilter(min, mag, anisotropy)
|
||||||
|
self.Video:setFilter(min, mag, anisotropy)
|
||||||
|
end
|
||||||
|
function c:IsPlaying()
|
||||||
|
return self.Video:isPlaying()
|
||||||
|
end
|
||||||
|
c:OnUpdate(function(self)
|
||||||
|
if self.Video:isPlaying()==false and self.handStart == true then
|
||||||
|
self:Stop()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
function gui:newDragItem(t,i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("TextImageButtonFrameDrag",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
c.WasBeingDragged=false
|
||||||
|
c.IsBeingDragged=false
|
||||||
|
c.Draggable=true
|
||||||
|
c.funcD={}
|
||||||
|
if type(i)=="string" then
|
||||||
|
c.Image=love.graphics.newImage(i)
|
||||||
|
c.ImageVisibility=1
|
||||||
|
c.ImageHeigth=c.Image:getHeight()
|
||||||
|
c.ImageWidth=c.Image:getWidth()
|
||||||
|
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||||
|
elseif type(i)=="image" then
|
||||||
|
c.Image=i
|
||||||
|
c.ImageVisibility=1
|
||||||
|
c.ImageHeigth=c.Image:getHeight()
|
||||||
|
c.ImageWidth=c.Image:getWidth()
|
||||||
|
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||||
|
end
|
||||||
|
c:OnDragStart(function(self,x,y)
|
||||||
|
if _GuiPro.hasDrag==false then
|
||||||
|
self:setParent(_GuiPro)
|
||||||
|
self:SetDualDim(x,y)
|
||||||
|
self:TopStack()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
c.rotation=0
|
||||||
|
c.Tween=0
|
||||||
|
c.XTween=0
|
||||||
|
c.text = t
|
||||||
|
c.AutoScaleText=false
|
||||||
|
c.FontHeight=_defaultfont:getHeight()
|
||||||
|
c.Font=_defaultfont
|
||||||
|
c.FontSize=15
|
||||||
|
c.TextFormat="center"
|
||||||
|
c.TextVisibility=1
|
||||||
|
c.TextColor = {0, 0, 0}
|
||||||
|
function c:OnDropped(func)
|
||||||
|
table.insert(self.funcD,func)
|
||||||
|
end
|
||||||
|
c:OnUpdate(function(self)
|
||||||
|
if love.mouse.isDown("m" or self.dragbut)==false and self==_GuiPro.DragItem and self.hovering==false then
|
||||||
|
_GuiPro.DragItem={}
|
||||||
|
for i=1,#self.func7 do
|
||||||
|
self.func7[i](self,(love.mouse.getX())-self.width/2,(love.mouse.getY())-self.height/2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
function gui:newItem(t,i,name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("TextImageButtonFrame",name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
if type(i)=="string" then
|
||||||
|
c.Image=love.graphics.newImage(i)
|
||||||
|
else
|
||||||
|
c.Image=i
|
||||||
|
end
|
||||||
|
c.rotation=0
|
||||||
|
c.ImageVisibility=1
|
||||||
|
c.Draggable=false
|
||||||
|
if c.Image~=nil then
|
||||||
|
c.ImageHeigth=c.Image:getHeight()
|
||||||
|
c.ImageWidth=c.Image:getWidth()
|
||||||
|
c.Quad=love.graphics.newQuad(0,0,w,h,c.ImageWidth,c.ImageHeigth)
|
||||||
|
end
|
||||||
|
c.Tween=0
|
||||||
|
c.XTween=0
|
||||||
|
c.text = t
|
||||||
|
c.AutoScaleText=false
|
||||||
|
c.FontHeight=_defaultfont:getHeight()
|
||||||
|
c.Font=_defaultfont
|
||||||
|
c.FontSize=15
|
||||||
|
c.TextFormat="center"
|
||||||
|
c.TextVisibility=1 -- 0=invisible,1=solid (self.TextVisibility*254+1)
|
||||||
|
c.TextColor = {0, 0, 0}
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
function gui:AdvTextBox(txt,x,y,w,h,sx,sy,sw,sh)
|
||||||
|
name="AdvTextBox"
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("AdvTextBoxFrame",name, x, y, w, 30, sx ,sy ,sw ,sh)
|
||||||
|
c.Draggable=true
|
||||||
|
c.dragbut="r"
|
||||||
|
c.BorderSize=0
|
||||||
|
c:ApplyGradient{Color.Blue,Color.sexy_purple}
|
||||||
|
c:newTextLabel(txt,"Holder",0,0,0,h-30,0,1,1,0).Color=Color.sexy_purple
|
||||||
|
c.funcO={}
|
||||||
|
c.funcX={}
|
||||||
|
c:OnDragStart(function(self)
|
||||||
|
self:TopStack()
|
||||||
|
end)
|
||||||
|
--local temp = c:newTextButton("X","Close",-25,5,20,20,1)
|
||||||
|
--temp.Tween=-5
|
||||||
|
--temp.XTween=-2
|
||||||
|
--temp:OnReleased(function(b,self) for i=1,#self.Parent.funcX do self.Parent.funcX[i](self.Parent) end end)
|
||||||
|
--temp.Color=Color.Red
|
||||||
|
c.tLink=c:newTextBox("puttext","TextBox",5,h-95,-40,30,0,1,1,1)
|
||||||
|
c.tLink.Color=Color.light_gray
|
||||||
|
c.tLink.ClearOnFocus=true
|
||||||
|
c.tLink:OnFocus(function(self) self.ClearOnFocus=false end)
|
||||||
|
local temp=c:newTextButton("OK","Ok",-35,h-65,30,30,1,1)
|
||||||
|
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcO do self.Parent.funcO[i](self.Parent,self.Parent.tLink.text) end end)
|
||||||
|
temp.Color=Color.Green
|
||||||
|
temp.XTween=-2
|
||||||
|
local temp=c:newTextButton("X","Cancel",-35,h-95,30,30,1,1)
|
||||||
|
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcX do self.Parent.funcX[i](self.Parent,self.Parent.tLink.text) end end)
|
||||||
|
temp.Color=Color.Red
|
||||||
|
temp.XTween=-2
|
||||||
|
function c:Close()
|
||||||
|
self.Visible=false
|
||||||
|
end
|
||||||
|
function c:Open()
|
||||||
|
self.Visible=true
|
||||||
|
end
|
||||||
|
function c:OnOk(func)
|
||||||
|
table.insert(self.funcO,func)
|
||||||
|
end
|
||||||
|
function c:OnX(func)
|
||||||
|
table.insert(self.funcX,func)
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
function _GuiPro.gradient(colors)
|
||||||
|
local direction = colors.direction or "horizontal"
|
||||||
|
colors.direction=nil
|
||||||
|
trans = colors.trans or 255
|
||||||
|
trans=math.floor(trans)
|
||||||
|
if direction == "horizontal" then
|
||||||
|
direction = true
|
||||||
|
elseif direction == "vertical" then
|
||||||
|
direction = false
|
||||||
|
else
|
||||||
|
error("Invalid direction '" .. tostring(direction) "' for gradient. Horizontal or vertical expected.")
|
||||||
|
end
|
||||||
|
local result = love.image.newImageData(direction and 1 or #colors, direction and #colors or 1)
|
||||||
|
for __i, color in ipairs(colors) do
|
||||||
|
local x, y
|
||||||
|
if direction then
|
||||||
|
x, y = 0, __i - 1
|
||||||
|
else
|
||||||
|
x, y = __i - 1, 0
|
||||||
|
end
|
||||||
|
result:setPixel(x, y, color[1], color[2], color[3], trans)
|
||||||
|
end
|
||||||
|
result = love.graphics.newImage(result)
|
||||||
|
result:setFilter('linear', 'linear')
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
function _GuiPro.drawinrect(img, x, y, w, h, r, ox, oy, kx, ky)
|
||||||
|
love.graphics.draw(img, x, y, r, w / img:getWidth(), h / img:getHeight(), ox, oy, kx, ky)
|
||||||
|
end
|
||||||
|
function gui:ApplyGradient(rules)
|
||||||
|
self.Image=nil
|
||||||
|
self.Type=self.Type.."w/GradImage"
|
||||||
|
self.rotation=0
|
||||||
|
self.ImageVisibility=rules.visibility or 1
|
||||||
|
self:SetImage(_GuiPro.gradient(rules))
|
||||||
|
end
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
function gui:BottomStack()
|
||||||
|
childs=self.Parent:getChildren()
|
||||||
|
for i=1,#childs do
|
||||||
|
if childs[i]==self then
|
||||||
|
table.remove(self.Parent.Children,i)
|
||||||
|
table.insert(self.Parent.Children,1,self)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
function gui:Center()
|
||||||
|
local x,y=self:getFullSize()
|
||||||
|
self:SetDualDim(-math.floor(x/2),-math.floor(y/2),nil,nil,.5,.5)
|
||||||
|
end
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
function gui:Destroy()
|
||||||
|
check=self.Parent:getChildren()
|
||||||
|
local cc=0
|
||||||
|
for cc=1,#check do
|
||||||
|
if check[cc]==self then
|
||||||
|
table.remove(self.Parent.Children,cc)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
function gui:GetAllChildren()
|
||||||
|
local Stuff = {}
|
||||||
|
function Seek(Items)
|
||||||
|
for i=1,#Items do
|
||||||
|
if Items[i].Visible==true then
|
||||||
|
table.insert(Stuff,Items[i])
|
||||||
|
local NItems = Items[i]:getChildren()
|
||||||
|
if NItems ~= nil then
|
||||||
|
Seek(NItems)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local Objs = self:getChildren()
|
||||||
|
for i=1,#Objs do
|
||||||
|
if Objs[i].Visible==true then
|
||||||
|
table.insert(Stuff,Objs[i])
|
||||||
|
local Items = Objs[i]:getChildren()
|
||||||
|
if Items ~= nil then
|
||||||
|
Seek(Items)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return Stuff
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:GetChild(name)
|
||||||
|
return self.Children[name] or self
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function InGrid(i,x,y,s)
|
||||||
|
return math.floor((i-1)/x)*s,(i-1)*s-(math.floor((i-1)/y)*(s*x))
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
function InGridX(i,w,h,xs,ys)
|
||||||
|
local xc,yc=math.floor(w/xs),math.floor(h/ys)
|
||||||
|
local xi,yi=(i-1)%xc,math.floor((i-1)/xc)
|
||||||
|
return xi*xs,yi*ys
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
function InGridY(i,w,h,xs,ys)
|
||||||
|
local xc,yc=math.floor(w/xs),math.floor(h/ys)
|
||||||
|
local xi,yi=math.floor((i-1)/yc),(i-1)%yc
|
||||||
|
return xi*xs,yi*ys
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:IsHovering()
|
||||||
|
return (love.mouse.getX() > self.x and love.mouse.getX() < self.x+self.width and love.mouse.getY() > self.y and love.mouse.getY() < self.y+self.height)
|
||||||
|
end
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
function gui:Move(x,y)
|
||||||
|
self.offset.pos.x=self.offset.pos.x+x
|
||||||
|
self.offset.pos.y=self.offset.pos.y+y
|
||||||
|
end
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
function gui:SetDualDim(x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
if _GuiPro.DPI_ENABLED then
|
||||||
|
if x then
|
||||||
|
x=self.DPI*x
|
||||||
|
end
|
||||||
|
if y then
|
||||||
|
y=self.DPI*y
|
||||||
|
end
|
||||||
|
if w then
|
||||||
|
w=self.DPI*w
|
||||||
|
end
|
||||||
|
if h then
|
||||||
|
h=self.DPI*h
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if sx then
|
||||||
|
self.scale.pos.x=sx
|
||||||
|
end
|
||||||
|
if sy then
|
||||||
|
self.scale.pos.y=sy
|
||||||
|
end
|
||||||
|
if x then
|
||||||
|
self.offset.pos.x=x
|
||||||
|
end
|
||||||
|
if y then
|
||||||
|
self.offset.pos.y=y
|
||||||
|
end
|
||||||
|
if sw then
|
||||||
|
self.scale.size.x=sw
|
||||||
|
end
|
||||||
|
if sh then
|
||||||
|
self.scale.size.y=sh
|
||||||
|
end
|
||||||
|
if w then
|
||||||
|
self.offset.size.x=w
|
||||||
|
end
|
||||||
|
if h then
|
||||||
|
self.offset.size.y=h
|
||||||
|
end
|
||||||
|
if self.Image then
|
||||||
|
self:SetImage(self.Image)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function gui:setDualDim(...)
|
||||||
|
self:SetDualDim(...)
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
_GuiPro.CursorN=love.mouse.getSystemCursor("arrow")
|
||||||
|
_GuiPro.CursorH=love.mouse.getSystemCursor("hand")
|
||||||
|
function gui:SetHand(img,x,y)
|
||||||
|
_GuiPro.CursorN=love.mouse.newCursor(img,x,y)
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:SetHover(img,x,y)
|
||||||
|
_GuiPro.CursorH=love.mouse.newCursor(img,x,y)
|
||||||
|
end
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
function gui:SetName(name)
|
||||||
|
self.Parent.Children[name]=self
|
||||||
|
self.Name=name
|
||||||
|
end
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
function gui:TopStack()
|
||||||
|
childs=self.Parent:getChildren()
|
||||||
|
for i=1,#childs do
|
||||||
|
if childs[i]==self then
|
||||||
|
table.remove(self.Parent.Children,i)
|
||||||
|
table.insert(self.Parent.Children,self)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:addDominance()
|
||||||
|
_GuiPro.TopHovered=self
|
||||||
|
end
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
function gui:addHotKey(key)
|
||||||
|
local temp=self:newFrame(0,0,0,0)
|
||||||
|
temp.Visible=false
|
||||||
|
temp:setHotKey(key)
|
||||||
|
return temp
|
||||||
|
end
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
function alphanumsort(o)
|
||||||
|
local function padnum(d) local dec, n = string.match(d, "(%.?)0*(.+)")
|
||||||
|
return #dec > 0 and ("%.12f"):format(d) or ("%s%03d%s"):format(dec, #n, n)
|
||||||
|
end
|
||||||
|
table.sort(o, function(a,b) return tostring(a):gsub("%.?%d+",padnum)..("%3d"):format(#b)< tostring(b):gsub("%.?%d+",padnum)..("%3d"):format(#a) end)
|
||||||
|
return o
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:anchorRight(n)
|
||||||
|
self:SetDualDim(-(self.width+n),nil,nil,nil,1)
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:centerX()
|
||||||
|
self:SetDualDim(-(self.width/2),nil,nil,nil,.5)
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:centerY()
|
||||||
|
self:SetDualDim(nil,-(self.height/2),nil,nil,nil,.5)
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:disrespectHierarchy()
|
||||||
|
_GuiPro.Hierarchy=false
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:getChildren()
|
||||||
|
return self.Children
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:getColor(cindex)
|
||||||
|
return Color[cindex]
|
||||||
|
end
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
function gui:getFullSize()
|
||||||
|
local maxx,maxy=-math.huge,-math.huge
|
||||||
|
local temp = self:GetAllChildren()
|
||||||
|
for i=1,#temp do
|
||||||
|
if temp[i].width>maxx then
|
||||||
|
maxx=temp[i].width+temp[i].offset.pos.x
|
||||||
|
elseif temp[i].height>maxy then
|
||||||
|
maxy=temp[i].height+temp[i].offset.pos.y
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return maxx,maxy
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
function gui:getHighest()
|
||||||
|
if self.Children[#self.Children]~=nil then
|
||||||
|
return self.Children[#self.Children]
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
function gui:getLowest()
|
||||||
|
if self.Children[1]~=nil then
|
||||||
|
return self.Children[1]
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
function gui:isDescendant(obj)
|
||||||
|
local things=obj:GetAllChildren()
|
||||||
|
for i=1,#things do
|
||||||
|
if things[i]==self then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:isHighest()
|
||||||
|
return (self==self.Parent:getHighest())
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:isLowest()
|
||||||
|
return (self==self.Parent:getLowest())
|
||||||
|
end
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
function gui.massMutate(t,...)
|
||||||
|
local mut={...}
|
||||||
|
for i=1,#mut do
|
||||||
|
mut[i]:Mutate(t)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
if love.filesystem.exists("CheckBoxes.png") then
|
||||||
|
_GuiPro.UC=gui:getTile("CheckBoxes.png",0,0,16,16)
|
||||||
|
_GuiPro.C=gui:getTile("CheckBoxes.png",16,0,16,16)
|
||||||
|
_GuiPro.UCH=gui:getTile("CheckBoxes.png",0,16,16,16)
|
||||||
|
_GuiPro.CH=gui:getTile("CheckBoxes.png",16,16,16,16)
|
||||||
|
end
|
||||||
|
function gui:newCheckBox(name,x,y)
|
||||||
|
if not(_GuiPro.UC) then error("CheckBoxes.png not found! Cannot currently use checkbox without the data") end
|
||||||
|
if type(name)~="String" then
|
||||||
|
x,y,name=name,x,"CheckBox"
|
||||||
|
end
|
||||||
|
local c=self:newImageLabel(_GuiPro.UC,name, x, y, 16,16)
|
||||||
|
c.Visibility=0
|
||||||
|
c.check=false
|
||||||
|
c:OnEnter(function(self)
|
||||||
|
if self.check then
|
||||||
|
self:SetImage(_GuiPro.CH)
|
||||||
|
else
|
||||||
|
self:SetImage(_GuiPro.UCH)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
function c:isChecked()
|
||||||
|
return self.check
|
||||||
|
end
|
||||||
|
c:OnExit(function(self)
|
||||||
|
if self.check then
|
||||||
|
self:SetImage(_GuiPro.C)
|
||||||
|
else
|
||||||
|
self:SetImage(_GuiPro.UC)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
c:OnReleased(function(b,self)
|
||||||
|
self.check=not(self.check)
|
||||||
|
if self.check then
|
||||||
|
self:SetImage(_GuiPro.CH)
|
||||||
|
else
|
||||||
|
self:SetImage(_GuiPro.UCH)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
function gui:newMessageBox(txt,x,y,w,h,sx,sy,sw,sh)
|
||||||
|
name="MessageBox"
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("MessageBoxFrame",name, x, y, w, 30, sx ,sy ,sw ,sh)
|
||||||
|
c.Draggable=true
|
||||||
|
c.dragbut="r"
|
||||||
|
c:ApplyGradient{Color.Blue,Color.sexy_purple}
|
||||||
|
c.BorderSize=0
|
||||||
|
c:newTextLabel(txt,"Holder",0,0,0,h-30,0,1,1,0).Color=Color.sexy_purple
|
||||||
|
c.funcO={}
|
||||||
|
c.funcX={}
|
||||||
|
c:OnDragStart(function(self)
|
||||||
|
self:TopStack()
|
||||||
|
end)
|
||||||
|
local temp = c:newTextButton("X","Close",-25,5,20,20,1)
|
||||||
|
temp.Tween=-5
|
||||||
|
temp.XTween=-2
|
||||||
|
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcX do self.Parent.funcX[i](self.Parent) end end)
|
||||||
|
temp.Color=Color.Red
|
||||||
|
local temp=c:newTextButton("OK","Ok",0,h-65,0,30,.25,1,.5)
|
||||||
|
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcO do self.Parent.funcO[i](self.Parent) end end)
|
||||||
|
temp.Color=Color.Green
|
||||||
|
function c:Close()
|
||||||
|
self.Visible=false
|
||||||
|
end
|
||||||
|
function c:Open()
|
||||||
|
self.Visible=true
|
||||||
|
end
|
||||||
|
function c:OnOk(func)
|
||||||
|
table.insert(self.funcO,func)
|
||||||
|
end
|
||||||
|
function c:OnX(func)
|
||||||
|
table.insert(self.funcX,func)
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
function gui:newPart(x, y,w ,h , sx ,sy ,sw ,sh)
|
||||||
|
local c = {}
|
||||||
|
setmetatable(c, gui)
|
||||||
|
if self==gui then
|
||||||
|
c.Parent=_GuiPro
|
||||||
|
else
|
||||||
|
c.Parent=self
|
||||||
|
end
|
||||||
|
c.funcs={}
|
||||||
|
c.funcs2={}
|
||||||
|
c.funcs3={}
|
||||||
|
c.funcs4={}
|
||||||
|
c.funcs5={}
|
||||||
|
c.func6={}
|
||||||
|
c.func7={}
|
||||||
|
c.func8={}
|
||||||
|
c.func9={}
|
||||||
|
c.func10={}
|
||||||
|
c.form="rectangle"
|
||||||
|
c.Color = {255, 255, 255}
|
||||||
|
c.scale={}
|
||||||
|
c.scale.size={}
|
||||||
|
c.scale.size.x=sw or 0
|
||||||
|
c.scale.size.y=sh or 0
|
||||||
|
c.offset={}
|
||||||
|
c.offset.size={}
|
||||||
|
c.offset.size.x=w or 0
|
||||||
|
c.offset.size.y=h or 0
|
||||||
|
c.scale.pos={}
|
||||||
|
c.scale.pos.x=sx or 0
|
||||||
|
c.scale.pos.y=sy or 0
|
||||||
|
c.offset.pos={}
|
||||||
|
c.offset.pos.x=x or 0
|
||||||
|
c.offset.pos.y=y or 0
|
||||||
|
c.VIS=true
|
||||||
|
c.Visible=true
|
||||||
|
c.Visibility=1
|
||||||
|
c.BorderColor={0,0,0}
|
||||||
|
c.BorderSize=0
|
||||||
|
c.Type="Part"
|
||||||
|
c.Name="GuiPart"
|
||||||
|
_GuiPro.count=_GuiPro.count+1
|
||||||
|
c.x=(c.Parent.width*c.scale.pos.x)+c.offset.pos.x+c.Parent.x
|
||||||
|
c.y=(c.Parent.height*c.scale.pos.y)+c.offset.pos.y+c.Parent.y
|
||||||
|
c.width=(c.Parent.width*c.scale.size.x)+c.offset.size.x
|
||||||
|
c.height=(c.Parent.height*c.scale.size.y)+c.offset.size.y
|
||||||
|
table.insert(c.Parent.Children,c)
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
function gui:newProgressBar(txt,x,y,w,h,sx,sy,sw,sh)
|
||||||
|
name="newProgressBar"
|
||||||
|
x,y,w,h,sx,sy,sw,sh=filter(name, x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local c=self:newBase("newProgressBarFrame",name, x, y, w, 30, sx ,sy ,sw ,sh)
|
||||||
|
c.Draggable=true
|
||||||
|
c.dragbut="r"
|
||||||
|
c.BorderSize=0
|
||||||
|
c:ApplyGradient{Color.Blue,Color.sexy_purple}
|
||||||
|
c:newTextLabel(txt,"Holder",0,0,0,h-30,0,1,1,0).Color=Color.sexy_purple
|
||||||
|
c.funcO={}
|
||||||
|
c.funcX={}
|
||||||
|
c:OnDragStart(function(self)
|
||||||
|
self:TopStack()
|
||||||
|
end)
|
||||||
|
local temp = c:newTextButton("X","Close",-25,5,20,20,1)
|
||||||
|
temp.Tween=-5
|
||||||
|
temp.XTween=-2
|
||||||
|
temp:OnReleased(function(b,self) for i=1,#self.Parent.funcX do self.Parent.funcX[i](self.Parent) end end)
|
||||||
|
temp.Color=Color.Red
|
||||||
|
c.BarBG=c:newTextButton("",5,h-65,-10,30,0,1,1)
|
||||||
|
c.BarBG:ApplyGradient{Color.Red,Color.light_red}
|
||||||
|
c.Bar=c.BarBG:newTextLabel("",0,0,0,0,0,0,0,1)
|
||||||
|
c.Bar:ApplyGradient{Color.Green,Color.light_green}
|
||||||
|
c.BarDisp=c.BarBG:newTextLabel("0%","0%",0,0,0,0,0,0,1,1)
|
||||||
|
c.BarDisp.Visibility=0
|
||||||
|
c.BarDisp.Link=c.Bar
|
||||||
|
c.BarDisp:OnUpdate(function(self)
|
||||||
|
self.text=self.Link.scale.size.x*100 .."%"
|
||||||
|
end)
|
||||||
|
c.Func1={}
|
||||||
|
function c:On100(func)
|
||||||
|
table.insert(self.Func1,func)
|
||||||
|
end
|
||||||
|
c:OnUpdate(function(self)
|
||||||
|
if self.Bar.scale.size.x*100>=100 then
|
||||||
|
for P=1,#self.Func1 do
|
||||||
|
self.Func1[P](self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
function c:SetPercentage(n)
|
||||||
|
self.Bar:SetDualDim(0,0,0,0,0,0,n/100,1)
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
function gui:newScrollBar(color1,color2)
|
||||||
|
local scrollbar=self:newFrame(-20,0,20,0,1,0,0,1)
|
||||||
|
scrollbar.funcS={}
|
||||||
|
scrollbar.Color=color1 or Color.saddle_brown
|
||||||
|
scrollbar:OnClicked(function(b,self,x,y)
|
||||||
|
love.mouse.setX(self.x+10)
|
||||||
|
if y>=10 and y<=self.height-10 then
|
||||||
|
self.mover:SetDualDim(0,y-10)
|
||||||
|
end
|
||||||
|
if y<10 then
|
||||||
|
love.mouse.setY(10+self.y)
|
||||||
|
end
|
||||||
|
if y>self.height-10 then
|
||||||
|
love.mouse.setY((self.height-10)+self.y)
|
||||||
|
end
|
||||||
|
for i=1,#self.funcS do
|
||||||
|
self.funcS[i](self,self:getPosition())
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
scrollbar:OnEnter(function(self)
|
||||||
|
self:addDominance()
|
||||||
|
end)
|
||||||
|
scrollbar:OnExit(function(self)
|
||||||
|
self:removeDominance()
|
||||||
|
end)
|
||||||
|
scrollbar.mover=scrollbar:newTextButton("","",0,0,20,20)
|
||||||
|
scrollbar.mover.Color=color2 or Color.light_brown
|
||||||
|
function scrollbar:getPosition()
|
||||||
|
return ((self.mover.offset.pos.y)/(self.height-20))*100
|
||||||
|
end
|
||||||
|
function scrollbar:setPosition(n)
|
||||||
|
print((self.height-20),n)
|
||||||
|
self.mover.offset.pos.y=((self.height-20)/(100/n))
|
||||||
|
for i=1,#self.funcS do
|
||||||
|
self.funcS[i](self,self:getPosition())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function scrollbar:OnScroll(func)
|
||||||
|
table.insert(self.funcS,func)
|
||||||
|
end
|
||||||
|
return scrollbar
|
||||||
|
end
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
function gui:newScrollMenu(title,tabN,onloop,x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local Main = self:newFrame(x, y, w, h, sx ,sy ,sw ,sh)
|
||||||
|
local Title=Main:newTextButton(title,"Title",0,0,0,20,0,0,1)
|
||||||
|
Title.Tween=-4
|
||||||
|
Title.FontSize=12
|
||||||
|
Title:OnReleased(function(b,self)
|
||||||
|
self.Parent.Tick=not(self.Parent.Tick)
|
||||||
|
end)
|
||||||
|
local scroll=Main:newTextButton("","Scroll",-20,20,20,-20,1,0,0,1)
|
||||||
|
scroll:OnClicked(function(b,self,x,y)
|
||||||
|
self.Parent.Mover:SetDualDim(0,y-10,20,20)
|
||||||
|
if self.Parent.Mover.offset.pos.y<0 then
|
||||||
|
self.Parent.Mover:SetDualDim(0,0,20,20)
|
||||||
|
end
|
||||||
|
if self.Parent.Mover.offset.pos.y>self.Parent.height-40 then
|
||||||
|
self.Parent.Mover:SetDualDim(0,self.Parent.height-40,20,20)
|
||||||
|
end
|
||||||
|
local temp = #self.Parent.TList
|
||||||
|
self.Parent.pos=(math.floor((temp*self.Parent.Mover.offset.pos.y)/self.height))+1
|
||||||
|
end)
|
||||||
|
Main:OnUpdate(function(self)
|
||||||
|
if self.Tick==false then
|
||||||
|
self.Visibility=0
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
scroll:OnUpdate(function(self)
|
||||||
|
self.Visible=self.Parent.Tick
|
||||||
|
end)
|
||||||
|
local Mover=scroll:newTextLabel("",0,0,20,20)
|
||||||
|
Main.Mover=Mover
|
||||||
|
Main.TList=tabN
|
||||||
|
Main.pos=1
|
||||||
|
Main.Tick=true
|
||||||
|
function Main:Update(title,tabN,onloop)
|
||||||
|
ch=self:getChildren()
|
||||||
|
for i=#ch,1,-1 do
|
||||||
|
ch[i]:Destroy()
|
||||||
|
end
|
||||||
|
Title=Main:newTextButton(title,"Title",0,0,0,20,0,0,1)
|
||||||
|
Title.Tween=-4
|
||||||
|
Title.FontSize=12
|
||||||
|
Title:OnReleased(function(b,self)
|
||||||
|
self.Parent.Tick=not(self.Parent.Tick)
|
||||||
|
end)
|
||||||
|
scroll=Main:newTextButton("","Scroll",-20,20,20,-20,1,0,0,1)
|
||||||
|
scroll:OnClicked(function(b,self,x,y)
|
||||||
|
self.Parent.Mover:SetDualDim(0,y-10,20,20)
|
||||||
|
if self.Parent.Mover.offset.pos.y<0 then
|
||||||
|
self.Parent.Mover:SetDualDim(0,0,20,20)
|
||||||
|
end
|
||||||
|
if self.Parent.Mover.offset.pos.y>self.Parent.height-40 then
|
||||||
|
self.Parent.Mover:SetDualDim(0,self.Parent.height-40,20,20)
|
||||||
|
end
|
||||||
|
local temp = #self.Parent.TList
|
||||||
|
self.Parent.pos=(math.floor((temp*self.Parent.Mover.offset.pos.y)/self.height))+1
|
||||||
|
end)
|
||||||
|
local Mover=scroll:newTextLabel("",0,0,20,20)
|
||||||
|
Main.Mover=Mover
|
||||||
|
Main.TList=tabN
|
||||||
|
Main.pos=1
|
||||||
|
Main.Tick=true
|
||||||
|
scroll:OnUpdate(function(self)
|
||||||
|
self.Visible=self.Parent.Tick
|
||||||
|
end)
|
||||||
|
for i=1,math.floor(Main.height/20)-1 do
|
||||||
|
local temp=Main:newTextButton("","Item"..i,0,i*20,-20,20,0,0,1)
|
||||||
|
temp.FontSize=10
|
||||||
|
temp.Tween=-4
|
||||||
|
temp.pos=i
|
||||||
|
temp:OnUpdate(function(self)
|
||||||
|
self.text=self.Parent.TList[(self.Parent.pos+self.pos)-1]
|
||||||
|
self.Visible=self.Parent.Tick
|
||||||
|
end)
|
||||||
|
if onloop then
|
||||||
|
onloop(temp,i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
io.write(tostring(Main.height).."\n")
|
||||||
|
for i=1,math.floor(Main.height/20)-1 do
|
||||||
|
local temp=Main:newTextButton("Item"..i,0,i*20,-20,20,0,0,1)
|
||||||
|
temp.FontSize=10
|
||||||
|
temp.Tween=-4
|
||||||
|
temp.pos=i
|
||||||
|
temp:OnUpdate(function(self)
|
||||||
|
if self.Parent.TList[(self.Parent.pos+self.pos)-1]~=nil then
|
||||||
|
self.text=self.Parent.TList[(self.Parent.pos+self.pos)-1]
|
||||||
|
else
|
||||||
|
self.text=""
|
||||||
|
end
|
||||||
|
self.Visible=self.Parent.Tick
|
||||||
|
end)
|
||||||
|
if onloop then
|
||||||
|
onloop(temp,i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return Main
|
||||||
|
end
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
function gui:destroyAllChildren()
|
||||||
|
local c=self.Children
|
||||||
|
for i=1,#c do
|
||||||
|
c[i]:Destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:removeDominance()
|
||||||
|
_GuiPro.TopHovered=nil
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:respectHierarchy()
|
||||||
|
_GuiPro.Hierarchy=true
|
||||||
|
end
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
function gui.round(num, idp)
|
||||||
|
local mult = 10^(idp or 0)
|
||||||
|
return math.floor(num * mult + 0.5) / mult
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui.setBG(i)
|
||||||
|
gui.ff:SetImage(i)
|
||||||
|
end
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
function gui:setColor(a,b,c)
|
||||||
|
if type(a)=="string" then
|
||||||
|
self.Color=Color[a]
|
||||||
|
elseif type(a)=="number" then
|
||||||
|
self.Color=Color.new(a,b,c)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function gui:setTextColor(a,b,c)
|
||||||
|
if type(a)=="string" then
|
||||||
|
self.TextColor=Color[a]
|
||||||
|
elseif type(a)=="number" then
|
||||||
|
self.TextColor=Color.new(a,b,c)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:setDefualtFont(font)
|
||||||
|
_defaultfont = font
|
||||||
|
end
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
function gui:setHotKey(key)
|
||||||
|
local tab=key:split("+")
|
||||||
|
self.hotkeys=tab
|
||||||
|
self.cooldown=false
|
||||||
|
self.Alarm=multi:newAlarm(1)
|
||||||
|
self.Alarm.parent=self
|
||||||
|
self.args={}
|
||||||
|
self.funcHK=multi:newConnection()
|
||||||
|
self.Alarm:OnRing(function(alarm) alarm.parent.cooldown=false end)
|
||||||
|
function self:OnHotKey(func)
|
||||||
|
self.funcHK:connect(func)
|
||||||
|
end
|
||||||
|
self:OnUpdate(function(self)
|
||||||
|
if self.cooldown then return end
|
||||||
|
for i=1,#self.hotkeys do
|
||||||
|
if not(love.keyboard.isDown(self.hotkeys[i])) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.cooldown=true
|
||||||
|
self.funcHK:Fire(self)
|
||||||
|
self.Alarm:Reset()
|
||||||
|
end)
|
||||||
|
end
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
function gui:setNewFont(FontSize)
|
||||||
|
self.Font=love.graphics.setNewFont(tonumber(FontSize))
|
||||||
|
end
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
function gui:setParent(parent,name)-- Needs fixing!!!
|
||||||
|
local temp=self.Parent:getChildren()
|
||||||
|
for i=1,#temp do
|
||||||
|
if temp[i]==self then
|
||||||
|
table.remove(self.Parent.Children,i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.insert(parent.Children,self)
|
||||||
|
self.Parent=parent
|
||||||
|
if name then
|
||||||
|
self:SetName(name)
|
||||||
|
end
|
||||||
|
end
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user