gosu_extensions 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/core/game_window.rb +17 -2
- data/lib/gosu_extensions.rb +1 -0
- data/lib/traits/user_interface.rb +32 -0
- data/spec/lib/core/traits_spec.rb +1 -1
- data/spec/lib/traits/user_interface_spec.rb +44 -0
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/lib/core/game_window.rb
CHANGED
@@ -54,6 +54,7 @@ class GameWindow < Gosu::Window
|
|
54
54
|
setup_steps
|
55
55
|
setup_scheduling
|
56
56
|
setup_font
|
57
|
+
setup_uis
|
57
58
|
|
58
59
|
setup_containers
|
59
60
|
|
@@ -163,7 +164,7 @@ class GameWindow < Gosu::Window
|
|
163
164
|
|
164
165
|
attr_accessor :collisions
|
165
166
|
def no_collision this, that = this
|
166
|
-
#
|
167
|
+
# The next line doesn't work, as &nil == nil
|
167
168
|
# collision this, that, &Collision::None
|
168
169
|
InitializerHooks.register self do
|
169
170
|
self.collisions << Collision.new(self, this, that)
|
@@ -235,6 +236,9 @@ class GameWindow < Gosu::Window
|
|
235
236
|
def setup_font
|
236
237
|
@font = Gosu::Font.new self, self.font_name, self.font_size
|
237
238
|
end
|
239
|
+
def setup_uis
|
240
|
+
@uis = []
|
241
|
+
end
|
238
242
|
def setup_environment
|
239
243
|
@environment = Environment.new
|
240
244
|
class << @environment
|
@@ -288,6 +292,7 @@ class GameWindow < Gosu::Window
|
|
288
292
|
@current_loop = lambda do
|
289
293
|
proceed if proceed_condition && instance_eval(&proceed_condition)
|
290
294
|
advance_step
|
295
|
+
handle_input
|
291
296
|
# TODO stopped
|
292
297
|
end
|
293
298
|
after_stopping
|
@@ -354,8 +359,18 @@ class GameWindow < Gosu::Window
|
|
354
359
|
# end
|
355
360
|
#
|
356
361
|
def unregister thing
|
362
|
+
# explicitly call unregister_ui thing if you want it
|
357
363
|
remove thing.shape
|
358
364
|
end
|
365
|
+
# Register a user interfaceable object.
|
366
|
+
#
|
367
|
+
def register_ui thing
|
368
|
+
@uis << thing
|
369
|
+
end
|
370
|
+
def unregister_ui thing
|
371
|
+
@uis.delete thing
|
372
|
+
end
|
373
|
+
|
359
374
|
# Remove this shape the next turn.
|
360
375
|
#
|
361
376
|
# Note: Internal use. Use unregister to properly remove a moveable.
|
@@ -444,7 +459,7 @@ class GameWindow < Gosu::Window
|
|
444
459
|
# @font.draw "P1 Score: ", 10, 10, ZOrder::UI, 1.0, 1.0, 0xffff0000
|
445
460
|
#
|
446
461
|
def draw_ui
|
447
|
-
|
462
|
+
@uis.each(&:draw_ui)
|
448
463
|
end
|
449
464
|
#
|
450
465
|
#
|
data/lib/gosu_extensions.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
#
|
2
|
+
#
|
3
|
+
module UserInterface extend Trait
|
4
|
+
|
5
|
+
def self.included base
|
6
|
+
base.extend ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
# Call this to install an UI on all instances of
|
10
|
+
# this class at the given position.
|
11
|
+
#
|
12
|
+
module ClassMethods
|
13
|
+
attr_accessor :ui
|
14
|
+
def ui x = 20, y = 10, color = Gosu::Color::BLACK, &display
|
15
|
+
InitializerHooks.append self do
|
16
|
+
ui x, y, color, &display
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Call this to dynamically add itself to the ui displaying.
|
22
|
+
#
|
23
|
+
def ui x = 20, y = 10, color = Gosu::Color::BLACK, &display
|
24
|
+
metaclass.instance_eval do
|
25
|
+
define_method :draw_ui do
|
26
|
+
window.font.draw instance_eval(&display), x, y, Layer::UI, 1.0, 1.0, color
|
27
|
+
end
|
28
|
+
end
|
29
|
+
window.register_ui self
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -6,7 +6,7 @@ describe Traits do
|
|
6
6
|
it "should return a list of all traits that can be included using it_is_a, it_is, or it_has" do
|
7
7
|
ActiveSupport::Deprecation.stub! :warn => :shut_up
|
8
8
|
|
9
|
-
Traits.list.should == [Attachable, Controllable, Damaging, Generator, Hitpoints, Imageable, Lives, Moveable, Pod, Shooter, ShortLived, Shot, Targetable, Targeting::Closest, Turnable]
|
9
|
+
Traits.list.should == [Attachable, Controllable, Damaging, Generator, Hitpoints, Imageable, Lives, Moveable, Pod, Shooter, ShortLived, Shot, Targetable, Targeting::Closest, Turnable, UserInterface]
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../../spec_helper')
|
2
|
+
|
3
|
+
describe UserInterface do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@window = stub :window
|
7
|
+
@user_interface = test_class_with(UserInterface).new @window
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "ui" do
|
11
|
+
before(:each) do
|
12
|
+
@font = stub :font, :null_object => true
|
13
|
+
@window.stub! :font => @font
|
14
|
+
@window.stub! :register_ui
|
15
|
+
end
|
16
|
+
it "should register itself with window" do
|
17
|
+
@window.should_receive(:register_ui).once.with @user_interface
|
18
|
+
|
19
|
+
@user_interface.ui
|
20
|
+
end
|
21
|
+
it "should install a method draw_ui" do
|
22
|
+
@user_interface.ui do end
|
23
|
+
|
24
|
+
lambda { @user_interface.draw_ui }.should_not raise_error
|
25
|
+
end
|
26
|
+
it "should do the right thing on calling draw_ui (defaults)" do
|
27
|
+
some_block = lambda { :some_result }
|
28
|
+
@user_interface.ui &some_block
|
29
|
+
|
30
|
+
@font.should_receive(:draw).once.with :some_result, 20, 10, Layer::UI, 1.0, 1.0, Gosu::Color::BLACK
|
31
|
+
|
32
|
+
@user_interface.draw_ui
|
33
|
+
end
|
34
|
+
it "should do the right thing on calling draw_ui" do
|
35
|
+
some_block = lambda { :some_result }
|
36
|
+
@user_interface.ui :some_x, :some_y, :some_color, &some_block
|
37
|
+
|
38
|
+
@font.should_receive(:draw).once.with :some_result, :some_x, :some_y, Layer::UI, 1.0, 1.0, :some_color
|
39
|
+
|
40
|
+
@user_interface.draw_ui
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 4
|
9
|
+
version: 0.2.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/traits/targeting.rb
|
90
90
|
- lib/traits/targeting/closest.rb
|
91
91
|
- lib/traits/turnable.rb
|
92
|
+
- lib/traits/user_interface.rb
|
92
93
|
- lib/units/sprite.rb
|
93
94
|
- lib/units/thing.rb
|
94
95
|
has_rdoc: true
|
@@ -145,4 +146,5 @@ test_files:
|
|
145
146
|
- spec/lib/traits/targetable_spec.rb
|
146
147
|
- spec/lib/traits/targeting_spec.rb
|
147
148
|
- spec/lib/traits/turnable_spec.rb
|
149
|
+
- spec/lib/traits/user_interface_spec.rb
|
148
150
|
- spec/lib/units/thing_spec.rb
|