Browse Source

Move store graphics out of `stores.cpp`

These graphics are used in various places outside of `stores.cpp`.
pull/4015/head
Gleb Mazovetskiy 4 years ago committed by Anders Jenbo
parent
commit
1519e995cf
  1. 1
      Source/CMakeLists.txt
  2. 13
      Source/diablo.cpp
  3. 7
      Source/engine/render/text_render.cpp
  4. 7
      Source/engine/render/text_render.hpp
  5. 6
      Source/error.cpp
  6. 2
      Source/error.h
  7. 2
      Source/items.cpp
  8. 22
      Source/panels/info_box.cpp
  9. 25
      Source/panels/info_box.hpp
  10. 1
      Source/quests.h
  11. 16
      Source/stores.cpp
  12. 8
      Source/stores.h

1
Source/CMakeLists.txt

@ -129,6 +129,7 @@ set(libdevilutionx_SRCS
DiabloUI/support_lines.cpp
DiabloUI/title.cpp
panels/charpanel.cpp
panels/info_box.cpp
panels/mainpanel.cpp
panels/spell_book.cpp
panels/spell_icons.cpp

13
Source/diablo.cpp

@ -52,6 +52,7 @@
#include "nthread.h"
#include "objects.h"
#include "options.h"
#include "panels/info_box.hpp"
#include "panels/spell_book.hpp"
#include "panels/spell_list.hpp"
#include "pfile.h"
@ -172,6 +173,7 @@ void FreeGame()
FreeInvGFX();
FreeGMenu();
FreeQuestText();
FreeInfoBoxGfx();
FreeStoreMem();
for (auto &player : Players)
@ -982,6 +984,9 @@ void DiabloInit()
// Item graphics are loaded early, they already get touched during hero selection.
InitItemGFX();
// Always available.
LoadSmallSelectionSpinner();
}
void DiabloSplash()
@ -1985,15 +1990,17 @@ void LoadGameLevel(bool firstflag, lvl_entry lvldir)
if (firstflag) {
InitInv();
InitQuestText();
InitStores();
InitInfoBoxGfx();
InitAutomapOnce();
InitHelp();
}
SetRndSeed(glSeedTbl[currlevel]);
if (leveltype == DTYPE_TOWN)
if (leveltype == DTYPE_TOWN) {
SetupTownStores();
} else {
FreeStoreMem();
}
IncProgress();
InitAutomap();

7
Source/engine/render/text_render.cpp

