Another step in pulling the maingame and editor apart.
No functional or logic changes in this one.
This commit is contained in:
parent
8f9d9f735d
commit
b73cfc56e9
4 changed files with 219 additions and 218 deletions
|
@ -287,6 +287,7 @@ reduced_editor_sources = \
|
|||
marked-up_text.cpp \
|
||||
minimap.cpp \
|
||||
preferences.cpp \
|
||||
preferences_display.cpp \
|
||||
reports.cpp \
|
||||
sdl_utils.cpp \
|
||||
show_dialog.cpp \
|
||||
|
|
|
@ -684,11 +684,6 @@ std::set<t_translation::t_letter> &encountered_terrains() {
|
|||
return encountered_terrains_set;
|
||||
}
|
||||
|
||||
bool compare_resolutions(const std::pair<int,int>& lhs, const std::pair<int,int>& rhs)
|
||||
{
|
||||
return lhs.first*lhs.second < rhs.first*rhs.second;
|
||||
}
|
||||
|
||||
bool green_confirm()
|
||||
{
|
||||
std::string confirmation = preferences::get("confirm_end_turn");
|
||||
|
|
|
@ -1056,219 +1056,6 @@ void show_preferences_dialog(display& disp, const config& game_cfg)
|
|||
}
|
||||
}
|
||||
|
||||
bool show_video_mode_dialog(display& disp)
|
||||
{
|
||||
const events::resize_lock prevent_resizing;
|
||||
const events::event_context dialog_events_context;
|
||||
|
||||
CVideo& video = disp.video();
|
||||
|
||||
SDL_PixelFormat format = *video.getSurface()->format;
|
||||
format.BitsPerPixel = video.getBpp();
|
||||
|
||||
const SDL_Rect* const * modes = SDL_ListModes(&format,FULL_SCREEN);
|
||||
|
||||
//the SDL documentation says that a return value of -1 if all dimensions
|
||||
//are supported/possible.
|
||||
if(modes == reinterpret_cast<SDL_Rect**>(-1)) {
|
||||
std::cerr << "Can support any video mode\n";
|
||||
// SDL says that all modes are possible so it's OK to use a
|
||||
// hardcoded list here.
|
||||
static const SDL_Rect scr_modes[] = {
|
||||
{ 0, 0, 800, 600 },
|
||||
{ 0, 0, 1024, 768 },
|
||||
{ 0, 0, 1280, 960 },
|
||||
{ 0, 0, 1280, 1024 },
|
||||
};
|
||||
static const SDL_Rect * const scr_modes_list[] = {
|
||||
&scr_modes[0],
|
||||
&scr_modes[1],
|
||||
&scr_modes[2],
|
||||
&scr_modes[3],
|
||||
NULL
|
||||
};
|
||||
|
||||
modes = scr_modes_list;
|
||||
} else if(modes == NULL) {
|
||||
std::cerr << "No modes supported\n";
|
||||
gui::message_dialog(disp,"",_("There are no alternative video modes available")).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::pair<int,int> > resolutions;
|
||||
|
||||
for(int i = 0; modes[i] != NULL; ++i) {
|
||||
if(modes[i]->w >= min_allowed_width && modes[i]->h >= min_allowed_height) {
|
||||
resolutions.push_back(std::pair<int,int>(modes[i]->w,modes[i]->h));
|
||||
}
|
||||
}
|
||||
|
||||
const std::pair<int,int> current_res(video.getSurface()->w,video.getSurface()->h);
|
||||
resolutions.push_back(current_res);
|
||||
|
||||
std::sort(resolutions.begin(),resolutions.end(),compare_resolutions);
|
||||
resolutions.erase(std::unique(resolutions.begin(),resolutions.end()),resolutions.end());
|
||||
|
||||
std::vector<std::string> options;
|
||||
for(std::vector<std::pair<int,int> >::const_iterator j = resolutions.begin(); j != resolutions.end(); ++j) {
|
||||
std::ostringstream option;
|
||||
if (*j == current_res)
|
||||
option << DEFAULT_ITEM;
|
||||
|
||||
option << j->first << "x" << j->second;
|
||||
options.push_back(option.str());
|
||||
}
|
||||
|
||||
const int result = gui::show_dialog(disp,NULL,"",
|
||||
_("Choose Resolution"),
|
||||
gui::OK_CANCEL,&options);
|
||||
if(size_t(result) < resolutions.size() && resolutions[result] != current_res) {
|
||||
set_resolution(resolutions[result]);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void show_hotkeys_dialog (display & disp, config *save_config)
|
||||
{
|
||||
log_scope ("show_hotkeys_dialog");
|
||||
|
||||
const events::event_context dialog_events_context;
|
||||
|
||||
const int centerx = disp.w()/2;
|
||||
const int centery = disp.h()/2;
|
||||
#ifdef USE_TINY_GUI
|
||||
const int width = 300; // FIXME: should compute this, but using what data ?
|
||||
const int height = 220;
|
||||
#else
|
||||
const int width = 700;
|
||||
const int height = 500;
|
||||
#endif
|
||||
const int xpos = centerx - width/2;
|
||||
const int ypos = centery - height/2;
|
||||
|
||||
gui::button close_button (disp.video(), _("Close Window"));
|
||||
std::vector<gui::button*> buttons;
|
||||
buttons.push_back(&close_button);
|
||||
|
||||
gui::dialog_frame f(disp.video(),_("Hotkey Settings"),gui::dialog_frame::default_style,true,&buttons);
|
||||
f.layout(xpos,ypos,width,height);
|
||||
f.draw();
|
||||
|
||||
SDL_Rect clip_rect = { 0, 0, disp.w (), disp.h () };
|
||||
SDL_Rect text_size = font::draw_text(NULL, clip_rect, font::SIZE_PLUS,
|
||||
font::NORMAL_COLOUR,_("Press desired Hotkey"),
|
||||
0, 0);
|
||||
|
||||
std::vector<std::string> menu_items;
|
||||
|
||||
std::vector<hotkey::hotkey_item>& hotkeys = hotkey::get_hotkeys();
|
||||
for(std::vector<hotkey::hotkey_item>::iterator i = hotkeys.begin(); i != hotkeys.end(); ++i) {
|
||||
if(i->hidden())
|
||||
continue;
|
||||
std::stringstream str,name;
|
||||
name << i->get_description();
|
||||
str << name.str();
|
||||
str << COLUMN_SEPARATOR;
|
||||
str << i->get_name();
|
||||
menu_items.push_back(str.str());
|
||||
}
|
||||
|
||||
std::ostringstream heading;
|
||||
heading << HEADING_PREFIX << _("Action") << COLUMN_SEPARATOR << _("Binding");
|
||||
menu_items.push_back(heading.str());
|
||||
|
||||
gui::menu::basic_sorter sorter;
|
||||
sorter.set_alpha_sort(0).set_alpha_sort(1);
|
||||
|
||||
gui::menu menu_(disp.video(), menu_items, false, height, -1, &sorter, &gui::menu::bluebg_style);
|
||||
menu_.sort_by(0);
|
||||
menu_.reset_selection();
|
||||
menu_.set_width(font::relative_size(400));
|
||||
menu_.set_location(xpos + font::relative_size(20), ypos);
|
||||
|
||||
gui::button change_button (disp.video(), _("Change Hotkey"));
|
||||
change_button.set_location(xpos + width - change_button.width () - font::relative_size(30),ypos + font::relative_size(80));
|
||||
|
||||
gui::button save_button (disp.video(), _("Save Hotkeys"));
|
||||
save_button.set_location(xpos + width - save_button.width () - font::relative_size(30),ypos + font::relative_size(130));
|
||||
|
||||
for(;;) {
|
||||
|
||||
if (close_button.pressed())
|
||||
break;
|
||||
|
||||
if (change_button.pressed ()) {
|
||||
// Lets change this hotkey......
|
||||
SDL_Rect dlgr = {centerx-text_size.w/2 - 30,
|
||||
centery-text_size.h/2 - 16,
|
||||
text_size.w+60,
|
||||
text_size.h+32};
|
||||
surface_restorer restorer(&disp.video(),dlgr);
|
||||
gui::dialog_frame mini_frame(disp.video());
|
||||
mini_frame.layout(centerx-text_size.w/2 - 20,
|
||||
centery-text_size.h/2 - 6,
|
||||
text_size.w+40,
|
||||
text_size.h+12);
|
||||
mini_frame.draw_background();
|
||||
mini_frame.draw_border();
|
||||
font::draw_text (&disp.video(), clip_rect, font::SIZE_LARGE,font::NORMAL_COLOUR,
|
||||
_("Press desired Hotkey"),centerx-text_size.w/2-10,
|
||||
centery-text_size.h/2-3);
|
||||
disp.update_display();
|
||||
SDL_Event event;
|
||||
event.type = 0;
|
||||
int character=0,keycode=0; //just to avoid warning
|
||||
int mod=0;
|
||||
while (event.type!=SDL_KEYDOWN) SDL_PollEvent(&event);
|
||||
do {
|
||||
if (event.type==SDL_KEYDOWN)
|
||||
{
|
||||
keycode=event.key.keysym.sym;
|
||||
character=event.key.keysym.unicode;
|
||||
mod=event.key.keysym.mod;
|
||||
};
|
||||
SDL_PollEvent(&event);
|
||||
disp.flip();
|
||||
disp.delay(10);
|
||||
} while (event.type!=SDL_KEYUP);
|
||||
restorer.restore();
|
||||
disp.update_display();
|
||||
|
||||
const hotkey::hotkey_item& oldhk = hotkey::get_hotkey(character, keycode, (mod & KMOD_SHIFT) != 0,
|
||||
(mod & KMOD_CTRL) != 0, (mod & KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0);
|
||||
hotkey::hotkey_item& newhk = hotkey::get_visible_hotkey(menu_.selection());
|
||||
|
||||
if(oldhk.get_id() != newhk.get_id() && !oldhk.null()) {
|
||||
gui::message_dialog(disp,"",_("This Hotkey is already in use.")).show();
|
||||
} else {
|
||||
newhk.set_key(character, keycode, (mod & KMOD_SHIFT) != 0,
|
||||
(mod & KMOD_CTRL) != 0, (mod & KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0);
|
||||
|
||||
menu_.change_item(menu_.selection(), 1, newhk.get_name());
|
||||
};
|
||||
}
|
||||
if (save_button.pressed()) {
|
||||
if (save_config == NULL) {
|
||||
save_hotkeys();
|
||||
} else {
|
||||
hotkey::save_hotkeys(*save_config);
|
||||
}
|
||||
}
|
||||
|
||||
menu_.process();
|
||||
|
||||
events::pump();
|
||||
events::raise_process_event();
|
||||
events::raise_draw_event();
|
||||
|
||||
disp.update_display();
|
||||
|
||||
disp.delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
bool show_theme_dialog(display& disp)
|
||||
{
|
||||
int action = 0;
|
||||
|
|
|
@ -173,4 +173,222 @@ void set_colour_cursors(bool value)
|
|||
cursor::set();
|
||||
}
|
||||
|
||||
void show_hotkeys_dialog (display & disp, config *save_config)
|
||||
{
|
||||
log_scope ("show_hotkeys_dialog");
|
||||
|
||||
const events::event_context dialog_events_context;
|
||||
|
||||
const int centerx = disp.w()/2;
|
||||
const int centery = disp.h()/2;
|
||||
#ifdef USE_TINY_GUI
|
||||
const int width = 300; // FIXME: should compute this, but using what data ?
|
||||
const int height = 220;
|
||||
#else
|
||||
const int width = 700;
|
||||
const int height = 500;
|
||||
#endif
|
||||
const int xpos = centerx - width/2;
|
||||
const int ypos = centery - height/2;
|
||||
|
||||
gui::button close_button (disp.video(), _("Close Window"));
|
||||
std::vector<gui::button*> buttons;
|
||||
buttons.push_back(&close_button);
|
||||
|
||||
gui::dialog_frame f(disp.video(),_("Hotkey Settings"),gui::dialog_frame::default_style,true,&buttons);
|
||||
f.layout(xpos,ypos,width,height);
|
||||
f.draw();
|
||||
|
||||
SDL_Rect clip_rect = { 0, 0, disp.w (), disp.h () };
|
||||
SDL_Rect text_size = font::draw_text(NULL, clip_rect, font::SIZE_PLUS,
|
||||
font::NORMAL_COLOUR,_("Press desired Hotkey"),
|
||||
0, 0);
|
||||
|
||||
std::vector<std::string> menu_items;
|
||||
|
||||
std::vector<hotkey::hotkey_item>& hotkeys = hotkey::get_hotkeys();
|
||||
for(std::vector<hotkey::hotkey_item>::iterator i = hotkeys.begin(); i != hotkeys.end(); ++i) {
|
||||
if(i->hidden())
|
||||
continue;
|
||||
std::stringstream str,name;
|
||||
name << i->get_description();
|
||||
str << name.str();
|
||||
str << COLUMN_SEPARATOR;
|
||||
str << i->get_name();
|
||||
menu_items.push_back(str.str());
|
||||
}
|
||||
|
||||
std::ostringstream heading;
|
||||
heading << HEADING_PREFIX << _("Action") << COLUMN_SEPARATOR << _("Binding");
|
||||
menu_items.push_back(heading.str());
|
||||
|
||||
gui::menu::basic_sorter sorter;
|
||||
sorter.set_alpha_sort(0).set_alpha_sort(1);
|
||||
|
||||
gui::menu menu_(disp.video(), menu_items, false, height, -1, &sorter, &gui::menu::bluebg_style);
|
||||
menu_.sort_by(0);
|
||||
menu_.reset_selection();
|
||||
menu_.set_width(font::relative_size(400));
|
||||
menu_.set_location(xpos + font::relative_size(20), ypos);
|
||||
|
||||
gui::button change_button (disp.video(), _("Change Hotkey"));
|
||||
change_button.set_location(xpos + width - change_button.width () - font::relative_size(30),ypos + font::relative_size(80));
|
||||
|
||||
gui::button save_button (disp.video(), _("Save Hotkeys"));
|
||||
save_button.set_location(xpos + width - save_button.width () - font::relative_size(30),ypos + font::relative_size(130));
|
||||
|
||||
for(;;) {
|
||||
|
||||
if (close_button.pressed())
|
||||
break;
|
||||
|
||||
if (change_button.pressed ()) {
|
||||
// Lets change this hotkey......
|
||||
SDL_Rect dlgr = {centerx-text_size.w/2 - 30,
|
||||
centery-text_size.h/2 - 16,
|
||||
text_size.w+60,
|
||||
text_size.h+32};
|
||||
surface_restorer restorer(&disp.video(),dlgr);
|
||||
gui::dialog_frame mini_frame(disp.video());
|
||||
mini_frame.layout(centerx-text_size.w/2 - 20,
|
||||
centery-text_size.h/2 - 6,
|
||||
text_size.w+40,
|
||||
text_size.h+12);
|
||||
mini_frame.draw_background();
|
||||
mini_frame.draw_border();
|
||||
font::draw_text (&disp.video(), clip_rect, font::SIZE_LARGE,font::NORMAL_COLOUR,
|
||||
_("Press desired Hotkey"),centerx-text_size.w/2-10,
|
||||
centery-text_size.h/2-3);
|
||||
disp.update_display();
|
||||
SDL_Event event;
|
||||
event.type = 0;
|
||||
int character=0,keycode=0; //just to avoid warning
|
||||
int mod=0;
|
||||
while (event.type!=SDL_KEYDOWN) SDL_PollEvent(&event);
|
||||
do {
|
||||
if (event.type==SDL_KEYDOWN)
|
||||
{
|
||||
keycode=event.key.keysym.sym;
|
||||
character=event.key.keysym.unicode;
|
||||
mod=event.key.keysym.mod;
|
||||
};
|
||||
SDL_PollEvent(&event);
|
||||
disp.flip();
|
||||
disp.delay(10);
|
||||
} while (event.type!=SDL_KEYUP);
|
||||
restorer.restore();
|
||||
disp.update_display();
|
||||
|
||||
const hotkey::hotkey_item& oldhk = hotkey::get_hotkey(character, keycode, (mod & KMOD_SHIFT) != 0,
|
||||
(mod & KMOD_CTRL) != 0, (mod & KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0);
|
||||
hotkey::hotkey_item& newhk = hotkey::get_visible_hotkey(menu_.selection());
|
||||
|
||||
if(oldhk.get_id() != newhk.get_id() && !oldhk.null()) {
|
||||
gui::message_dialog(disp,"",_("This Hotkey is already in use.")).show();
|
||||
} else {
|
||||
newhk.set_key(character, keycode, (mod & KMOD_SHIFT) != 0,
|
||||
(mod & KMOD_CTRL) != 0, (mod & KMOD_ALT) != 0, (mod & KMOD_LMETA) != 0);
|
||||
|
||||
menu_.change_item(menu_.selection(), 1, newhk.get_name());
|
||||
};
|
||||
}
|
||||
if (save_button.pressed()) {
|
||||
if (save_config == NULL) {
|
||||
save_hotkeys();
|
||||
} else {
|
||||
hotkey::save_hotkeys(*save_config);
|
||||
}
|
||||
}
|
||||
|
||||
menu_.process();
|
||||
|
||||
events::pump();
|
||||
events::raise_process_event();
|
||||
events::raise_draw_event();
|
||||
|
||||
disp.update_display();
|
||||
|
||||
disp.delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
bool compare_resolutions(const std::pair<int,int>& lhs, const std::pair<int,int>& rhs)
|
||||
{
|
||||
return lhs.first*lhs.second < rhs.first*rhs.second;
|
||||
}
|
||||
|
||||
bool show_video_mode_dialog(display& disp)
|
||||
{
|
||||
const events::resize_lock prevent_resizing;
|
||||
const events::event_context dialog_events_context;
|
||||
|
||||
CVideo& video = disp.video();
|
||||
|
||||
SDL_PixelFormat format = *video.getSurface()->format;
|
||||
format.BitsPerPixel = video.getBpp();
|
||||
|
||||
const SDL_Rect* const * modes = SDL_ListModes(&format,FULL_SCREEN);
|
||||
|
||||
//the SDL documentation says that a return value of -1 if all dimensions
|
||||
//are supported/possible.
|
||||
if(modes == reinterpret_cast<SDL_Rect**>(-1)) {
|
||||
std::cerr << "Can support any video mode\n";
|
||||
// SDL says that all modes are possible so it's OK to use a
|
||||
// hardcoded list here.
|
||||
static const SDL_Rect scr_modes[] = {
|
||||
{ 0, 0, 800, 600 },
|
||||
{ 0, 0, 1024, 768 },
|
||||
{ 0, 0, 1280, 960 },
|
||||
{ 0, 0, 1280, 1024 },
|
||||
};
|
||||
static const SDL_Rect * const scr_modes_list[] = {
|
||||
&scr_modes[0],
|
||||
&scr_modes[1],
|
||||
&scr_modes[2],
|
||||
&scr_modes[3],
|
||||
NULL
|
||||
};
|
||||
|
||||
modes = scr_modes_list;
|
||||
} else if(modes == NULL) {
|
||||
std::cerr << "No modes supported\n";
|
||||
gui::message_dialog(disp,"",_("There are no alternative video modes available")).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<std::pair<int,int> > resolutions;
|
||||
|
||||
for(int i = 0; modes[i] != NULL; ++i) {
|
||||
if(modes[i]->w >= min_allowed_width && modes[i]->h >= min_allowed_height) {
|
||||
resolutions.push_back(std::pair<int,int>(modes[i]->w,modes[i]->h));
|
||||
}
|
||||
}
|
||||
|
||||
const std::pair<int,int> current_res(video.getSurface()->w,video.getSurface()->h);
|
||||
resolutions.push_back(current_res);
|
||||
|
||||
std::sort(resolutions.begin(),resolutions.end(),compare_resolutions);
|
||||
resolutions.erase(std::unique(resolutions.begin(),resolutions.end()),resolutions.end());
|
||||
|
||||
std::vector<std::string> options;
|
||||
for(std::vector<std::pair<int,int> >::const_iterator j = resolutions.begin(); j != resolutions.end(); ++j) {
|
||||
std::ostringstream option;
|
||||
if (*j == current_res)
|
||||
option << DEFAULT_ITEM;
|
||||
|
||||
option << j->first << "x" << j->second;
|
||||
options.push_back(option.str());
|
||||
}
|
||||
|
||||
const int result = gui::show_dialog(disp,NULL,"",
|
||||
_("Choose Resolution"),
|
||||
gui::OK_CANCEL,&options);
|
||||
if(size_t(result) < resolutions.size() && resolutions[result] != current_res) {
|
||||
set_resolution(resolutions[result]);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue