Class: Menu

Inherits:
Gtk::Box
  • Object
show all
Defined in:
lib/Hashiparmentier/UI/Menu.rb

Constant Summary collapse

@@mode =
1
@@taille =
7
@@difficulte =
0

Instance Method Summary collapse

Constructor Details

#initializeMenu

Returns a new instance of Menu.



34
35
36
37
38
39
# File 'lib/Hashiparmentier/UI/Menu.rb', line 34

def initialize()
		super(:vertical, 0)
		@builder = Gtk::Builder.new
		#@racine = racine
		self.afficheDemarrage()
end

Instance Method Details

#afficheDemarrageObject



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
# File 'lib/Hashiparmentier/UI/Menu.rb', line 41

def afficheDemarrage()
		if(@window != nil) then
			@window.destroy()
		end
		@builder.add_from_file("lib/Hashiparmentier/glade/menu.glade")

    # --- GET_OBJECT
        # --- WINDOWS ---
			@window = @builder.get_object("windowMenu")

        # --- BTN ---
			@btnQuitter = @builder.get_object("btnQuitter")
        @btnJouer = @builder.get_object("btnJouer")
        @btnAide = @builder.get_object("btnAide")
        @btnRegles = @builder.get_object("btnRegles")
        @btnAstuces = @builder.get_object("btnAstuces")

        # --- TGL ---
        @tglMNormal = @builder.get_object("tglNormal")
        @tglAventure = @builder.get_object("tglAventure")
        @tgl77 = @builder.get_object("tgl77")
        @tgl1010 = @builder.get_object("tgl1010")
        @tgl1515 = @builder.get_object("tgl1515")
        @tglFacile = @builder.get_object("tglFacile")
        @tglNormal = @builder.get_object("tglNorma")
			@tglDiff = @builder.get_object("tglDifficile")

			# -- LABEL
			@lbTaille = @builder.get_object("lbTaille")
			@lbTaille.style_context.add_provider(@@CSS_LABEL_MENU, Gtk::StyleProvider::PRIORITY_USER)
			@lbDiff = @builder.get_object("lbDiff")
			@lbDiff.style_context.add_provider(@@CSS_LABEL_MENU, Gtk::StyleProvider::PRIORITY_USER)
			@lbTaille = @builder.get_object("lbTaille")
			@lbTaille.style_context.add_provider(@@CSS_LABEL_MENU, Gtk::StyleProvider::PRIORITY_USER)
			@lbPseudo = @builder.get_object("lbPseudo")
			@lbPseudo.style_context.add_provider(@@CSS_LABEL_MENU, Gtk::StyleProvider::PRIORITY_USER)

			@btnQuitter.style_context.add_provider(@@CSS_BTN_BOTMENU, Gtk::StyleProvider::PRIORITY_USER)
			@btnJouer.style_context.add_provider(@@CSS_BTN_BOTMENU, Gtk::StyleProvider::PRIORITY_USER)

        @btnAide.style_context.add_provider(@@CSS_BTN_TOPMENU, Gtk::StyleProvider::PRIORITY_USER)
        @btnRegles.style_context.add_provider(@@CSS_BTN_TOPMENU, Gtk::StyleProvider::PRIORITY_USER)
        @btnAstuces.style_context.add_provider(@@CSS_BTN_TOPMENU, Gtk::StyleProvider::PRIORITY_USER)


		# --- ENTRY
			@pseudo = @builder.get_object("entryPseudo")

		# --- CSS
		@window.style_context.add_provider(@@CSS_BG_MENU, Gtk::StyleProvider::PRIORITY_USER)
		@tglMNormal.style_context.add_provider(@@CSS_BUTTON_ACTIVE, Gtk::StyleProvider::PRIORITY_USER)
		@tglAventure.style_context.add_provider(@@CSS_BUTTON_ACTIVE, Gtk::StyleProvider::PRIORITY_USER)
    @tgl77.style_context.add_provider(@@CSS_BUTTON_ACTIVE, Gtk::StyleProvider::PRIORITY_USER)
    @tgl1010.style_context.add_provider(@@CSS_BUTTON_ACTIVE, Gtk::StyleProvider::PRIORITY_USER)
    @tgl1515.style_context.add_provider(@@CSS_BUTTON_ACTIVE, Gtk::StyleProvider::PRIORITY_USER)
    @tglFacile.style_context.add_provider(@@CSS_BUTTON_ACTIVE, Gtk::StyleProvider::PRIORITY_USER)
    @tglNormal.style_context.add_provider(@@CSS_BUTTON_ACTIVE, Gtk::StyleProvider::PRIORITY_USER)
		@tglDiff.style_context.add_provider(@@CSS_BUTTON_ACTIVE, Gtk::StyleProvider::PRIORITY_USER)
    # --- SIGNAUX ---
        # --- WINDOWS ---
        @window.signal_connect('destroy') { |_widget| Gtk.main_quit }

        # --- BTN ---
        @btnQuitter.signal_connect('clicked') { |_widget| Gtk.main_quit }
        @btnJouer.signal_connect('clicked') { |_widget| valide() }
        @btnAide.signal_connect('clicked') { |_widget| AfficherAide() }
        @btnRegles.signal_connect('clicked') { |_widget| AfficherRegles()  }
  @btnAstuces.signal_connect('clicked') { |_widget| AfficherAstuces() }

    @window.show()
    # Appel de la gestion des signaux
    self.gestionTgl()
		Gtk.main()
