14 {:token => 'data/token_baratheon.png'},
15 {:token => 'data/token_lannister.png'},
16 {:token => 'data/token_stark.png'},
17 {:token => 'data/token_greyjoy.png'},
18 {:token => 'data/token_tyrell.png'},
19 {:token => 'data/token_martell.png'}
22 class Tracks < Qt::Widget
28 ll = Qt::VBoxLayout.new
31 @tracks << Track.new(i)
33 btn = Qt::PushButton.new("ready #{i}")
34 btn.setSizePolicy(Qt::SizePolicy::Minimum, Qt::SizePolicy::Expanding)
35 btn.connect(:clicked, @tracks.last, :updateOrder)
37 l = Qt::HBoxLayout.new
38 l.addWidget(@tracks.last)
51 class Track < Qt::GraphicsView
56 attr_accessor :scene,:order,:tokens,:view,:type
69 def initialize(kind, players = 6, parent = 0)
77 when THRONE then Qt::Pixmap.new("data/track_throne.png")
78 when FIEFDOM then Qt::Pixmap.new("data/track_fiefdom.png")
79 when COURT then Qt::Pixmap.new("data/track_court.png")
80 else puts "Track: invalid type #{type}"
82 #pix = Qt::Pixmap.new("data/map_no_tracks_no_wild.jpg")
83 #pix = Qt::Pixmap.new("data/map_no_tracks.jpg")
84 #bg = Qt::GraphicsPixmapItem.new(pix)
86 #@bg.graphicsEffect = Qt::GraphicsBlurEffect.new
87 @bg.graphicsEffect = Qt::GraphicsOpacityEffect.new
88 @bg.graphicsEffect.opacity = 0.4
92 # @order[i] = House::BARATHEON + i;
93 @tokens << Token.new(House::BARATHEON + i, @bg)
94 #@tokens.last.setFlags(Qt::GraphicsItem::ItemIsMovable | Qt::GraphicsItem::ItemSendsGeometryChanges)
95 #@tokens.last.setPos(40+152*i,15)
96 @tokens.last.setPos(240+150*i, 22)
99 @scene = Qt::GraphicsScene.new
100 @scene.setSceneRect(0,0,TRACK_W,TRACK_H)
101 #@scene.setSceneRect(0,0,pix.width,pix.height)
104 self.setScene(@scene)
106 self.verticalScrollBarPolicy = Qt::ScrollBarAlwaysOff
107 self.horizontalScrollBarPolicy = Qt::ScrollBarAlwaysOff
110 self.setInteractive(@high)
118 ni = Hash[@tokens.each_with_index.map{|t,j| [j, Math.hypot(cx - t.x, cy - t.y)]}].min_by{|k,v| v}[0]
119 @tokens[i],@tokens[ni] = @tokens[ni],@tokens[i]
125 setInteractive(@high)
127 puts "new order: #{@tokens.map {|t| t.house}.join(',')}"
130 def setInteractive(enabled)
131 @bg.graphicsEffect.enabled = !enabled
132 @bg.enabled = enabled
135 def resizeEvent(event)
140 class Token < Qt::GraphicsPixmapItem
143 def initialize(house, p = 0)
145 pix = Qt::Pixmap.new(HOUSE_DATA[@house][:token])
151 self.setFlags(Qt::GraphicsItem::ItemIsMovable | Qt::GraphicsItem::ItemSendsGeometryChanges)
154 def mousePressEvent(event)
160 def mouseReleaseEvent(event)
161 @finished = false if (@finished)
167 def itemChange(change, value)
168 @finished = true if (change == Qt::GraphicsItem::ItemPositionHasChanged)
170 return super(change, value)
174 class Over < Qt::GraphicsPixmapItem
177 class TrackStars < Track
178 STARS_A = [3,2,1,0,0,0]
179 STARS_B = [3,3,2,1,0,0]