Skip to content

Commit

Permalink
Game Menu: Fixed positioning of page titles in Options menus
Browse files Browse the repository at this point in the history
Pages are now dynamically constructed.
  • Loading branch information
danij-deng committed Jan 4, 2012
1 parent fb6109a commit a563ab4
Show file tree
Hide file tree
Showing 7 changed files with 642 additions and 642 deletions.
49 changes: 40 additions & 9 deletions doomsday/plugins/common/include/hu_lib.h
Expand Up @@ -194,12 +194,19 @@ typedef struct mn_object_s {
void* data1;
int data2;

// Auto initialized:

/// Current geometry.
Rect* _geometry;

/// MenuPage which owns this object (if any).
struct mn_page_s* _page;
} mn_object_t;

mn_obtype_e MNObject_Type(const mn_object_t* obj);

struct mn_page_s* MNObject_Page(const mn_object_t* obj);

int MNObject_Flags(const mn_object_t* obj);

/**
Expand Down Expand Up @@ -292,23 +299,48 @@ typedef enum {
#define VALID_MNPAGE_FONTID(v) ((v) >= MENU_FONT1 && (v) < MENU_FONT_COUNT)

typedef struct mn_page_s {
mn_object_t* objects; // List of objects.
/// Collection of objects on this page.
mn_object_t* objects;
int objectsCount;

/// "Physical" geometry in fixed 320x200 screen coordinate space.
Point2Raw origin;
Rect* geometry;

/// Previous page else @c NULL
struct mn_page_s* previous;

/// Title of this page.
ddstring_t title;

/// Index of the currently focused object else @c -1
int focus;

/// Predefined fonts objects on this page.
fontid_t fonts[MENU_FONT_COUNT];

/// Predefined colors for objects on this page.
uint colors[MENU_COLOR_COUNT];
void (*drawer) (struct mn_page_s* page, const Point2Raw* origin);

/// Page drawing routine.
void (*drawer) (struct mn_page_s* page, const Point2Raw* offset);

/// Menu command responder routine.
int (*cmdResponder) (struct mn_page_s* page, menucommand_e cmd);
struct mn_page_s* previous; // Pointer to the previous page, if any.
void* data;

// Auto-initialized.
int objectsCount;
int focus; // Index of the focus object.
Rect* geometry;
/// User data.
void* userData;
} mn_page_t;

void MNPage_Initialize(mn_page_t* page);

void MNPage_SetTitle(mn_page_t* page, const char* title);

void MNPage_SetX(mn_page_t* page, int x);
void MNPage_SetY(mn_page_t* page, int y);

void MNPage_SetPreviousPage(mn_page_t* page, mn_page_t* prevPage);

/// @return Currently focused object else @c NULL
mn_object_t* MNPage_FocusObject(mn_page_t* page);

Expand Down Expand Up @@ -680,7 +712,6 @@ extern const mn_rendstate_t* mnRendState;

short MN_MergeMenuEffectWithDrawTextFlags(short f);

int MN_CountObjects(mn_object_t* list);
mn_object_t* MN_MustFindObjectOnPage(mn_page_t* page, int group, int flags);

void MN_DrawPage(mn_page_t* page, float alpha, boolean showFocusCursor);
Expand Down
40 changes: 8 additions & 32 deletions doomsday/plugins/common/include/hu_menu.h
Expand Up @@ -76,35 +76,7 @@
#define MENU_CURSOR_FRAMECOUNT 2
#define MENU_CURSOR_TICSPERFRAME 8

extern mn_page_t MainMenu;
extern mn_page_t GameTypeMenu;
#if __JHEXEN__
extern mn_page_t PlayerClassMenu;
#endif
#if __JDOOM__ || __JHERETIC__
extern mn_page_t EpisodeMenu;
#endif
//extern mn_page_t SkillMenu;
extern mn_page_t OptionsMenu;
extern mn_page_t SoundMenu;
extern mn_page_t GameplayMenu;
extern mn_page_t HudMenu;
extern mn_page_t AutomapMenu;
extern mn_object_t AutomapMenuObjects[];
#if __JHERETIC__ || __JHEXEN__
extern mn_page_t FilesMenu;
#endif
extern mn_page_t LoadMenu;
extern mn_page_t SaveMenu;
extern mn_page_t MultiplayerMenu;
extern mn_page_t PlayerSetupMenu;
#if __JHERETIC__ || __JHEXEN__
extern mn_page_t InventoryMenu;
#endif
extern mn_page_t WeaponMenu;

extern int menuTime;

extern boolean menuNominatingQuickSaveSlot;

/// Register the console commands, variables, etc..., of this module.
Expand Down Expand Up @@ -137,6 +109,13 @@ void Hu_MenuTicker(timespan_t ticLength);
/// @return @c true if the menu is presently visible.
boolean Hu_MenuIsVisible(void);

mn_page_t* Hu_MenuFindPageByName(const char* name);

mn_page_t* Hu_MenuNewPage(const char* name, const Point2Raw* origin,
void (*drawer) (struct mn_page_s* page, const Point2Raw* origin),
int (*cmdResponder) (struct mn_page_s* page, menucommand_e cmd),
void* userData);

/**
* This is the main menu drawing routine (called every tic by the drawing
* loop) Draws the current menu 'page' by calling the funcs attached to
Expand All @@ -147,8 +126,7 @@ void Hu_MenuDrawer(void);
void Hu_MenuDrawFocusCursor(int x, int y, int focusObjectHeight, float alpha);

void Hu_MenuDrawPageTitle(const char* title, int x, int y);

void Hu_MenuDrawPageNavigation(mn_page_t* page, int x, int y);
void Hu_MenuDrawPageHelp(const char* help, int x, int y);

/// @return @c true if the input event @a ev was eaten.
int Hu_MenuPrivilegedResponder(event_t* ev);
Expand Down Expand Up @@ -189,8 +167,6 @@ mn_page_t* Hu_MenuActivePage(void);
*/
void Hu_MenuSetActivePage(mn_page_t* page);