end

#afficheLabel(label) ⇒ Object



307
308
309
310
311
312
313
# File 'lib/Hashiparmentier/UI/Menu.rb', line 307

def afficheLabel(label)

	pack_start(@label = Gtk::Label.new(label), :expand => true, :fill => true)

	show_all

end

#AfficherAideObject



247
248
249
# File 'lib/Hashiparmentier/UI/Menu.rb', line 247

def AfficherAide()
	@aide = AideUI.new()
end

#AfficherAstucesObject



255
256
257
# File 'lib/Hashiparmentier/UI/Menu.rb', line 255

def AfficherAstuces()
	@astuces = AstucesUI.new()
end

#afficheReglesObject



315
316
317
# File 'lib/Hashiparmentier/UI/Menu.rb', line 315

def afficheRegles
	@fenetreRegles.show_all
end

#AfficherReglesObject



251
252
253
# File 'lib/Hashiparmentier/UI/Menu.rb', line 251

def AfficherRegles()
	@regles = ReglesUI.new()
end

#commencerPartie(grille, nomCompte) ⇒ Object



265
266
267
268
269
# File 'lib/Hashiparmentier/UI/Menu.rb', line 265

def commencerPartie(grille,nomCompte)
	@fenetreScroll.hide
	@jeu = FenetreJeuUI.new(@@mode, grille,nomCompte,@window,@fenetreScroll)
	Gtk.main_quit
end

#gestionTglObject



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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/Hashiparmentier/UI/Menu.rb', line 116

