Jump to content
  • entries
    4
  • comments
    0
  • views
    1,561

UI Window Manager


Andy90

745 views

 Share

 

I had already created a similar window handler for Leadwerks in a previous project. As I'm currently importing my project into the new engine, I thought it was time to refine this functionality.

But what exactly can the Window Handler do?
As the name suggests, it manages multiple "UI Windows" so that only one is displayed at a time. This is particularly useful when working with different windows for the UI, such as one for inventory, another for a crafting menu, and yet another for dialog options, etc. The Window Handler prevents multiple windows from being open simultaneously, as it closes all others before opening a new one.

How does the Window Handler work?
The functionality is kept simple: You create a new variable of type UIWindowHandler and generate your "UI Windows" using the UIWindow class, which you then add to the UIWindowHandler. The UIWindow class automatically creates the desired panels. By using `window_manager->ShowWindow("window_1");`, for example, you can open a specific window. In my project, I've added the UIWindowHandler to a global header so that my components can access it.

UIWindowHandler.h

#pragma once
#include "UltraEngine.h"
#include "UIWindow.h"

using namespace UltraEngine;
using namespace std;

class UIWindowHandler
{
public:
	vector<UIWindow*> windows;

	UIWindowHandler();
	void AddWindow(UIWindow* window);
	void CloseAllWindows();
	void ShowWindow(UIWindow* window);
	void ShowWindow(string widnowName);
};

UIWindowHandler.cpp

#include "UltraEngine.h"
#include "UIWindowHandler.h"

UIWindowHandler::UIWindowHandler() {
	
}

void UIWindowHandler::AddWindow(UIWindow* window)
{
	this->windows.push_back(window);
}

void UIWindowHandler::CloseAllWindows()
{
	for (auto window : this->windows) 
	{
		window->CloseWindow();
	}
}

void UIWindowHandler::ShowWindow(UIWindow* window) 
{
	this->CloseAllWindows();
	window->ShowWindow();
}

void UIWindowHandler::ShowWindow(string widnowName)
{
	this->CloseAllWindows();
	for (auto window : this->windows) {
		if (window->name == widnowName) {
			window->ShowWindow();
		}
	}
}

UIWindow.h

#pragma once
#include "UltraEngine.h"

using namespace UltraEngine;

class UIWindow
{
private:
	shared_ptr<Interface> ui;

public:
	string name;
	shared_ptr<Widget> panel;

	UIWindow(string name, shared_ptr<Interface> ui);
	UIWindow(string name, float x, float y, float width, float height, shared_ptr<Interface> ui);
	bool IsHidden();
	void CloseWindow();
	void ShowWindow();	
};

UIWindow.cpp

#include "UltraEngine.h"
#include "UIWindow.h"

UIWindow::UIWindow(string name, shared_ptr<Interface> ui) 
{
	this->name = name;
	this->ui = ui;
	this->panel = CreatePanel(0, 0, 128, 128, ui->root);
}

UIWindow::UIWindow(string name, float x, float y, float width, float height, shared_ptr<Interface> ui)
{
	this->name = name;
	this->ui = ui;
	this->panel = CreatePanel(x, y, width, height, ui->root);
}

bool UIWindow::IsHidden() 
{
	if (this->panel != nullptr) {
		if (this->panel->GetHidden()) {
			return true;
		}
	}
	return false;
}

void UIWindow::CloseWindow() 
{
	this->panel->SetHidden(true);
}

void UIWindow::ShowWindow()
{
	this->panel->SetHidden(false);
}

 

  • Like 2
 Share

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...