Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion game/content-hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master-c3312fa76076c1b2e32b7e4bf49ac647e6c5f87c
master-8394de137ea6d45de7f52f9fbd1d3104bdc300d8
23 changes: 19 additions & 4 deletions game/game_libs/ui/BaseMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const char* uiSounds[] = {
"media/launch_select1.wav",
"media/launch_deny1.wav",
"",
""};
""
};

// they match default WON colors.lst now, except alpha
unsigned int uiColorHelp = 0xFF7F7F7F; // 127, 127, 127, 255 // hint letters color
Expand Down Expand Up @@ -198,7 +199,8 @@ void UI_DrawPic(
int height,
const unsigned int color,
CImage& pic,
const ERenderMode eRenderMode)
const ERenderMode eRenderMode
)
{
HIMAGE hPic = pic.Handle();

Expand Down Expand Up @@ -315,7 +317,8 @@ int UI_DrawString(
const unsigned int color,
int charH,
uint justify,
uint flags)
uint flags
)
{
uint modulate, shadowModulate = 0;
int xx = 0, yy, ofsX = 0, ofsY = 0, ch;
Expand Down Expand Up @@ -1032,17 +1035,29 @@ static void UI_LoadSounds(void)
for ( int i = 0; i < SND_COUNT; i++ )
{
if ( !uiSounds[i] || *uiSounds[i] == '\0' )
{
continue;
}

if ( !EngFuncs::FileExists(uiSounds[i]) )
{
size_t len = strlen(uiSoundOldPrefix);

if ( !strncmp(uiSounds[i], uiSoundOldPrefix, len) )
PlatformLib_SNPrintF(uiStatic.sounds[i], sizeof(uiStatic.sounds[i]), "%s%s", uiSoundNewPrefix, uiSounds[i] + len);
{
PlatformLib_SNPrintF(
uiStatic.sounds[i],
sizeof(uiStatic.sounds[i]),
"%s%s",
uiSoundNewPrefix,
uiSounds[i] + len
);
}
}
else
{
Q_strncpy(uiStatic.sounds[i], uiSounds[i], sizeof(uiStatic.sounds[i]));
}
}
}