@ -25,6 +25,8 @@
namespace devilution {
std::optional<CelSprite> pSPentSpn2Cels;
namespace {
constexpr char32_t ZWSP = U'\u200B'; // Zero-width space
@ -372,6 +374,11 @@ int DoDrawString(const Surface &out, string_view text, Rectangle rect, Point &ch
} // namespace
void LoadSmallSelectionSpinner()
{
pSPentSpn2Cels = LoadCel("Data\\PentSpn2.CEL", 12);
}
void UnloadFonts(GameFontTables size, text_color color)
{
uint32_t fontStyle = (color << 24) | (size << 16);

7
Source/engine/render/text_render.hpp

@ -118,8 +118,15 @@ private:
std::string formatted_;
};
/**
* @brief Small text selection cursor.
*
* Also used in the stores and the quest log.
*/
extern std::optional<CelSprite> pSPentSpn2Cels;
void LoadSmallSelectionSpinner();
void UnloadFonts(GameFontTables size, text_color color);
/**

6
Source/error.cpp

@ -12,6 +12,7 @@
#include "control.h"
#include "engine/render/cel_render.hpp"
#include "engine/render/text_render.hpp"
#include "panels/info_box.hpp"
#include "stores.h"
#include "utils/language.h"
@ -113,11 +114,10 @@ const char *const MsgStrings[] = {
void InitDiabloMsg(diablo_message e)
{
std::string msg = _(MsgStrings[e]);
InitDiabloMsg(msg);
InitDiabloMsg(LanguageTranslate(MsgStrings[e]));
}
void InitDiabloMsg(std::string msg)
void InitDiabloMsg(const std::string &msg)
{
if (DiabloMessages.size() >= MAX_SEND_STR_LEN)
return;

2
Source/error.h

@ -71,7 +71,7 @@ enum diablo_message : uint8_t {
};
void InitDiabloMsg(diablo_message e);
void InitDiabloMsg(std::string msg);
void InitDiabloMsg(const std::string &msg);
bool IsDiabloMsgAvailable();
void CancelCurrentDiabloMsg();
void ClrDiabloMsg();

2
Source/items.cpp

@ -29,8 +29,10 @@
#include "lighting.h"
#include "missiles.h"
#include "options.h"
#include "panels/info_box.hpp"
#include "panels/ui_panels.hpp"
#include "player.h"
#include "spells.h"
#include "stores.h"
#include "town.h"
#include "utils/language.h"

22
Source/panels/info_box.cpp

@ -0,0 +1,22 @@
#include "panels/info_box.hpp"
#include "engine/load_cel.hpp"
namespace devilution {
std::optional<CelSprite> pSTextBoxCels;
std::optional<CelSprite> pSTextSlidCels;
void InitInfoBoxGfx()
{
pSTextSlidCels = LoadCel("Data\\TextSlid.CEL", 12);
pSTextBoxCels = LoadCel("Data\\TextBox2.CEL", 271);
}
void FreeInfoBoxGfx()
{
pSTextBoxCels = std::nullopt;
pSTextSlidCels = std::nullopt;
}
} // namespace devilution

25
Source/panels/info_box.hpp

@ -0,0 +1,25 @@
#pragma once
#include "engine/cel_sprite.hpp"
#include "utils/stdcompat/optional.hpp"
namespace devilution {
/**
* @brief Info box frame
*
* Used in stores, the quest log, the help window, and the unique item info window.
*/
extern std::optional<CelSprite> pSTextBoxCels;
/**
* @brief Info box scrollbar graphics.
*
* Used in stores and `DrawDiabloMsg`.
*/
extern std::optional<CelSprite> pSTextSlidCels;
void InitInfoBoxGfx();
void FreeInfoBoxGfx();
} // namespace devilution

1
Source/quests.h

@ -13,6 +13,7 @@
#include "gendung.h"
#include "monster.h"
#include "objdat.h"
#include "panels/info_box.hpp"
#include "textdat.h"
#include "utils/attributes.h"
#include "utils/stdcompat/optional.hpp"

16
Source/stores.cpp

@ -17,6 +17,7 @@
#include "init.h"
#include "minitext.h"
#include "options.h"
#include "panels/info_box.hpp"
#include "towners.h"
#include "utils/language.h"
@ -24,10 +25,6 @@ namespace devilution {
Item golditem;
std::optional<CelSprite> pSPentSpn2Cels;
std::optional<CelSprite> pSTextBoxCels;
std::optional<CelSprite> pSTextSlidCels;
talk_id stextflag;
int storenumh;
@ -2282,11 +2279,8 @@ void AddStoreHoldRepair(Item *itm, int8_t i)
storenumh++;
}
void InitStores()
void SetupTownStores()
{
pSPentSpn2Cels = LoadCel("Data\\PentSpn2.CEL", 12);
pSTextBoxCels = LoadCel("Data\\TextBox2.CEL", 271);
pSTextSlidCels = LoadCel("Data\\TextSlid.CEL", 12);
ClearSText(0, STORE_LINES);
stextflag = STORE_NONE;
stextsize = false;
@ -2299,10 +2293,7 @@ void InitStores()
boyitem._itype = ItemType::None;
boylevel = 0;
}
void SetupTownStores()
{
auto &myPlayer = Players[MyPlayerId];
int l = myPlayer._pLevel / 2;
@ -2325,8 +2316,7 @@ void SetupTownStores()
void FreeStoreMem()
{
pSTextBoxCels = std::nullopt;
pSTextSlidCels = std::nullopt;
stextflag = STORE_NONE;
}
void PrintSString(const Surface &out, int margin, int line, const char *text, UiFlags flags, int price)

8
Source/stores.h

@ -67,13 +67,6 @@ struct STextStruct {
}
};
/** Shop frame graphics */
extern std::optional<CelSprite> pSTextBoxCels;
/** Small text selection cursor */
extern std::optional<CelSprite> pSPentSpn2Cels;
/** Scrollbar graphics */
extern std::optional<CelSprite> pSTextSlidCels;
/** Currently active store */
extern talk_id stextflag;
@ -108,7 +101,6 @@ extern int boylevel;
extern Item boyitem;
void AddStoreHoldRepair(Item *itm, int8_t i);
void InitStores();
void SetupTownStores();
void FreeStoreMem();
void PrintSString(const Surface &out, int margin, int line, const char *text, UiFlags flags, int price = 0);

Loading…
Cancel
Save