Mercurial > mm7
changeset 1815:bd899dfd976c
MainMenuWindow
author | Nomad |
---|---|
date | Tue, 08 Oct 2013 11:04:08 +0200 |
parents | 8e17ceba3a40 |
children | 9442b7c19a64 |
files | NewUI/Core/UIControl.h NewUI/MainMenu.cpp NewUI/MainMenu.h NewUI/UIControl.h OSWindow.cpp OSWindow.h mm7_2.cpp |
diffstat | 7 files changed, 161 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NewUI/Core/UIControl.h Tue Oct 08 11:04:08 2013 +0200 @@ -0,0 +1,75 @@ +#pragma once +#include <list> + +class UIControl +{ + public: + virtual void Show() = 0; + + virtual bool Focused() = 0; + + // Events + virtual bool OnKey(int key) + { + for (auto i = children.begin(); i != children.end(); ++i) + if ((*i)->OnKey(key)) + return true; + return false; + } + + virtual bool OnMouseLeftClick(int x, int y) + { + for (auto i = children.begin(); i != children.end(); ++i) + if ((*i)->OnMouseLeftClick(x, y)) + return true; + return false; + } + + virtual bool OnMouseRightClick(int x, int y) + { + for (auto i = children.begin(); i != children.end(); ++i) + if ((*i)->OnMouseRightClick(x, y)) + return true; + return false; + } + + virtual bool OnMouseEnter() + { + for (auto i = children.begin(); i != children.end(); ++i) + if ((*i)->OnMouseEnter()) + return true; + return false; + } + + virtual bool OnMouseLeave() + { + for (auto i = children.begin(); i != children.end(); ++i) + if ((*i)->OnMouseLeave()) + return true; + return false; + } + + // Container + virtual bool AddControl(UIControl *ctrl) + { + if (std::find(children.begin(), children.end(), ctrl) == children.end()) + { + children.push_back(ctrl); + return true; + } + return false; + } + + virtual bool RemoveControl(UIControl *ctrl) + { + auto i = std::find(children.begin(), children.end(), ctrl); + + children.remove(ctrl); + if (i != children.end()) + return true; + return false; + } + + protected: + std::list<UIControl *> children; +}; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NewUI/MainMenu.cpp Tue Oct 08 11:04:08 2013 +0200 @@ -0,0 +1,44 @@ +#include "MainMenu.h" + + +bool MainMenuWindow::OnMouseLeftClick(int x, int y) +{ + if (UIControl::OnMouseLeftClick(x, y)) + return true; + return false; +} + +bool MainMenuWindow::OnMouseRightClick(int x, int y) +{ + if (UIControl::OnMouseRightClick(x, y)) + return true; + return false; +} + +bool MainMenuWindow::OnKey(int key) +{ + if (UIControl::OnKey(key)) + return true; + return false; +} + + +void MainMenuWindow::Show() {} +bool MainMenuWindow::Focused() {return false;} + +bool MainMenuWindow::Initialize() +{ + return true; +} + +MainMenuWindow *MainMenuWindow::Create() +{ + auto window = new MainMenuWindow; + if (window) + if (!window->Initialize()) + { + delete window; + window = nullptr; + } + return window; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NewUI/MainMenu.h Tue Oct 08 11:04:08 2013 +0200 @@ -0,0 +1,28 @@ +#pragma once +#include "Core/UIControl.h" + + +class MainMenuWindow: public UIControl +{ + public: + static MainMenuWindow *Create(); + + bool Initialize(); + + // UIControl + virtual void Show() override; + + // UIControl + virtual bool Focused() override; + + // UIControl + virtual bool OnKey(int key) override; + // UIControl + virtual bool OnMouseLeftClick(int x, int y) override; + // UIControl + virtual bool OnMouseRightClick(int x, int y) override; + // UIControl + //virtual bool OnMouseEnter() override; + // UIControl + //virtual bool OnMouseLeave() override; +}; \ No newline at end of file
--- a/NewUI/UIControl.h Mon Oct 07 13:08:53 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -#pragma once - -class UIControl -{ - public: - virtual void Show() = 0; - - virtual bool Focused() = 0; - - // Events - virtual bool OnKey(int key) = 0; - - virtual bool OnMouseLeftClick(int x, int y) = 0; - virtual bool OnMouseRightClick(int x, int y) = 0; - virtual bool OnMouseEnter() = 0; - virtual bool OnMouseLeave() = 0; -}; \ No newline at end of file
--- a/OSWindow.cpp Mon Oct 07 13:08:53 2013 +0200 +++ b/OSWindow.cpp Tue Oct 08 11:04:08 2013 +0200 @@ -19,12 +19,11 @@ #include "ErrorHandling.h" -bool OSWindow::OnKey(int) {return false;} -bool OSWindow::OnMouseEnter() {return false;} -bool OSWindow::OnMouseLeave() {return false;} - bool OSWindow::OnMouseLeftClick(int x, int y) { + if (UIControl::OnMouseLeftClick(x, y)) + return true; + if (pVideoPlayer->pVideoFrame.pPixels) pVideoPlayer->bStopBeforeSchedule = true; @@ -42,6 +41,9 @@ bool OSWindow::OnMouseRightClick(int x, int y) { + if (UIControl::OnMouseRightClick(x, y)) + return true; + if (pVideoPlayer->pVideoFrame.pPixels) pVideoPlayer->bStopBeforeSchedule = true;
--- a/OSWindow.h Mon Oct 07 13:08:53 2013 +0200 +++ b/OSWindow.h Tue Oct 08 11:04:08 2013 +0200 @@ -1,6 +1,6 @@ #pragma once #include "OSAPI.h" -#include "NewUI/UIControl.h" +#include "NewUI/Core/UIControl.h" class OSWindow: public UIControl { @@ -26,15 +26,15 @@ virtual bool Focused() override {return GetFocus() == api_handle;} // UIControl - virtual bool OnKey(int key) override; + //virtual bool OnKey(int key) override; // UIControl virtual bool OnMouseLeftClick(int x, int y) override; // UIControl virtual bool OnMouseRightClick(int x, int y) override; // UIControl - virtual bool OnMouseEnter() override; + //virtual bool OnMouseEnter() override; // UIControl - virtual bool OnMouseLeave() override; + //virtual bool OnMouseLeave() override; protected: bool Initialize(const wchar_t *title, int window_width, int window_height);
--- a/mm7_2.cpp Mon Oct 07 13:08:53 2013 +0200 +++ b/mm7_2.cpp Tue Oct 08 11:04:08 2013 +0200 @@ -64,6 +64,7 @@ #include "texts.h" #include "MM7.h" #include "Lights.h" +#include "NewUI/MainMenu.h" //----- (004BB756) -------------------------------------------------------- int UseNPCSkill(NPCProf profession) @@ -4338,6 +4339,9 @@ Log::Warning(L"MM: entering main loop"); while ( 1 ) { + auto main_menu_window = MainMenuWindow::Create(); + window->AddControl(main_menu_window); + MainMenu_Loop(); uGameState = GAME_STATE_PLAYING; while ( 1 )