author_engine 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +7 -0
- data/API.md +81 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +10 -0
- data/SAVEFILE.md +23 -0
- data/assets/fonts/Connection.otf +0 -0
- data/assets/fonts/ConnectionBold.otf +0 -0
- data/assets/fonts/README.md +3 -0
- data/assets/fonts/SIL Open Font License.txt +94 -0
- data/assets/ui/bucket_icon.png +0 -0
- data/assets/ui/code_icon.png +0 -0
- data/assets/ui/error_icon.png +0 -0
- data/assets/ui/level_icon.png +0 -0
- data/assets/ui/loading_icon.png +0 -0
- data/assets/ui/lock_icon.png +0 -0
- data/assets/ui/pencil_icon.png +0 -0
- data/assets/ui/play_icon.png +0 -0
- data/assets/ui/sprite_icon.png +0 -0
- data/assets/ui/unlock_icon.png +0 -0
- data/author_engine.gemspec +41 -0
- data/bin/author_engine +4 -0
- data/lib/author_engine/button.rb +154 -0
- data/lib/author_engine/code_editor/cursor.rb +339 -0
- data/lib/author_engine/code_editor/highlighting.rb +49 -0
- data/lib/author_engine/container.rb +24 -0
- data/lib/author_engine/containers/editor.rb +97 -0
- data/lib/author_engine/containers/loader.rb +105 -0
- data/lib/author_engine/game/game.rb +26 -0
- data/lib/author_engine/game/parts/colors.rb +59 -0
- data/lib/author_engine/game/parts/common.rb +13 -0
- data/lib/author_engine/game/parts/graphics.rb +41 -0
- data/lib/author_engine/game/parts/input.rb +25 -0
- data/lib/author_engine/image.rb +53 -0
- data/lib/author_engine/palette.rb +114 -0
- data/lib/author_engine/save_file.rb +134 -0
- data/lib/author_engine/sprite.rb +4 -0
- data/lib/author_engine/sprite_picker.rb +154 -0
- data/lib/author_engine/support.rb +22 -0
- data/lib/author_engine/text.rb +41 -0
- data/lib/author_engine/version.rb +3 -0
- data/lib/author_engine/view.rb +55 -0
- data/lib/author_engine/views/code_editor.rb +154 -0
- data/lib/author_engine/views/level_editor.rb +7 -0
- data/lib/author_engine/views/play_viewer.rb +163 -0
- data/lib/author_engine/views/sprite_editor.rb +333 -0
- data/lib/author_engine/window.rb +132 -0
- data/lib/author_engine.rb +32 -0
- data/test_3.authorengine +519 -0
- data/testing.authorengine +578 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa9450a11aa87c07b6af55a87d7ebf3a68feaff0c671662e6662a14ebf45a004
|
4
|
+
data.tar.gz: 52c74e684c1d5c402083b5dfa7a630ad99d445ec5cd786db9fc3a3d324f7c9a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b0173f8357c12aadd3d0ac99e0a7b2c78d862d93bca6940d3f383be701e51d00dfd5c63ea7873fb7289778389846bbce2cdb5129c5e5bb6b8801895d0f5f018
|
7
|
+
data.tar.gz: a59df8c02965376c9824385f756516a5af44a4c88854c748a8246bf6f2929a63048e6c1f040214cbd193b5837d91f1ca24ab0161d3d9a9e8984a16fd8aafec61
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/API.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Game API
|
2
|
+
An example game
|
3
|
+
``` ruby
|
4
|
+
# Your setup method
|
5
|
+
def init
|
6
|
+
@x = 0
|
7
|
+
@y = 0
|
8
|
+
@z = 0
|
9
|
+
|
10
|
+
@birdie = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
# All drawing operations must happen in draw
|
14
|
+
def draw
|
15
|
+
rect(@x, @y, width, height, black, @z)
|
16
|
+
sprite(@birdie, @x, @y, @z)
|
17
|
+
text("string", @x, @y, 10, @z, white)
|
18
|
+
end
|
19
|
+
|
20
|
+
def update
|
21
|
+
@x+=1 if button?("right")
|
22
|
+
@x-=1 if button?("left")
|
23
|
+
@y-=1 if button?("up")
|
24
|
+
@y+=1 if button?("down")
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
# Common
|
29
|
+
### width
|
30
|
+
Virtual display width (e.g. 128)
|
31
|
+
|
32
|
+
### height
|
33
|
+
Virtual display height (e.g. 128)
|
34
|
+
|
35
|
+
### fps
|
36
|
+
Current Frames Per Second
|
37
|
+
|
38
|
+
### milliseconds
|
39
|
+
Milliseconds since game started
|
40
|
+
|
41
|
+
# Graphics
|
42
|
+
### rect(x = 0, y = 0, width = 1, height = 1, color = white, z = 0)
|
43
|
+
### sprite(sprite_sheet_index, x = 0, y = 0, z = 0, color = white)
|
44
|
+
### text(string, x = 0, y = 0, size = 4, z = 0, color = white)
|
45
|
+
|
46
|
+
### translate(x, y, &block)
|
47
|
+
Translate the contents of block by x and y
|
48
|
+
### rotate(angle, around_x = 0, around_y = 0, &block)
|
49
|
+
Rotate the contents of block by angle, rotating about at around_x and around_y
|
50
|
+
|
51
|
+
# Input
|
52
|
+
### button?(string)
|
53
|
+
returns true if the specied button is currently being pressed
|
54
|
+
|
55
|
+
Valid values for string are:
|
56
|
+
#### "left"
|
57
|
+
#### "right"
|
58
|
+
#### "up"
|
59
|
+
#### "down"
|
60
|
+
#### "x"
|
61
|
+
mapped to the X key
|
62
|
+
#### "y"
|
63
|
+
mapped to the C key
|
64
|
+
|
65
|
+
# Colors
|
66
|
+
### black
|
67
|
+
### dark_blue
|
68
|
+
### dark_purple
|
69
|
+
### dark_green
|
70
|
+
### brown
|
71
|
+
### dark_gray
|
72
|
+
### light_gray
|
73
|
+
### white
|
74
|
+
### red
|
75
|
+
### orange
|
76
|
+
### yellow
|
77
|
+
### green
|
78
|
+
### blue
|
79
|
+
### indigo
|
80
|
+
### pink
|
81
|
+
### peach
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
author_engine (0.1.0)
|
5
|
+
coderay (~> 1.1.2)
|
6
|
+
gosu (~> 0.14.4)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.2)
|
12
|
+
gosu (0.14.4)
|
13
|
+
minitest (5.11.3)
|
14
|
+
rake (10.5.0)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
author_engine!
|
21
|
+
bundler (~> 1.16)
|
22
|
+
minitest (~> 5.0)
|
23
|
+
rake (~> 10.0)
|
24
|
+
|
25
|
+
BUNDLED WITH
|
26
|
+
1.16.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Cyberarm
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# AuthorEngine
|
2
|
+
A virtual console¹ that you code in Ruby.
|
3
|
+
|
4
|
+
![animated_gif](#)
|
5
|
+
|
6
|
+
# Getting Started
|
7
|
+
## Install
|
8
|
+
`gem install author_engine`
|
9
|
+
|
10
|
+
## Run
|
11
|
+
`author_engine`
|
12
|
+
### Options
|
13
|
+
`--native` Open AuthorEngine in fullscreen and maximized.
|
14
|
+
|
15
|
+
# Interface
|
16
|
+
## Play
|
17
|
+
![play_view](#)
|
18
|
+
## Sprite Editor
|
19
|
+
![sprite_editor_view](#)
|
20
|
+
## Level Editor
|
21
|
+
![level_editor_view](#)
|
22
|
+
## Code Editor
|
23
|
+
![code_editor_view](#)
|
24
|
+
|
25
|
+
|
26
|
+
¹: Does not directly run any kind of assembly
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cyberarm/author_engineV2.
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/SAVEFILE.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Save File
|
2
|
+
``` text
|
3
|
+
# header text
|
4
|
+
# comments
|
5
|
+
# author
|
6
|
+
|
7
|
+
___CODE___
|
8
|
+
def init
|
9
|
+
end
|
10
|
+
|
11
|
+
def draw
|
12
|
+
end
|
13
|
+
|
14
|
+
def update
|
15
|
+
end
|
16
|
+
|
17
|
+
___SPRITES___
|
18
|
+
512x128
|
19
|
+
RGBASTREAM of spritesheet which is sliced at spritesheet.width * 4
|
20
|
+
|
21
|
+
___LEVELS___
|
22
|
+
???
|
23
|
+
```
|
Binary file
|
Binary file
|
@@ -0,0 +1,94 @@
|
|
1
|
+
Copyright (c) 2017, Jasper @ KineticPlasma Fonts (cannotintospacefonts@gmail.com),
|
2
|
+
with Reserved Font Name Connection.
|
3
|
+
|
4
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
5
|
+
This license is copied below, and is also available with a FAQ at:
|
6
|
+
http://scripts.sil.org/OFL
|
7
|
+
|
8
|
+
|
9
|
+
-----------------------------------------------------------
|
10
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
11
|
+
-----------------------------------------------------------
|
12
|
+
|
13
|
+
PREAMBLE
|
14
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
15
|
+
development of collaborative font projects, to support the font creation
|
16
|
+
efforts of academic and linguistic communities, and to provide a free and
|
17
|
+
open framework in which fonts may be shared and improved in partnership
|
18
|
+
with others.
|
19
|
+
|
20
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
21
|
+
redistributed freely as long as they are not sold by themselves. The
|
22
|
+
fonts, including any derivative works, can be bundled, embedded,
|
23
|
+
redistributed and/or sold with any software provided that any reserved
|
24
|
+
names are not used by derivative works. The fonts and derivatives,
|
25
|
+
however, cannot be released under any other type of license. The
|
26
|
+
requirement for fonts to remain under this license does not apply
|
27
|
+
to any document created using the fonts or their derivatives.
|
28
|
+
|
29
|
+
DEFINITIONS
|
30
|
+
"Font Software" refers to the set of files released by the Copyright
|
31
|
+
Holder(s) under this license and clearly marked as such. This may
|
32
|
+
include source files, build scripts and documentation.
|
33
|
+
|
34
|
+
"Reserved Font Name" refers to any names specified as such after the
|
35
|
+
copyright statement(s).
|
36
|
+
|
37
|
+
"Original Version" refers to the collection of Font Software components as
|
38
|
+
distributed by the Copyright Holder(s).
|
39
|
+
|
40
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
41
|
+
or substituting -- in part or in whole -- any of the components of the
|
42
|
+
Original Version, by changing formats or by porting the Font Software to a
|
43
|
+
new environment.
|
44
|
+
|
45
|
+
"Author" refers to any designer, engineer, programmer, technical
|
46
|
+
writer or other person who contributed to the Font Software.
|
47
|
+
|
48
|
+
PERMISSION & CONDITIONS
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
50
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
51
|
+
redistribute, and sell modified and unmodified copies of the Font
|
52
|
+
Software, subject to the following conditions:
|
53
|
+
|
54
|
+
1) Neither the Font Software nor any of its individual components,
|
55
|
+
in Original or Modified Versions, may be sold by itself.
|
56
|
+
|
57
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
58
|
+
redistributed and/or sold with any software, provided that each copy
|
59
|
+
contains the above copyright notice and this license. These can be
|
60
|
+
included either as stand-alone text files, human-readable headers or
|
61
|
+
in the appropriate machine-readable metadata fields within text or
|
62
|
+
binary files as long as those fields can be easily viewed by the user.
|
63
|
+
|
64
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
65
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
66
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
67
|
+
presented to the users.
|
68
|
+
|
69
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
70
|
+
Software shall not be used to promote, endorse or advertise any
|
71
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
72
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
73
|
+
permission.
|
74
|
+
|
75
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
76
|
+
must be distributed entirely under this license, and must not be
|
77
|
+
distributed under any other license. The requirement for fonts to
|
78
|
+
remain under this license does not apply to any document created
|
79
|
+
using the Font Software.
|
80
|
+
|
81
|
+
TERMINATION
|
82
|
+
This license becomes null and void if any of the above conditions are
|
83
|
+
not met.
|
84
|
+
|
85
|
+
DISCLAIMER
|
86
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
87
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
88
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
89
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
90
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
91
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
92
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
93
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
94
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "author_engine/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "author_engine"
|
8
|
+
spec.version = AuthorEngine::VERSION
|
9
|
+
spec.authors = ["Cyberarm"]
|
10
|
+
spec.email = ["matthewlikesrobots@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A virtual console that you code in Ruby.}
|
13
|
+
spec.description = %q{Create arcade style games quickly and easily}
|
14
|
+
spec.homepage = "https://github.com/cyberarm/author_engineV2"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "bin"
|
32
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_dependency "gosu", "~> 0.14.4"
|
36
|
+
spec.add_dependency "coderay", "~> 1.1.2"
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
41
|
+
end
|
data/bin/author_engine
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
class AuthorEngine
|
2
|
+
class Button
|
3
|
+
include Support
|
4
|
+
|
5
|
+
PADDING = 2
|
6
|
+
|
7
|
+
attr_reader :label, :text, :block, :image, :width, :height, :x, :y, :tag
|
8
|
+
attr_accessor :z
|
9
|
+
def initialize(label: nil, tooltip: nil, image: nil, x: 0, y: 0, z: 0, color:, tag: nil, &block)
|
10
|
+
@label, @image = label, image
|
11
|
+
@x, @y, @z = x, y, z
|
12
|
+
@color = color
|
13
|
+
@tag = tag
|
14
|
+
@block = block
|
15
|
+
|
16
|
+
@width, @height = 0, 0
|
17
|
+
@x_padding = PADDING * window.scale_x
|
18
|
+
@y_padding = PADDING * window.scale_y
|
19
|
+
|
20
|
+
if @label.is_a?(String)
|
21
|
+
@text = AuthorEngine::Text.new(message: @label, x: @x, y: @y, z: @z)
|
22
|
+
end
|
23
|
+
|
24
|
+
if @image.is_a?(String)
|
25
|
+
@image = AuthorEngine::Image.new(@image, retro: true)
|
26
|
+
end
|
27
|
+
|
28
|
+
if tooltip.is_a?(String)
|
29
|
+
@tooltip = AuthorEngine::Text.new(message: tooltip, x: @x, y: @y+@height, z: 1000)
|
30
|
+
end
|
31
|
+
|
32
|
+
set_interactive_colors
|
33
|
+
position_elements
|
34
|
+
|
35
|
+
return self
|
36
|
+
end
|
37
|
+
|
38
|
+
def image=(gosu_image)
|
39
|
+
@image = gosu_image
|
40
|
+
position_elements
|
41
|
+
end
|
42
|
+
|
43
|
+
def label=(text)
|
44
|
+
@label.text = text
|
45
|
+
position_elements
|
46
|
+
end
|
47
|
+
|
48
|
+
def draw
|
49
|
+
if mouse_over? && Gosu.button_down?(Gosu::MsLeft)
|
50
|
+
draw_background(@color_active)
|
51
|
+
elsif mouse_over?
|
52
|
+
draw_background(@color_hover)
|
53
|
+
else
|
54
|
+
draw_background(@color)
|
55
|
+
end
|
56
|
+
draw_element
|
57
|
+
|
58
|
+
draw_tooltip if @tooltip && mouse_over?
|
59
|
+
end
|
60
|
+
|
61
|
+
def button_up(id)
|
62
|
+
call if mouse_over? && (id == Gosu::MsLeft)
|
63
|
+
end
|
64
|
+
|
65
|
+
def x=(n)
|
66
|
+
@x = n
|
67
|
+
position_elements
|
68
|
+
end
|
69
|
+
|
70
|
+
def y=(n)
|
71
|
+
@y = n
|
72
|
+
position_elements
|
73
|
+
end
|
74
|
+
|
75
|
+
def label=(s)
|
76
|
+
@label = s
|
77
|
+
@text.message = s
|
78
|
+
position_elements
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_interactive_colors
|
82
|
+
if @color.value > 0.7
|
83
|
+
@color_active = window.darken(@color, 50)
|
84
|
+
@color_hover = window.darken(@color)
|
85
|
+
else
|
86
|
+
@color_active = window.lighten(@color, 50)
|
87
|
+
@color_hover = window.lighten(@color)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
def mouse_over?
|
93
|
+
if window.mouse_x.between?(@x, @x+@width) &&
|
94
|
+
window.mouse_y.between?(@y, @y+@height)
|
95
|
+
true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def draw_background(color)
|
100
|
+
Gosu.draw_rect(@x, @y, @width, @height, color, @z)
|
101
|
+
end
|
102
|
+
|
103
|
+
def draw_element
|
104
|
+
if @text && @text.is_a?(AuthorEngine::Text)
|
105
|
+
@text.draw
|
106
|
+
|
107
|
+
elsif @image && @image.is_a?(AuthorEngine::Sprite)
|
108
|
+
@image.draw
|
109
|
+
|
110
|
+
elsif @image && @image.is_a?(AuthorEngine::Image)
|
111
|
+
@image.draw(@x+@x_padding, @y+@y_padding, @z, (1 * window.square_scale), (1 * window.square_scale))
|
112
|
+
|
113
|
+
else
|
114
|
+
raise "Nothing to draw! (text and image were nil or invalid types)"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def draw_tooltip
|
119
|
+
Gosu.draw_rect(@tooltip.x-@x_padding, @tooltip.y-(@y_padding*2), @tooltip.width+(@x_padding*2), @tooltip.height+(@y_padding*2), Gosu::Color.rgba(0,0,0, 200), @tooltip.z)
|
120
|
+
@tooltip.draw
|
121
|
+
end
|
122
|
+
|
123
|
+
def position_elements
|
124
|
+
if @text && @text.is_a?(AuthorEngine::Text)
|
125
|
+
@text.x, @text.y = @x+@x_padding, @y+@y_padding
|
126
|
+
@width, @height = @text.width+(@x_padding*2), @text.height+(@y_padding*2)
|
127
|
+
|
128
|
+
elsif @image && @image.is_a?(AuthorEngine::Sprite)
|
129
|
+
@image.x, @image.y = @x+@x_padding, @y+@y_padding
|
130
|
+
@width, @height = @image.width+(@x_padding*2), @image.height+(@y_padding*2)
|
131
|
+
|
132
|
+
elsif @image && @image.is_a?(AuthorEngine::Image)
|
133
|
+
@width, @height = (@image.width * window.square_scale)+(@x_padding*2), (@image.height * window.square_scale)+(@y_padding)
|
134
|
+
|
135
|
+
else
|
136
|
+
raise "From Button -> text and image were nil or invalid types"
|
137
|
+
end
|
138
|
+
|
139
|
+
if @tooltip
|
140
|
+
if (@x + @tooltip.width + @x_padding) > window.width
|
141
|
+
@tooltip.x = @x - (((@x+@tooltip.width) - window.width) + @x_padding)
|
142
|
+
else
|
143
|
+
@tooltip.x = (@x - @tooltip.width / 2) + @width/2
|
144
|
+
end
|
145
|
+
|
146
|
+
@tooltip.y = (@y + @height + (@y_padding*2))
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def call
|
151
|
+
@block.call(self) if @block
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|