Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ bld/
*.exe
*.out
*.app

# Custom
**/*.vcxproj
**/*.sln
!build/*
86 changes: 86 additions & 0 deletions LemonUI.SHV.Example/Example.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once

#include <Helpers.hpp>
#include <ScaledText.hpp>
#include <Scaleform.hpp>

#include <string>

class Example
{
private:
LemonUI::ScaledText* m_scaledText = nullptr;
LemonUI::Scaleform m_scaleform{ "mp_mm_card_freemode", { 0.122f, 0.3f }, { 0.28f, 0.6f } };

bool m_scaleformFocus = false;

public:
void RenderScaledText()
{
if (this->m_scaledText == nullptr)
{
return;
}
LemonUI::Vec2 currentRes = LemonUI::GetScreenResolution();
this->m_scaledText->SetPos({ currentRes.x / 2, currentRes.y - 60 });
this->m_scaledText->Draw();
}

void DeleteCreateScaledText()
{
if (this->m_scaledText == nullptr)
{
this->m_scaledText = new LemonUI::ScaledText{ "Created with LemonUI.SHV by EntenKoeniq" };
this->m_scaledText->SetScale(0.35f);
this->m_scaledText->SetDropShadow(true);
}
else
{
delete this->m_scaledText;
this->m_scaledText = nullptr;
}
}

void RenderScaleform()
{
if (!this->m_scaleformFocus)
{
return;
}

this->m_scaleform.StartFunction("SET_DATA_SLOT_EMPTY");
this->m_scaleform.PushParam(0);
this->m_scaleform.FinishFunction();

this->m_scaleform.StartFunction("SET_DATA_SLOT");
this->m_scaleform.PushParam(0);
this->m_scaleform.PushParam(std::string("16ms"));
this->m_scaleform.PushParam(std::string("EntenKoeniq"));
this->m_scaleform.PushParam(116);
this->m_scaleform.PushParam(0);
this->m_scaleform.PushParam(0);
this->m_scaleform.PushParam(std::string(""));
this->m_scaleform.PushParam(std::string(""));
this->m_scaleform.PushParam(2);
this->m_scaleform.PushParam(std::string(""));
this->m_scaleform.PushParam(std::string(""));
this->m_scaleform.PushParam(std::string(" "));
this->m_scaleform.FinishFunction();

this->m_scaleform.StartFunction("SET_TITLE");
this->m_scaleform.PushParam(std::string("Player list"));
this->m_scaleform.PushParam(std::string("1 players"));
this->m_scaleform.FinishFunction();

this->m_scaleform.CallFunction("DISPLAY_VIEW");

this->m_scaleform.Draw();
}

void FocusScaleform()
{
this->m_scaleformFocus = !this->m_scaleformFocus;
}
};

extern Example* _pGame = nullptr;
74 changes: 74 additions & 0 deletions LemonUI.SHV.Example/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "pch.h"
#include "Example.hpp"

#include <Helpers.hpp>

#include <natives.hpp>

static void scriptKeyboardHandler(DWORD key, WORD repeats, BYTE scanCode, BOOL isExtended, BOOL isWithAlt, BOOL wasDownBefore, BOOL isUpNow)
{
if (wasDownBefore == FALSE && isUpNow == FALSE)
{
if (key == VK_F3)
{
_pGame->DeleteCreateScaledText();
}
else if (key == VK_F4)
{
_pGame->FocusScaleform();
}
}
}

static void scriptMainFunc()
{
while (DLC::GET_IS_LOADING_SCREEN_ACTIVE())
{
WAIT(0);
}
srand(GetTickCount());

_pGame = new Example();

LemonUI::ShowNotify("Welcome to ~y~LemonUI.SHV");
LemonUI::ShowNotify("Use F3 to show/hide ScaledText and F4 to show/hide Scaleform");

while (true)
{
_pGame->RenderScaledText();
_pGame->RenderScaleform();

WAIT(0);
}
}

static void scriptInitialize(HMODULE hModule)
{
scriptRegister(hModule, scriptMainFunc);
keyboardHandlerRegister(scriptKeyboardHandler);
}

static void scriptUninitialize(HMODULE hModule)
{
keyboardHandlerUnregister(scriptKeyboardHandler);
scriptUnregister(hModule);

if (_pGame != nullptr)
{
delete _pGame;
}
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
scriptInitialize(hModule);
break;
case DLL_PROCESS_DETACH:
scriptUninitialize(hModule);
break;
}
return TRUE;
}
1 change: 1 addition & 0 deletions LemonUI.SHV.Example/pch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "pch.h"
3 changes: 3 additions & 0 deletions LemonUI.SHV.Example/pch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include <windows.h>
4 changes: 0 additions & 4 deletions LemonUI.SHV/Alignment.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion LemonUI.SHV/Alignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace LemonUI
/// <summary>
/// The alignment of the element to draw.
/// </summary>
enum Alignment
enum class Alignment
{
/// <summary>
/// Aligns the element to the Center.
Expand Down
16 changes: 16 additions & 0 deletions LemonUI.SHV/Font.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

namespace LemonUI
{
/// <summary>
/// An enum representing the fonts available in game.
/// </summary>
enum class Font : unsigned char /* uint8_t */
{
ChaletLondon = 0,
HouseScript = 1,
Monospace = 2,
CharletComprimeColonge = 4,
Pricedown = 7
};
}
43 changes: 43 additions & 0 deletions LemonUI.SHV/Helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "pch.h"
#include "Helpers.hpp"

