104 |
bool handle_keydown (const SDL_Event *e); |
bool handle_keydown (const SDL_Event *e); |
105 |
bool handle_mousedown (const SDL_Event *e); |
bool handle_mousedown (const SDL_Event *e); |
106 |
|
|
107 |
// Variables. |
/* |
108 |
|
** Variables. |
109 |
|
*/ |
110 |
ImageCache cache; |
ImageCache cache; |
111 |
LevelPack *level_pack; // The level pack |
LevelPack *level_pack; // The current level pack |
112 |
|
|
113 |
int ifirst; // Index of "upper left" level |
int ifirst; // Index of "upper left" level |
114 |
int iselected; // Index of selected level |
int iselected; // Index of selected level |
149 |
void set_levelpack (unsigned index); |
void set_levelpack (unsigned index); |
150 |
|
|
151 |
// Menu interface. |
// Menu interface. |
152 |
|
void tick (double time); |
153 |
void draw_background(px::GC &gc); |
void draw_background(px::GC &gc); |
154 |
|
|
155 |
// Widget interface. |
// Widget interface. |
642 |
class FullscreenButton : public TextButton { |
class FullscreenButton : public TextButton { |
643 |
// ActionListener interface. |
// ActionListener interface. |
644 |
void on_action(Widget *) { |
void on_action(Widget *) { |
645 |
|
bool old = FullScreen; |
646 |
FullScreen = video::ToggleFullscreen(); |
FullScreen = video::ToggleFullscreen(); |
647 |
update(); |
if (old != FullScreen) |
648 |
|
update(); |
649 |
|
else |
650 |
|
options::MustRestart = true; |
651 |
} |
} |
652 |
public: |
public: |
653 |
FullscreenButton() : TextButton("", this) { update(); } |
FullscreenButton() : TextButton("", this) { update(); } |
847 |
int mode = get_mode() + 1; |
int mode = get_mode() + 1; |
848 |
if (mode >= video::VM_COUNT) mode = 0; |
if (mode >= video::VM_COUNT) mode = 0; |
849 |
options::VideoMode = mode; |
options::VideoMode = mode; |
850 |
|
options::MustRestart = true; |
851 |
update(); |
update(); |
852 |
} |
} |
853 |
public: |
public: |
909 |
// Options menu |
// Options menu |
910 |
//---------------------------------------------------------------------- |
//---------------------------------------------------------------------- |
911 |
OptionsMenu::OptionsMenu() |
OptionsMenu::OptionsMenu() |
912 |
: back(new TextButton("Back", this)) |
: back(new TextButton("Back", this)), |
913 |
, fullscreen(new FullscreenButton) |
fullscreen(new FullscreenButton), |
914 |
|
m_restartinfo (new Label("")) |
915 |
{ |
{ |
916 |
const int spacing = 5; |
const int spacing = 5; |
917 |
const int big_spacing = 60; |
const int big_spacing = 60; |
921 |
BuildVList left (this, Rect(0, 0, but_width, but_height), spacing); |
BuildVList left (this, Rect(0, 0, but_width, but_height), spacing); |
922 |
BuildVList right(this, Rect(but_width+big_spacing, 0, but_width, but_height), spacing); |
BuildVList right(this, Rect(but_width+big_spacing, 0, but_width, but_height), spacing); |
923 |
|
|
924 |
left.add(fullscreen); |
left.add (fullscreen); |
925 |
left.add (new MouseSpeedButton); |
left.add (new MouseSpeedButton); |
926 |
left.add (new SkipSolvedButton); |
left.add (new SkipSolvedButton); |
927 |
left.add (new DifficultyButton); |
left.add (new DifficultyButton); |
937 |
Rect l = left.pos(); |
Rect l = left.pos(); |
938 |
Rect r = right.pos(); |
Rect r = right.pos(); |
939 |
|
|
940 |
|
add (m_restartinfo, Rect (l.x, l.y + 15, 400, 20)); |
941 |
|
m_restartinfo->set_alignment (HALIGN_LEFT); |
942 |
|
update_info(); |
943 |
|
|
944 |
l.x = (l.x+r.x)/2; |
l.x = (l.x+r.x)/2; |
945 |
l.y = Max(l.y, r.y)+big_spacing; |
l.y = Max(l.y, r.y)+big_spacing; |
946 |
|
|
948 |
} |
} |
949 |
} |
} |
950 |
|
|
951 |
bool |
void OptionsMenu::update_info() |
|
OptionsMenu::on_event (const SDL_Event &e) |
|
952 |
{ |
{ |
953 |
|
if (options::MustRestart) |
954 |
|
m_restartinfo->set_text ("Please restart Enigma to activate your changes!"); |
955 |
|
else |
956 |
|
m_restartinfo->set_text (""); |
957 |
|
} |
958 |
|
|
959 |
|
bool OptionsMenu::on_event (const SDL_Event &e) |
960 |
|
{ |
961 |
|
bool handled=false; |
962 |
if (e.type == SDL_MOUSEBUTTONDOWN |
if (e.type == SDL_MOUSEBUTTONDOWN |
963 |
&& e.button.button == SDL_BUTTON_RIGHT) |
&& e.button.button == SDL_BUTTON_RIGHT) |
964 |
{ |
{ |
965 |
Menu::quit(); |
Menu::quit(); |
966 |
return true; |
handled = true; |
967 |
} |
} |
968 |
else if (e.type == SDL_KEYDOWN) { |
else if (e.type == SDL_KEYDOWN) { |
969 |
if ((e.key.keysym.sym==SDLK_RETURN) && |
if ((e.key.keysym.sym==SDLK_RETURN) && |
971 |
{ |
{ |
972 |
// update state of FullscreenButton : |
// update state of FullscreenButton : |
973 |
dynamic_cast<FullscreenButton*>(fullscreen)->update(); |
dynamic_cast<FullscreenButton*>(fullscreen)->update(); |
974 |
return true; |
handled = true; |
975 |
} |
} |
|
|
|
976 |
} |
} |
977 |
|
return handled; |
|
return false; |
|
978 |
} |
} |
979 |
|
|
980 |
void OptionsMenu::on_action(Widget *w) |
void OptionsMenu::on_action(Widget *w) |
983 |
Menu::quit(); |
Menu::quit(); |
984 |
} |
} |
985 |
|
|
986 |
|
void OptionsMenu::tick (double) |
987 |
|
{ |
988 |
|
update_info(); |
989 |
|
} |
990 |
|
|
991 |
void OptionsMenu::draw_background(px::GC &gc) |
void OptionsMenu::draw_background(px::GC &gc) |
992 |
{ |
{ |
993 |
video::SetCaption("Enigma - Options Menu"); |
video::SetCaption("Enigma - Options Menu"); |
1061 |
levelwidget->set_listener(this); |
levelwidget->set_listener(this); |
1062 |
|
|
1063 |
set_position(pos); |
set_position(pos); |
1064 |
|
} |
1065 |
|
|
1066 |
|
void LevelMenu::tick(double) |
1067 |
|
{ |
1068 |
update_info(); |
update_info(); |
1069 |
} |
} |
1070 |
|
|
1084 |
else |
else |
1085 |
handled = Menu::on_event (e); |
handled = Menu::on_event (e); |
1086 |
} |
} |
|
else |
|
|
update_info(); |
|
1087 |
return handled; |
return handled; |
1088 |
} |
} |
1089 |
|
|
1114 |
else if (w == m_nextlp) { |
else if (w == m_nextlp) { |
1115 |
set_levelpack (m_ilevelpack+1); |
set_levelpack (m_ilevelpack+1); |
1116 |
} |
} |
|
update_info(); |
|
1117 |
} |
} |
1118 |
|
|
1119 |
void |
void |