def gestionTgl()
       #Gestion des paramètres selon [Mode], [Taille] et [Difficulté]

	#1-Mode de jeu : Normal OU Aventure
	@tglMNormal.signal_connect('toggled') {

		if (@@mode != 1) && @tglAventure.active?
			@tglAventure.active = false;
			@tglMNormal.active = true;
			@@mode = 1;
			#puts "Mode : Normal - #{@@mode}";
		else if !(@tglMNormal.active?) && !(@tglAventure.active?)
			@tglMNormal.active = true;
			@@mode = 1;
			#puts "Mode : Normal - #{@@mode}";
			end
		end
	}

	@tglAventure.signal_connect('toggled') {

		if (@@mode != 2) && @tglMNormal.active?
			@tglMNormal.active = false;
			@tglAventure.active = true;
			@@mode = 2;
			#puts "Mode : Aventure - #{@@mode}";
		else if !(@tglAventure.active?) && !(@tglMNormal.active?)
			@tglAventure.active = true;
			@@mode = 2;
			#puts "Mode : Aventure - #{@@mode}";
			end
		end
       }

       #2-Taille de grille : 7*7, 10*10 OU 15*15
	@tgl77.signal_connect('toggled') {

		if (@@taille != 7)  && (@tgl1010.active? || @tgl1515.active?)
			@tgl1010.active = false;
			@tgl1515.active = false;
			@tgl77.active = true;
			@@taille = 7;
			#puts "Taille grille : 7*7 - #{@@taille}";
		else if !(@tgl77.active?) && !(@tgl1010.active?) && !(@tgl1515.active?)
				@tgl77.active = true;
				@@taille = 7;
				#puts "Taille grille : 7*7 - #{@@taille}";
			end
		end
	}

	@tgl1010.signal_connect('toggled') {

		if (@@taille != 10) && (@tgl77.active? || @tgl1515.active?)
			@tgl77.active = false;
			@tgl1515.active = false;
			@tgl1010.active = true;
			@@taille = 10;
			#puts "Taille grille : 10*10 - #{@@taille}";
		else if !(@tgl1010.active?) && !(@tgl77.active?) && !(@tgl1515.active?)
				@tgl1010.active = true;
				@@taille = 10;
				#puts "Taille grille : 10*10 - #{@@taille}";
			end
		end
	}

	@tgl1515.signal_connect('toggled') {

		if (@@taille != 15) && (@tgl77.active? || @tgl1010.active?)
			@tgl77.active = false;
			@tgl1010.active = false;
			@tgl1515.active = true;
			@@taille = 15;
			#puts "Taille grille : 15*15 - #{@@taille}";
		else if !(@tgl1515.active?) && !(@tgl77.active?) && !(@tgl1010.active?)
				@tgl1515.active = true;
				@@taille = 15;
				#puts "Taille grille : 15*15 - #{@@taille}";
			end
		end
	}

	#3-Difficulté de la grille : Facile, Normal OU Difficile
	@tglFacile.signal_connect('toggled'){

		if (@@difficulte != 0) && (@tglNormal.active? || @tglDiff.active?)
			@tglNormal.active = false;
			@tglDiff.active = false;
			@tglFacile.active = true;
			@@difficulte = 0;
			#puts "Difficultée : Facile - #{@@difficulte}";
		else if !(@tglFacile.active?) && !(@tglNormal.active?) && !(@tglDiff.active?)
				@tglFacile.active = true;
				@@difficulte = 0;
				#puts "Difficultée : Facile - #{@@difficulte}";
			end
		end
	}

	@tglNormal.signal_connect('toggled'){
		if (@@difficulte != 1) && (@tglFacile.active? || @tglDiff.active?)
			@tglDiff.active = false;
			@tglFacile.active = false;
			@tglNormal.active = true;
			@@difficulte = 1;
			#puts "Difficultée : Normale - #{@@difficulte}";
		else if !(@tglNormal.active?) && !(@tglFacile.active?) && !(@tglDiff.active?)
				@tglNormal.active = true;
				@@difficulte = 1;
				#puts "Difficultée : Normale - #{@@difficulte}";
			end
		end
	}

	@tglDiff.signal_connect('toggled'){
		if (@@difficulte != 2) && (@tglFacile.active? || @tglNormal.active?)
			@tglFacile.active = false;
			@tglNormal.active = false;
			@tglDiff.active = true;
			@@difficulte = 2;
			#puts "Difficultée : Difficile - #{@@difficulte}";
		else if !(@tglDiff.active?) && !(@tglFacile.active?) && !(@tglNormal.active?)
				@tglDiff.active = true;
				@@difficulte = 2;
				#puts "Difficultée : Difficile - #{@@difficulte}";
			end
		end
	}
end

#removeChild(fenetre) ⇒ Object



259
260
261
262
263
# File 'lib/Hashiparmentier/UI/Menu.rb', line 259

def removeChild(fenetre)
	fenetre.each_all do |c|
	  remove(c)
	end
end

#retourMenuObject



271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/Hashiparmentier/UI/Menu.rb', line 271

def retourMenu()

	each_all do |c|
	  remove(c)
	end

	pack_start(@titre, :expand => true, :fill => true)
	pack_start(@choixNom, :expand => true, :fill => true)
	pack_start(@choixTaille, :expand => true, :fill => true)
	pack_start(@choixDifficulte, :expand => true, :fill => true)
	pack_start(@surBoxValide, :expand => true, :fill => true)

end