From ac5f25f186294d2cc8059ce80b2cd51549f7c7f3 Mon Sep 17 00:00:00 2001 From: EmilyV99 Date: Sat, 12 Aug 2023 20:38:02 -0400 Subject: [PATCH] feat: More subscreen work, generic scripts on buttonpress and custom selectiontext --- src/dialog/subscr_props.cpp | 222 +++++++++++++++++++++++++++--------- src/dialog/subscr_props.h | 16 ++- src/new_subscr.cpp | 99 ++++++++++------ src/new_subscr.h | 10 +- src/zc/ffscript.cpp | 9 +- src/zc/ffscript.h | 2 +- src/zc/zc_subscr.cpp | 16 +-- src/zc/zc_sys.cpp | 1 - src/zq/zq_subscr.cpp | 60 +++++++--- 9 files changed, 312 insertions(+), 123 deletions(-) diff --git a/src/dialog/subscr_props.cpp b/src/dialog/subscr_props.cpp index 22d4a26dfa..1f8448f84d 100644 --- a/src/dialog/subscr_props.cpp +++ b/src/dialog/subscr_props.cpp @@ -9,6 +9,8 @@ #include "gui/common.h" #include "base/misctypes.h" +extern script_data *genericscripts[NUMSCRIPTSGENERIC]; + static bool dlg_retval = false; bool call_subscrprop_dialog(SubscrWidget* widg, int32_t obj_ind) { @@ -24,7 +26,8 @@ SubscrPropDialog::SubscrPropDialog(SubscrWidget* widg, int32_t obj_ind) : list_buttons(GUI::ZCListData::buttons()), list_items(GUI::ZCListData::items(true)), list_counters(GUI::ZCListData::ss_counters()), - list_itemclass(GUI::ZCListData::itemclass(true)) + list_itemclass(GUI::ZCListData::itemclass(true)), + list_genscr(GUI::ZCListData::generic_script()) {} static const GUI::ListData two_three_rows @@ -207,6 +210,34 @@ char* repl_escchar(char* buf, char const* ptr, bool compact) } } +#define INITD_LAB_WIDTH 12_em +std::shared_ptr SubscrPropDialog::GEN_INITD(int ind) +{ + using namespace GUI::Builder; + using namespace GUI::Props; + std::string lbl = local_gen_meta.initd[ind]; + if(lbl.empty()) + lbl = "InitD["+std::to_string(ind)+"]:"; + return Row(padding = 0_px, hAlign = 1.0, + geninitd_lbl[ind] = Label(minwidth = INITD_LAB_WIDTH, text = lbl, textAlign = 2), + geninitd_btn[ind] = Button(forceFitH = true, text = "?", + hPadding = 0_px, + disabled = local_gen_meta.initd_help[ind].empty(), + onPressFunc = [&, ind]() + { + InfoDialog("InitD Info",local_gen_meta.initd_help[ind]).show(); + }), + TextField( + fitParent = true, minwidth = 8_em, + type = GUI::TextField::type::SWAP_ZSINT2, + val = local_subref->generic_initd[ind], swap_type = local_gen_meta.initd_type[ind], + onValChangedFunc = [&, ind](GUI::TextField::type,std::string_view,int32_t val) + { + local_subref->generic_initd[ind] = val; + }) + ); +} + static size_t sprop_tab = 0; static char tbuf[1025] = {0}; std::shared_ptr SubscrPropDialog::view() @@ -215,29 +246,6 @@ std::shared_ptr SubscrPropDialog::view() using namespace GUI::Props; char titlebuf[512]; sprintf(titlebuf, "%s Properties (Object #%d)", sso_name(local_subref->getType()), index); - //Generate the basic window, with a reference to the row - std::shared_ptr windowRow; - window = Window( - title = titlebuf, - onClose = message::CANCEL, - hPadding = 0_px, - Column( - windowRow = Row(padding = 0_px), - Row( - Button( - text = "&OK", - topPadding = 0.5_em, - minwidth = 90_px, - onClick = message::OK, - focused = true), - Button( - text = "&Cancel", - topPadding = 0.5_em, - minwidth = 90_px, - onClick = message::CANCEL) - ) - ) - ); std::shared_ptr loc_grid; //Generate 'location' grid @@ -303,25 +311,6 @@ std::shared_ptr SubscrPropDialog::view() ) ), g1 = Rows<2>() - ), - Rows<3>( - CBOX(local_subref->flags,SUBSCRFLAG_SELECTABLE,"Cursor Selectable",3), - // - Label(text = "Position:", hAlign = 1.0), - NUM_FIELD(local_subref->pos, -9999, 9999), - INFOBTN("The unique position ID of this slot"), - Label(text = "Up Select:", hAlign = 1.0), - NUM_FIELD(local_subref->pos_up, -9999, 9999), - INFOBTN("The unique position ID to move to when pressing 'Up'"), - Label(text = "Down Select:", hAlign = 1.0), - NUM_FIELD(local_subref->pos_down, -9999, 9999), - INFOBTN("The unique position ID to move to when pressing 'Down'"), - Label(text = "Left Select:", hAlign = 1.0), - NUM_FIELD(local_subref->pos_left, -9999, 9999), - INFOBTN("The unique position ID to move to when pressing 'Left' / 'L' quickswap"), - Label(text = "Right Select:", hAlign = 1.0), - NUM_FIELD(local_subref->pos_right, -9999, 9999), - INFOBTN("The unique position ID to move to when pressing 'Right' / 'R' quickswap") ) ); if(show_xy) @@ -1124,47 +1113,166 @@ std::shared_ptr SubscrPropDialog::view() default: attrib_grid = Column(Label(text = "ERROR")); break; } } + + std::shared_ptr g; + std::shared_ptr tpan = TabPanel(ptr = &sprop_tab); switch(mergetype) { default: case mtNONE: //3 in horz row { - windowRow->add(Frame(title = "Location", fitParent = true, loc_grid)); + tpan->add(TabRef(name = "Basic", g = Rows<2>(padding = 0_px))); + g->add(Frame(title = "Location", fitParent = true, loc_grid)); if(addcolor) - windowRow->add(Frame(title = "Color", fitParent = true, col_grid)); + g->add(Frame(title = "Color", fitParent = true, col_grid)); if(addattrib) - windowRow->add(Frame(title = "Attributes", fitParent = true, attrib_grid)); + g->add(Frame(title = "Attributes", fitParent = true, attrib_grid)); break; } case mtFORCE_TAB: //3 separate tabs { - std::shared_ptr tp; - windowRow->add( - tp = TabPanel( - ptr = &sprop_tab - )); - tp->add(TabRef(name = "Location", loc_grid)); - if(addcolor) tp->add(TabRef(name = "Color", col_grid)); - if(addattrib) tp->add(TabRef(name = "Attributes", attrib_grid)); + tpan->add(TabRef(name = "Location", loc_grid)); + if(addcolor) tpan->add(TabRef(name = "Color", col_grid)); + if(addattrib) tpan->add(TabRef(name = "Attributes", attrib_grid)); break; } case mtLOCTOP: { + tpan->add(TabRef(name = "Basic", g = Row(padding = 0_px))); if(addcolor) { - windowRow->add(Column(padding = 0_px, + g->add(Column(padding = 0_px, Frame(title = "Location", fitParent = true, loc_grid), Frame(title = "Color", fitParent = true, col_grid))); } - else windowRow->add(Frame(title = "Location", fitParent = true, loc_grid)); + else g->add(Frame(title = "Location", fitParent = true, loc_grid)); if(addattrib) - windowRow->add(Frame(title = "Attributes", fitParent = true, attrib_grid)); + g->add(Frame(title = "Attributes", fitParent = true, attrib_grid)); break; } } + tpan->add(TabRef(name = "Selection", Rows<2>( + Frame(title = "Cursor Selectable", info = "If the subscreen cursor can select this" + " widget, and the selectable position information for selecting it.", + fitParent = true, + Column(padding = 0_px, + Checkbox( + text = "Is Selectable", + checked = local_subref->flags & SUBSCRFLAG_SELECTABLE, + onToggleFunc = [&](bool state) + { + SETFLAG(local_subref->flags, SUBSCRFLAG_SELECTABLE, state); + updateSelectable(); + }), + selgs[0] = Rows<3>( + Label(text = "Position:", hAlign = 1.0), + NUM_FIELD(local_subref->pos, -9999, 9999), + INFOBTN("The unique position ID of this slot"), + Label(text = "Up Select:", hAlign = 1.0), + NUM_FIELD(local_subref->pos_up, -9999, 9999), + INFOBTN("The unique position ID to move to when pressing 'Up'"), + Label(text = "Down Select:", hAlign = 1.0), + NUM_FIELD(local_subref->pos_down, -9999, 9999), + INFOBTN("The unique position ID to move to when pressing 'Down'"), + Label(text = "Left Select:", hAlign = 1.0), + NUM_FIELD(local_subref->pos_left, -9999, 9999), + INFOBTN("The unique position ID to move to when pressing 'Left' / 'L' quickswap"), + Label(text = "Right Select:", hAlign = 1.0), + NUM_FIELD(local_subref->pos_right, -9999, 9999), + INFOBTN("The unique position ID to move to when pressing 'Right' / 'R' quickswap") + ) + ) + ), + selframes[0] = Frame(title = "Generic Frozen Script", + info = "Run a Generic Frozen Script when a button is pressed." + "\nThe script will run before any other effects that occur from" + " pressing the button (such as equipping an item to a button).", + fitParent = true, + Row( + selgs[1] = Column(padding = 0_px, + GEN_INITD(0), + GEN_INITD(1), + GEN_INITD(2), + GEN_INITD(3), + GEN_INITD(4), + GEN_INITD(5), + GEN_INITD(6), + GEN_INITD(7) + ), + Column( + Label(text = "Script:", hAlign = 0.0), + DropDownList(data = list_genscr, + vPadding = 0_px, + fitParent = true, selectedValue = local_subref->generic_script, + onSelectFunc = [&](int32_t val) + { + local_subref->generic_script = val; + updateSelectable(); + }), + selgs[2] = INTBTN_PANEL2(local_subref->gen_script_btns,"Run Button:") + ) + ) + ), + selframes[1] = Frame(title = "Selection Text", + info = "If not blank, use this text for 'Selection Text' widgets.", + fitParent = true, colSpan = 2, + TextField( + type = GUI::TextField::type::TEXT, + maxLength = 255, + text = local_subref->override_text, + onValChangedFunc = [&](GUI::TextField::type,std::string_view text,int32_t) + { + local_subref->override_text = text; + }) + ) + ))); + window = Window( + title = titlebuf, + onClose = message::CANCEL, + hPadding = 0_px, + Column( + tpan, + Row( + Button( + text = "&OK", + topPadding = 0.5_em, + minwidth = 90_px, + onClick = message::OK, + focused = true), + Button( + text = "&Cancel", + topPadding = 0.5_em, + minwidth = 90_px, + onClick = message::CANCEL) + ) + ) + ); + updateSelectable(); return window; } +void SubscrPropDialog::updateSelectable() +{ + bool seldis = !(local_subref->flags & SUBSCRFLAG_SELECTABLE); + selgs[0]->setDisabled(seldis); + selframes[0]->setDisabled(seldis); + selframes[1]->setDisabled(seldis); + selgs[1]->setDisabled(seldis || !local_subref->generic_script); + selgs[2]->setDisabled(seldis || !local_subref->generic_script); + + if(local_subref->generic_script) + local_gen_meta = genericscripts[local_subref->generic_script]->meta; + else local_gen_meta.zero(); + + for(int q = 0; q < 8; ++q) + { + std::string lbl = local_gen_meta.initd[q]; + if(lbl.empty()) + lbl = "InitD["+std::to_string(q)+"]"; + geninitd_lbl[q]->setText(lbl); + geninitd_btn[q]->setDisabled(local_gen_meta.initd_help[q].empty()); + } +} void SubscrPropDialog::updateColors() { switch(local_subref->getType()) diff --git a/src/dialog/subscr_props.h b/src/dialog/subscr_props.h index 91773a1890..50fdb15570 100644 --- a/src/dialog/subscr_props.h +++ b/src/dialog/subscr_props.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -26,7 +28,8 @@ class SubscrPropDialog: public GUI::Dialog }; SubscrPropDialog(SubscrWidget* widg, int32_t obj_ind); - + + std::shared_ptr GEN_INITD(int ind); std::shared_ptr view() override; bool handleMessage(const GUI::DialogMessage& msg); @@ -38,13 +41,22 @@ class SubscrPropDialog: public GUI::Dialog std::shared_ptr ddl; std::shared_ptr fonttf; std::shared_ptr labels[2]; + + std::shared_ptr selgs[3]; + std::shared_ptr selframes[2]; + + std::shared_ptr geninitd_lbl[8]; + std::shared_ptr geninitd_btn[8]; SubscrWidget* subref; SubscrWidget* local_subref; int32_t index; + zasm_meta local_gen_meta; + GUI::ListData list_font, list_shadtype, list_aligns, list_buttons, list_items, - list_counters, list_itemclass; + list_counters, list_itemclass, list_genscr; + void updateSelectable(); void updateColors(); void update_wh(); }; diff --git a/src/new_subscr.cpp b/src/new_subscr.cpp index d490c02f3d..7fbafed0fd 100644 --- a/src/new_subscr.cpp +++ b/src/new_subscr.cpp @@ -474,6 +474,8 @@ bool SubscrWidget::copy_prop(SubscrWidget const* src, bool all) override_text = src->override_text; gen_script_btns = src->gen_script_btns; generic_script = src->generic_script; + for(int q = 0; q < 8; ++q) + generic_initd[q] = src->generic_initd[q]; type = src->type; } return true; @@ -507,12 +509,18 @@ int32_t SubscrWidget::read(PACKFILE *f, word s_version) return qe_invalid; if(!p_igetl(&pos_right,f)) return qe_invalid; - if(!p_getcstr(&override_text,f)) - return qe_invalid; - if(!p_getc(&gen_script_btns,f)) + if(!p_getwstr(&override_text,f)) return qe_invalid; if(!p_igetw(&generic_script,f)) return qe_invalid; + if(generic_script) + { + if(!p_getc(&gen_script_btns,f)) + return qe_invalid; + for(int q = 0; q < 8; ++q) + if(!p_igetl(&generic_initd[q],f)) + return qe_invalid; + } } return 0; } @@ -546,12 +554,18 @@ int32_t SubscrWidget::write(PACKFILE *f) const new_return(12); if(!p_iputl(pos_right,f)) new_return(13); - if(!p_putcstr(override_text,f)) + if(!p_putwstr(override_text,f)) new_return(14); - if(!p_putc(gen_script_btns,f)) - new_return(15); if(!p_iputw(generic_script,f)) - new_return(16); + new_return(15); + if(generic_script) + { + if(!p_putc(gen_script_btns,f)) + new_return(16); + for(int q = 0; q < 8; ++q) + if(!p_iputl(generic_initd[q],f)) + new_return(17); + } } return 0; } @@ -901,16 +915,10 @@ word SW_Time::getW() const { char *ts; auto tm = game ? game->get_time() : 0; - switch(type) - { - case ssoBSTIME: - ts = time_str_short2(tm); - break; - case ssoTIME: - case ssoSSTIME: - ts = time_str_med(tm); - break; - } + if(flags&SUBSCR_TIME_ALTSTR) + ts = time_str_short2(tm); + else + ts = time_str_med(tm); return text_length(get_zc_font(fontid), ts) + shadow_w(shadtype); } word SW_Time::getH() const @@ -2826,23 +2834,34 @@ byte SW_SelectedText::getType() const } void SW_SelectedText::draw(BITMAP* dest, int32_t xofs, int32_t yofs, SubscrPage& page) const { + SubscrWidget* widg = page.get_sel_widg(); + if(!widg) return; FONT* tempfont = get_zc_font(fontid); std::string str; - - int32_t itemid=page.get_sel_item(true); - if(itemid > -1) + if(widg->override_text.size()) + str = widg->override_text; + else { - // If it's a combined bow and arrow, the item ID will have 0xF000 added. - if(itemid>=0xF000) - itemid-=0xF000; - - // 0 can mean either the item with index 0 is selected or there's no - // valid item to select, so be sure Hero has whatever it would be. - if(!game->get_item(itemid)) - return; - - itemdata const& itm = itemsbuf[itemid]; - str = itm.get_name(); + int32_t itemid=widg->getItemVal(true); + if(itemid > -1) + { + // If it's a combined bow and arrow, the item ID will have 0xF000 added. + bool bowarrow = itemid&0xF000; + if(bowarrow) + itemid&=~0xF000; + + #if IS_PLAYER + // 0 can mean either the item with index 0 is selected or there's no + // valid item to select, so be sure Hero has whatever it would be. + if(!game->get_item(itemid)) + return; + #endif + + itemdata const& itm = itemsbuf[itemid]; + str = itm.get_name(); + if(bowarrow) + str = "Bow & " + str; + } } if(str.size()) draw_textbox(dest, getX()+xofs, getY()+yofs, getW(), getH(), tempfont, @@ -3547,6 +3566,14 @@ int32_t ZCSubscreen::read(PACKFILE *f, word s_version) return qe_invalid; if(!p_getc(&sub_type,f)) return qe_invalid; + if(!p_igetw(&script,f)) + return qe_invalid; + if(script) + { + for(int q = 0; q < 8; ++q) + if(!p_igetl(&initd[q],f)) + return qe_invalid; + } byte pagecnt; if(!p_getc(&pagecnt,f)) return qe_invalid; @@ -3565,9 +3592,17 @@ int32_t ZCSubscreen::write(PACKFILE *f) const new_return(1); if(!p_putc(sub_type,f)) new_return(2); + if(!p_iputw(script,f)) + new_return(3); + if(script) + { + for(int q = 0; q < 8; ++q) + if(!p_iputl(initd[q],f)) + new_return(4); + } byte pagecnt = zc_min(255,pages.size()); if(!p_putc(pagecnt,f)) - new_return(3); + new_return(5); for(byte q = 0; q < pagecnt; ++q) if(auto ret = pages[q].write(f)) return ret; diff --git a/src/new_subscr.h b/src/new_subscr.h index d4561deff5..008175290b 100644 --- a/src/new_subscr.h +++ b/src/new_subscr.h @@ -224,9 +224,9 @@ struct SubscrWidget int32_t pos_right; std::string override_text; - byte gen_script_btns; word generic_script; - //!TODO Generic InitD[]? + int32_t generic_initd[8]; + byte gen_script_btns; SubscrWidget() = default; SubscrWidget(byte ty); @@ -810,7 +810,7 @@ struct SubscrPage int32_t move_legacy(int dir, int startp, int fp=-1, int fp2=-1, int fp3=-1, bool equip_only=true, bool item_only=true); SubscrWidget* get_widg_pos(int32_t pos, bool item_only); SubscrWidget* get_sel_widg(); - int32_t get_item_pos(int32_t pos, bool item_only); + int32_t get_item_pos(int32_t pos, bool item_only = true); int32_t get_sel_item(bool display = false); int32_t get_pos_of_item(int32_t itemid); @@ -833,6 +833,10 @@ struct ZCSubscreen byte curpage, sub_type; std::string name; + //!TODO Subscreen Scripts + word script; + int32_t initd[8]; + SubscrPage& cur_page(); SubscrPage* get_page(byte ind); bool get_page_pos(int32_t itmid, byte& pg, byte& pos); diff --git a/src/zc/ffscript.cpp b/src/zc/ffscript.cpp index 549160061d..99cfee074a 100644 --- a/src/zc/ffscript.cpp +++ b/src/zc/ffscript.cpp @@ -38194,10 +38194,17 @@ void FFScript::runOnLaunchEngine() //script_drawing_commands.push_commands(tmpDrawCommands); GameFlags &= ~GAMEFLAG_SCRIPTMENU_ACTIVE; } -bool FFScript::runGenericFrozenEngine(const word script) +bool FFScript::runGenericFrozenEngine(const word script, const int32_t *init_data) { static int32_t local_i = 0; if(script < 1 || script >= NUMSCRIPTSGENERIC) return false; + if(init_data) + { + for(int q = 0; q < 8; ++q) + { + user_scripts[script].initd[q] = init_data[q]; + } + } if(!genericscripts[script]->valid()) return false; //No script to run //Store script refinfo push_ri(); diff --git a/src/zc/ffscript.h b/src/zc/ffscript.h index c8c3db985e..b47f8743aa 100644 --- a/src/zc/ffscript.h +++ b/src/zc/ffscript.h @@ -991,7 +991,7 @@ void runF6Engine(); void runOnDeathEngine(); void runOnLaunchEngine(); void runGenericPassiveEngine(int32_t scrtm); -bool runGenericFrozenEngine(const word script); +bool runGenericFrozenEngine(const word script, const int32_t* init_data = nullptr); bool runActiveSubscreenScriptEngine(); bool runOnMapScriptEngine(); void doScriptMenuDraws(); diff --git a/src/zc/zc_subscr.cpp b/src/zc/zc_subscr.cpp index 2d8c56b86b..5740c95c4d 100644 --- a/src/zc/zc_subscr.cpp +++ b/src/zc/zc_subscr.cpp @@ -23,7 +23,8 @@ #include "base/mapscr.h" #include "base/misctypes.h" -extern HeroClass Hero; +extern HeroClass Hero; +extern FFScript FFCore; extern int32_t directItem; extern int32_t directItemA; extern int32_t directItemB; @@ -141,6 +142,7 @@ void dosubscr() auto& pg = new_subscreen_active->cur_page(); if (replay_version_check(0, 11)) load_control_state(); + byte btn_press = getIntBtnInput(0xFF, true, false, false, false, true); int32_t pos = pg.cursor_pos; if(rUp()) pg.move_cursor(SEL_UP); @@ -183,14 +185,15 @@ void dosubscr() SubscrWidget* widg = pg.get_sel_widg(); - //!TODO SUBSCR If widg needs to respond to other buttons, check them here... - byte btn_press = getIntBtnInput(0xFF, true, false, false, false, true); if(widg) { + if(widg->generic_script && (btn_press&widg->gen_script_btns)) + { + FFCore.runGenericFrozenEngine(widg->generic_script, widg->generic_initd); + } bool can_equip = true; - if(widg->getType() == widgITEMSLOT && !(widg->flags & SUBSCR_CURITM_NONEQP)) + if(widg->getType() == widgITEMSLOT && (widg->flags & SUBSCR_CURITM_NONEQP)) can_equip = false; - // if(can_equip) { @@ -329,8 +332,7 @@ void dosubscr() } } } - getIntBtnInput(btn_press, true, false, false, true); //eat input - if(pos!=pg.cursor_pos) + if(pos!=pg.cursor_pos) sfx(QMisc.miscsfx[sfxSUBSCR_CURSOR_MOVE]); do_dcounters(); diff --git a/src/zc/zc_sys.cpp b/src/zc/zc_sys.cpp index 1fbbc5cd9a..2aec707e46 100644 --- a/src/zc/zc_sys.cpp +++ b/src/zc/zc_sys.cpp @@ -76,7 +76,6 @@ int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c); extern byte monochrome_console; extern HeroClass Hero; -extern FFScript FFCore; extern ZModule zcm; extern zcmodule moduledata; extern sprite_list guys, items, Ewpns, Lwpns, Sitems, chainlinks, decorations; diff --git a/src/zq/zq_subscr.cpp b/src/zq/zq_subscr.cpp index 1c4e0fdf83..3651312030 100644 --- a/src/zq/zq_subscr.cpp +++ b/src/zq/zq_subscr.cpp @@ -340,6 +340,7 @@ void update_subscr_dlg(bool start); int32_t d_subscreen_proc(int32_t msg,DIALOG *d,int32_t) { SubscrPage& pg = subscr_edit.cur_page(); + int hei = subscr_edit.sub_type==sstPASSIVE ? 56 : 168; switch(msg) { case MSG_START: @@ -358,7 +359,6 @@ int32_t d_subscreen_proc(int32_t msg,DIALOG *d,int32_t) case MSG_DRAW: { Sitems.animate(); - int hei = subscr_edit.sub_type==sstPASSIVE ? 56 : 168; BITMAP *buf = create_bitmap_ex(8,256,hei); if(buf) @@ -411,7 +411,7 @@ int32_t d_subscreen_proc(int32_t msg,DIALOG *d,int32_t) if(isinRect(scaled_mouse_x,scaled_mouse_y,d->x, d->y, d->x+d->w-1, d->y+d->h-1)) { scaled_mouse_x = round((scaled_mouse_x - d->x) * (256.0/d->w)); - scaled_mouse_y = round((scaled_mouse_y - d->y) * (168.0/d->h)); + scaled_mouse_y = round((scaled_mouse_y - d->y) * (double(hei)/d->h)); } else scaled_mouse_x = scaled_mouse_y = -999; switch(ssmouse_type) @@ -1226,6 +1226,21 @@ static DIALOG subscreen_dlg[] = int32_t onActivePassive() { + bool run = true; + if(subscr_edit.sub_type == sstACTIVE && subscr_edit.pages.size()>1) + { + bool singular = subscr_edit.pages.size()==2; + std::string pgs = singular ? "page 2" : fmt::format("pages 2-{}",subscr_edit.pages.size()); + AlertDialog(fmt::format("Delete Page{}",singular?"":"s"), + fmt::format("Are you sure you want to delete {} by" + " switching to a passive subscreen?", pgs), + [&](bool ret,bool) + { + run = ret; + }).show(); + } + if(!run) return D_O_K; + if(subscr_edit.sub_type == sstPASSIVE) { subscr_edit.sub_type = sstACTIVE; @@ -1237,8 +1252,10 @@ int32_t onActivePassive() subscr_edit.sub_type = sstPASSIVE; subscreen_dlg[3].h=116; subscreen_dlg[4].h=subscreen_dlg[3].h-4; + while(subscr_edit.pages.size() > 1) + subscr_edit.delete_page(1); } - + update_subscr_dlg(false); return D_REDRAW; } @@ -2257,7 +2274,7 @@ void update_subscr_dlg(bool start) } subscreen_dlg[49].y = subscreen_dlg[48].y = subscreen_dlg[47].y = subscreen_dlg[46].y = subscreen_dlg[45].y = - subscreen_dlg[3].y+subscreen_dlg[3].h; + subscreen_dlg[3].y+168*2+2; subscreen_dlg[45].y += (subscreen_dlg[46].h-dlg_fontheight(subscreen_dlg[45]))/2; subscreen_dlg[50].y = subscreen_dlg[51].y = subscreen_dlg[52].y = @@ -2271,20 +2288,26 @@ void update_subscr_dlg(bool start) subscreen_dlg[8].w = subscreen_dlg[1].x-subscreen_dlg[8].x-2; } } - sprintf(pgbuf, "Pg %d/%zd", subscr_edit.curpage+1,subscr_edit.pages.size()); - int tw = 8+dlg_fontlen(subscreen_dlg[45]); - subscreen_dlg[50].x = subscreen_dlg[46].x = subscreen_dlg[45].x-(tw/2)-subscreen_dlg[46].w; - subscreen_dlg[51].x = subscreen_dlg[47].x = subscreen_dlg[45].x+(tw/2); - subscreen_dlg[52].x = subscreen_dlg[48].x = subscreen_dlg[46].x - subscreen_dlg[48].w; - subscreen_dlg[53].x = subscreen_dlg[49].x = subscreen_dlg[47].x + subscreen_dlg[47].w; - subscreen_dlg[54].x = subscreen_dlg[45].x - subscreen_dlg[54].w/2; - SETFLAG(subscreen_dlg[46].flags,D_DISABLED,subscr_edit.curpage<1); - SETFLAG(subscreen_dlg[47].flags,D_DISABLED,subscr_edit.curpage>=subscr_edit.pages.size()-1); - SETFLAG(subscreen_dlg[49].flags,D_DISABLED,subscr_edit.pages.size()>=MAX_SUBSCR_PAGES); - SETFLAG(subscreen_dlg[50].flags,D_DISABLED,subscr_edit.curpage<1); - SETFLAG(subscreen_dlg[52].flags,D_DISABLED,subscr_edit.curpage<1); - SETFLAG(subscreen_dlg[51].flags,D_DISABLED,subscr_edit.curpage>=subscr_edit.pages.size()-1); - SETFLAG(subscreen_dlg[53].flags,D_DISABLED,subscr_edit.curpage>=subscr_edit.pages.size()-1); + bool nopages = subscr_edit.sub_type==sstPASSIVE; + for(int q = 45; q <= 54; ++q) + SETFLAG(subscreen_dlg[q].flags,D_HIDDEN,nopages); + if(!nopages) + { + sprintf(pgbuf, "Pg %d/%zd", subscr_edit.curpage+1,subscr_edit.pages.size()); + SETFLAG(subscreen_dlg[46].flags,D_DISABLED,subscr_edit.curpage<1); + SETFLAG(subscreen_dlg[47].flags,D_DISABLED,subscr_edit.curpage>=subscr_edit.pages.size()-1); + SETFLAG(subscreen_dlg[49].flags,D_DISABLED,subscr_edit.pages.size()>=MAX_SUBSCR_PAGES); + SETFLAG(subscreen_dlg[50].flags,D_DISABLED,subscr_edit.curpage<1); + SETFLAG(subscreen_dlg[52].flags,D_DISABLED,subscr_edit.curpage<1); + SETFLAG(subscreen_dlg[51].flags,D_DISABLED,subscr_edit.curpage>=subscr_edit.pages.size()-1); + SETFLAG(subscreen_dlg[53].flags,D_DISABLED,subscr_edit.curpage>=subscr_edit.pages.size()-1); + int tw = 8+dlg_fontlen(subscreen_dlg[45]); + subscreen_dlg[50].x = subscreen_dlg[46].x = subscreen_dlg[45].x-(tw/2)-subscreen_dlg[46].w; + subscreen_dlg[51].x = subscreen_dlg[47].x = subscreen_dlg[45].x+(tw/2); + subscreen_dlg[52].x = subscreen_dlg[48].x = subscreen_dlg[46].x - subscreen_dlg[48].w; + subscreen_dlg[53].x = subscreen_dlg[49].x = subscreen_dlg[47].x + subscreen_dlg[47].w; + subscreen_dlg[54].x = subscreen_dlg[45].x - subscreen_dlg[54].w/2; + } // Disable pastes if no copies bool nocopies = (!propCopyWidg || propCopyWidg->getType()==widgNULL); SETFLAG(subscreen_rc_menu[3].flags,D_DISABLED,nocopies); @@ -2293,7 +2316,6 @@ void update_subscr_dlg(bool start) SETFLAG(ss_edit_menu[5].flags,D_DISABLED,nocopies); SETFLAG(ss_edit_menu[6].flags,D_DISABLED,nocopies); SETFLAG(ss_edit_menu[7].flags,D_DISABLED,nocopies); - zprint2("TXTFLD Y H %d %d\n",subscreen_dlg[8].y,subscreen_dlg[53].y+subscreen_dlg[53].h); } void broadcast_dialog_message(DIALOG* dialog, int32_t msg, int32_t c); bool edit_subscreen()