about summary refs log tree commit diff stats
path: root/LICENSE
diff options
context:
space:
mode:
Diffstat (limited to 'LICENSE')
0 files changed, 0 insertions, 0 deletions
or Star Rauchenberger <fefferburbia@gmail.com> 2021-03-13 07:45:55 -0500 committer Star Rauchenberger <fefferburbia@gmail.com> 2021-03-13 15:34:50 -0500 Added pause menu opening and closing animation' href='/tanetane/commit/src/menu_system.cpp?id=764efea5a38b970fa57d8c0197673276023b58aa'>764efea ^
fce3740 ^
764efea ^

c6b5e93 ^
764efea ^


f839e07 ^
fce3740 ^














f839e07 ^
fce3740 ^


f839e07 ^
fce3740 ^

f839e07 ^

764efea ^







7270918 ^
37bbad7 ^
fce3740 ^


8a7d87a ^
9107e9e ^








8a7d87a ^
02c991e ^




fce3740 ^






7270918 ^
f9dd0fb ^

10c92d7 ^

f9dd0fb ^



37bbad7 ^




10c92d7 ^
37bbad7 ^



fce3740 ^
10c92d7 ^
c6b5e93 ^
10c92d7 ^
764efea ^

10c92d7 ^
fce3740 ^









10c92d7 ^
fce3740 ^


10c92d7 ^
764efea ^
2581f03 ^

fce3740 ^
7b0ac7f ^




2581f03 ^


fce3740 ^
7b0ac7f ^




2581f03 ^
f9dd0fb ^
8a7d87a ^






9107e9e ^



8a7d87a ^










9107e9e ^



8a7d87a ^



f9dd0fb ^
fce3740 ^




10c92d7 ^

f9dd0fb ^
fce3740 ^

10c92d7 ^
f9dd0fb ^

fce3740 ^





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
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

                        
                          


                                  
                                



                                                                           
                     

                              
                                       


                                                      
                                             














                                      
         


                                                   
 

                                                      

       







                                    
 
                                       


                                                     
                                                           








                                                                                                                        
                                                           




                                                                                         






                                                                           
                                        

                                                                 

                                    



                                                      




                                                                         
                                                                                         



                                                                                                                     
                                
 
                                 
                                                         

 
                                               









                                                                 
 


                                                              
   
 

                              
                               




                                                             


                                
                                 




                                                             
 
 






                                                                       



                                          










                                                                                



                                          



                                                                 
                                   




                                                                             

                                                                 
 

                                         
     

   





                                            
#include "menu_system.h"
#include "game.h"
#include "script_system.h"

void MenuSystem::tick(double dt) {
  pauseAnimation_.tick(dt);
  menuChangeAnimation_.tick(dt);

  if (openState_ == OpenState::Animating && pauseAnimation_.isComplete()) {
    if (pauseAnimation_.getProgress() == 0.0) {
      openState_ = OpenState::Closed;
      menus_.clear();

      game_.unpauseGameplay();
      game_.getMixer().unpauseSounds();
    } else if (pauseAnimation_.getProgress() == 1.0) {
      openState_ = OpenState::Open;
    }
  } else if (openState_ == OpenState::Open) {
    if (!isMenuChanging_) {
      cursorBobTimer_.accumulate(dt);
      while (cursorBobTimer_.step()) {
        if (cursorBobDown_) {
          cursorBob_++;

          if (cursorBob_ >= 4) {
            cursorBobDown_ = false;
          }
        } else {
          cursorBob_--;

          if (cursorBob_ <= 0) {
            cursorBobDown_ = true;
          }
        }
      }
    } else if (menuChangeAnimation_.isComplete()) {
      isMenuChanging_ = false;

      if (menuChangeAnimation_.getProgress() == 0.0) {
        menus_.pop_back();
      }
    }
  }
}

