Reimplement click handling in scene.
[kaya.git] / lib / mainwindow.rb
blob54b84e60e8dd79f5c227e2d36daabd8395b76b90
1 require 'qtutils'
2 require 'board/board'
3 require 'board/pool'
4 require 'board/table'
5 require 'board/scene'
6 require 'history'
7 require 'controller'
9 class MainWindow < KDE::XmlGuiWindow
10   include ActionHandler
11   
12   Theme = Struct.new(:pieces, :board, :layout)
13   
14   def initialize(loader, game)
15     super nil
16     
17     @loader = loader
18     
19     load_board(game)
20     
21     setup_actions
22     setupGUI
23   end
25 private
27   def setup_actions
28     std_action :open_new do
29       puts "new game"
30     end
31     std_action :quit, :slot => :close
32     regular_action :back, :icon => 'go-previous', 
33                           :text => KDE.i18n("&Back") do
34       @board.fire :back
35     end
36     regular_action :forward, :icon => 'go-next', 
37                              :text => KDE.i18n("&Forward") do
38       @board.fire :forward
39     end
40                   
41   end
42   
43   def load_board(game)
44     config = KDE::Global.config.group('themes')
45     
46     theme = Theme.new
47     theme.pieces = @loader.get_matching('Celtic', game,
48       (game.keywords || []) + ['pieces'], [], :shadow => true)
49     theme.board = @loader.get_matching(nil, game,
50       ['board'], game.keywords || [])
51     theme.layout = @loader.get_matching(nil, game,
52       ['layout'], game.keywords || [])
53     
54     scene = Scene.new
55     
56     state = game.state.new.tap {|s| s.setup }
57     
58     field = AnimationField.new(20)
59     @board = Board.new(scene, theme, game, state, field)
60     if game.respond_to? :pool
61       @pools = game.players.inject({}) do |res, player|
62         res[player] = Pool.new(scene, theme, game, field)
63         res
64       end
65     end
66     
67     table = Table.new scene, theme, self,
68       :board => @board,
69       :pools => @pools
70       
71     self.central_widget = table
73     history = History.new(state)
74     controller = Controller.new(@board, history)
75   end
76 end