Expand Down
12 changes: 11 additions & 1 deletion game/game_libs/ui_new/src/framework/MenuPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void MenuPage::ProcessEvent(Rml::Event& event)
{
const int keyId = GetEventKeyId(event);

if ( keyId == Rml::Input::KI_ESCAPE && m_RequestPopOnEscapeKey )
if ( keyId == Rml::Input::KI_ESCAPE && m_RequestPopOnEscapeKey && ShouldPop("") )
{
event.StopPropagation();
SetCurrentRequest(MenuRequestType::PopMenu);
Expand Down Expand Up @@ -70,6 +70,11 @@ void MenuPage::OnBeginDocumentUnloaded()

void MenuPage::RequestPop(Rml::String menuToSwapIn)
{
if ( !ShouldPop(menuToSwapIn) )
{
return;
}

Rml::VariantList args;

if ( !menuToSwapIn.empty() )
Expand All @@ -80,6 +85,11 @@ void MenuPage::RequestPop(Rml::String menuToSwapIn)
SetCurrentRequest(MenuRequestType::PopMenu, args);
}

bool MenuPage::ShouldPop(const Rml::String&) const
{
return true;
}

void MenuPage::HandlePushMenu(Rml::DataModelHandle, Rml::Event&, const Rml::VariantList& args)
{
SetCurrentRequest(MenuRequestType::PushMenu, args);
Expand Down
1 change: 1 addition & 0 deletions game/game_libs/ui_new/src/framework/MenuPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MenuPage : public BaseMenu
void OnBeginDocumentUnloaded() override;

void RequestPop(Rml::String menuToSwapIn = Rml::String());
virtual bool ShouldPop(const Rml::String& menuToSwapIn) const;

private:
void ProcessEvent(Rml::Event& event);
Expand Down
47 changes: 22 additions & 25 deletions game/game_libs/ui_new/src/framework/MenuStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const MenuDirectoryEntry* MenuStack::Pop()
{
if ( m_Stack.empty() )
{
ASSERT(false);
return nullptr;
}

Expand Down Expand Up @@ -88,25 +89,29 @@ size_t MenuStack::Size() const

void MenuStack::SetTopDocumentVisible(bool visible)
{
if ( !m_Stack.empty() )
if ( m_Stack.empty() )
{
const MenuDirectoryEntry* entry = m_Stack.back();
Rml::ElementDocument* document = entry->document;
return;
}

if ( document )
{
if ( visible )
{
document->Show();
}
else
{
// If there are any pending requests, cancel them.
entry->menuPtr->ClearCurrentRequest();
const MenuDirectoryEntry* entry = m_Stack.back();
Rml::ElementDocument* document = entry->document;

document->Hide();
}
}
if ( !document )
{
return;
}

if ( visible )
{
document->Show();
}
else
{
// If there are any pending requests, cancel them.
entry->menuPtr->ClearCurrentRequest();

document->Hide();
}
}

Expand Down Expand Up @@ -176,15 +181,7 @@ void MenuStack::HandlePopMenuRequest(const Rml::String& name)
{
if ( name.empty() )
{
if ( m_Stack.size() > 1 )
{
Pop();
}
else
{
Rml::Log::Message(Rml::Log::Type::LT_WARNING, "Ignoring pop request from only menu in stack");
}

Pop();
return;
}

Expand Down
39 changes: 38 additions & 1 deletion game/game_libs/ui_new/src/menus/MainMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "menus/MainMenu.h"
#include "udll_int.h"

static constexpr const char* const NAME_SHOW_CONSOLE_BUTTON = "showConsoleButton";
static constexpr const char* const EVENT_SHOW_DEVELOPER_CONSOLE = "showDeveloperConsole";

const char* const MainMenu::NAME = "main_menu";

Expand All @@ -10,5 +14,38 @@ MainMenu::MainMenu() :

bool MainMenu::OnSetUpDataModelBindings(Rml::DataModelConstructor& constructor)
{
return MenuPage::OnSetUpDataModelBindings(constructor) && m_MenuFrameDataBinding.SetUpDataBindings(constructor);
if ( !MenuPage::OnSetUpDataModelBindings(constructor) || !m_MenuFrameDataBinding.SetUpDataBindings(constructor) )
{
return false;
}

if ( !constructor.BindEventCallback(EVENT_SHOW_DEVELOPER_CONSOLE, &MainMenu::HandleShowDeveloperConsole, this) )
{
return false;
}

const bool bindSuccess = constructor.BindFunc(
NAME_SHOW_CONSOLE_BUTTON,
[this](Rml::Variant& outValue)
{
outValue = Rml::Variant(ShouldPop(""));
}
);

if ( !bindSuccess )
{
return false;
}

return true;
}

bool MainMenu::ShouldPop(const Rml::String&) const
{
return gpGlobals->developer != 0;
}

void MainMenu::HandleShowDeveloperConsole(Rml::DataModelHandle, Rml::Event&, const Rml::VariantList&)
{
RequestPop();
}
3 changes: 3 additions & 0 deletions game/game_libs/ui_new/src/menus/MainMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class MainMenu : public MenuPage

protected:
bool OnSetUpDataModelBindings(Rml::DataModelConstructor& constructor) override;
bool ShouldPop(const Rml::String& menuToSwapIn) const override;

private:
void HandleShowDeveloperConsole(Rml::DataModelHandle handle, Rml::Event& event, const Rml::VariantList& args);

MenuFrameDataBinding m_MenuFrameDataBinding;
};
62 changes: 0 additions & 62 deletions game/game_libs/ui_new/src/rmlui/RenderInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,65 +224,3 @@ void RenderInterfaceImpl::SetTransform(const Rml::Matrix4f* transform)

gUiGlFuncs.renderer.setTransform(nullptr);
}

void RenderInterfaceImpl::RenderDebugTriangle()
{
static Rml::CompiledGeometryHandle geom = 0;
static Rml::TextureHandle texture = 0;

if ( !geom )
{
static const float extent = 200.0f;

static const Rml::Vertex verticesArray[] = {
{{0, 0}, Rml::ColourbPremultiplied {255, 0, 0, 255}, {0, 0}},
{{extent, 0}, Rml::ColourbPremultiplied {255, 0, 0, 255}, {1, 0}},
{{extent / 2.0f, extent}, Rml::ColourbPremultiplied {255, 0, 0, 255}, {0.5f, 1}},
};

static const int indicesArray[] = {
0,
1,
2,
};

Rml::Span<const Rml::Vertex> vertices(verticesArray, 3);
Rml::Span<const int> indices(indicesArray, 3);
geom = CompileGeometry(vertices, indices);
}

if ( !texture )
{
static constexpr int WIDTH = 16;
static constexpr int HEIGHT = 16;

uint32_t texDataRGBA[WIDTH * HEIGHT];
memset(&texDataRGBA, 0xFF, sizeof(texDataRGBA));

Rml::Span<const Rml::byte> texData(reinterpret_cast<const Rml::byte*>(texDataRGBA), sizeof(texDataRGBA));
texture = GenerateTexture(texData, Rml::Vector2i(WIDTH, HEIGHT));
}

gUiGlFuncs.renderer.beginFrame(0, 0, m_ViewportWidth, m_ViewportHeight);
gUiGlFuncs.renderer.clear(0x000000FF, 0);

gUiGlFuncs.renderer.pushProjectionMatrixTranslation(20, 50, 0);

const GeometryView* geometry = reinterpret_cast<GeometryView*>(geom);
const Rml::Vertex* vertices = geometry->vertices.data();
const int* indices = geometry->indices.data();
const int num_indices = static_cast<int>(geometry->indices.size());

gUiGlFuncs.renderer.prepareToDrawWithTexture(
static_cast<uint32_t>(texture),
vertices,
sizeof(Rml::Vertex),
offsetof(Rml::Vertex, position),
offsetof(Rml::Vertex, colour),
offsetof(Rml::Vertex, tex_coord)
);

gUiGlFuncs.renderer.drawElements(num_indices, indices);
gUiGlFuncs.renderer.popProjectionMatrix();
gUiGlFuncs.renderer.endFrame();
}
2 changes: 0 additions & 2 deletions game/game_libs/ui_new/src/rmlui/RenderInterfaceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class RenderInterfaceImpl : public Rml::RenderInterface

void SetTransform(const Rml::Matrix4f* transform) override;

void RenderDebugTriangle();

private:
struct GeometryView
{
Expand Down
49 changes: 21 additions & 28 deletions game/game_libs/ui_new/src/rmlui/RmlUiBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,21 @@ bool RmlUiBackend::IsVisible() const
return m_Visible;
}

void RmlUiBackend::ReceiveStartupComplete()
void RmlUiBackend::ReceiveShowMenu()
{
ASSERT(IsInitialised());

if ( !IsInitialised() )
{
return;
}

const MenuDirectoryEntry* menu = m_MenuDirectory.GetMenuEntry(MainMenu::NAME);
ASSERT(menu);

m_MenuStack.Push(menu);
ReceiveShowMenu();
}
m_Visible = true;

void RmlUiBackend::ReceiveShowMenu()
{
if ( !IsInitialised() )
if ( m_MenuStack.IsEmpty() )
{
return;
const MenuDirectoryEntry* menu = m_MenuDirectory.GetMenuEntry(MainMenu::NAME);
ASSERT(menu);
m_MenuStack.Push(menu);
}

m_Visible = true;
}

void RmlUiBackend::ReceiveHideMenu()
Expand Down Expand Up @@ -283,6 +274,13 @@ Rml::Context* RmlUiBackend::GetRmlContext() const
return m_RmlContext;
}

bool RmlUiBackend::ShouldPopToConsole()
{
bool out = m_ShouldPopToConsole;
m_ShouldPopToConsole = false;
return out;
}

void RmlUiBackend::SetStoreNextKey(bool onPressed)
{
if ( !IsInitialised() )
Expand Down Expand Up @@ -331,8 +329,16 @@ void RmlUiBackend::Update(float currentTime)
return;
}

bool hadMenusInStack = !m_MenuStack.IsEmpty();

m_MenuStack.Update(currentTime);
m_RmlContext->Update();
m_MenuStack.HandleRequests();

if ( hadMenusInStack && m_MenuStack.IsEmpty() )
{
m_ShouldPopToConsole = true;
}
}

void RmlUiBackend::Render()
Expand All @@ -345,19 +351,6 @@ void RmlUiBackend::Render()
m_RenderInterface.BeginFrame();
m_RmlContext->Render();
m_RenderInterface.EndFrame();

// Now that rendering is done, modify the menu stack if needed.
m_MenuStack.HandleRequests();
}

void RmlUiBackend::RenderDebugTriangle()
{
if ( !IsInitialised() )
{
return;
}

m_RenderInterface.RenderDebugTriangle();
}

void RmlUiBackend::ReleaseResources()
Expand Down
Loading
Loading