Skip to content

Commit

Permalink
Add option to restore old module collapse behavior if desired
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Jan 15, 2025
1 parent 0fe8105 commit aac0d40
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 34 deletions.
37 changes: 36 additions & 1 deletion source/m_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ void Parse_Option(const std::string &name, const std::string &value)
{
custom_prefix = value;
}
#ifndef OBSIDIAN_CONSOLE_ONLY
else if (StringCompare(name, "collapse_disabled_modules") == 0)
{
collapse_disabled_modules = StringToInt(value) ? true : false;
}
#endif
else if (StringCompare(name, "default_output_path") == 0)
{
default_output_path = value;
Expand Down Expand Up @@ -210,6 +216,9 @@ bool Options_Save(const std::string &filename)
fprintf(option_fp, "mature_word_lists = %d\n", (mature_word_lists ? 1 : 0));
fprintf(option_fp, "filename_prefix = %d\n", filename_prefix);
fprintf(option_fp, "custom_prefix = %s\n", custom_prefix.c_str());
#ifndef OBSIDIAN_CONSOLE_ONLY
fprintf(option_fp, "collapse_disabled_modules = %d\n", (collapse_disabled_modules ? 1 : 0));
#endif
fprintf(option_fp, "%s", StringFormat("default_output_path = %s\n\n", default_output_path.c_str()).c_str());

VFS_OptWrite(option_fp);
Expand Down Expand Up @@ -252,6 +261,7 @@ class UI_OptionsWin : public Fl_Window
UI_CustomCheckBox *opt_overwrite;
UI_CustomCheckBox *opt_debug;
UI_CustomCheckBox *opt_limit_break;
UI_CustomCheckBox *opt_collapse_disabled;

public:
UI_OptionsWin(int W, int H, const char *label = NULL);
Expand Down Expand Up @@ -493,6 +503,21 @@ class UI_OptionsWin : public Fl_Window
}
}

static void callback_CollapseDisabled(Fl_Widget *w, void *data)
{
UI_OptionsWin *that = (UI_OptionsWin *)data;

collapse_disabled_modules = that->opt_collapse_disabled->value() ? true : false;

// clang-format off
fl_alert("%s", _("Toggling module collapsing requires a restart.\nObsidian will now restart."));
// clang-format on

main_action = MAIN_HARD_RESTART;

that->want_quit = true;
}

