forked from Nowyyy/Project-Hashi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHypothese.rb
More file actions
145 lines (112 loc) · 4.69 KB
/
Copy pathHypothese.rb
File metadata and controls
145 lines (112 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
require 'gtk3'
load 'HashiGrid.rb'
##
# Cette classe représente le mode Hypothèse
# Elle est responsable de la création du mode hypothèse
# - Créer une copie du plateau courant
class Hypothese
# $window -> la fenêtre contenant le plateau de jeu
# Constructeur du mode hypothèse
# * +plateau+ Référence sur le plateau de jeu
def initialize(plateau)
main_window_res = "./Ressources/Glade/hypo.glade"
builder = Gtk::Builder.new
builder.add_from_file(main_window_res)
hypo = builder.get_object('hypo')
hypo.set_title "Hypothèse"
hypo.signal_connect "destroy" do
hypo.destroy
plateau.getPlateau().set_sensitive(true)
end
hypo.set_window_position Gtk::WindowPosition::CENTER
css_file = Gtk::CssProvider.new
css_file.load(data: <<-CSS)
button {
all:unset;
}
button:hover {
opacity: .6;
}
.bg-hypo {
background-color: #F8DDD7;
}
CSS
# #Reglage du bouton Undo
boutonUndo = builder.get_object('btnUndo')
# #Reglage du bouton Redo
boutonRedo = builder.get_object('btnRedo')
# #Initialisation de la grille
# # Copie des noeuds contenus dans la grille
copy_grille = plateau.grid.collect(&:dup)
# # Création d'une nouvelle grille
@hypoGrille = HashiGrid.new(plateau.grid.nomniv,plateau.grid.diff, plateau.grid.lignes, plateau.grid.colonnes)
@hypoGrille.set_column_homogeneous(true)
@hypoGrille.set_row_homogeneous(true)
@hypoGrille.colonnes = plateau.grid.colonnes
@hypoGrille.lignes = plateau.grid.lignes
@hypoGrille.sommets = plateau.grid.sommets
# # On parcourt le tableau des iles/ponts copiés
copy_grille.each do |x|
# Si c'est une ile
# On copie les attributs de l'ile
if x.status != 'p'
btn = Ile.new(@hypoGrille,x.degreeMax.to_s,x.column,x.row)
btn.degree = x.degree
btn.estComplet = x.estComplet
btn.northEdge = x.northEdge
btn.southEdge = x.southEdge
btn.westEdge = x.westEdge
btn.eastEdge = x.eastEdge
btn.update
else
# Si c'est un pont on copie les attributs
# et on met à jour le pont
btn = Pont.new(@hypoGrille,x.column,x.row)
btn.set_typePont( x.get_typePont )
btn.estDouble = x.estDouble
btn.set_directionPont ( x.get_directionPont )
btn.update
end
# On attache la référence de la grille
@hypoGrille.attach(btn, x.column,x.row, 1,1)
end
# # Chargement des voisins
@hypoGrille.chargeVoisins
boxJeu = builder.get_object('boxJeu')
boxJeu.add(@hypoGrille)
#Creation et affichage de la fenêtre principale
boxPrincipale = builder.get_object('boxPrincipale')
aide = Aide.new(@hypoGrille)
label_aide = builder.get_object('label_indice')
boutonIndice = builder.get_object('btnIndice')
boutonIndice.signal_connect('clicked'){
label_aide.set_label(aide.getMessageAide)
boxPrincipale.show_all
}
btnValider = builder.get_object('btnValider')
btnValider.signal_connect('clicked'){
boxJeu.remove(@hypoGrille)
plateau.hypotheseValider(@hypoGrille)
hypo.destroy
$window.getPlateau().set_sensitive(true)
}
btnAnnuler = builder.get_object('btnAnnuler')
btnAnnuler.signal_connect('clicked'){
hypo.destroy
$window.getPlateau().set_sensitive(true)
}
boutonUndo.signal_connect('clicked'){
@hypoGrille.undoPrevious
}
boutonRedo.signal_connect('clicked'){
@hypoGrille.redoPrevious
}
btnAnnuler.style_context.add_provider(css_file, Gtk::StyleProvider::PRIORITY_USER)
btnValider.style_context.add_provider(css_file, Gtk::StyleProvider::PRIORITY_USER)
boutonUndo.style_context.add_provider(css_file, Gtk::StyleProvider::PRIORITY_USER)
boutonIndice.style_context.add_provider(css_file, Gtk::StyleProvider::PRIORITY_USER)
boutonRedo.style_context.add_provider(css_file, Gtk::StyleProvider::PRIORITY_USER)
hypo.style_context.add_provider(css_file, Gtk::StyleProvider::PRIORITY_USER)
hypo.show_all
end
end