Skip to content

Commit

Permalink
Support for achievement types (#1052)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamiras authored Jan 24, 2024
1 parent b54bfc5 commit 1adb9f7
Show file tree
Hide file tree
Showing 32 changed files with 501 additions and 8 deletions.
27 changes: 27 additions & 0 deletions data/missable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef MISSABLE_H
#define MISSABLE_H

const uint8_t MISSABLE_PIXELS[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x23,0xae,0xa7,0x00,0x0a,0xe1,0xab,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x27,0x00,0x14,0xfe,0xf4,0x05,0x3a,0xff,0xce,0x00,0x03,0x4c,0x00,0x00,0x00,0x00,
0x00,0x00,0x02,0x96,0xf8,0x38,0x00,0x56,0x6e,0x80,0x80,0x6d,0x35,0x00,0x87,0xff,0x88,0x00,0x00,0x00,
0x00,0x00,0x00,0x90,0xf7,0x55,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x5d,0xf0,0x3d,0x00,0x00,0x00,
0x00,0x0c,0x00,0x04,0x2b,0x00,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x00,0x11,0x00,0x0d,0x34,0x00,
0x07,0xe2,0xaa,0x0f,0x00,0x00,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x00,0x00,0x21,0xeb,0xe6,0x09,
0x3c,0xf7,0xcf,0x01,0x00,0x00,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x00,0x00,0x01,0xcb,0xc1,0x1f,
0x00,0x18,0x31,0x00,0x00,0x00,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x00,0x00,0x00,0x11,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x46,
0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x00,0x00,0x00,0x02,0xff,0xfd,
0xff,0xff,0x04,0x00,0x00,0x00,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x00,0x00,0x00,0x00,0xbc,0xb8,
0x8d,0x89,0x08,0x00,0x00,0x00,0x00,0x00,0x72,0xab,0xab,0x72,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x45,0x5a,0x06,
0x04,0x6a,0xb5,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc7,0xff,0x61,
0x0a,0xe4,0xff,0x49,0x00,0x00,0x00,0x00,0x8e,0xd5,0xd5,0x8e,0x00,0x00,0x00,0x00,0x02,0x62,0xbf,0x0a,
0x00,0x51,0x51,0x01,0x01,0x00,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x00,0x35,0x27,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0xc6,0x62,0x00,0x00,0xab,0xff,0xff,0xab,0x00,0x00,0x3a,0xf5,0xdc,0x14,0x00,0x00,
0x00,0x00,0x00,0x60,0xff,0xd8,0x08,0x19,0x6b,0x80,0x80,0x68,0x62,0x17,0x0a,0xca,0x9d,0x05,0x00,0x00,
0x00,0x00,0x00,0x00,0x5d,0x33,0x00,0x83,0xff,0x81,0x00,0xaf,0xff,0x61,0x00,0x0c,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0xe6,0x57,0x00,0x60,0xb2,0x47,0x00,0x00,0x00,0x00,0x00,0x00,
};

#endif MISSABLE_H
Binary file added data/missable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions data/png_to_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python3
import PIL.Image as Image

def convert(source, output, name):
bytes = []
with Image.open(source, mode='r') as img:
bytes = img.tobytes()

with open(output, mode='w') as f:
f.write("#ifndef {0}_H\n".format(name));
f.write("#define {0}_H\n\n".format(name));
f.write("const uint8_t {0}_PIXELS[] = {{\n".format(name));

i = 0
num_bytes = len(bytes)
while i < num_bytes:
f.write(" ")
for j in range(0,20):
if i < num_bytes:
# just write the alpha value. if it's non-zero the RGB will be constant
f.write("0x{0:02x},".format(bytes[i+3]))
i += 4
f.write("\n")

f.write("};\n\n");
f.write("#endif {0}_H\n".format(name));

convert('missable.png', 'missable.h', 'MISSABLE')
convert('progression.png', 'progression.h', 'PROGRESSION')
convert('win-condition.png', 'win-condition.h', 'WIN_CONDITION')

27 changes: 27 additions & 0 deletions data/progression.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef PROGRESSION_H
#define PROGRESSION_H

const uint8_t PROGRESSION_PIXELS[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x14,0x00,0x00,0x14,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x11,0x89,0xe7,0xfa,0x17,0x17,0xfa,0xe8,0x89,0x13,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x06,0xe7,0xff,0xd6,0x7a,0x02,0x02,0x7a,0xd6,0xff,0xe8,0x41,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x84,0x58,0x01,0x00,0x00,0x00,0x00,0x01,0x5a,0xf0,0xf7,0x41,0x00,0x00,0x00,
0x00,0x00,0x11,0x7e,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2e,0xef,0xe7,0x13,0x00,0x00,
0x00,0x00,0x8a,0xff,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5a,0xff,0x87,0x00,0x00,
0x00,0x02,0xeb,0xd5,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x6d,0x0c,0x00,0x01,0xd6,0xea,0x02,0x00,
0x00,0x2b,0xff,0x84,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0xc9,0xff,0x3e,0x00,0x00,0x87,0xff,0x2c,0x00,
0x00,0x08,0x7e,0x1d,0x00,0x00,0x25,0xc2,0x3b,0x0f,0xc8,0xff,0x83,0x00,0x00,0x00,0x60,0xff,0x4a,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x25,0xf2,0xf2,0xd0,0xff,0x83,0x00,0x00,0x00,0x00,0x61,0xff,0x49,0x00,
0x00,0x00,0x9b,0x50,0x00,0x00,0x00,0x3b,0xf2,0xff,0x83,0x00,0x00,0x00,0x00,0x00,0x87,0xff,0x2c,0x00,
0x00,0x01,0xe9,0xd5,0x01,0x00,0x00,0x00,0x32,0x5a,0x00,0x00,0x00,0x00,0x00,0x01,0xd7,0xea,0x02,0x00,
0x00,0x00,0x8a,0xff,0x57,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5d,0xff,0x86,0x00,0x00,
0x00,0x00,0x12,0xe6,0x87,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0xef,0xe6,0x12,0x00,0x00,
0x00,0x00,0x00,0x07,0x01,0x0f,0x3e,0x01,0x00,0x00,0x00,0x00,0x01,0x5c,0xf1,0xf7,0x40,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7f,0xff,0xd5,0x7a,0x02,0x02,0x7a,0xd7,0xff,0xe7,0x3f,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x12,0x8a,0xea,0xfa,0x17,0x17,0xfa,0xe7,0x87,0x12,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x15,0x00,0x00,0x14,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

#endif PROGRESSION_H
Binary file added data/progression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions data/win-condition.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef WIN_CONDITION_H
#define WIN_CONDITION_H

const uint8_t WIN_CONDITION_PIXELS[] = {
0x00,0x00,0x00,0x00,0x00,0x12,0x06,0x00,0x00,0x0c,0x0c,0x00,0x00,0x06,0x12,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xeb,0x96,0x00,0x00,0xc1,0xc1,0x00,0x00,0x96,0xeb,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xff,0xa9,0x00,0x00,0xd4,0xd4,0x00,0x00,0xa9,0xff,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xff,0xa9,0x00,0x00,0xd4,0xd4,0x00,0x00,0xa9,0xff,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xff,0xa9,0x00,0x00,0xd3,0xd3,0x00,0x00,0xa9,0xff,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xff,0xa9,0x00,0x00,0x5c,0x5c,0x00,0x00,0xa9,0xff,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xff,0xa9,0x00,0x00,0x00,0x00,0x00,0x00,0xa9,0xff,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xff,0xa9,0x00,0x00,0x00,0x00,0x00,0x00,0xa9,0xff,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x95,0x56,0x00,0x00,0x96,0x96,0x00,0x00,0x56,0x95,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x34,0xfe,0xfe,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb3,0xfd,0xfd,0xb3,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x05,0x43,0x6f,0x9d,0xfe,0xa8,0xa8,0xfe,0x9d,0x6f,0x43,0x05,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x71,0xff,0xff,0xff,0xe4,0x28,0x28,0xe4,0xff,0xff,0xff,0x71,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1b,0xdc,0xff,0x78,0x00,0x00,0x00,0x00,0x78,0xff,0xdc,0x1b,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x1c,0xdc,0xfd,0x25,0x00,0x00,0x25,0xfd,0xdc,0x1c,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x8f,0xff,0x1e,0x07,0x07,0x1e,0xff,0x8f,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xb4,0xfa,0x6c,0xe2,0xe2,0x6c,0xfa,0xb4,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xd8,0xff,0xff,0xe8,0xe8,0xff,0xff,0xd8,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0xdd,0xe8,0x73,0x0a,0x0a,0x73,0xe8,0xdd,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x09,0x00,0x00,0x00,0x00,0x09,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
};

#endif WIN_CONDITION_H
Binary file added data/win-condition.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/RA_Resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@
#define IDC_RA_MEMVIEWER_4 1240
#define IDC_RA_DISPLAY_PROGRESS_INDICATOR 1241
#define IDC_RA_MEMVIEW_32BITBE 1242
#define IDC_RA_LBL_TYPE 1243
#define IDC_RA_TYPE 1244


#define IDD_RA_MEMORY 1501
Expand Down
6 changes: 4 additions & 2 deletions src/RA_Shared.rc
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,11 @@ BEGIN
EDITTEXT IDC_RA_TITLE,50,4,214,13,ES_AUTOHSCROLL
LTEXT "ID:",IDC_RA_LBL_ID,282,7,11,8
EDITTEXT IDC_RA_ID,293,5,44,13,ES_AUTOHSCROLL | WS_DISABLED,WS_EX_RIGHT
CONTROL "Active",IDC_RA_CHK_ACTIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,345,6,40,10
CONTROL "Active",IDC_RA_CHK_ACTIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,340,6,40,10
LTEXT "Description:",IDC_STATIC,4,23,42,8
EDITTEXT IDC_RA_DESCRIPTION,50,21,333,13,ES_AUTOHSCROLL
EDITTEXT IDC_RA_DESCRIPTION,50,21,287,13,ES_AUTOHSCROLL
LTEXT "Type:",IDC_RA_LBL_TYPE,328,23,23,8
COMBOBOX IDC_RA_TYPE,348,21,22,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Points:",IDC_RA_LBL_POINTS,4,40,23,8
COMBOBOX IDC_RA_POINTS,50,38,42,13,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Format:",IDC_RA_LBL_FORMAT,4,40,23,8
Expand Down
1 change: 1 addition & 0 deletions src/api/UpdateAchievement.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public:
unsigned int Points{ 0U };
unsigned int Category{ 0U };
std::string Badge;
unsigned int Type { 0U };

using Callback = std::function<void(const Response& response)>;

Expand Down
1 change: 1 addition & 0 deletions src/api/impl/ConnectedServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ UpdateAchievement::Response ConnectedServer::UpdateAchievement(const UpdateAchie
api_params.points = request.Points;
api_params.category = request.Category;
api_params.badge = request.Badge.c_str();
api_params.type = request.Type;

rc_api_request_t api_request;
if (rc_api_init_update_achievement_request(&api_request, &api_params) == RC_OK)
Expand Down
91 changes: 87 additions & 4 deletions src/data/models/AchievementModel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "AchievementModel.hh"

#include "RA_Log.h"

#include "data\context\GameContext.hh"

#include "data\models\LocalBadgesModel.hh"
Expand All @@ -17,6 +19,7 @@ namespace data {
namespace models {

const IntModelProperty AchievementModel::PointsProperty("AchievementModel", "Points", 5);
const IntModelProperty AchievementModel::AchievementTypeProperty("AchievementModel", "Type", ra::etoi(ra::data::models::AchievementType::None));
const StringModelProperty AchievementModel::BadgeProperty("AchievementModel", "Badge", L"00000");
const BoolModelProperty AchievementModel::PauseOnResetProperty("AchievementModel", "PauseOnReset", false);
const BoolModelProperty AchievementModel::PauseOnTriggerProperty("AchievementModel", "PauseOnTrigger", false);
Expand All @@ -30,6 +33,7 @@ AchievementModel::AchievementModel() noexcept
GSL_SUPPRESS_F6 SetValue(TypeProperty, ra::etoi(AssetType::Achievement));

SetTransactional(PointsProperty);
SetTransactional(AchievementTypeProperty);
SetTransactional(BadgeProperty);

GSL_SUPPRESS_F6 AddAssetDefinition(m_pTrigger, TriggerProperty);
Expand Down Expand Up @@ -65,6 +69,11 @@ void AchievementModel::OnValueChanged(const IntModelProperty::ChangeArgs& args)
if (m_pAchievement)
SyncPoints();
}
else if (args.Property == AchievementTypeProperty)
{
if (m_pAchievement)
SyncAchievementType();
}
else if (args.Property == IDProperty)
{
if (m_pAchievement)
Expand Down Expand Up @@ -319,6 +328,28 @@ void AchievementModel::SyncPoints()
m_pAchievement->public_.points = GetPoints();
}

void AchievementModel::SyncAchievementType()
{
switch (GetAchievementType())
{
case ra::data::models::AchievementType::None:
m_pAchievement->public_.type = RC_CLIENT_ACHIEVEMENT_TYPE_STANDARD;
break;
case ra::data::models::AchievementType::Missable:
m_pAchievement->public_.type = RC_CLIENT_ACHIEVEMENT_TYPE_MISSABLE;
break;
case ra::data::models::AchievementType::Progression:
m_pAchievement->public_.type = RC_CLIENT_ACHIEVEMENT_TYPE_PROGRESSION;
break;
case ra::data::models::AchievementType::Win:
m_pAchievement->public_.type = RC_CLIENT_ACHIEVEMENT_TYPE_WIN;
break;
default:
m_pAchievement->public_.type = gsl::narrow_cast<uint8_t>(GetValue(AchievementTypeProperty));
break;
}
}

void AchievementModel::SyncCategory()
{
switch (GetCategory())
Expand Down Expand Up @@ -421,6 +452,26 @@ void AchievementModel::Attach(struct rc_client_achievement_info_t& pAchievement,
SetUpdatedTime(pAchievement.updated_time);
SetTrigger(sTrigger);

switch (pAchievement.public_.type)
{
case RC_CLIENT_ACHIEVEMENT_TYPE_STANDARD:
SetAchievementType(ra::data::models::AchievementType::None);
break;
case RC_CLIENT_ACHIEVEMENT_TYPE_MISSABLE:
SetAchievementType(ra::data::models::AchievementType::Missable);
break;
case RC_CLIENT_ACHIEVEMENT_TYPE_PROGRESSION:
SetAchievementType(ra::data::models::AchievementType::Progression);
break;
case RC_CLIENT_ACHIEVEMENT_TYPE_WIN:
SetAchievementType(ra::data::models::AchievementType::Win);
break;
default:
RA_LOG_ERR("Unsupported achievement type: %d", pAchievement.public_.type);
SetValue(AchievementTypeProperty, pAchievement.public_.type);
break;
}

CreateServerCheckpoint();
CreateLocalCheckpoint();

Expand All @@ -446,14 +497,35 @@ void AchievementModel::AttachAndInitialize(struct rc_client_achievement_info_t&
SyncCategory();
SyncTrigger();
SyncState();
SyncAchievementType();
}

void AchievementModel::Serialize(ra::services::TextWriter& pWriter) const
{
WriteQuoted(pWriter, GetLocalAssetDefinition(m_pTrigger));
WritePossiblyQuoted(pWriter, GetLocalValue(NameProperty));
WritePossiblyQuoted(pWriter, GetLocalValue(DescriptionProperty));
pWriter.Write(":::"); // progress/max/format/author
pWriter.Write("::"); // progress/max

switch (GetAchievementType())
{
case ra::data::models::AchievementType::None:
WritePossiblyQuoted(pWriter, "");
break;
case ra::data::models::AchievementType::Missable:
WritePossiblyQuoted(pWriter, "missable");
break;
case ra::data::models::AchievementType::Progression:
WritePossiblyQuoted(pWriter, "progression");
break;
case ra::data::models::AchievementType::Win:
WritePossiblyQuoted(pWriter, "win_condition");
break;
default:
WriteNumber(pWriter, GetValue(TypeProperty));
break;
}

WritePossiblyQuoted(pWriter, GetLocalValue(AuthorProperty));
WriteNumber(pWriter, GetLocalValue(PointsProperty));
pWriter.Write("::::"); // created/modified/upvotes/downvotes
Expand Down Expand Up @@ -504,9 +576,9 @@ bool AchievementModel::Deserialize(ra::Tokenizer& pTokenizer)
if (!pTokenizer.Consume(':'))
return false;

// field 7: progress format (unused)
pTokenizer.AdvanceTo(':');
if (!pTokenizer.Consume(':'))
// field 7: achievement type
std::string sType;
if (!ReadPossiblyQuoted(pTokenizer, sType))
return false;

// field 8: author (unused)
Expand Down Expand Up @@ -555,6 +627,17 @@ bool AchievementModel::Deserialize(ra::Tokenizer& pTokenizer)
SetBadge(ra::Widen(sBadge));
SetTrigger(sTrigger);

if (sType.empty())
SetAchievementType(ra::data::models::AchievementType::None);
else if (sType == "missable")
SetAchievementType(ra::data::models::AchievementType::Missable);
else if (sType == "progression")
SetAchievementType(ra::data::models::AchievementType::Progression);
else if (sType == "win_condition")
SetAchievementType(ra::data::models::AchievementType::Win);
else
SetValue(AchievementTypeProperty, atoi(sType.c_str()));

return true;
}

Expand Down
24 changes: 24 additions & 0 deletions src/data/models/AchievementModel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ namespace ra {
namespace data {
namespace models {

enum AchievementType
{
None = 0,
Missable,
Progression,
Win,
};

class AchievementModel : public AssetModelBase
{
public:
Expand All @@ -32,6 +40,21 @@ public:
/// </summary>
void SetPoints(int nValue) { SetValue(PointsProperty, nValue); }

/// <summary>
/// The <see cref="ModelProperty" /> for the achievement type.
/// </summary>
static const IntModelProperty AchievementTypeProperty;

/// <summary>
/// Gets the type of the achievement.
/// </summary>
AchievementType GetAchievementType() const { return ra::itoe<AchievementType>(GetValue(AchievementTypeProperty)); }

/// <summary>
/// Sets the type for the achievement.
/// </summary>
void SetAchievementType(AchievementType nValue) { SetValue(AchievementTypeProperty, ra::etoi(nValue)); }

/// <summary>
/// The <see cref="ModelProperty" /> for the badge.
/// </summary>
Expand Down Expand Up @@ -166,6 +189,7 @@ private:
void SyncDescription();
void SyncBadge();
void SyncPoints();
void SyncAchievementType();
void SyncCategory();
void SyncState();
void SyncTrigger();
Expand Down
2 changes: 2 additions & 0 deletions src/ui/drawing/ISurface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public:
/// <param name="nAlpha">The new opacity (0.0-1.0).</param>
virtual void SetOpacity(double fAlpha) = 0;

virtual void SetPixels(int nX, int nY, int nWidth, int nHeight, uint32_t* pARGB) = 0;

protected:
ISurface() noexcept = default;
};
Expand Down
12 changes: 12 additions & 0 deletions src/ui/drawing/gdi/GDIBitmapSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ static constexpr uint8_t BlendPixel(std::uint8_t nTarget, std::uint8_t nBlend, s
return gsl::narrow_cast<std::uint8_t>(((nBlend * nAlpha) + (nTarget * (256 - nAlpha))) / 256);
}

void GDIBitmapSurface::SetPixels(int nX, int nY, int nWidth, int nHeight, uint32_t* pARGB) noexcept
{
const auto nStride = ra::to_signed(GetWidth());
std::uint32_t* pBits = m_pBits + gsl::narrow_cast<size_t>(nY) * nStride + nX;

while (nHeight--)
{
memcpy(pBits + gsl::narrow_cast<size_t>(nHeight) * nStride, pARGB, nWidth * sizeof(uint32_t));
pARGB += nWidth;
}
}

void GDIBitmapSurface::WriteText(int nX, int nY, int nFont, Color nColor, const std::wstring& sText)
{
if (sText.empty())
Expand Down
2 changes: 2 additions & 0 deletions src/ui/drawing/gdi/GDIBitmapSurface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public:

HBITMAP GetHBitmap() const noexcept { return m_hBitmap; }

void SetPixels(int nX, int nY, int nWidth, int nHeight, uint32_t* pARGB) noexcept override;

protected:
std::uint32_t* m_pBits; // see note below about initializing this

Expand Down
Loading

0 comments on commit 1adb9f7

Please sign in to comment.