# HG changeset patch # User Nomad # Date 1381223048 -7200 # Node ID bd899dfd976c75635f22f4e07bb9926f20b1c23e # Parent 8e17ceba3a409b74c4737378e270fad34f416158 MainMenuWindow diff -r 8e17ceba3a40 -r bd899dfd976c NewUI/Core/UIControl.h --- /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 + +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 children; +}; \ No newline at end of file diff -r 8e17ceba3a40 -r bd899dfd976c NewUI/MainMenu.cpp --- /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 diff -r 8e17ceba3a40 -r bd899dfd976c NewUI/MainMenu.h --- /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 diff -r 8e17ceba3a40 -r bd899dfd976c NewUI/UIControl.h --- 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 diff -r 8e17ceba3a40 -r bd899dfd976c OSWindow.cpp --- 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; diff -r 8e17ceba3a40 -r bd899dfd976c OSWindow.h --- 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); diff -r 8e17ceba3a40 -r bd899dfd976c mm7_2.cpp --- 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 )