static void callback_PrefixHelp(Fl_Widget *w, void *data)
{
fl_cursor(FL_CURSOR_DEFAULT);
Expand Down Expand Up @@ -752,6 +777,16 @@ UI_OptionsWin::UI_OptionsWin(int W, int H, const char *label) : Fl_Window(W, H,
opt_limit_break->selection_color(SELECTION);
opt_limit_break->down_box(button_style);

cy += opt_limit_break->h() + y_step * .5;

opt_collapse_disabled = new UI_CustomCheckBox(cx + W * .38, cy, listwidth, KromulentHeight(24), "");
opt_collapse_disabled->copy_label(_(" Collapse Disabled Modules"));
opt_collapse_disabled->value(collapse_disabled_modules ? 1 : 0);
opt_collapse_disabled->callback(callback_CollapseDisabled, this);
opt_collapse_disabled->labelfont(font_style);
opt_collapse_disabled->selection_color(SELECTION);
opt_collapse_disabled->down_box(button_style);

//----------------

int dh = KromulentHeight(60);
Expand Down Expand Up @@ -809,7 +844,7 @@ int UI_OptionsWin::handle(int event)

void DLG_OptionsEditor(void)
{
int opt_w = KromulentWidth(500);
int opt_w = KromulentWidth(550);
int opt_h = KromulentHeight(475);

UI_OptionsWin *option_window = new UI_OptionsWin(opt_w, opt_h, _("OBSIDIAN Misc Options"));
Expand Down
1 change: 1 addition & 0 deletions source/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ static int old_h = 0;
static std::string old_seed;
static std::string old_name;
static uint8_t *old_pixels;
bool collapse_disabled_modules = false;
#endif
int filename_prefix = 0;
std::string custom_prefix = "CUSTOM_";
Expand Down
1 change: 1 addition & 0 deletions source/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ extern int window_scaling;
extern int font_scaling;
extern int num_fonts;
extern std::vector<std::pair<std::string, int>> font_menu_items;
extern bool collapse_disabled_modules;
#endif
extern int filename_prefix;
extern std::string custom_prefix;
Expand Down
106 changes: 75 additions & 31 deletions source/ui_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ UI_Module::UI_Module(int X, int Y, int W, int H, const std::string &id, const st
box(box_style);

id_name = id;
og_label = label;

if ((red >= 0) && (green >= 0) && (blue >= 0))
{
Expand Down Expand Up @@ -116,7 +115,10 @@ void UI_Module::AddHeader(const std::string &opt, const std::string &label, int

if (!mod_button->value())
{
rhead->deactivate();
if (collapse_disabled_modules)
rhead->hide();
else
rhead->deactivate();
}

add(rhead);
Expand Down Expand Up @@ -146,7 +148,10 @@ void UI_Module::AddUrl(const std::string &opt, const std::string &label, const s

if (!mod_button->value())
{
rurl->deactivate();
if (collapse_disabled_modules)
rurl->hide();
else
rurl->deactivate();
}

add(rurl);
Expand Down Expand Up @@ -212,7 +217,10 @@ void UI_Module::AddOption(const std::string &opt, const std::string &label, cons

if (!mod_button->value())
{
rch->deactivate();
if (collapse_disabled_modules)
rch->hide();
else
rch->deactivate();
}

add(rch);
Expand Down Expand Up @@ -401,7 +409,10 @@ void UI_Module::AddSliderOption(const std::string &opt, std::string &label, cons

if (!mod_button->value())
{
rsl->deactivate();
if (collapse_disabled_modules)
rsl->hide();
else
rsl->deactivate();
}

add(rsl);
Expand Down Expand Up @@ -466,7 +477,10 @@ void UI_Module::AddButtonOption(const std::string &opt, const std::string &label

if (!mod_button->value())
{
rbt->deactivate();
if (collapse_disabled_modules)
rbt->hide();
else
rbt->deactivate();
}

add(rbt);
Expand All @@ -481,19 +495,23 @@ void UI_Module::AddButtonOption(const std::string &opt, const std::string &label

int UI_Module::CalcHeight() const
{
return cur_opt_y + KromulentHeight(6);
}

void UI_Module::update_Enable()
{
if (!Is_UI())
if (collapse_disabled_modules)
{
if (mod_button->value())
heading->copy_label(og_label.c_str());
{
return cur_opt_y + KromulentHeight(6);
}
else
heading->copy_label(StringFormat("%s (DISABLED)", og_label.c_str()).c_str());
{
return KromulentHeight(34);
}
}
else
return cur_opt_y + KromulentHeight(6);
}

void UI_Module::update_Enable()
{
std::map<std::string, UI_RChoice *>::const_iterator IT;
std::map<std::string, UI_RSlide *>::const_iterator IT2;
std::map<std::string, UI_RButton *>::const_iterator IT3;
Expand All @@ -506,11 +524,17 @@ void UI_Module::update_Enable()

if (mod_button->value())
{
M->activate();
if (collapse_disabled_modules)
M->show();
else
M->activate();
}
else
{
M->deactivate();
if (collapse_disabled_modules)
M->hide();
else
M->deactivate();
}
}

Expand All @@ -520,50 +544,77 @@ void UI_Module::update_Enable()

if (mod_button->value())
{
M->activate();
if (collapse_disabled_modules)
M->show();
else
M->activate();
}
else
{
M->deactivate();
if (collapse_disabled_modules)
M->hide();
else
M->deactivate();
}
}

for (IT3 = choice_map_button.begin(); IT3 != choice_map_button.end(); IT3++)
{
UI_RButton *M = IT3->second;

if (mod_button->value())
{
M->activate();
if (collapse_disabled_modules)
M->show();
else
M->activate();
}
else
{
M->deactivate();
if (collapse_disabled_modules)
M->hide();
else
M->deactivate();
}
}

for (IT4 = choice_map_header.begin(); IT4 != choice_map_header.end(); IT4++)
{
UI_RHeader *M = IT4->second;

if (mod_button->value())
{
M->activate();
if (collapse_disabled_modules)
M->show();
else
M->activate();
}
else
{
M->deactivate();
if (collapse_disabled_modules)
M->hide();
else
M->deactivate();
}
}

for (IT5 = choice_map_url.begin(); IT5 != choice_map_url.end(); IT5++)
{
UI_RLink *M = IT5->second;

if (mod_button->value())
{
M->activate();
if (collapse_disabled_modules)
M->show();
else
M->activate();
}
else
{
M->deactivate();
if (collapse_disabled_modules)
M->hide();
else
M->deactivate();
}
}
}
Expand Down Expand Up @@ -1269,13 +1320,6 @@ bool UI_CustomMods::ShowModule(const std::string &id, bool new_shown)
if (new_shown)
{
M->show();
if (!M->Is_UI())
{
if (M->mod_button->value())
M->heading->copy_label(M->og_label.c_str());
else
M->heading->copy_label(StringFormat("%s (DISABLED)", M->og_label.c_str()).c_str());
}
}
else
{
Expand Down
2 changes: 0 additions & 2 deletions source/ui_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class UI_Module : public Fl_Group

std::string id_name;

std::string og_label; // For toggling the (Disabled) text

// only used while positioning the options (as they are added)
int cur_opt_y;

Expand Down

0 comments on commit aac0d40

Please sign in to comment.