Skip to content

Commit

Permalink
Implement DisplayString stuff (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonwil authored Oct 6, 2023
1 parent 5b0b6d5 commit f110482
Show file tree
Hide file tree
Showing 16 changed files with 588 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ set(GAMEENGINE_SRC
game/client/languagefilter.cpp
game/client/line2d.cpp
game/client/maputil.cpp
game/client/messagestream/hotkey.cpp
game/client/messagestream/metaevent.cpp
game/client/messagestream/selectionxlat.cpp
game/client/optionpreferences.cpp
Expand Down Expand Up @@ -405,6 +406,8 @@ set(GAMEENGINE_SRC
platform/w3dengine/client/w3ddebugdisplay.cpp
platform/w3dengine/client/w3ddebugicons.cpp
platform/w3dengine/client/w3ddisplay.cpp
platform/w3dengine/client/w3ddisplaystring.cpp
platform/w3dengine/client/w3ddisplaystringmanager.cpp
platform/w3dengine/client/w3ddynamiclight.cpp
platform/w3dengine/client/w3dfilesystem.cpp
platform/w3dengine/client/w3dgameclient.cpp
Expand Down
6 changes: 3 additions & 3 deletions src/game/client/displaystring.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class DisplayString : public MemoryPoolObject
virtual void Reset();
virtual void Set_Font(GameFont *font) { m_font = font; }
virtual GameFont *Get_Font() { return m_font; }
virtual void Set_Word_Wrap(int length) = 0;
virtual void Set_Word_Wrap(int wrap_width) = 0;
virtual void Set_Word_Wrap_Centered(bool on) = 0;
virtual void Draw(int x, int y, int color, int border_color) = 0;
virtual void Draw(int x, int y, int color, int border_color, int x_offset, int y_offset) = 0;
virtual void Draw(int x, int y, int color, int border_color, int border_x_offset, int border_y_offset) = 0;
virtual void Get_Size(int *x, int *y) = 0;
virtual int Get_Width(int char_count) = 0;
virtual void Set_Use_Hotkey(bool state, int val) = 0;
virtual void Set_Use_Hotkey(bool state, int color) = 0;
virtual void Set_Clip_Region(IRegion2D *region) {}
virtual void Remove_Last_Char();
virtual void Add_Char(wchar_t ch);
Expand Down
4 changes: 4 additions & 0 deletions src/game/client/displaystringmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
DisplayStringManager *g_theDisplayStringManager = nullptr;
#endif

DisplayStringManager::DisplayStringManager() : m_stringList(nullptr), m_currentCheckpoint(nullptr) {}

DisplayStringManager::~DisplayStringManager() {}

/**
* @brief Links a DisplayString into the managers internal list.
*
Expand Down
4 changes: 2 additions & 2 deletions src/game/client/displaystringmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DisplayStringManager : public SubsystemInterface
void Link(DisplayString *string);
void Unlink(DisplayString *string);

private:
protected:
DisplayString *m_stringList;
DisplayString *m_currentCheckpoint;
};
Expand All @@ -45,4 +45,4 @@ class DisplayStringManager : public SubsystemInterface
extern DisplayStringManager *&g_theDisplayStringManager;
#else
extern DisplayStringManager *g_theDisplayStringManager;
#endif
#endif
1 change: 1 addition & 0 deletions src/game/client/drawgroupinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class DrawGroupInfo

static const FieldParse s_parseTable[];
friend class Drawable;
friend class W3DDisplayStringManager;
};

#ifdef GAME_DLL
Expand Down
4 changes: 3 additions & 1 deletion src/game/client/globallanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class GlobalLanguage : public SubsystemInterface
{
public:
friend W3DFontLibrary;
friend class W3DDisplayString;

GlobalLanguage();
virtual ~GlobalLanguage() {}
Expand All @@ -60,6 +61,7 @@ class GlobalLanguage : public SubsystemInterface
const FontDesc &Copyright_Font() const { return m_copyrightFont; }
const FontDesc &Debug_Display_Font() const { return m_nativeDebugDisplayFont; }
const FontDesc &Default_Window_Font() const { return m_defaultWindowFont; }
const FontDesc &Default_Display_String_Font() const { return m_defaultDisplayStringFont; }

static void Parse_Language_Definition(INI *ini);
static void Parse_Font_Filename(INI *ini, void *formal, void *store, void const *user_data);
Expand Down Expand Up @@ -98,4 +100,4 @@ class GlobalLanguage : public SubsystemInterface
extern GlobalLanguage *&g_theGlobalLanguage;
#else
extern GlobalLanguage *g_theGlobalLanguage;
#endif
#endif
37 changes: 37 additions & 0 deletions src/game/client/messagestream/hotkey.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file
*
* @author Jonathan Wilson
*
* @brief Hotkey
*
* @copyright Thyme is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 2 of the License, or (at your option) any later version.
* A full copy of the GNU General Public License can be found in
* LICENSE
*/
#include "hotkey.h"
#include "unicodestring.h"

#ifndef GAME_DLL
HotKeyManager *g_theHotKeyManager;
#endif

Utf8String HotKeyManager::Search_Hot_Key(const Utf16String &key)
{
if (!key.Is_Empty()) {
for (const unichar_t *i = key.Str(); i != nullptr && *i != '\0'; i++) {
if (*i == '&') {
Utf16String str(Utf16String::s_emptyString);
str.Concat(i[1]);
Utf8String str2;
str2.Translate(str.Str());
return str2;
}
}
}

return Utf8String::s_emptyString;
}
51 changes: 51 additions & 0 deletions src/game/client/messagestream/hotkey.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @file
*
* @author Jonathan Wilson
*
* @brief Hotkey
*
* @copyright Thyme is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 2 of the License, or (at your option) any later version.
* A full copy of the GNU General Public License can be found in
* LICENSE
*/
#pragma once
#include "always.h"
#include "subsysteminterface.h"
#include <map>

class GameWindow;

class HotKey
{
public:
HotKey() : m_window(nullptr) {}

private:
Utf8String *m_key;
GameWindow *m_window;
friend class HotKeyManager;
};

class HotKeyManager : public SubsystemInterface
{
public:
virtual ~HotKeyManager() override;

virtual void Init() override;
virtual void Reset() override;
virtual void Update() override;
Utf8String Search_Hot_Key(const Utf16String &str);

private:
std::map<Utf8String, HotKey> m_hotKeys;
};

#ifdef GAME_DLL
extern HotKeyManager *&g_theHotKeyManager;
#else
extern HotKeyManager *g_theHotKeyManager;
#endif
4 changes: 4 additions & 0 deletions src/hooker/setupglobals_zh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,3 +828,7 @@ SelectionTranslator *&g_theSelectionTranslator = Make_Global<SelectionTranslator
class HeaderTemplateManager;
HeaderTemplateManager *&g_theHeaderTemplateManager =
Make_Global<HeaderTemplateManager *>(PICK_ADDRESS(0x00A2BEFC, 0x04CA9B04));

// hotkey.cpp
class HotKeyManager;
HotKeyManager *&g_theHotKeyManager = Make_Global<HotKeyManager *>(PICK_ADDRESS(0x00A2C678, 0x04CA8B00));
1 change: 1 addition & 0 deletions src/hooker/setuphooks_zh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,7 @@ void Setup_Hooks()
Hook_Any(0x007753A0, W3DGameClient::Create_VideoPlayer);
Hook_Any(0x00775460, W3DGameClient::Create_SnowManager);
Hook_Any(0x00775260, W3DGameClient::Create_WindowManager);
Hook_Any(0x00775340, W3DGameClient::Create_DisplayStringManager);

// w3dprojectedshadow.cpp
Hook_Any(0x0075ECC0, W3DProjectedShadowManager::Hook_Ctor);
Expand Down
Loading

0 comments on commit f110482

Please sign in to comment.