Mercurial > nagslang
comparison tools/area_editor.py @ 220:06c52529e2ed
Add placeholder object mode menu
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 04 Sep 2013 16:37:10 +0200 |
parents | 42c565c5ce76 |
children | 4197350b9897 |
comparison
equal
deleted
inserted
replaced
219:f9e92d540bfa | 220:06c52529e2ed |
---|---|
36 MENU_BUTTON_HEIGHT = 35 | 36 MENU_BUTTON_HEIGHT = 35 |
37 MENU_PAD = 6 | 37 MENU_PAD = 6 |
38 MENU_HALF_PAD = MENU_PAD // 2 | 38 MENU_HALF_PAD = MENU_PAD // 2 |
39 MENU_LEFT = SCREEN[0] + MENU_HALF_PAD | 39 MENU_LEFT = SCREEN[0] + MENU_HALF_PAD |
40 MENU_WIDTH = 200 - MENU_PAD | 40 MENU_WIDTH = 200 - MENU_PAD |
41 | |
42 BUTTON_RECT = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) | |
43 CHECK_RECT = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2, | |
44 MENU_BUTTON_HEIGHT // 2) | |
41 | 45 |
42 | 46 |
43 class EditorLevel(Level): | 47 class EditorLevel(Level): |
44 | 48 |
45 def __init__(self, name, x=800, y=600): | 49 def __init__(self, name, x=800, y=600): |
351 super(EditorApp, self).__init__(surface) | 355 super(EditorApp, self).__init__(surface) |
352 self.level = level | 356 self.level = level |
353 self.level_widget = LevelWidget(self.level) | 357 self.level_widget = LevelWidget(self.level) |
354 self.add(self.level_widget) | 358 self.add(self.level_widget) |
355 | 359 |
360 self._dMenus = {} | |
361 | |
362 self._make_draw_menu() | |
363 self._make_objects_menu() | |
364 | |
365 self._menu_mode = 'drawing' | |
366 self._populate_menu() | |
367 | |
368 def _make_draw_menu(self): | |
369 widgets = [] | |
370 | |
356 # Add poly buttons | 371 # Add poly buttons |
357 y = 15 | 372 y = 15 |
358 for poly in range(1, 7): | 373 for poly in range(1, 7): |
359 but = PolyButton(poly, self.level_widget) | 374 but = PolyButton(poly, self.level_widget) |
360 but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH // 2 - MENU_PAD, | 375 but.rect = pygame.rect.Rect(0, 0, MENU_WIDTH // 2 - MENU_PAD, |
363 but.rect.move_ip(MENU_LEFT, y) | 378 but.rect.move_ip(MENU_LEFT, y) |
364 else: | 379 else: |
365 but.rect.move_ip(MENU_LEFT + MENU_WIDTH // 2 - MENU_HALF_PAD, | 380 but.rect.move_ip(MENU_LEFT + MENU_WIDTH // 2 - MENU_HALF_PAD, |
366 y) | 381 y) |
367 y += MENU_BUTTON_HEIGHT + MENU_PAD | 382 y += MENU_BUTTON_HEIGHT + MENU_PAD |
368 self.add(but) | 383 widgets.append(but) |
369 | |
370 button_rect = pygame.rect.Rect(0, 0, MENU_WIDTH, MENU_BUTTON_HEIGHT) | |
371 | |
372 check_rect = pygame.rect.Rect(0, 0, MENU_BUTTON_HEIGHT // 2, | |
373 MENU_BUTTON_HEIGHT // 2) | |
374 | 384 |
375 end_poly_but = PolyButton(None, self.level_widget) | 385 end_poly_but = PolyButton(None, self.level_widget) |
376 end_poly_but.rect = button_rect.copy() | 386 end_poly_but.rect = BUTTON_RECT.copy() |
377 end_poly_but.rect.move_ip(MENU_LEFT, y) | 387 end_poly_but.rect.move_ip(MENU_LEFT, y) |
378 self.add(end_poly_but) | 388 widgets.append(end_poly_but) |
379 y += MENU_BUTTON_HEIGHT + MENU_PAD | 389 y += MENU_BUTTON_HEIGHT + MENU_PAD |
380 | 390 |
381 draw_line = Button("Draw interior wall", self.level_widget.line_mode) | 391 draw_line = Button("Draw interior wall", self.level_widget.line_mode) |
382 draw_line.rect = button_rect.copy() | 392 draw_line.rect = BUTTON_RECT.copy() |
383 draw_line.rect.move_ip(MENU_LEFT, y) | 393 draw_line.rect.move_ip(MENU_LEFT, y) |
384 self.add(draw_line) | 394 widgets.append(draw_line) |
385 y += MENU_BUTTON_HEIGHT + MENU_PAD | 395 y += MENU_BUTTON_HEIGHT + MENU_PAD |
386 | 396 |
387 fill_but = Button('Fill exterior', action=self.level_widget.set_filled) | 397 fill_but = Button('Fill exterior', action=self.level_widget.set_filled) |
388 fill_but.rect = button_rect.copy() | 398 fill_but.rect = BUTTON_RECT.copy() |
389 fill_but.rect.move_ip(MENU_LEFT, y) | 399 fill_but.rect.move_ip(MENU_LEFT, y) |
390 self.add(fill_but) | 400 widgets.append(fill_but) |
391 y += MENU_BUTTON_HEIGHT + MENU_PAD | 401 y += MENU_BUTTON_HEIGHT + MENU_PAD |
392 | 402 |
393 save_but = Button('Save Level', action=self.save) | 403 save_but = Button('Save Level', action=self.save) |
394 save_but.rect = button_rect.copy() | 404 save_but.rect = BUTTON_RECT.copy() |
395 save_but.rect.move_ip(MENU_LEFT, y) | 405 save_but.rect.move_ip(MENU_LEFT, y) |
396 self.add(save_but) | 406 widgets.append(save_but) |
397 y += MENU_BUTTON_HEIGHT + MENU_PAD | 407 y += MENU_BUTTON_HEIGHT + MENU_PAD |
398 | 408 |
399 close_poly_but = Button('Close Polygon', | 409 close_poly_but = Button('Close Polygon', |
400 action=self.level_widget.close_poly) | 410 action=self.level_widget.close_poly) |
401 close_poly_but.rect = button_rect.copy() | 411 close_poly_but.rect = BUTTON_RECT.copy() |
402 close_poly_but.rect.move_ip(MENU_LEFT, y) | 412 close_poly_but.rect.move_ip(MENU_LEFT, y) |
403 self.add(close_poly_but) | 413 widgets.append(close_poly_but) |
404 y += MENU_BUTTON_HEIGHT + MENU_PAD | 414 y += MENU_BUTTON_HEIGHT + MENU_PAD |
405 | 415 |
406 white = pygame.color.Color("white") | 416 white = pygame.color.Color("white") |
407 self.show_objs = CheckBox(fg_color=white) | 417 self.show_objs = CheckBox(fg_color=white) |
408 self.show_objs.rect = check_rect.copy() | 418 self.show_objs.rect = CHECK_RECT.copy() |
409 self.show_objs.rect.move_ip(MENU_LEFT, y) | 419 self.show_objs.rect.move_ip(MENU_LEFT, y) |
410 label = Label("Show Objects", fg_color=white) | 420 label = Label("Show Objects", fg_color=white) |
411 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) | 421 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) |
412 self.add(self.show_objs) | 422 widgets.append(self.show_objs) |
413 self.add(label) | 423 widgets.append(label) |
414 y += label.rect.height + MENU_PAD | 424 y += label.rect.height + MENU_PAD |
415 | 425 |
416 self.show_enemies = CheckBox(fg_color=white) | 426 self.show_enemies = CheckBox(fg_color=white) |
417 self.show_enemies.rect = check_rect.copy() | 427 self.show_enemies.rect = CHECK_RECT.copy() |
418 self.show_enemies.rect.move_ip(MENU_LEFT, y) | 428 self.show_enemies.rect.move_ip(MENU_LEFT, y) |
419 label = Label("Show enemy start pos", fg_color=white) | 429 label = Label("Show enemy start pos", fg_color=white) |
420 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) | 430 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) |
421 self.add(self.show_enemies) | 431 widgets.append(self.show_enemies) |
422 self.add(label) | 432 widgets.append(label) |
423 y += label.rect.height + MENU_PAD | 433 y += label.rect.height + MENU_PAD |
424 | 434 |
435 switch_but = Button('Switch to Objects', action=self.switch_to_objects) | |
436 switch_but.rect = BUTTON_RECT.copy() | |
437 switch_but.rect.move_ip(MENU_LEFT, y) | |
438 widgets.append(switch_but) | |
439 y += switch_but.rect.height + MENU_PAD | |
440 | |
425 quit_but = Button('Quit', action=self.quit) | 441 quit_but = Button('Quit', action=self.quit) |
426 quit_but.rect = button_rect.copy() | 442 quit_but.rect = BUTTON_RECT.copy() |
427 quit_but.rect.move_ip(MENU_LEFT, y) | 443 quit_but.rect.move_ip(MENU_LEFT, y) |
428 self.add(quit_but) | 444 widgets.append(quit_but) |
445 | |
446 self._dMenus['drawing'] = widgets | |
447 | |
448 def _make_objects_menu(self): | |
449 widgets = [] | |
450 | |
451 # Add poly buttons | |
452 y = 15 | |
453 | |
454 save_but = Button('Save Level', action=self.save) | |
455 save_but.rect = BUTTON_RECT.copy() | |
456 save_but.rect.move_ip(MENU_LEFT, y) | |
457 widgets.append(save_but) | |
458 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
459 | |
460 switch_but = Button('Switch to Drawing', action=self.switch_to_draw) | |
461 switch_but.rect = BUTTON_RECT.copy() | |
462 switch_but.rect.move_ip(MENU_LEFT, y) | |
463 widgets.append(switch_but) | |
464 y += switch_but.rect.height + MENU_PAD | |
465 | |
466 quit_but = Button('Quit', action=self.quit) | |
467 quit_but.rect = BUTTON_RECT.copy() | |
468 quit_but.rect.move_ip(MENU_LEFT, y) | |
469 widgets.append(quit_but) | |
470 | |
471 self._dMenus['objects'] = widgets | |
429 | 472 |
430 def key_down(self, ev): | 473 def key_down(self, ev): |
431 if ev.key == pgl.K_ESCAPE: | 474 if ev.key == pgl.K_ESCAPE: |
432 self.quit() | 475 self.quit() |
433 elif ev.key == pgl.K_s: | 476 elif ev.key == pgl.K_s: |
442 # display success | 485 # display success |
443 alert("Level %s saved successfully." % self.level.name) | 486 alert("Level %s saved successfully." % self.level.name) |
444 else: | 487 else: |
445 # display errors | 488 # display errors |
446 alert("Failed to save level.\n\n%s" % '\n'.join(messages)) | 489 alert("Failed to save level.\n\n%s" % '\n'.join(messages)) |
490 | |
491 def switch_to_draw(self): | |
492 if self._menu_mode != 'drawing': | |
493 self._clear_menu() | |
494 self._menu_mode = 'drawing' | |
495 self._populate_menu() | |
496 | |
497 def switch_to_objects(self): | |
498 if self._menu_mode != 'objects': | |
499 self._clear_menu() | |
500 self._menu_mode = 'objects' | |
501 self._populate_menu() | |
502 | |
503 def _clear_menu(self): | |
504 for widget in self._dMenus[self._menu_mode]: | |
505 self.remove(widget) | |
506 | |
507 def _populate_menu(self): | |
508 self.level_widget.change_poly(None) | |
509 for widget in self._dMenus[self._menu_mode]: | |
510 self.add(widget) | |
511 self.invalidate() | |
447 | 512 |
448 def mouse_move(self, ev): | 513 def mouse_move(self, ev): |
449 self.level_widget.mouse_move(ev) | 514 self.level_widget.mouse_move(ev) |
450 | 515 |
451 def draw(self, surface): | 516 def draw(self, surface): |