Debian Codegraph @

Examples/GUIStyle/MenuSystem/NS_Menu_Game.cpp

raw
1 // NS_Menu_Game.cpp: implementation of the NS_Menu_Game class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include "NS_Menu_Game.h"
6 #include <iostream>
7
8 #include "ClanLib/display.h"
9 #include "../ZZ_Theme/listbox_zz.h"
10
11 //////////////////////////////////////////////////////////////////////
12 // Construction/Destruction
13 //////////////////////////////////////////////////////////////////////
14
15 NS_Menu_Game::NS_Menu_Game(NS_MenuManager & menu_manager,
16 CL_StyleManager & style_manager,
17 std::string const & path_to_resource)
18 : NS_MenuGeneric(menu_manager, style_manager, path_to_resource),
19 back_ground(new CL_Sprite("menu_right_bottom", style_manager.get_resources()))
20 {
21 CL_Button * btn_to_main_menu = dynamic_cast<CL_Button*>(comp_manager->get_component(("btn_to_main_menu")));
22 if (btn_to_main_menu)
23 slots.connect(btn_to_main_menu->sig_clicked(), this, &NS_Menu_Game::on_switch_to_main_menu);
24
25 is_need_update = true;
26 }
27
28 NS_Menu_Game::~NS_Menu_Game()
29 {
30 delete back_ground;
31 }
32
33 void NS_Menu_Game::on_quit()
34 {
35 NS_MenuGeneric::quit();
36 }
37
38 void NS_Menu_Game::on_switch_to_main_menu()
39 {
40 switch_to("menu_main");
41 }
42
43 void NS_Menu_Game::switch_to(std::string const & menu_name)
44 {
45 is_need_update = true;
46 NS_MenuGeneric::switch_to(menu_name);
47 }
48
49 void NS_Menu_Game::on_begin_paint()
50 {
51 back_ground->draw(0,0);
52 }
53
54 //-----------------------------------------------------------------------------
55 void NS_Menu_Game::run_task()
56 {
57 if (is_need_update)
58 {
59 CL_ListBox * levels = dynamic_cast<CL_ListBox*>(comp_manager->get_component("lb_level"));
60 if (levels)
61 {
62 levels->clear();
63 levels->insert_item(new CL_ListBoxItem_ZZ("level 3", true), -1, true);
64 levels->insert_item(new CL_ListBoxItem_ZZ("level 5", false), -1, true);
65 levels->insert_item(new CL_ListBoxItem_ZZ("level 2", true), -1, true);
66 levels->insert_item(new CL_ListBoxItem_ZZ("level 4", false), -1, true);
67 levels->insert_item(new CL_ListBoxItem_ZZ("level 1", true), -1, true);
68 levels->insert_item(new CL_ListBoxItem_ZZ("level 6", false), -1, true);
69
70 levels->sort();
71 for(int i = 0; i < levels->get_count(); ++i)
72 {
73 CL_ListBoxItem_ZZ * level = (CL_ListBoxItem_ZZ *)levels->get_item(i);
74 if (level->get_solved() == false)
75 {
76 levels->set_current_item(i);
77 break;
78 }
79 }
80 }
81 is_need_update = false;
82 }
83 NS_MenuGeneric::run_task();
84 }