void Hu_MenuComposeSubpageString(mn_page_t* page, size_t bufSize, char* buf);

/**
* Initialize a new singleplayer game according to the options set via the menu.
* @param confirmed If @c true this game configuration has already been confirmed.
Expand Down
2 changes: 0 additions & 2 deletions doomsday/plugins/common/include/m_ctrl.h
Expand Up @@ -31,8 +31,6 @@

#include "hu_lib.h"

extern mn_page_t ControlsMenu;

void Hu_MenuInitControlsPage(void);
void Hu_MenuDrawControlsPage(mn_page_t* page, const Point2Raw* origin);
void Hu_MenuControlGrabDrawer(const char* niceName, float alpha);
Expand Down
6 changes: 3 additions & 3 deletions doomsday/plugins/common/src/g_game.c
Expand Up @@ -3289,7 +3289,7 @@ static void openLoadMenu(void)
/// \fixme This should be called automatically when opening the page
/// thus making this function redundant.
Hu_MenuUpdateGameSaveWidgets();
Hu_MenuSetActivePage(&LoadMenu);
Hu_MenuSetActivePage(Hu_MenuFindPageByName("LoadGame"));
}

static void openSaveMenu(void)
Expand All @@ -3298,7 +3298,7 @@ static void openSaveMenu(void)
/// \fixme This should be called automatically when opening the page
/// thus making this function redundant.
Hu_MenuUpdateGameSaveWidgets();
Hu_MenuSetActivePage(&SaveMenu);
Hu_MenuSetActivePage(Hu_MenuFindPageByName("SaveGame"));
}

int G_QuickLoadGameResponse(msgresponse_t response, void* context)
Expand Down Expand Up @@ -3385,7 +3385,7 @@ void G_QuickSaveGame(void)
{
Hu_MenuCommand(MCMD_OPEN);
Hu_MenuUpdateGameSaveWidgets();
Hu_MenuSetActivePage(&SaveMenu);
Hu_MenuSetActivePage(Hu_MenuFindPageByName("SaveGame"));
menuNominatingQuickSaveSlot = true;
return;
}
Expand Down
103 changes: 95 additions & 8 deletions doomsday/plugins/common/src/hu_lib.c
Expand Up @@ -697,13 +697,6 @@ static void MNEdit_LoadResources(void)
pEditMiddle = R_DeclarePatch(MNDATA_EDIT_BACKGROUND_PATCH_MIDDLE);
}

int MN_CountObjects(mn_object_t* list)
{
int count;
for(count = 0; MNObject_Type(list) != MN_NONE; list++, count++);
return count;
}

mn_object_t* MN_MustFindObjectOnPage(mn_page_t* page, int group, int flags)
{
mn_object_t* obj = MNPage_FindObject(page, group, flags);
Expand Down Expand Up @@ -856,6 +849,68 @@ static void applyPageLayout(mn_page_t* page)
}
}

static void composeSubpageString(mn_page_t* page, char* buf, size_t bufSize)
{
assert(page);
if(!buf || 0 == bufSize) return;
dd_snprintf(buf, bufSize, "Page %i/%i", 0, 0);
}

static void drawPageNavigation(mn_page_t* page, int x, int y)
{
const int currentPage = 0;//(page->firstObject + page->numVisObjects/2) / page->numVisObjects + 1;
const int totalPages = 1;//(int)ceil((float)page->objectsCount/page->numVisObjects);
#if __JDOOM__ || __JDOOM64__
char buf[1024];
#endif

if(!page || totalPages <= 1) return;

#if __JDOOM__ || __JDOOM64__
composeSubpageString(page, buf, 1024);

DGL_Enable(DGL_TEXTURE_2D);
FR_SetFont(FID(GF_FONTA));
FR_SetColorv(cfg.menuTextColors[1]);
FR_SetAlpha(mnRendState->pageAlpha);

FR_DrawTextXY3(buf, x, y, ALIGN_TOP, MN_MergeMenuEffectWithDrawTextFlags(0));

DGL_Disable(DGL_TEXTURE_2D);
#else
DGL_Enable(DGL_TEXTURE_2D);
DGL_Color4f(1, 1, 1, mnRendState->pageAlpha);

GL_DrawPatchXY2( pInvPageLeft[currentPage == 0 || (menuTime & 8)], x - 144, y, ALIGN_RIGHT);
GL_DrawPatchXY2(pInvPageRight[currentPage == totalPages-1 || (menuTime & 8)], x + 144, y, ALIGN_LEFT);

DGL_Disable(DGL_TEXTURE_2D);
#endif
}

static void drawPageHeading(mn_page_t* page, const Point2Raw* offset)
{
Point2Raw origin;

if(!page) return;

/// \kludge no title = no heading.
if(Str_IsEmpty(&page->title)) return;

origin.x = SCREENWIDTH/2;
origin.y = (SCREENHEIGHT/2) - ((SCREENHEIGHT/2-5)/cfg.menuScale);
if(offset)
{
origin.x += offset->x;
origin.y += offset->y;
}

FR_PushAttrib();
Hu_MenuDrawPageTitle(Str_Text(&page->title), origin.x, origin.y); origin.y += 16;
drawPageNavigation(page, origin.x, origin.y);
FR_PopAttrib();
}

void MN_DrawPage(mn_page_t* page, float alpha, boolean showFocusCursor)
{
mn_object_t* focusObj;
Expand Down Expand Up @@ -959,7 +1014,7 @@ void MN_DrawPage(mn_page_t* page, float alpha, boolean showFocusCursor)
FR_PopAttrib();
}

// Finally, the focus cursor?
// How about a focus cursor?
/// \todo cursor should be drawn on top of the page drawer.
if(showFocusCursor && focusObj)
{
Expand All @@ -969,6 +1024,8 @@ void MN_DrawPage(mn_page_t* page, float alpha, boolean showFocusCursor)
DGL_MatrixMode(DGL_MODELVIEW);
DGL_PopMatrix();

drawPageHeading(page, NULL/*no offset*/);

// The page has its own drawer.
if(page->drawer)
{
Expand All @@ -984,6 +1041,30 @@ static boolean MNActionInfo_IsActionExecuteable(mn_actioninfo_t* info)
return (info->callback != 0);
}

void MNPage_SetTitle(mn_page_t* page, const char* title)
{
assert(page);
Str_Set(&page->title, title? title : "");
}

void MNPage_SetX(mn_page_t* page, int x)
{
assert(page);
page->origin.x = x;
}

void MNPage_SetY(mn_page_t* page, int y)
{
assert(page);
page->origin.y = y;
}

void MNPage_SetPreviousPage(mn_page_t* page, mn_page_t* prevPage)
{
assert(page);
page->previous = prevPage;
}

mn_object_t* MNPage_FocusObject(mn_page_t* page)
{
assert(page);
Expand Down Expand Up @@ -1246,6 +1327,12 @@ mn_obtype_e MNObject_Type(const mn_object_t* obj)
return obj->_type;
}

mn_page_t* MNObject_Page(const mn_object_t* obj)
{
assert(obj);
return obj->_page;
}

int MNObject_Flags(const mn_object_t* obj)
{
assert(obj);
Expand Down

0 comments on commit a563ab4

Please sign in to comment.