if retval ~= "" then
retval = retval ..","
end
+
+ local color = ""
if v.is_modpack then
local rawlist = filterlist.get_raw_list(render_list)
end
if all_enabled == false then
- retval = retval .. mt_color_grey
+ color = mt_color_grey
else
- retval = retval .. mt_color_dark_green
+ color = mt_color_dark_green
end
end
if v.typ == "game_mod" then
- retval = retval .. mt_color_blue
+ color = mt_color_blue
else
if v.enabled then
- retval = retval .. mt_color_green
+ color = mt_color_green
end
end
+
+ retval = retval .. color
if v.modpack ~= nil then
retval = retval .. " "
end
"button[9.25,6.35;2,0.5;btn_config_world_save;" .. fgettext("Save") .. "]" ..
"button[7.4,6.35;2,0.5;btn_config_world_cancel;" .. fgettext("Cancel") .. "]"
- if mod ~= nil and mod.name ~= "" then
+ if mod ~= nil and mod.name ~= "" and mod.typ ~= "game_mod" then
if mod.is_modpack then
local rawlist = filterlist.get_raw_list(modmgr.modlist)
modmgr.world_config_selected_mod = event.index
if event.typ == "DCL" then
- local mod = filterlist.get_list(modmgr.modlist)[event.index]
-
- if mod.typ == "game_mod" then
- return nil
- end
-
- if not mod.is_modpack then
- mod.enabled = not mod.enabled
- else
- local list = filterlist.get_raw_list(modmgr.modlist)
- local toset = nil
-
- for i=1,#list,1 do
- if list[i].modpack == mod.name then
- if toset == nil then
- toset = not list[i].enabled
- end
-
- list[i].enabled = toset
- end
- end
- end
+ modmgr.world_config_enable_mod(nil)
end
end
+ if fields["key_enter"] ~= nil then
+ modmgr.world_config_enable_mod(nil)
+ end
+
if fields["cb_mod_enable"] ~= nil then
- local mod = filterlist.get_list(modmgr.modlist)
- [engine.get_textlist_index("world_config_modlist")]
- if fields["cb_mod_enable"] == "true" then
- mod.enabled = true
- else
- mod.enabled = false
- end
+ local toset = (fields["cb_mod_enable"] == "true")
+ modmgr.world_config_enable_mod(toset)
end
if fields["btn_mp_enable"] ~= nil or
fields["btn_mp_disable"] then
- local mod = filterlist.get_list(modmgr.modlist)
- [engine.get_textlist_index("world_config_modlist")]
-
- local toset=false
- if fields["btn_mp_enable"] ~= nil then
- toset = true
- end
- local list = filterlist.get_raw_list(modmgr.modlist)
-
- for i=1,#list,1 do
- if list[i].modpack == mod.name then
- list[i].enabled = toset
- end
- end
+ local toset = (fields["btn_mp_enable"] ~= nil)
+ modmgr.world_config_enable_mod(toset)
end
if fields["cb_hide_gamemods"] ~= nil then
return nil
end
--------------------------------------------------------------------------------
+function modmgr.world_config_enable_mod(toset)
+ local mod = filterlist.get_list(modmgr.modlist)
+ [engine.get_textlist_index("world_config_modlist")]
+
+ if mod.typ == "game_mod" then
+ -- game mods can't be enabled or disabled
+ elseif not mod.is_modpack then
+ if toset == nil then
+ mod.enabled = not mod.enabled
+ else
+ mod.enabled = toset
+ end
+ else
+ local list = filterlist.get_raw_list(modmgr.modlist)
+ for i=1,#list,1 do
+ if list[i].modpack == mod.name then
+ if toset == nil then
+ toset = not list[i].enabled
+ end
+ list[i].enabled = toset
+ end
+ end
+ end
+end
+--------------------------------------------------------------------------------
function modmgr.handle_delete_mod_buttons(fields)
local mod = filterlist.get_list(modmgr.global_mods)[modmgr.selected_mod]
}
}
+void GUIFormSpecMenu::setInitialFocus()
+{
+ // Set initial focus according to following order of precedence:
+ // 1. first empty editbox
+ // 2. first editbox
+ // 3. first listbox
+ // 4. last button
+ // 5. first focusable (not statictext, not tabheader)
+ // 6. first child element
+
+ core::list<gui::IGUIElement*> children = getChildren();
+
+ // in case "children" contains any NULL elements, remove them
+ for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
+ it != children.end();) {
+ if (*it)
+ ++it;
+ else
+ it = children.erase(it);
+ }
+
+ // 1. first empty editbox
+ for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
+ it != children.end(); ++it) {
+ if ((*it)->getType() == gui::EGUIET_EDIT_BOX
+ && (*it)->getText()[0] == 0) {
+ Environment->setFocus(*it);
+ return;
+ }
+ }
+
+ // 2. first editbox
+ for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
+ it != children.end(); ++it) {
+ if ((*it)->getType() == gui::EGUIET_EDIT_BOX) {
+ Environment->setFocus(*it);
+ return;
+ }
+ }
+
+ // 3. first listbox
+ for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
+ it != children.end(); ++it) {
+ if ((*it)->getType() == gui::EGUIET_LIST_BOX) {
+ Environment->setFocus(*it);
+ return;
+ }
+ }
+
+ // 4. last button
+ for (core::list<gui::IGUIElement*>::Iterator it = children.getLast();
+ it != children.end(); --it) {
+ if ((*it)->getType() == gui::EGUIET_BUTTON) {
+ Environment->setFocus(*it);
+ return;
+ }
+ }
+
+ // 5. first focusable (not statictext, not tabheader)
+ for (core::list<gui::IGUIElement*>::Iterator it = children.begin();
+ it != children.end(); ++it) {
+ if ((*it)->getType() != gui::EGUIET_STATIC_TEXT &&
+ (*it)->getType() != gui::EGUIET_TAB_CONTROL) {
+ Environment->setFocus(*it);
+ return;
+ }
+ }
+
+ // 6. first child element
+ if (children.empty())
+ Environment->setFocus(this);
+ else
+ Environment->setFocus(*(children.begin()));
+}
+
int GUIFormSpecMenu::getListboxIndex(std::string listboxname) {
std::wstring wlistboxname = narrow_to_wide(listboxname.c_str());
spec.flabel = wlabel; //Needed for displaying text on MSVC
gui::IGUICheckBox* e = Environment->addCheckBox(fselected, rect, this,
spec.fid, spec.flabel.c_str());
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
m_checkboxes.push_back(std::pair<FieldSpec,gui::IGUICheckBox*>(spec,e));
m_fields.push_back(spec);
return;
if(type == "button_exit")
spec.is_exit = true;
- Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
+ gui::IGUIButton* e = Environment->addButton(rect, this, spec.fid,
+ spec.flabel.c_str());
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
m_fields.push_back(spec);
return;
}
//now really show list
gui::IGUIListBox *e = Environment->addListBox(rect, this,spec.fid);
- //don't reset if we already have a user specified selection
- if (data->listbox_selections.find(fname_w) == data->listbox_selections.end()) {
- e->setAutoScrollEnabled(false);
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
}
if (str_transparent == "false")
//now really show list
gui::IGUIComboBox *e = Environment->addComboBox(rect, this,spec.fid);
- //don't reset if we already have a user specified selection
- //if (data->combobox_selections.find(fname_w) == data->listbox_selections.end()) {
- // e->setAutoScrollEnabled(false);
- //}
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
for (unsigned int i=0; i < items.size(); i++) {
e->addItem(narrow_to_wide(items[i]).c_str());
spec.send = true;
gui::IGUIEditBox * e = Environment->addEditBox(0, rect, true, this, spec.fid);
- Environment->setFocus(e);
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
if (label.length() > 1)
{
{
spec.send = true;
gui::IGUIEditBox *e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
- Environment->setFocus(e);
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
irr::SEvent evt;
evt.EventType = EET_KEY_INPUT_EVENT;
{
spec.send = true;
gui::IGUIEditBox *e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid);
- Environment->setFocus(e);
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
if (type == "textarea")
{
pressed_texture = texture;
gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
e->setUseAlphaChannel(true);
e->setImage(texture);
e->setPressedImage(pressed_texture);
gui::IGUITabControl *e = Environment->addTabControl(rect,this,show_background,show_border,spec.fid);
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
e->setNotClipped(true);
for (unsigned int i=0; i< buttons.size(); i++) {
);
gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
e->setUseAlphaChannel(true);
e->setImage(texture);
e->setPressedImage(texture);
}
}
+ //preserve focus
+ gui::IGUIElement *focused_element = Environment->getFocus();
+ if (focused_element && focused_element->getParent() == this) {
+ s32 focused_id = focused_element->getID();
+ if (focused_id > 257) {
+ for (u32 i=0; i<m_fields.size(); i++) {
+ if (m_fields[i].fid == focused_id) {
+ mydata.focused_fieldname =
+ m_fields[i].fname;
+ break;
+ }
+ }
+ }
+ }
+
// Remove children
removeChildren();
m_tooltip_element->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
m_tooltip_element->setWordWrap(false);
}
+
+ //set initial focus if parser didn't set it
+ focused_element = Environment->getFocus();
+ if (!focused_element
+ || !isMyChild(focused_element)
+ || focused_element->getType() == gui::EGUIET_TAB_CONTROL)
+ setInitialFocus();
}
GUIFormSpecMenu::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
}
}
+bool GUIFormSpecMenu::preprocessEvent(const SEvent& event)
+{
+ // Fix Esc/Return key being eaten by checkboxen and listboxen
+ if(event.EventType==EET_KEY_INPUT_EVENT)
+ {
+ KeyPress kp(event.KeyInput);
+ if (kp == EscapeKey || kp == getKeySetting("keymap_inventory")
+ || event.KeyInput.Key==KEY_RETURN)
+ {
+ gui::IGUIElement *focused = Environment->getFocus();
+ if (focused && isMyChild(focused) &&
+ (focused->getType() == gui::EGUIET_LIST_BOX ||
+ focused->getType() == gui::EGUIET_CHECK_BOX)) {
+ OnEvent(event);
+ return true;
+ }
+ }
+ }
+ // Mouse wheel events: send to hovered element instead of focused
+ if(event.EventType==EET_MOUSE_INPUT_EVENT
+ && event.MouseInput.Event == EMIE_MOUSE_WHEEL)
+ {
+ s32 x = event.MouseInput.X;
+ s32 y = event.MouseInput.Y;
+ gui::IGUIElement *hovered =
+ Environment->getRootGUIElement()->getElementFromPoint(
+ core::position2d<s32>(x, y));
+ if (hovered && isMyChild(hovered)) {
+ hovered->OnEvent(event);
+ return true;
+ }
+ }
+ return false;
+}
+
bool GUIFormSpecMenu::OnEvent(const SEvent& event)
{
if(event.EventType==EET_KEY_INPUT_EVENT)
s.send = true;
acceptInput();
s.send = false;
- // Restore focus to the full form
- Environment->setFocus(this);
return true;
}
}
return true;
}else{
s.send = false;
- // Restore focus to the full form
- Environment->setFocus(this);
return true;
}
}
s.send = true;
acceptInput();
s.send=false;
- // Restore focus to the full form
- Environment->setFocus(this);
}
}
return true;