ddnet/src/game/client/components/menus.h

339 lines
10 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef GAME_CLIENT_COMPONENTS_MENUS_H
#define GAME_CLIENT_COMPONENTS_MENUS_H
#include <base/vmath.h>
#include <base/tl/sorted_array.h>
#include <engine/demo.h>
2011-06-26 15:10:13 +00:00
#include <engine/friends.h>
2011-03-26 16:44:34 +00:00
#include <game/voting.h>
2010-05-29 07:25:38 +00:00
#include <game/client/component.h>
#include <game/client/ui.h>
// compnent to fetch keypresses, override all other input
class CMenusKeyBinder : public CComponent
{
public:
bool m_TakeKey;
bool m_GotKey;
IInput::CEvent m_Key;
CMenusKeyBinder();
virtual bool OnInput(IInput::CEvent Event);
};
class CMenus : public CComponent
{
2010-05-29 07:25:38 +00:00
static vec4 ms_GuiColor;
static vec4 ms_ColorTabbarInactiveOutgame;
static vec4 ms_ColorTabbarActiveOutgame;
static vec4 ms_ColorTabbarInactiveIngame;
static vec4 ms_ColorTabbarActiveIngame;
static vec4 ms_ColorTabbarInactive;
static vec4 ms_ColorTabbarActive;
2010-05-29 07:25:38 +00:00
vec4 ButtonColorMul(const void *pID);
int DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
int DoButton_Sprite(const void *pID, int ImageID, int SpriteID, int Checked, const CUIRect *pRect, int Corners);
int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect);
2010-05-29 07:25:38 +00:00
int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
int DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners);
int DoButton_CheckBox_Common(const void *pID, const char *pText, const char *pBoxText, const CUIRect *pRect);
int DoButton_CheckBox(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
int DoButton_CheckBox_Number(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
/*static void ui_draw_menu_button(const void *id, const char *text, int checked, const CUIRect *r, const void *extra);
static void ui_draw_keyselect_button(const void *id, const char *text, int checked, const CUIRect *r, const void *extra);
static void ui_draw_menu_tab_button(const void *id, const char *text, int checked, const CUIRect *r, const void *extra);
static void ui_draw_settings_tab_button(const void *id, const char *text, int checked, const CUIRect *r, const void *extra);
*/
int DoButton_Icon(int ImageId, int SpriteId, const CUIRect *pRect);
2010-05-29 07:25:38 +00:00
int DoButton_GridHeader(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
//static void ui_draw_browse_icon(int what, const CUIRect *r);
//static void ui_draw_grid_header(const void *id, const char *text, int checked, const CUIRect *r, const void *extra);
2010-05-29 07:25:38 +00:00
/*static void ui_draw_checkbox_common(const void *id, const char *text, const char *boxtext, const CUIRect *r, const void *extra);
static void ui_draw_checkbox(const void *id, const char *text, int checked, const CUIRect *r, const void *extra);
static void ui_draw_checkbox_number(const void *id, const char *text, int checked, const CUIRect *r, const void *extra);
*/
int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden=false, int Corners=CUI::CORNER_ALL);
2010-05-29 07:25:38 +00:00
//static int ui_do_edit_box(void *id, const CUIRect *rect, char *str, unsigned str_size, float font_size, bool hidden=false);
float DoScrollbarV(const void *pID, const CUIRect *pRect, float Current);
float DoScrollbarH(const void *pID, const CUIRect *pRect, float Current);
void DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
int DoKeyReader(void *pID, const CUIRect *pRect, int Key);
//static int ui_do_key_reader(void *id, const CUIRect *rect, int key);
void UiDoGetButtons(int Start, int Stop, CUIRect View);
struct CListboxItem
{
int m_Visible;
int m_Selected;
CUIRect m_Rect;
CUIRect m_HitRect;
};
void UiDoListboxStart(const void *pID, const CUIRect *pRect, float RowHeight, const char *pTitle, const char *pBottomText, int NumItems,
int ItemsPerRow, int SelectedIndex, float ScrollValue);
CListboxItem UiDoListboxNextItem(const void *pID, bool Selected = false);
CListboxItem UiDoListboxNextRow();
2010-05-29 07:25:38 +00:00
int UiDoListboxEnd(float *pScrollValue, bool *pItemActivated);
2010-05-29 07:25:38 +00:00
//static void demolist_listdir_callback(const char *name, int is_dir, void *user);
//static void demolist_list_callback(const CUIRect *rect, int index, void *user);
enum
{
POPUP_NONE=0,
POPUP_FIRST_LAUNCH,
POPUP_CONNECTING,
POPUP_MESSAGE,
POPUP_DISCONNECTED,
POPUP_PURE,
POPUP_LANGUAGE,
POPUP_COUNTRY,
POPUP_DELETE_DEMO,
POPUP_RENAME_DEMO,
2011-03-23 12:06:35 +00:00
POPUP_REMOVE_FRIEND,
POPUP_SOUNDERROR,
2010-05-29 07:25:38 +00:00
POPUP_PASSWORD,
POPUP_QUIT,
2010-05-29 07:25:38 +00:00
};
enum
{
PAGE_NEWS=1,
PAGE_GAME,
PAGE_PLAYERS,
2010-05-29 07:25:38 +00:00
PAGE_SERVER_INFO,
PAGE_CALLVOTE,
PAGE_INTERNET,
PAGE_LAN,
PAGE_FAVORITES,
PAGE_DEMOS,
PAGE_SETTINGS,
PAGE_SYSTEM,
2011-02-23 07:33:21 +00:00
PAGE_DDRace,
PAGE_BROWSER,
PAGE_GHOST
2010-05-29 07:25:38 +00:00
};
int m_GamePage;
int m_Popup;
int m_ActivePage;
bool m_MenuActive;
bool m_UseMouseButtons;
vec2 m_MousePos;
2010-05-29 07:25:38 +00:00
int64 m_LastInput;
2011-02-27 16:56:03 +00:00
// loading
int m_LoadCurrent;
int m_LoadTotal;
2010-05-29 07:25:38 +00:00
//
char m_aMessageTopic[512];
char m_aMessageBody[512];
char m_aMessageButton[512];
2010-05-29 07:25:38 +00:00
void PopupMessage(const char *pTopic, const char *pBody, const char *pButton);
// TODO: this is a bit ugly but.. well.. yeah
2010-05-29 07:25:38 +00:00
enum { MAX_INPUTEVENTS = 32 };
static IInput::CEvent m_aInputEvents[MAX_INPUTEVENTS];
static int m_NumInputEvents;
2010-05-29 07:25:38 +00:00
// some settings
static float ms_ButtonHeight;
static float ms_ListheaderHeight;
static float ms_FontmodHeight;
// for settings
bool m_NeedRestartGraphics;
bool m_NeedRestartSound;
2010-05-29 07:25:38 +00:00
bool m_NeedSendinfo;
int m_SettingPlayerPage;
2010-05-29 07:25:38 +00:00
//
bool m_EscapePressed;
bool m_EnterPressed;
bool m_DeletePressed;
2010-12-16 00:52:29 +00:00
// for map download popup
int64 m_DownloadLastCheckTime;
int m_DownloadLastCheckSize;
float m_DownloadSpeed;
2010-05-29 07:25:38 +00:00
// for call vote
int m_CallvoteSelectedOption;
int m_CallvoteSelectedPlayer;
2011-03-26 16:44:34 +00:00
char m_aCallvoteReason[VOTE_REASON_LENGTH];
2010-05-29 07:25:38 +00:00
// demo
struct CDemoItem
{
char m_aFilename[128];
char m_aName[128];
bool m_IsDir;
2010-10-06 21:07:35 +00:00
int m_StorageType;
bool m_InfosLoaded;
bool m_Valid;
CDemoHeader m_Info;
bool operator<(const CDemoItem &Other) { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false :
m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false :
str_comp_filenames(m_aFilename, Other.m_aFilename) < 0; }
2010-05-29 07:25:38 +00:00
};
//sorted_array<CDemoItem> m_lDemos;
2010-06-04 20:14:02 +00:00
char m_aCurrentDemoFolder[256];
char m_aCurrentDemoFile[64];
int m_DemolistSelectedIndex;
bool m_DemolistSelectedIsDir;
int m_DemolistStorageType;
void DemolistOnUpdate(bool Reset);
//void DemolistPopulate();
static int DemolistFetchCallback(const char *pName, int IsDir, int StorageType, void *pUser);
2011-03-23 12:06:35 +00:00
2011-06-26 15:10:13 +00:00
// friends
struct CFriendItem
{
const CFriendInfo *m_pFriendInfo;
int m_NumFound;
bool operator<(const CFriendItem &Other)
{
if(m_NumFound && !Other.m_NumFound)
return true;
else if(!m_NumFound && Other.m_NumFound)
return false;
else
{
int Result = str_comp(m_pFriendInfo->m_aName, Other.m_pFriendInfo->m_aName);
if(Result)
return Result < 0;
else
return str_comp(m_pFriendInfo->m_aClan, Other.m_pFriendInfo->m_aClan) < 0;
}
}
};
sorted_array<CFriendItem> m_lFriends;
2011-03-23 12:06:35 +00:00
int m_FriendlistSelectedIndex;
2011-06-26 15:10:13 +00:00
void FriendlistOnUpdate();
2010-05-29 07:25:38 +00:00
// found in menus.cpp
int Render();
//void render_background();
//void render_loading(float percent);
int RenderMenubar(CUIRect r);
void RenderNews(CUIRect MainView);
2010-05-29 07:25:38 +00:00
// found in menus_demo.cpp
void RenderDemoPlayer(CUIRect MainView);
void RenderDemoList(CUIRect MainView);
2010-05-29 07:25:38 +00:00
// found in menus_ingame.cpp
void RenderGame(CUIRect MainView);
void RenderPlayers(CUIRect MainView);
2010-05-29 07:25:38 +00:00
void RenderServerInfo(CUIRect MainView);
void RenderServerControl(CUIRect MainView);
void RenderServerControlKick(CUIRect MainView, bool FilterSpectators);
2010-05-29 07:25:38 +00:00
void RenderServerControlServer(CUIRect MainView);
2010-05-29 07:25:38 +00:00
// found in menus_browser.cpp
int m_SelectedIndex;
2011-06-26 15:10:13 +00:00
int m_ScrollOffset;
2010-05-29 07:25:38 +00:00
void RenderServerbrowserServerList(CUIRect View);
void RenderServerbrowserServerDetail(CUIRect View);
void RenderServerbrowserFilters(CUIRect View);
2011-03-23 12:06:35 +00:00
void RenderServerbrowserFriends(CUIRect View);
2010-05-29 07:25:38 +00:00
void RenderServerbrowser(CUIRect MainView);
2011-06-26 15:10:13 +00:00
static void ConchainFriendlistUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainServerbrowserUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
2010-05-29 07:25:38 +00:00
// found in menus_settings.cpp
void RenderLanguageSelection(CUIRect MainView);
2010-05-29 07:25:38 +00:00
void RenderSettingsGeneral(CUIRect MainView);
void RenderSettingsPlayer(CUIRect MainView);
2011-04-01 17:36:44 +00:00
void RenderSettingsTee(CUIRect MainView);
2010-05-29 07:25:38 +00:00
void RenderSettingsControls(CUIRect MainView);
void RenderSettingsGraphics(CUIRect MainView);
void RenderSettingsSound(CUIRect MainView);
void RenderSettings(CUIRect MainView);
2010-05-29 07:25:38 +00:00
void SetActive(bool Active);
public:
void RenderBackground();
void UseMouseButtons(bool Use) { m_UseMouseButtons = Use; }
static CMenusKeyBinder m_Binder;
2010-05-29 07:25:38 +00:00
CMenus();
2011-02-27 16:56:03 +00:00
void RenderLoading();
2010-05-29 07:25:38 +00:00
bool IsActive() const { return m_MenuActive; }
virtual void OnInit();
virtual void OnStateChange(int NewState, int OldState);
virtual void OnReset();
virtual void OnRender();
virtual bool OnInput(IInput::CEvent Event);
virtual bool OnMouseMove(float x, float y);
// DDRace
int DoButton_CheckBox_DontCare(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
sorted_array<CDemoItem> m_lDemos;
void DemolistPopulate();
// Ghost
struct CGhostItem
{
char m_aFilename[256];
char m_aPlayer[MAX_NAME_LENGTH];
float m_Time;
bool m_Active;
int m_ID;
bool operator<(const CGhostItem &Other) { return m_Time < Other.m_Time; }
bool operator==(const CGhostItem &Other) { return m_ID == Other.m_ID; }
};
sorted_array<CGhostItem> m_lGhosts;
CGhostItem *m_OwnGhost;
2011-02-23 07:33:21 +00:00
int m_DDRacePage;
void GhostlistPopulate();
private:
static int GhostlistFetchCallback(const char *pName, int IsDir, int StorageType, void *pUser);
// found in menus_ingame.cpp
void RenderInGameDDRace(CUIRect MainView);
void RenderGhost(CUIRect MainView);
void RenderInGameBrowser(CUIRect MainView);
// found in menus_settings.cpp
void RenderSettingsDDRace(CUIRect MainView);
2010-05-29 07:25:38 +00:00
};
#endif