Skip to content

Commit

Permalink
feat: config default font to creature/static-text/animated-text/widge…
Browse files Browse the repository at this point in the history
…t text
  • Loading branch information
mehah committed May 13, 2023
1 parent 0b6edef commit 4d43431
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 41 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

### Based on [edubart/otclient](https://github.com/edubart/otclient) Rev: [2.760](https://github.com/edubart/otclient/commit/fc39ee4adba8e780a2820bfda66fc942d74cedf4)

#### [Note: for those who are with the walking system stuttering...](https://github.com/mehah/otclient/blob/main/init.lua#L7)
#### [Note: for those who are with the walking system stuttering...](https://github.com/mehah/otclient/blob/main/modules/client_config/config.lua#L5)

### Features

- C++20
- Refactored/Optimized Rendering System
- Auto Reload Module (Set true in [init.lua](https://github.com/mehah/otclient/blob/1026132e3dfa661807a1ff10ced2f4e09f1b7a7d/init.lua#L4) to enable)
- Auto Reload Module (Set true in [init.lua](https://github.com/mehah/otclient/blob/1026132e3dfa661807a1ff10ced2f4e09f1b7a7d/init.lua#L5) to enable)
- Attached Effects System (to create aura, wings...) (code sample: [effects.lua](https://github.com/mehah/otclient/blob/main/modules/game_attachedeffects/effects.lua), [outfit_618.lua](https://github.com/mehah/otclient/blob/main/modules/game_attachedeffects/configs/outfit_618.lua), [code test](https://github.com/mehah/otclient/blob/main/modules/game_attachedeffects/attachedeffects.lua#L1))
- Idle Animation Support
- Highlight Mouse Target (press shift to select any object)
Expand Down
20 changes: 6 additions & 14 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
-- this is the first file executed when the application starts
-- we have to load the first modules form here

-- set true so that modules are reloaded when modified. (Note: Use only dev mod)
AUTO_RELOAD_MODULE = false

-- WALKING SYSTEM
-- Set true if using Nostalrius 7.2, Nekiro TFS-1.5-Downgrades-7.72
-- or any protocol below 860 that the walking system is stuttering.
g_game.setForceNewWalkingFormula(true)

-- set latest supported version
g_game.setLastSupportedVersion(1291)

-- updater
-- updater
Services = {
--updater = "http://localhost/api/updater.php",
}
Expand All @@ -27,8 +20,8 @@ g_logger.info("== operating system: " .. g_platform.getOSName())

-- print first terminal message
g_logger.info(g_app.getName() .. ' ' .. g_app.getVersion() .. ' rev ' .. g_app.getBuildRevision() .. ' (' ..
g_app.getBuildCommit() .. ') built on ' .. g_app.getBuildDate() .. ' for arch ' ..
g_app.getBuildArch())
g_app.getBuildCommit() .. ') built on ' .. g_app.getBuildDate() .. ' for arch ' ..
g_app.getBuildArch())

-- add data directory to the search path
if not g_resources.addSearchPath(g_resources.getWorkDir() .. 'data', true) then
Expand Down Expand Up @@ -61,7 +54,6 @@ g_modules.ensureModuleLoaded('gamelib')
g_modules.ensureModuleLoaded("startup")

local function loadModules()

-- client modules 100-499
g_modules.autoLoadModules(499)
g_modules.ensureModuleLoaded('client')
Expand All @@ -82,8 +74,8 @@ end

-- run updater, must use data.zip
if g_app.hasUpdater() then
g_modules.ensureModuleLoaded("updater")
return Updater.init(loadModules)
g_modules.ensureModuleLoaded("updater")
return Updater.init(loadModules)
end

loadModules()
1 change: 1 addition & 0 deletions modules/client/client.otmod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Module
load-later:
- client_styles
- client_locales
- client_config
- client_topmenu
- client_background
- client_options
Expand Down
14 changes: 14 additions & 0 deletions modules/client_config/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function init()
-- WALKING SYSTEM
-- Set true if using Nostalrius 7.2, Nekiro TFS-1.5-Downgrades-7.72
-- or any protocol below 860 that the walking system is stuttering.
g_game.setForceNewWalkingFormula(true)

-- set latest supported version
g_game.setLastSupportedVersion(1291)

g_fonts.setWidgetTextFont('verdana-11px-antialised')
g_fonts.setStaticTextFont('verdana-11px-rounded')
g_fonts.setAnimatedTextFont('verdana-11px-rounded')
g_fonts.setCreatureNameFont('verdana-11px-rounded')
end
8 changes: 8 additions & 0 deletions modules/client_config/config.otmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Module
name: client_config
description: Client Config
author: Mehah
website: https://github.com/mehah/otclient
sandboxed: true
scripts: [ config ]
@onLoad: init()
2 changes: 1 addition & 1 deletion src/client/animatedtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

AnimatedText::AnimatedText()
{
m_cachedText.setFont(g_fonts.getFont("verdana-11px-rounded"));
m_cachedText.setFont(g_fonts.getAnimatedTextFont());
m_cachedText.setAlign(Fw::AlignLeft);
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ double Creature::speedC = 0;

Creature::Creature() :m_type(Proto::CreatureTypeUnknown)
{
m_name.setFont(g_fonts.getFont("verdana-11px-rounded"));
m_name.setFont(g_fonts.getCreatureNameFont());
m_name.setAlign(Fw::AlignTopCenter);

// Example of how to send a UniformValue to shader
Expand Down
2 changes: 1 addition & 1 deletion src/client/statictext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

StaticText::StaticText()
{
m_cachedText.setFont(g_fonts.getFont("verdana-11px-rounded"));
m_cachedText.setFont(g_fonts.getStaticTextFont());
m_cachedText.setAlign(Fw::AlignCenter);
}

Expand Down
3 changes: 1 addition & 2 deletions src/framework/graphics/cachedtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#include <framework/graphics/drawpoolmanager.h>
#include "fontmanager.h"

CachedText::CachedText() : m_font(g_fonts.getDefaultFont()), m_align(Fw::AlignCenter), m_coordsBuffer(std::make_shared<CoordsBuffer>())
{}
CachedText::CachedText() : m_align(Fw::AlignCenter), m_coordsBuffer(std::make_shared<CoordsBuffer>()) {}

void CachedText::draw(const Rect& rect, const Color& color)
{
Expand Down
26 changes: 13 additions & 13 deletions src/framework/graphics/fontmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,14 @@

FontManager g_fonts;

FontManager::FontManager() : m_defaultFont(std::make_shared<BitmapFont>("emptyfont")) {}
void FontManager::terminate() { clearFonts(); }

void FontManager::terminate()
{
m_fonts.clear();
m_defaultFont = nullptr;
}

void FontManager::clearFonts()
{
void FontManager::clearFonts() {
m_fonts.clear();
m_defaultFont = std::make_shared<BitmapFont>("emptyfont");
m_creatureNameFont = nullptr;
m_animatedTextFont = nullptr;
m_staticTextFont = nullptr;
m_widgetTextFont = nullptr;
}

bool FontManager::importFont(const std::string& file)
Expand All @@ -63,8 +59,12 @@ bool FontManager::importFont(const std::string& file)
m_fonts.emplace_back(font);

// set as default if needed
if (!m_defaultFont || fontNode->valueAt<bool>("default", false))
m_defaultFont = font;
if (fontNode->valueAt<bool>("default", false)) {
m_creatureNameFont = font;
m_animatedTextFont = font;
m_staticTextFont = font;
m_widgetTextFont = font;
}

return true;
} catch (const stdext::exception& e) {
Expand Down Expand Up @@ -92,5 +92,5 @@ BitmapFontPtr FontManager::getFont(const std::string_view fontName)

// when not found, fallback to default font
g_logger.error(stdext::format("font '%s' not found", fontName));
return getDefaultFont();
return nullptr;
}
18 changes: 13 additions & 5 deletions src/framework/graphics/fontmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,30 @@
class FontManager
{
public:
FontManager();

void terminate();
void clearFonts();

bool importFont(const std::string& file);

bool fontExists(const std::string_view fontName);
BitmapFontPtr getFont(const std::string_view fontName);
BitmapFontPtr getDefaultFont() { return m_defaultFont; }

void setDefaultFont(const std::string_view fontName) { m_defaultFont = getFont(fontName); }
BitmapFontPtr getCreatureNameFont() { return m_creatureNameFont; }
BitmapFontPtr getAnimatedTextFont() { return m_animatedTextFont; }
BitmapFontPtr getStaticTextFont() { return m_staticTextFont; }
BitmapFontPtr getWidgetTextFont() { return m_widgetTextFont; }

void setCreatureNameFont(const std::string_view fontName) { m_creatureNameFont = getFont(fontName); }
void setAnimatedTextFont(const std::string_view fontName) { m_animatedTextFont = getFont(fontName); }
void setStaticTextFont(const std::string_view fontName) { m_staticTextFont = getFont(fontName); }
void setWidgetTextFont(const std::string_view fontName) { m_widgetTextFont = getFont(fontName); }

private:
std::vector<BitmapFontPtr> m_fonts;
BitmapFontPtr m_defaultFont;
BitmapFontPtr m_creatureNameFont;
BitmapFontPtr m_animatedTextFont;
BitmapFontPtr m_staticTextFont;
BitmapFontPtr m_widgetTextFont;
};

extern FontManager g_fonts;
5 changes: 4 additions & 1 deletion src/framework/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ void Application::registerLuaFunctions()
g_lua.bindSingletonFunction("g_fonts", "clearFonts", &FontManager::clearFonts, &g_fonts);
g_lua.bindSingletonFunction("g_fonts", "importFont", &FontManager::importFont, &g_fonts);
g_lua.bindSingletonFunction("g_fonts", "fontExists", &FontManager::fontExists, &g_fonts);
g_lua.bindSingletonFunction("g_fonts", "setDefaultFont", &FontManager::setDefaultFont, &g_fonts);
g_lua.bindSingletonFunction("g_fonts", "setCreatureNameFont", &FontManager::setCreatureNameFont, &g_fonts);
g_lua.bindSingletonFunction("g_fonts", "setAnimatedTextFont", &FontManager::setAnimatedTextFont, &g_fonts);
g_lua.bindSingletonFunction("g_fonts", "setStaticTextFont", &FontManager::setStaticTextFont, &g_fonts);
g_lua.bindSingletonFunction("g_fonts", "setWidgetTextFont", &FontManager::setWidgetTextFont, &g_fonts);

// ParticleManager
g_lua.registerSingletonClass("g_particles");
Expand Down
2 changes: 1 addition & 1 deletion src/framework/ui/uiwidgettext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

void UIWidget::initText()
{
m_font = g_fonts.getDefaultFont();
m_font = g_fonts.getWidgetTextFont();
m_textAlign = Fw::AlignCenter;
m_coordsBuffer = std::make_shared<CoordsBuffer>();
}
Expand Down

0 comments on commit 4d43431

Please sign in to comment.