-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Menu Manager #36
Menu Manager #36
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Player class is on its way (#38) I want to merge it later today if there are no objections. Then you can adjust it to suit your needs, I mean removing m_playerMenu
and m_playerPage
.
include/public/IMenuSystem.hpp
Outdated
MENU_BACK = -1 | ||
}; | ||
|
||
enum ItemStatus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum class ItemStatus
then its options can be named just Enabled
, Disabled
, Hide
.
include/public/IMenuSystem.hpp
Outdated
ItemHide | ||
}; | ||
|
||
enum MenuStyle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum class MenuStyle
then options Item
and Text
.
src/MenuSystem.cpp
Outdated
std::size_t slot = 0; | ||
|
||
|
||
auto addItem = [&](ItemStatus r, std::size_t s, std::string n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string_view
src/MenuSystem.hpp
Outdated
{ | ||
std::shared_ptr<Menu> menu = std::make_shared<Menu>(m_mid++, std::forward<Args>(args)...); | ||
m_menus.push_back(menu); | ||
return menu; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be changed to emplace_back
src/MenuSystem.cpp
Outdated
while (*n); | ||
} | ||
|
||
std::string replace(const std::string& str, const std::string& from, const std::string& to) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string_view
for params
src/MenuSystem.cpp
Outdated
return ""; | ||
|
||
if(item >= m_items.size()) | ||
return m_staticSlots[item - m_items.size()].get()->name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
src/MenuSystem.cpp
Outdated
return false; | ||
|
||
if(item >= m_items.size()) | ||
m_staticSlots[item - m_items.size()].get()->name = name.data(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use .get()
src/MenuSystem.hpp
Outdated
public: | ||
struct MenuItem | ||
{ | ||
MenuItem(std::string n, |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
src/MenuSystem.hpp
Outdated
int m_time; | ||
std::size_t m_itemsPerPage; | ||
int m_keys; | ||
int m_slots[10]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::array
src/MenuSystem.hpp
Outdated
std::size_t m_itemsPerPage; | ||
int m_keys; | ||
int m_slots[10]; | ||
std::unique_ptr<MenuItem> m_staticSlots[10]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::array
src/MenuSystem.cpp
Outdated
plr = plrMngr->getPlayerCore(i); | ||
|
||
if(!plr->isInGame() | ||
|| !plrMngr->getPlayerCore(i)->getMenu() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use plr
as well
src/MenuSystem.cpp
Outdated
|
||
if(!plr->isInGame() | ||
|| !plrMngr->getPlayerCore(i)->getMenu() | ||
|| plrMngr->getPlayerCore(i)->getMenu()->getId() == index) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you meant !=
src/MenuSystem.cpp
Outdated
int gmsgShowMenu = 0; | ||
int gmsgVGUIMenu = 0; | ||
|
||
Menu::MenuItem::MenuItem(std::string n, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string_view
scripts/include/menus.inc
Outdated
); | ||
}; | ||
|
||
typedef CallbackHandler = function ItemStatus (Menu menu, MenuItem item, int player); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can use Player
include/public/IMenuSystem.hpp
Outdated
public: | ||
using MenuHandler = void (*)(IMenu *const menu, std::size_t item, int player); | ||
virtual IMenu *registerMenu(MenuHandler handler, MenuStyle style, bool global) = 0; | ||
virtual IMenu *registerMenu(SourcePawn::IPluginFunction *func, MenuStyle style, bool global) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any use case registering menu in module and have callback in plugin?
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
include/public/IMenuSystem.hpp
Outdated
{ | ||
public: | ||
using MenuItemCallback = ItemStatus (*)(IMenu *const menu, std::size_t item, int player); | ||
using MenuHandler = void (*)(IMenu *const menu, std::size_t item, int player); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
scripts/include/menus.inc
Outdated
/* | ||
* @brief Sets a item data. | ||
* | ||
* @param data Item datar. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
include/public/IMenuSystem.hpp
Outdated
|
||
virtual int getTime() const = 0; | ||
virtual int getKeys() const = 0; | ||
virtual int keyToSlot(int key) const = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it need to be exported?
include/public/IMenuSystem.hpp
Outdated
|
||
virtual void setHandler(MenuHandler func) = 0; | ||
|
||
virtual void execHandler(int player, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these execHandler
and setHandler
need to be in api
src/MenuSystem.hpp
Outdated
|
||
void setNumberFormat(std::string_view format); | ||
|
||
void setHandler(std::variant<SourcePawn::IPluginFunction *, MenuHandler> &&func); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be removed
src/PlayerSystem.hpp
Outdated
@@ -61,6 +66,9 @@ class Player : public IPlayer | |||
std::string m_name; | |||
std::string m_ip; | |||
std::string m_steamID; | |||
|
|||
std::shared_ptr<Menu> m_menu; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::weak_ptr
src/MenuSystem.hpp
Outdated
std::variant<SourcePawn::IPluginFunction *, MenuItemCallback> &&callback, | ||
std::variant<cell_t, void *> &&data); | ||
|
||
bool setStaticItem(std::size_t positon, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be exported to modules api?
src/MenuSystem.hpp
Outdated
std::variant<SourcePawn::IPluginFunction *, MenuItemCallback> &&callback, | ||
std::variant<cell_t, void *> &&data); | ||
|
||
bool setItemName(std::size_t item, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. This could be useful to change name of item menu in item callback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the lack of input recently, been busy lately.
std::shared_ptr<Menu> findMenuCore(std::size_t index) const; | ||
|
||
void destroyMenu(std::size_t index); | ||
void clearMenus(); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
include/public/IMenuSystem.hpp
Outdated
public: | ||
using MenuHandler = void (*)(IMenu *const menu, std::size_t item, int player); | ||
virtual IMenu *registerMenu(MenuHandler handler, MenuStyle style, bool global) = 0; | ||
virtual IMenu *findMenu(std::size_t mid) const = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think modules need this exported. Also destroyMenu(IMenu *menu)
is missing here.
std::variant<SourcePawn::IPluginFunction *, MenuItemCallback> &&callback, | ||
std::variant<cell_t, void *> &&data) | ||
{ | ||
if(position >= m_itemsPerPage) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
include/public/IMenuSystem.hpp
Outdated
{ | ||
public: | ||
using MenuItemCallback = ItemStatus (*)(IMenu *const menu, std::size_t item, int player); | ||
using MenuHandler = void (*)(IMenu *const menu, std::size_t item, int player); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMenuItem
class could be created and all related item's funcs move there from IMenu
int Player
could be IPlayer player
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's the last review and it should be good to go.
MenuItemCallback callback, | ||
void *data) override; | ||
|
||
bool setStaticItem(std::size_t position, |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Fix typo in exit item
Description
Implementation of menu manager
Motivation and Context
Fixes #28
How has this been tested?
Screenshots (if appropriate):
Types of changes
Checklist: