Skip to content

Commit 1277739

Browse files
committed
add banner editor tool + a few other small fixes
1 parent f93d0f0 commit 1277739

File tree

13 files changed

+213
-29
lines changed

13 files changed

+213
-29
lines changed

include/ResUtil.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "GenUtil.hpp"
4+
#include "io/BtiIO.hpp"
45
#include "constants.hpp"
56

67
#include <json.hpp>
@@ -12,6 +13,17 @@
1213
#include <string>
1314
#include <map>
1415

16+
struct GCBanner {
17+
uint32_t mMagic;
18+
uint8_t mPadding[28];
19+
uint8_t mImage[0x1800];
20+
char mGameTitle[0x20];
21+
char mDeveloper[0x20];
22+
char mGameTitleFull[0x40];
23+
char mDeveloperFull[0x40];
24+
char mGameDescription[0x80];
25+
};
26+
1527
namespace LResUtility
1628
{
1729
extern std::map<std::string, nlohmann::ordered_json> NameMaps;
@@ -41,6 +53,8 @@ namespace LResUtility
4153
public:
4254
bool mLoadedGameArchive = false;
4355
std::shared_ptr<Archive::Rarc> mGameArchive { nullptr };
56+
GCBanner mBanner;
57+
uint8_t mBannerImage[96*32*4] { 0 };
4458
void Init();
4559
void Cleanup();
4660
};

include/io/BtiIO.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ namespace ImageFormat {
1717
}
1818

1919
namespace Encode {
20-
void CMPR(bStream::CStream* stream, uint16_t width, uint16_t height, uint8_t* imageData);
21-
void RGB5A3(bStream::CStream* stream, uint16_t width, uint16_t height, uint8_t* imageData);
22-
void RGB565(bStream::CStream* stream, uint16_t width, uint16_t height, uint8_t* imageData);
20+
void CMPR(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData);
21+
void RGB5A3(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData);
22+
void RGB565(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData);
2323

2424

25-
void I4(bStream::CStream* stream, uint16_t width, uint16_t height, uint8_t* imageData);
26-
void I8(bStream::CStream* stream, uint16_t width, uint16_t height, uint8_t* imageData);
25+
void I4(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData);
26+
void I8(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData);
2727

28-
void IA4(bStream::CStream* stream, uint16_t width, uint16_t height, uint8_t* imageData);
29-
void IA8(bStream::CStream* stream, uint16_t width, uint16_t height, uint8_t* imageData);
28+
void IA4(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData);
29+
void IA8(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData);
3030
}
3131
};
3232

include/ui/BooldozerEditor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,5 @@ class LBooldozerEditor
109109
bool mOpenRootFlag { false };
110110
bool mOpenActorEditor { false };
111111
bool mOpenControlsDialog { false };
112-
112+
bool mOpenBannerEditor { false };
113113
};

src/DOM/RoomDOMNode.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,6 @@ void LRoomDOMNode::RenderDetailsUI(float dt)
674674
}
675675

676676
if(LUIUtility::RenderFileDialog("saveRoomTitlecard", imgPath)){
677-
int x,y,n;
678-
unsigned char* img = stbi_load(imgPath.c_str(), &x, &y, &n, 0);
679-
680-
auto fileData = GCResourceManager.mGameArchive->GetFile(std::format("/kawano/roomname/{}", LResUtility::GetNameMap("MapTitlecards")["titlecards"][mRoomNumber].get<std::string>()));
681677
stbi_write_png(imgPath.c_str(), RoomTitlecard.mWidth, RoomTitlecard.mHeight, 4, RoomTitlecard.GetData(), RoomTitlecard.mWidth*4);
682678
}
683679

src/ResUtil.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ void LResUtility::LGCResourceManager::Init()
5151
MapThumbnails[id] = 0xFFFFFFFF;
5252
}
5353