void MenuSystem::openPauseMenu() {
  pauseAnimation_.start(125, 1.0);
  openState_ = OpenState::Animating;

  game_.pauseGameplay();

  std::vector<MenuBuilder> builders = {
    MenuBuilder().Command("Settings")
                 .ActivationFunction([this] (Game&) {
                   openSubmenu(Menu({
                     MenuBuilder().Slider("Music Volume: ")
                                  .InitialValue(game_.getMixer().isMusicMuted() ? 0 : game_.getMixer().getMusicVolume())
                                  .MaxValue(10)
                                  .SelectionChangedFunction([this] (MenuItem& menuItem) {
                                    if (game_.getMixer().isMusicMuted()) {
                                      menuItem.value = game_.getMixer().getMusicVolume();
                                    }

                                    game_.getMixer().setMusicVolume(menuItem.value);
                                  }),
                     MenuBuilder().Slider("Sound Volume: ")
                                  .InitialValue(game_.getMixer().getSoundVolume())
                                  .MaxValue(10)
                                  .SelectionChangedFunction([this] (MenuItem& menuItem) {
                                    game_.getMixer().setSoundVolume(menuItem.value);
                                  }),
                     MenuBuilder().Command("Back")
                                  .ActivationFunction([this] (Game& game) {
                                    closePauseMenu();
                                  })
                                  .SkipSoundEffect()
                   }));
                 }),
    MenuBuilder().Command("Resume Game")
                 .ActivationFunction([] (Game& game) {
                   game.getSystem<MenuSystem>().closePauseMenu();
                 })
                 .SkipSoundEffect(),
    MenuBuilder().Command("Quit")
                 .ActivationFunction([] (Game& game) {
                   game.quit();
                 })
  };

  if (game_.getMap().hasExitArea()) {
    builders.push_back(MenuBuilder().Command("Exit Area")
                                    .ActivationFunction([] (Game& game) {
                                      game.getSystem<MenuSystem>().closePauseMenu(false);
                                      game.getSystem<ScriptSystem>().runScript(game.getMap().getName(), "exit_area");
                                    }));
  }

  menus_.emplace_back(builders);

  game_.getMixer().pauseSounds();
  game_.getMixer().playSound("../res/sfx/menu_open.wav");
}

void MenuSystem::closePauseMenu(bool playSfx) {
  if (menus_.size() > 1) {
    isMenuChanging_ = true;
    menuChangeAnimation_.start(250, 0.0);

    if (playSfx) {
      game_.getMixer().playSound("../res/sfx/menu_deselect.wav");
    }
  } else {
    pauseAnimation_.start(125, 0.0);
    openState_ = OpenState::Animating;

    if (playSfx) {
      game_.getMixer().playSound("../res/sfx/menu_close.wav");
    }
  }
}

void MenuSystem::pressedUp() {
  menus_.back().moveCursorUp();

  cursorBob_ = 0;
  cursorBobDown_ = true;

  game_.getMixer().playSound("../res/sfx/vertical_menu.wav");
}

void MenuSystem::pressedDown() {
  menus_.back().moveCursorDown();

  cursorBob_ = 0;
  cursorBobDown_ = true;

  game_.getMixer().playSound("../res/sfx/vertical_menu.wav");
}

void MenuSystem::pressedLeft() {
  Menu& curMenu = menus_.back();
  MenuItem& menuItem = curMenu.getItems()[curMenu.getCursorPosition()];

  if (menuItem.type == MenuType::Slider && menuItem.value > 0) {
    menuItem.value--;

    if (menuItem.selectionChanged) {
      menuItem.selectionChanged(menuItem);
    }

    game_.getMixer().playSound("../res/sfx/horizontal_menu.wav");
  }
}

void MenuSystem::pressedRight() {
  Menu& curMenu = menus_.back();
  MenuItem& menuItem = curMenu.getItems()[curMenu.getCursorPosition()];

  if (menuItem.type == MenuType::Slider && menuItem.value < menuItem.maxValue) {
    menuItem.value++;

    if (menuItem.selectionChanged) {
      menuItem.selectionChanged(menuItem);
    }

    game_.getMixer().playSound("../res/sfx/horizontal_menu.wav");
  }
}

void MenuSystem::activateOption() {
  Menu& curMenu = menus_.back();
  const MenuItem& menuItem = curMenu.getItems()[curMenu.getCursorPosition()];

  if (menuItem.type == MenuType::Command) {
    if (menuItem.playSfx) {
      game_.getMixer().playSound("../res/sfx/menu_activate.wav");
    }

    if (menuItem.activationFunction) {
      menuItem.activationFunction(game_);
    }
  }
}

void MenuSystem::openSubmenu(Menu submenu) {
  menus_.push_back(std::move(submenu));
  isMenuChanging_ = true;
  menuChangeAnimation_.start(250, 1.0);
}