Convert main menu to inherit from newmenu
This commit is contained in:
parent
8e65573c56
commit
76acfdd38f
|
@ -117,9 +117,9 @@ static inline window_event_result (WINDOW_SEND_EVENT)(window &w, const d_event &
|
||||||
void menu_destroy_hook(window *w);
|
void menu_destroy_hook(window *w);
|
||||||
|
|
||||||
template <typename T1, typename... ConstructionArgs>
|
template <typename T1, typename... ConstructionArgs>
|
||||||
T1 *window_create(const short x, const short y, const short w, const short h, ConstructionArgs &&... args)
|
T1 *window_create(ConstructionArgs &&... args)
|
||||||
{
|
{
|
||||||
auto r = std::make_unique<T1>(x, y, w, h, std::forward<ConstructionArgs>(args)...);
|
auto r = std::make_unique<T1>(std::forward<ConstructionArgs>(args)...);
|
||||||
r->send_creation_events();
|
r->send_creation_events();
|
||||||
return r.release();
|
return r.release();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||||
|
|
||||||
#include "fwd-event.h"
|
#include "fwd-event.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -44,7 +43,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||||
#ifdef dsx
|
#ifdef dsx
|
||||||
#include "gamefont.h"
|
#include "gamefont.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#endif
|
|
||||||
|
namespace dcx {
|
||||||
|
|
||||||
struct listbox;
|
struct listbox;
|
||||||
|
|
||||||
|
@ -154,11 +154,8 @@ public:
|
||||||
ntstring<NM_MAX_TEXT_LEN> saved_text;
|
ntstring<NM_MAX_TEXT_LEN> saved_text;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace dcx {
|
|
||||||
|
|
||||||
extern const char *Newmenu_allowed_chars;
|
extern const char *Newmenu_allowed_chars;
|
||||||
|
|
||||||
#ifdef dsx
|
|
||||||
enum class tab_processing_flag : uint8_t
|
enum class tab_processing_flag : uint8_t
|
||||||
{
|
{
|
||||||
ignore,
|
ignore,
|
||||||
|
@ -281,11 +278,9 @@ int newmenu_do2(const menu_title title, const menu_subtitle subtitle, partial_ra
|
||||||
{
|
{
|
||||||
return newmenu_do2(title, subtitle, std::move(items), reinterpret_cast<newmenu_subfunction>(subfunction), static_cast<void *>(const_cast<T *>(userdata)), citem, filename);
|
return newmenu_do2(title, subtitle, std::move(items), reinterpret_cast<newmenu_subfunction>(subfunction), static_cast<void *>(const_cast<T *>(userdata)), citem, filename);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef dsx
|
|
||||||
namespace dsx {
|
namespace dsx {
|
||||||
newmenu *newmenu_do4(menu_title title, menu_subtitle subtitle, partial_range_t<newmenu_item *> items, newmenu_subfunction subfunction, void *userdata, int citem, menu_filename filename, tiny_mode_flag TinyMode = tiny_mode_flag::normal, tab_processing_flag TabsFlag = tab_processing_flag::ignore);
|
newmenu *newmenu_do4(menu_title title, menu_subtitle subtitle, partial_range_t<newmenu_item *> items, newmenu_subfunction subfunction, void *userdata, int citem, menu_filename filename, tiny_mode_flag TinyMode = tiny_mode_flag::normal, tab_processing_flag TabsFlag = tab_processing_flag::ignore);
|
||||||
|
|
||||||
|
@ -360,7 +355,6 @@ typedef cstring_tie<5> nm_messagebox_tie;
|
||||||
|
|
||||||
int nm_messagebox_str(menu_title title, const nm_messagebox_tie &tie, menu_subtitle str);
|
int nm_messagebox_str(menu_title title, const nm_messagebox_tie &tie, menu_subtitle str);
|
||||||
int vnm_messagebox_aN(menu_title title, const nm_messagebox_tie &tie, const char *format, ...) __attribute_format_printf(3, 4);
|
int vnm_messagebox_aN(menu_title title, const nm_messagebox_tie &tie, const char *format, ...) __attribute_format_printf(3, 4);
|
||||||
#endif
|
|
||||||
|
|
||||||
void nm_draw_background(grs_canvas &, int x1, int y1, int x2, int y2);
|
void nm_draw_background(grs_canvas &, int x1, int y1, int x2, int y2);
|
||||||
void nm_restore_background(int x, int y, int w, int h);
|
void nm_restore_background(int x, int y, int w, int h);
|
||||||
|
@ -386,12 +380,12 @@ void nm_restore_background(int x, int y, int w, int h);
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
namespace dcx {
|
||||||
window *listbox_get_window(listbox &lb);
|
window *listbox_get_window(listbox &lb);
|
||||||
const char **listbox_get_items(listbox &lb);
|
const char **listbox_get_items(listbox &lb);
|
||||||
int listbox_get_citem(listbox &lb);
|
int listbox_get_citem(listbox &lb);
|
||||||
void listbox_delete_item(listbox &lb, int item);
|
void listbox_delete_item(listbox &lb, int item);
|
||||||
|
|
||||||
namespace dcx {
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using listbox_subfunction_t = window_event_result (*)(listbox *menu,const d_event &event, T *userdata);
|
using listbox_subfunction_t = window_event_result (*)(listbox *menu,const d_event &event, T *userdata);
|
||||||
|
|
||||||
|
@ -656,5 +650,4 @@ static constexpr menu_number_bias_wrapper_t<B, T> menu_number_bias_wrapper(T &t)
|
||||||
{
|
{
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -131,10 +131,10 @@ enum class main_menu_item_index
|
||||||
end,
|
end,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct main_menu
|
struct main_menu_items
|
||||||
{
|
{
|
||||||
enumerated_array<newmenu_item, static_cast<std::size_t>(main_menu_item_index::end), main_menu_item_index> m;
|
enumerated_array<newmenu_item, static_cast<std::size_t>(main_menu_item_index::end), main_menu_item_index> m;
|
||||||
main_menu();
|
main_menu_items();
|
||||||
};
|
};
|
||||||
|
|
||||||
#if DXX_USE_UDP
|
#if DXX_USE_UDP
|
||||||
|
@ -167,7 +167,7 @@ netgame_menu::netgame_menu()
|
||||||
|
|
||||||
static std::array<window *, 16> menus;
|
static std::array<window *, 16> menus;
|
||||||
|
|
||||||
main_menu::main_menu()
|
main_menu_items::main_menu_items()
|
||||||
{
|
{
|
||||||
nm_set_item_menu(m[main_menu_item_index::start_new_singleplayer_game], TXT_NEW_GAME);
|
nm_set_item_menu(m[main_menu_item_index::start_new_singleplayer_game], TXT_NEW_GAME);
|
||||||
nm_set_item_menu(m[main_menu_item_index::load_existing_singleplayer_game], TXT_LOAD_GAME);
|
nm_set_item_menu(m[main_menu_item_index::load_existing_singleplayer_game], TXT_LOAD_GAME);
|
||||||
|
@ -276,6 +276,15 @@ namespace dsx {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
struct main_menu : main_menu_items, newmenu
|
||||||
|
{
|
||||||
|
main_menu(grs_canvas &src) :
|
||||||
|
newmenu(menu_title{""}, menu_subtitle{nullptr}, menu_filename{Menu_pcx_name}, tiny_mode_flag::normal, tab_processing_flag::ignore, adjusted_citem::create(m, 0), src)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual int subfunction_handler(const d_event &event) override;
|
||||||
|
};
|
||||||
|
|
||||||
static window_event_result do_new_game_menu();
|
static window_event_result do_new_game_menu();
|
||||||
#ifndef RELEASE
|
#ifndef RELEASE
|
||||||
void do_sandbox_menu();
|
void do_sandbox_menu();
|
||||||
|
@ -687,7 +696,7 @@ int dispatch_menu_option(const netgame_menu_item_index select)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
static int main_menu_handler(newmenu *, const d_event &event, main_menu *mm)
|
int main_menu::subfunction_handler(const d_event &event)
|
||||||
{
|
{
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
|
@ -758,7 +767,6 @@ static int main_menu_handler(newmenu *, const d_event &event, main_menu *mm)
|
||||||
}
|
}
|
||||||
|
|
||||||
case EVENT_WINDOW_CLOSE:
|
case EVENT_WINDOW_CLOSE:
|
||||||
std::default_delete<main_menu>()(mm);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -775,9 +783,8 @@ static int main_menu_handler(newmenu *, const d_event &event, main_menu *mm)
|
||||||
//returns number of item chosen
|
//returns number of item chosen
|
||||||
int DoMenu()
|
int DoMenu()
|
||||||
{
|
{
|
||||||
main_menu *mm = new main_menu;
|
auto menu = window_create<main_menu>(grd_curscreen->sc_canvas);
|
||||||
newmenu_do3(menu_title{""}, menu_subtitle{nullptr}, mm->m, main_menu_handler, mm, 0, menu_filename{Menu_pcx_name});
|
(void)menu;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1747,6 +1747,8 @@ int nm_messagebox_str(const menu_title title, const nm_messagebox_tie &tie, cons
|
||||||
|
|
||||||
#define LB_ITEMS_ON_SCREEN 8
|
#define LB_ITEMS_ON_SCREEN 8
|
||||||
|
|
||||||
|
namespace dcx {
|
||||||
|
|
||||||
struct listbox : listbox_layout, window
|
struct listbox : listbox_layout, window
|
||||||
{
|
{
|
||||||
listbox(grs_canvas &canvas, listbox_layout &&ll) :
|
listbox(grs_canvas &canvas, listbox_layout &&ll) :
|
||||||
|
@ -1793,6 +1795,8 @@ void listbox_delete_item(listbox &lb, int item)
|
||||||
lb.citem = lb.nitems ? lb.nitems - 1 : 0;
|
lb.citem = lb.nitems ? lb.nitems - 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
static void update_scroll_position(listbox_layout &lb)
|
static void update_scroll_position(listbox_layout &lb)
|
||||||
|
|
Loading…
Reference in a new issue