54+
std::filesystem::path bannerPath(std::filesystem::path(OPTIONS.mRootPath) / "files" / "opening.bnr");
55+
if(std::filesystem::exists(bannerPath)){
56+
bStream::CFileStream bnr(bannerPath.string(), bStream::Endianess::Big, bStream::OpenMode::In);
57+
bnr.readBytesTo((uint8_t*)&mBanner, sizeof(mBanner));
58+
bnr.seek(0x20);
59+
ImageFormat::Decode::RGB5A3(&bnr, 96, 32, mBannerImage);
60+
}
61+
5462
}
5563

5664
void LResUtility::LGCResourceManager::Cleanup(){}

src/UPathRenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,14 @@ void CPathRenderer::Draw(LSceneCamera *Camera) {
169169

170170

171171
uint32_t start = 0;
172-
glUniform1i(mPointModeUniform, GL_TRUE);
172+
glUniform1i(mPointModeUniform, 1);
173173
for(auto& line : mPaths){
174174
glDrawArrays(GL_POINTS, start, line.size());
175175
start += line.size();
176176
}
177177

178178
start = 0;
179-
glUniform1i(mPointModeUniform, GL_FALSE);
179+
glUniform1i(mPointModeUniform, 0);
180180
for(auto& line : mPaths){
181181
glDrawArrays(GL_LINE_STRIP, start, line.size());
182182
start += line.size();

src/UPlaneRenderer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ void CPlaneRenderer::Init(std::string texPath){
138138
}
139139

140140
void CPlaneRenderer::Draw(glm::mat4* transform, uint32_t id, uint32_t selected, int32_t texScaleX, int32_t texScaleY){
141+
glEnable(GL_DEPTH_TEST);
142+
glDepthFunc(GL_LESS);
143+
144+
glEnable(GL_BLEND);
145+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
146+
147+
glEnable(GL_PROGRAM_POINT_SIZE);
148+
141149
glBindTexture(GL_TEXTURE_2D, mTexture);
142150

143151
glm::mat4 mvp = LEditorScene::GetEditorScene()->Camera.GetProjectionMatrix() * LEditorScene::GetEditorScene()->Camera.GetViewMatrix();

src/io/BtiIO.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ uint16_t RGBA8toIA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a){
3838
return output;
3939
}
4040

41+
uint16_t RGBA8toRGB5A3(uint8_t r, uint8_t g, uint8_t b, uint8_t a){
42+
uint16_t color = 0x0000;
43+
if(a != 0xFF){
44+
a >>= 5;
45+
r >>= 4;
46+
g >>= 4;
47+
b >>= 4;
48+
color = 0x0000;
49+
color |= ((a & 0x7) << 12);
50+
color |= ((r & 0xF) << 8);
51+
color |= ((g & 0xF) << 4);
52+
color |= ((b & 0xF) << 0);
53+
} else {
54+
r >>= 3;
55+
g >>= 3;
56+
b >>= 3;
57+
color = 0x8000;
58+
color |= ((r & 0x1F) << 10);
59+
color |= ((g & 0x1F) << 5);
60+
color |= ((b & 0x1F) << 0);
61+
}
62+
return color;
63+
}
64+
4165
uint32_t RGB565toRGBA8(uint16_t data) {
4266
uint8_t r = (data & 0xF100) >> 11;
4367
uint8_t g = (data & 0x07E0) >> 5;
@@ -389,9 +413,41 @@ namespace Decode {
389413

390414
namespace Encode {
391415
void CMPR(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData){}
392-
void RGB5A3(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData){}
393416
void RGB565(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData){}
394417

418+
void RGB5A3(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData){
419+
if (imageData.size() == 0)
420+
return;
421+
422+
uint32_t numBlocksW = width / 4;
423+
uint32_t numBlocksH = height / 4;
424+
425+
// Iterate the blocks in the image
426+
for (int blockY = 0; blockY < numBlocksH; blockY++) {
427+
for (int blockX = 0; blockX < numBlocksW; blockX++) {
428+
// Iterate the pixels in the current block
429+
for (int pixelY = 0; pixelY < 4; pixelY++) {
430+
for (int pixelX = 0; pixelX < 4; pixelX++) {
431+
// Bounds check to ensure the pixel is within the image.
432+
if ((blockX * 4 + pixelX >= width) || (blockY * 4 + pixelY >= height))
433+
continue;
434+
435+
// RGB values for this pixel are stored in a 16-bit integer.
436+
uint32_t destIndex = (width * ((blockY * 4) + pixelY) + (blockX * 4) + pixelX) * 4;
437+
uint8_t r = imageData[destIndex];
438+
uint8_t g = imageData[destIndex + 1];
439+
uint8_t b = imageData[destIndex + 2];
440+
uint8_t a = imageData[destIndex + 3];
441+
442+
uint16_t rgb5a3 = ColorFormat::RGBA8toRGB5A3(r,g,b,a);
443+
stream->writeUInt16(rgb5a3);
444+
445+
}
446+
}
447+
}
448+
}
449+
}
450+
395451
void I4(bStream::CStream* stream, uint16_t width, uint16_t height, std::vector<uint8_t>& imageData){
396452
if(imageData.size() == 0) return;
397453

src/modes/DoorMode.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,9 @@ void LDoorMode::RenderGizmo(LEditorScene* renderer_scene){
146146
glm::mat4 proj = renderer_scene->getCameraProj();
147147
ImGuizmo::Manipulate(&view[0][0], &proj[0][0], mGizmoMode, ImGuizmo::WORLD, &(*m)[0][0], NULL, NULL);
148148

149-
if(mPreviousSelection == nullptr || mPreviousSelection != mSelectionManager.GetPrimarySelection()){
150-
auto rooms = std::dynamic_pointer_cast<LDoorDOMNode>(mPreviousSelection)->GetRoomReferences();
151-
if(rooms.first != nullptr && !renderer_scene->HasRoomLoaded(rooms.first->GetRoomNumber())){
152-
renderer_scene->SetRoom(rooms.first);
153-
}
149+
auto rooms = std::dynamic_pointer_cast<LDoorDOMNode>(mSelectionManager.GetPrimarySelection())->GetRoomReferences();
150+
if(rooms.first != nullptr && rooms.second != nullptr && (!renderer_scene->HasRoomLoaded(rooms.first->GetRoomNumber())|| !renderer_scene->HasRoomLoaded(rooms.second->GetRoomNumber()))){
151+
renderer_scene->SetRoom(rooms.first);
154152
}
155153
}
156154
}

src/modes/EnemyMode.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ void LEnemyMode::RenderGizmo(LEditorScene* renderer_scene){
9898
glm::mat4 proj = renderer_scene->getCameraProj();
9999
ImGuizmo::Manipulate(&view[0][0], &proj[0][0], mGizmoMode, ImGuizmo::LOCAL, &(*m)[0][0], NULL, NULL);
100100

101-
if(mPreviousSelection == nullptr || mPreviousSelection != mSelectionManager.GetPrimarySelection()){
102-
if(!mPreviousSelection->GetParentOfType<LRoomDOMNode>(EDOMNodeType::Room).expired() && !renderer_scene->HasRoomLoaded(mPreviousSelection->GetParentOfType<LRoomDOMNode>(EDOMNodeType::Room).lock()->GetRoomNumber())){
103-
renderer_scene->SetRoom(mPreviousSelection->GetParentOfType<LRoomDOMNode>(EDOMNodeType::Room).lock());
104-
}
101+
if(!mSelectionManager.GetPrimarySelection()->GetParentOfType<LRoomDOMNode>(EDOMNodeType::Room).expired() && !renderer_scene->HasRoomLoaded(mSelectionManager.GetPrimarySelection()->GetParentOfType<LRoomDOMNode>(EDOMNodeType::Room).lock()->GetRoomNumber())){
102+
renderer_scene->SetRoom(mSelectionManager.GetPrimarySelection()->GetParentOfType<LRoomDOMNode>(EDOMNodeType::Room).lock());
105103
}
106104
}
107105
}

0 commit comments

Comments
 (0)