Implemented drag and drop.
[kaya.git] / lib / mainwindow.rb
blob11626773e78b310502749d599c3cd971be2e3c6a
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       @controller.back
35     end
36     regular_action :forward, :icon => 'go-next', 
37                              :text => KDE.i18n("&Forward") do
38       @controller.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)
60     pools = if game.respond_to? :pool
61       game.players.inject({}) do |res, player|
62         res[player] = Pool.new(scene, theme, game)
63         res
64       end
65     else
66       {}
67     end
68     
69     elements = { :board => board,
70                  :pools => pools }
71     table = Table.new scene, theme, self, elements
73     history = History.new(state)
74     @controller = Controller.new(scene, elements, game, history)
75     
76     self.central_widget = table
77   end
78 end