namespace LemonUI
{
void ShowNotify(const std::string& message)
{
HUD::BEGIN_TEXT_COMMAND_THEFEED_POST("STRING");
HUD::ADD_TEXT_COMPONENT_SUBSTRING_PLAYER_NAME(message.c_str());
HUD::END_TEXT_COMMAND_THEFEED_POST_TICKER(FALSE, FALSE);
}

Vec2 GetScreenResolution()
{
int width, height;
GRAPHICS::GET_ACTIVE_SCREEN_RESOLUTION_(&width, &height);
return { static_cast<float>(width), static_cast<float>(height) };
}

float GetAspectRatio()
{
return GRAPHICS::GET_ASPECT_RATIO_(0);
}

void ToRelative(const float& absoluteX, const float& absoluteY, float* relativeX, float* relativeY)
{
Vec2 currentRes = GetScreenResolution();
float width = currentRes.y * GetAspectRatio();
*relativeX = absoluteX / width;
*relativeY = absoluteY / currentRes.y;
}

Vec2 GetRectCenter(const Vec2& pos, const Vec2& size)
{
return { pos.x + size.x / 2.0f, pos.y + size.y / 2.0f };
}

Vec2 GetScreenScale(const Vec2& vec)
{
Vec2 currentRes = GetScreenResolution();
return { vec.x / currentRes.x, vec.y / currentRes.y };
}
}
14 changes: 14 additions & 0 deletions LemonUI.SHV/Helpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "Vectors.hpp"

#include <string>

namespace LemonUI
{
extern void ShowNotify(const std::string& message);
extern Vec2 GetScreenResolution();
extern float GetAspectRatio();
extern void ToRelative(const float& absoluteX, const float& absoluteY, float* relativeX, float* relativeY);
extern Vec2 GetRectCenter(const Vec2& pos, const Vec2& size);
extern Vec2 GetScreenScale(const Vec2& vector);
}
2 changes: 1 addition & 1 deletion LemonUI.SHV/IDrawable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ namespace LemonUI
/// <summary>
/// Draws the item on the screen.
/// </summary>
virtual void Draw() = 0;
virtual void Draw() const = 0;
};
}
17 changes: 17 additions & 0 deletions LemonUI.SHV/IScaleform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include "IDrawable.hpp"

namespace LemonUI
{
/// <summary>
/// Scaleforms are 2D Adobe Flash-like objects.
/// </summary>
class IScaleform : public IDrawable
{
public:
/// <summary>
/// Draws the Scaleform in full screen.
/// </summary>
virtual void DrawFullScreen() const = 0;
};
}
Loading