persona-3-dual
A DS demake of Persona 3
Loading...
Searching...
No Matches
SignContractView.cpp
Go to the documentation of this file.
2
3#include "core/globals.hpp"
4#include "core/logger.hpp"
5#include "data/audioDb.hpp"
7
8#include <cstring>
9#include <nds.h>
10#include <stdio.h>
11
13{
14 sfxCmpt->stopSFX();
15}
16
18{
19 if (signContract == nullptr)
20 {
21 signContract = engine.createEntity();
22 graphics = engine.createComponent<GraphicsComponent>();
23 musicCmpt = engine.createComponent<MusicComponent>();
24 sfxCmpt = engine.createComponent<SFXComponent>();
25
26 signContract->addComponent(graphics);
27 signContract->addComponent(musicCmpt);
28 signContract->addComponent(sfxCmpt);
29 }
30
31 // set both screens to black
32 setBrightness(3, -16);
33
34 // setup music
35 sfxCmpt->registerSFX(SFX::SFX_1);
36 sfxCmpt->registerSFX(SFX::SFX_2);
37 sfxCmpt->registerSFX(SFX::SFX_0);
39
40 videoSetMode(MODE_5_2D);
41 videoSetModeSub(MODE_3_2D | DISPLAY_BG3_ACTIVE);
42
43 // map vram banks to main engine background
44 vramSetBankA(VRAM_A_MAIN_BG_0x06000000);
45 vramSetBankD(VRAM_D_MAIN_BG_0x06020000);
46 // map vram to sub screen
47 vramSetBankC(VRAM_C_SUB_BG);
48
49 // initialize backgrounds
50 bg = bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 9, 2);
51 bgSetPriority(bg, 0);
52 int bgSubId = bgInitSub(0, BgType_Text8bpp, BgSize_T_256x256, 8, 0);
53
54 // load contract background from runtime assets
55 GraphicAsset contractBg = graphics->loadGraphic("graphics/SignContractView/backgrounds/contract/contract");
56
57 dmaFillHalfWords(0, bgGetMapPtr(bg), 8192);
58 dmaCopy(contractBg.tiles, bgGetGfxPtr(bg), contractBg.tilesLen);
59 dmaCopy(contractBg.map, bgGetMapPtr(bg), contractBg.mapLen);
60
61 dmaCopy(contractBg.pal, BG_PALETTE, contractBg.palLen);
62
63 graphics->unloadGraphic(contractBg);
64
66 bgSub[0] = bgSubId;
67 ae::broadcastEvent(Event::ConfigureUIScreen{bgSub, bgMain, &oamSub, &oamMain, {signContractScreen}});
68 ae::broadcastEvent(Event::ShowScreen{signContractScreen});
69
70 fadeTimer.start(ae::q20_12_t{0.8});
72
73 logMessage(LogSeverity::DEBUG, "SignContractView initialized");
74}
75
77{
78 switch (transitionPhase)
79 {
81 {
82 if (fadeTimer.isFinished())
83 {
84 setBrightness(3, 0);
86 }
87 else
88 {
89 int brightness = -16 + (fadeTimer.getProgress().raw_value() >> 8);
90 setBrightness(3, brightness);
91 }
92 break;
93 }
94
96 {
97 if (signContractScreen->update() == 1)
98 {
99 cancelSFX();
100 musicCmpt->pauseMusic();
101 fadeTimer.start(ae::q20_12_t{0.85});
103 }
104
105 if (systemKeysDown & KEY_TOUCH)
106 {
107 touchRead(&touch);
108
109 if (signContractScreen->onTouch(&touch) == 1)
110 {
111 cancelSFX();
112 musicCmpt->pauseMusic();
113 fadeTimer.start(ae::q20_12_t{0.85});
115 }
116 else
117 {
118 cancelSFX();
119 sfxCmpt->playSFX(SFX::SFX_1, 255, 128);
120 }
121 }
122 break;
123 }
124
126 {
127 if (fadeTimer.isFinished())
128 {
129 setBrightness(3, -16);
131 }
132 else
133 {
134 int fadeVal = fadeTimer.getProgress().raw_value() >> 8;
135 setBrightness(3, -fadeVal);
136 }
137 break;
138 }
139 }
140
142}
143
145{
146 if (signContract != nullptr)
147 {
148 engine.destroyEntity(signContract);
149
150 signContract = nullptr;
151 graphics = nullptr;
152 signContractScreen = nullptr;
153 musicCmpt = nullptr;
154 sfxCmpt = nullptr;
155 }
156
158}
@ SFX_2
@ SFX_0
@ SFX_1
ViewState
Definition StateTypes.hpp:4
Manages the mapping of UIScreens to these hardware layers.
virtual void cleanup()
Definition BaseView.cpp:8
static SignContractScreen * getInstance()
std::array< int, 2 > bgMain
TransitionPhase transitionPhase
SFXComponent * sfxCmpt
ae::Entity * signContract
std::array< int, 3 > bgSub
MusicComponent * musicCmpt
void cleanup() override
void init() override
SignContractScreen * signContractScreen
GraphicsComponent * graphics
ViewState update() override
Holds global variables used game-wide.
volatile u32 systemKeysDown
Definition main.cpp:36
GameEngine engine
Definition main.cpp:31
void logMessage(LogSeverity severity, std::string_view message, std::source_location location)
Logs a diagnostic message and halts only for fatal messages.
Definition logger.cpp:110
Util to handle error logging.
All parameters needed to configure UIScreens.
Definition UIEvents.hpp:22
Event to show specified screen.
Definition UIEvents.hpp:83
Holds loaded graphics data.