Mercurial > nagslang
comparison tools/area_editor.py @ 244:93a20b51963f
Merge
author | David Sharpe |
---|---|
date | Wed, 04 Sep 2013 22:26:15 +0200 |
parents | 261fd65a8816 |
children | 30137dc83a72 |
comparison
equal
deleted
inserted
replaced
243:46707efbb3a5 | 244:93a20b51963f |
---|---|
29 from albow.table_view import TableView, TableColumn | 29 from albow.table_view import TableView, TableColumn |
30 | 30 |
31 from nagslang.options import parse_args | 31 from nagslang.options import parse_args |
32 from nagslang.constants import SCREEN | 32 from nagslang.constants import SCREEN |
33 from nagslang.level import Level, POLY_COLORS, LINE_COLOR | 33 from nagslang.level import Level, POLY_COLORS, LINE_COLOR |
34 from nagslang.enemies import Enemy | 34 from nagslang.enemies import Enemy, get_editable_enemies |
35 | 35 from nagslang.game_object import get_editable_game_objects |
36 from nagslang.puzzle import get_editable_puzzlers | |
36 | 37 |
37 # layout constants | 38 # layout constants |
38 MENU_BUTTON_HEIGHT = 35 | 39 MENU_BUTTON_HEIGHT = 35 |
39 MENU_PAD = 6 | 40 MENU_PAD = 6 |
40 MENU_HALF_PAD = MENU_PAD // 2 | 41 MENU_HALF_PAD = MENU_PAD // 2 |
375 but = Button(text, action=lambda x=text: edit_box.dismiss(x)) | 376 but = Button(text, action=lambda x=text: edit_box.dismiss(x)) |
376 buttons.append(but) | 377 buttons.append(but) |
377 row = Row(buttons) | 378 row = Row(buttons) |
378 row.rect = pygame.rect.Rect(0, 450, 700, 50) | 379 row.rect = pygame.rect.Rect(0, 450, 700, 50) |
379 edit_box.add(row) | 380 edit_box.add(row) |
381 edit_box.get_selection = lambda: table.get_selection() | |
380 return edit_box | 382 return edit_box |
381 | 383 |
382 def edit_objects(self): | 384 def edit_objects(self): |
383 edit_box = self._make_edit_dialog(self.level._game_objects) | 385 edit_box = self._make_edit_dialog(self.level._game_objects) |
384 res = edit_box.present() | 386 res = edit_box.present() |
387 choice = edit_box.get_selection() | |
388 if choice is None: | |
389 return | |
385 if res == 'OK': | 390 if res == 'OK': |
386 # Edit object stuff goes here | 391 # Edit object stuff goes here |
387 pass | 392 pass |
388 elif res == 'Delete': | 393 elif res == 'Delete': |
389 pass | 394 pass |
390 | 395 |
391 def edit_enemies(self): | 396 def edit_enemies(self): |
392 edit_box = self._make_edit_dialog(self.level._enemies) | 397 edit_box = self._make_edit_dialog(self.level._enemies) |
393 res = edit_box.present() | 398 res = edit_box.present() |
399 choice = edit_box.get_selection() | |
400 if choice is None: | |
401 return | |
394 if res == 'OK': | 402 if res == 'OK': |
395 # Edit object stuff goes here | 403 # Edit object stuff goes here |
396 pass | 404 pass |
397 elif res == 'Delete': | 405 elif res == 'Delete': |
406 pass | |
407 | |
408 def _make_choice_dialog(self, classes): | |
409 # Dialog to hold the editor | |
410 data = [] | |
411 for cls_name, cls in classes: | |
412 data.append({"classname": cls_name, "class": cls}) | |
413 edit_box = Dialog() | |
414 edit_box.rect = pygame.rect.Rect(0, 0, 700, 500) | |
415 table = ObjectTable(data) | |
416 edit_box.add(table) | |
417 buttons = [] | |
418 for text in ['OK', 'Cancel']: | |
419 but = Button(text, action=lambda x=text: edit_box.dismiss(x)) | |
420 buttons.append(but) | |
421 row = Row(buttons) | |
422 row.rect = pygame.rect.Rect(0, 450, 700, 50) | |
423 edit_box.add(row) | |
424 edit_box.get_selection = lambda: table.get_selection() | |
425 return edit_box | |
426 | |
427 def add_game_object(self): | |
428 classes = get_editable_game_objects() | |
429 choose = self._make_choice_dialog(classes) | |
430 res = choose.present() | |
431 choice = choose.get_selection() | |
432 if res == 'OK' and choice is not None: | |
433 pass | |
434 | |
435 def add_enemy(self): | |
436 classes = get_editable_enemies() | |
437 choose = self._make_choice_dialog(classes) | |
438 res = choose.present() | |
439 choice = choose.get_selection() | |
440 if res == 'OK' and choice is not None: | |
441 pass | |
442 | |
443 def add_puzzler(self): | |
444 classes = get_editable_puzzlers() | |
445 choose = self._make_choice_dialog(classes) | |
446 res = choose.present() | |
447 choice = choose.get_selection() | |
448 if res == 'OK' and choice is not None: | |
398 pass | 449 pass |
399 | 450 |
400 | 451 |
401 class PolyButton(Button): | 452 class PolyButton(Button): |
402 """Button for coosing the correct polygon""" | 453 """Button for coosing the correct polygon""" |
463 fill_but.rect = BUTTON_RECT.copy() | 514 fill_but.rect = BUTTON_RECT.copy() |
464 fill_but.rect.move_ip(MENU_LEFT, y) | 515 fill_but.rect.move_ip(MENU_LEFT, y) |
465 widgets.append(fill_but) | 516 widgets.append(fill_but) |
466 y += MENU_BUTTON_HEIGHT + MENU_PAD | 517 y += MENU_BUTTON_HEIGHT + MENU_PAD |
467 | 518 |
468 save_but = Button('Save Level', action=self.save) | |
469 save_but.rect = BUTTON_RECT.copy() | |
470 save_but.rect.move_ip(MENU_LEFT, y) | |
471 widgets.append(save_but) | |
472 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
473 | |
474 close_poly_but = Button('Close Polygon', | 519 close_poly_but = Button('Close Polygon', |
475 action=self.level_widget.close_poly) | 520 action=self.level_widget.close_poly) |
476 close_poly_but.rect = BUTTON_RECT.copy() | 521 close_poly_but.rect = BUTTON_RECT.copy() |
477 close_poly_but.rect.move_ip(MENU_LEFT, y) | 522 close_poly_but.rect.move_ip(MENU_LEFT, y) |
478 widgets.append(close_poly_but) | 523 widgets.append(close_poly_but) |
495 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) | 540 label.rect.move_ip(MENU_LEFT + MENU_BUTTON_HEIGHT // 2 + MENU_PAD, y) |
496 widgets.append(self.show_enemies) | 541 widgets.append(self.show_enemies) |
497 widgets.append(label) | 542 widgets.append(label) |
498 y += label.rect.height + MENU_PAD | 543 y += label.rect.height + MENU_PAD |
499 | 544 |
545 y += MENU_PAD | |
500 switch_but = Button('Switch to Objects', action=self.switch_to_objects) | 546 switch_but = Button('Switch to Objects', action=self.switch_to_objects) |
501 switch_but.rect = BUTTON_RECT.copy() | 547 switch_but.rect = BUTTON_RECT.copy() |
502 switch_but.rect.move_ip(MENU_LEFT, y) | 548 switch_but.rect.move_ip(MENU_LEFT, y) |
503 widgets.append(switch_but) | 549 widgets.append(switch_but) |
504 y += switch_but.rect.height + MENU_PAD | 550 y += switch_but.rect.height + MENU_PAD |
505 | 551 |
552 save_but = Button('Save Level', action=self.save) | |
553 save_but.rect = BUTTON_RECT.copy() | |
554 save_but.rect.move_ip(MENU_LEFT, y) | |
555 widgets.append(save_but) | |
556 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
557 | |
558 y += MENU_PAD | |
506 quit_but = Button('Quit', action=self.quit) | 559 quit_but = Button('Quit', action=self.quit) |
507 quit_but.rect = BUTTON_RECT.copy() | 560 quit_but.rect = BUTTON_RECT.copy() |
508 quit_but.rect.move_ip(MENU_LEFT, y) | 561 quit_but.rect.move_ip(MENU_LEFT, y) |
509 widgets.append(quit_but) | 562 widgets.append(quit_but) |
510 | 563 |
528 edir_enemies_but.rect = BUTTON_RECT.copy() | 581 edir_enemies_but.rect = BUTTON_RECT.copy() |
529 edir_enemies_but.rect.move_ip(MENU_LEFT, y) | 582 edir_enemies_but.rect.move_ip(MENU_LEFT, y) |
530 widgets.append(edir_enemies_but) | 583 widgets.append(edir_enemies_but) |
531 y += MENU_BUTTON_HEIGHT + MENU_PAD | 584 y += MENU_BUTTON_HEIGHT + MENU_PAD |
532 | 585 |
533 save_but = Button('Save Level', action=self.save) | 586 add_obj_but = Button('Add Game Object', |
534 save_but.rect = BUTTON_RECT.copy() | 587 action=self.level_widget.add_game_object) |
535 save_but.rect.move_ip(MENU_LEFT, y) | 588 add_obj_but.rect = BUTTON_RECT.copy() |
536 widgets.append(save_but) | 589 add_obj_but.rect.move_ip(MENU_LEFT, y) |
537 y += MENU_BUTTON_HEIGHT + MENU_PAD | 590 widgets.append(add_obj_but) |
538 | 591 y += MENU_BUTTON_HEIGHT + MENU_PAD |
592 | |
593 add_puzzle_but = Button('Add Puzzler', | |
594 action=self.level_widget.add_puzzler) | |
595 add_puzzle_but.rect = BUTTON_RECT.copy() | |
596 add_puzzle_but.rect.move_ip(MENU_LEFT, y) | |
597 widgets.append(add_puzzle_but) | |
598 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
599 | |
600 add_enemy_but = Button('Add Enemy', | |
601 action=self.level_widget.add_enemy) | |
602 add_enemy_but.rect = BUTTON_RECT.copy() | |
603 add_enemy_but.rect.move_ip(MENU_LEFT, y) | |
604 widgets.append(add_enemy_but) | |
605 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
606 | |
607 y += MENU_PAD | |
539 switch_but = Button('Switch to Drawing', action=self.switch_to_draw) | 608 switch_but = Button('Switch to Drawing', action=self.switch_to_draw) |
540 switch_but.rect = BUTTON_RECT.copy() | 609 switch_but.rect = BUTTON_RECT.copy() |
541 switch_but.rect.move_ip(MENU_LEFT, y) | 610 switch_but.rect.move_ip(MENU_LEFT, y) |
542 widgets.append(switch_but) | 611 widgets.append(switch_but) |
543 y += switch_but.rect.height + MENU_PAD | 612 y += switch_but.rect.height + MENU_PAD |
544 | 613 |
614 save_but = Button('Save Level', action=self.save) | |
615 save_but.rect = BUTTON_RECT.copy() | |
616 save_but.rect.move_ip(MENU_LEFT, y) | |
617 widgets.append(save_but) | |
618 y += MENU_BUTTON_HEIGHT + MENU_PAD | |
619 | |
620 y += MENU_PAD | |
545 quit_but = Button('Quit', action=self.quit) | 621 quit_but = Button('Quit', action=self.quit) |
546 quit_but.rect = BUTTON_RECT.copy() | 622 quit_but.rect = BUTTON_RECT.copy() |
547 quit_but.rect.move_ip(MENU_LEFT, y) | 623 quit_but.rect.move_ip(MENU_LEFT, y) |
548 widgets.append(quit_but) | 624 widgets.append(quit_but) |
549 | 625 |