1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/MenuStyle_Base.cpp Sat May 12 23:45:52 2007 +0000
1.3 @@ -0,0 +1,162 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * ===============================================================
1.7 + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
1.8 + * ===============================================================
1.9 + *
1.10 + * This file is not open source and may not be copied without explicit
1.11 + * written permission of AlliedModders LLC. This file may not be redistributed
1.12 + * in whole or significant part.
1.13 + * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
1.14 + *
1.15 + * Version: $Id$
1.16 + */
1.17 +#include <stdarg.h>
1.18 +#include "sm_stringutil.h"
1.19 +#include "MenuStyle_Base.h"
1.20 +
1.21 +CBaseMenu::CBaseMenu(IMenuStyle *pStyle) :
1.22 +m_pStyle(pStyle), m_Strings(512), m_Pagination(7), m_ExitButton(true)
1.23 +{
1.24 +}
1.25 +
1.26 +CBaseMenu::~CBaseMenu()
1.27 +{
1.28 +}
1.29 +
1.30 +bool CBaseMenu::AppendItem(const char *info, const ItemDrawInfo &draw)
1.31 +{
1.32 + if (m_Pagination == MENU_NO_PAGINATION
1.33 + && m_items.size() >= m_pStyle->GetMaxPageItems())
1.34 + {
1.35 + return false;
1.36 + }
1.37 +
1.38 + CItem item;
1.39 +
1.40 + item.infoString = m_Strings.AddString(info);
1.41 + if (draw.display)
1.42 + {
1.43 + item.displayString = m_Strings.AddString(draw.display);
1.44 + }
1.45 + item.style = draw.style;
1.46 +
1.47 +
1.48 + m_items.push_back(item);
1.49 +
1.50 + return true;
1.51 +}
1.52 +
1.53 +bool CBaseMenu::InsertItem(unsigned int position, const char *info, const ItemDrawInfo &draw)
1.54 +{
1.55 + if (m_Pagination == MENU_NO_PAGINATION
1.56 + && m_items.size() >= m_pStyle->GetMaxPageItems())
1.57 + {
1.58 + return false;
1.59 + }
1.60 +
1.61 + if (position >= m_items.size())
1.62 + {
1.63 + return false;
1.64 + }
1.65 +
1.66 + CItem item;
1.67 + item.infoString = m_Strings.AddString(info);
1.68 + if (draw.display)
1.69 + {
1.70 + item.displayString = m_Strings.AddString(draw.display);
1.71 + }
1.72 + item.style = draw.style;
1.73 +
1.74 + CVector<CItem>::iterator iter = m_items.iterAt(position);
1.75 + m_items.insert(iter, item);
1.76 +
1.77 + return true;
1.78 +}
1.79 +
1.80 +bool CBaseMenu::RemoveItem(unsigned int position)
1.81 +{
1.82 + if (position >= m_items.size())
1.83 + {
1.84 + return false;
1.85 + }
1.86 +
1.87 + m_items.erase(m_items.iterAt(position));
1.88 +
1.89 + if (m_items.size() == 0)
1.90 + {
1.91 + m_Strings.Reset();
1.92 + }
1.93 +
1.94 + return true;
1.95 +}
1.96 +
1.97 +void CBaseMenu::RemoveAllItems()
1.98 +{
1.99 + m_items.clear();
1.100 + m_Strings.Reset();
1.101 +}
1.102 +
1.103 +const char *CBaseMenu::GetItemInfo(unsigned int position, ItemDrawInfo *draw/* =NULL */)
1.104 +{
1.105 + if (position >= m_items.size())
1.106 + {
1.107 + return NULL;
1.108 + }
1.109 +
1.110 + if (draw)
1.111 + {
1.112 + draw->display = m_Strings.GetString(m_items[position].displayString);
1.113 + draw->style = m_items[position].style;
1.114 + }
1.115 +
1.116 + return m_Strings.GetString(m_items[position].infoString);
1.117 +}
1.118 +
1.119 +unsigned int CBaseMenu::GetItemCount()
1.120 +{
1.121 + return m_items.size();
1.122 +}
1.123 +
1.124 +bool CBaseMenu::SetPagination(unsigned int itemsPerPage)
1.125 +{
1.126 + if (itemsPerPage > 7)
1.127 + {
1.128 + return false;
1.129 + }
1.130 +
1.131 + m_Pagination = itemsPerPage;
1.132 +
1.133 + return true;
1.134 +}
1.135 +
1.136 +unsigned int CBaseMenu::GetPagination()
1.137 +{
1.138 + return m_Pagination;
1.139 +}
1.140 +
1.141 +IMenuStyle *CBaseMenu::GetDrawStyle()
1.142 +{
1.143 + return m_pStyle;
1.144 +}
1.145 +
1.146 +void CBaseMenu::SetDefaultTitle(const char *message)
1.147 +{
1.148 + m_Title.assign(message);
1.149 +}
1.150 +
1.151 +const char *CBaseMenu::GetDefaultTitle()
1.152 +{
1.153 + return m_Title.c_str();
1.154 +}
1.155 +
1.156 +bool CBaseMenu::GetExitButton()
1.157 +{
1.158 + return m_ExitButton;
1.159 +}
1.160 +
1.161 +bool CBaseMenu::SetExitButton(bool set)
1.162 +{
1.163 + m_ExitButton = set;
1.164 + return true;
1.165 +}