summaryrefslogtreecommitdiff
path: root/src/koopatlas/shop.cpp
diff options
context:
space:
mode:
authorTreeki <treeki@gmail.com>2012-10-25 04:59:11 +0200
committerTreeki <treeki@gmail.com>2012-10-25 04:59:11 +0200
commit0bee9e3ae3bd5a9f4a9f0ea8a4d04955a90798fa (patch)
tree999ea89b9eb357fbd4a0b7d8acd6c71f2a82c8f6 /src/koopatlas/shop.cpp
parent47795a5f0eee896df557e4e3481068e510fe51fb (diff)
downloadkamek-0bee9e3ae3bd5a9f4a9f0ea8a4d04955a90798fa.tar.gz
kamek-0bee9e3ae3bd5a9f4a9f0ea8a4d04955a90798fa.zip
refactoring, API fixes and shop mostly finished
Diffstat (limited to 'src/koopatlas/shop.cpp')
-rw-r--r--src/koopatlas/shop.cpp117
1 files changed, 105 insertions, 12 deletions
diff --git a/src/koopatlas/shop.cpp b/src/koopatlas/shop.cpp
index 9da5fc0..b42c58a 100644
--- a/src/koopatlas/shop.cpp
+++ b/src/koopatlas/shop.cpp
@@ -15,13 +15,14 @@ void dWMShop_c::ShopModel_c::setupItem(float x, float y, ItemTypes type) {
{ "I_propeller", "g3d/I_propeller.brres", "I_propeller_model", "wait2" },
{ "I_kinoko_bundle","g3d/I_mini_kinoko.brres", "I_mini_kinoko", "wait2" },
{ "I_star", "g3d/I_star.brres", "I_star", "wait2" },
- { "I_hammer", "g3d/I_hammer.brres", "I_hammer", "wait2" },
+ { "I_hammer", "g3d/I_fireflower.brres", "I_fireflower", "wait2" },
{ "I_kinoko_bundle","g3d/I_life_kinoko.brres", "I_life_kinoko", "wait2" },
{ "obj_coin", "g3d/obj_coin.brres", "obj_coin", "wait2" }
};
this->x = x;
this->y = y;
+ scaleFactor = 2.3f;
int id = (int)type;
@@ -29,8 +30,14 @@ void dWMShop_c::ShopModel_c::setupItem(float x, float y, ItemTypes type) {
res.data = getResource(Produce[id][0], Produce[id][1]);
nw4r::g3d::ResMdl mdlRes = res.GetResMdl(Produce[id][2]);
- model.setup(mdlRes, &allocator, ANM_VTX, 1, 0);
- SetupTextures_Item(&model, 1);
+ model.setup(mdlRes, &allocator, 0x224, 1, 0);
+
+ if (type == COINS) {
+ SetupTextures_MapObj(&model, 1);
+ this->y += 20.0f;
+ scaleFactor = 2.7f;
+ } else
+ SetupTextures_Item(&model, 1);
nw4r::g3d::ResAnmChr anmChr = res.GetResAnmChr(Produce[id][3]);
animation.setup(mdlRes, anmChr, &allocator, 0);
@@ -45,12 +52,14 @@ void dWMShop_c::ShopModel_c::setupLakitu(int id) {
"g3d/ghost.brres", "g3d/space.brres", "g3d/koopa.brres", "g3d/sewer.brres", "g3d/goldwood.brres"
};
+ scaleFactor = 1.0f;
+
allocator.link(-1, GameHeaps[0], 0, 0x20);
res.data = getResource("lakitu", models[id]);
nw4r::g3d::ResMdl mdlRes = res.GetResMdl("lakitu");
- model.setup(mdlRes, &allocator, ANM_VTX, 1, 0);
- SetupTextures_Item(&model, 1);
+ model.setup(mdlRes, &allocator, 0x224, 1, 0);
+ SetupTextures_Enemy(&model, 1);
nw4r::g3d::ResAnmChr anmChr = res.GetResAnmChr("idle");
animation.setup(mdlRes, anmChr, &allocator, 0);
@@ -62,7 +71,7 @@ void dWMShop_c::ShopModel_c::setupLakitu(int id) {
void dWMShop_c::ShopModel_c::playAnim(const char *name, float rate) {
nw4r::g3d::ResAnmChr anmChr = res.GetResAnmChr(name);
- animation.bind(&model, anmChr, 1);
+ animation.bind(&model, anmChr, 0);
model.bindAnim(&animation, 0.0f);
animation.setUpdateRate(rate);
}
@@ -73,12 +82,12 @@ void dWMShop_c::ShopModel_c::execute() {
void dWMShop_c::ShopModel_c::draw() {
mMtx mtx;
- Vec pos = {250.0f, 170.0f, 3000.0f};
- Vec scale = {1.0f, 1.0f, 1.0f};
- mtx.translation(pos.x, pos.y, pos.z);
-
+ mtx.translation(x, y, 1000.0f);
model.setDrawMatrix(mtx);
+
+ Vec scale = {scaleFactor, scaleFactor, scaleFactor};
model.setScale(&scale);
+
model.calcWorld(false);
model.scheduleForDrawing();
}
@@ -111,7 +120,6 @@ int dWMShop_c::onCreate() {
layout.build("shop.brlyt");
- layout.layout.rootPane->trans.x = -112.0f;
if (IsWideScreen()) {
layout.layout.rootPane->scale.x = 0.735f;
} else {
@@ -154,6 +162,36 @@ int dWMShop_c::onCreate() {
};
layout.getTextBoxes(tbNames, &Title, 6);
+ // Warning: weird code coming up
+ const char *crap = "000102031\0" "2\0";
+ char name[12];
+ for (int i = 0; i < 6; i++) {
+ strcpy(name, "BtnLeftXX");
+ name[7] = crap[i*2];
+ name[8] = crap[i*2+1];
+ BtnLeft[i] = layout.findPictureByName(name);
+
+ strcpy(name, "BtnMidXX");
+ name[6] = crap[i*2];
+ name[7] = crap[i*2+1];
+ BtnMid[i] = layout.findPictureByName(name);
+
+ strcpy(name, "BtnRightXX");
+ name[8] = crap[i*2];
+ name[9] = crap[i*2+1];
+ BtnRight[i] = layout.findPictureByName(name);
+ }
+
+ leftCol.setTexMap(BtnLeft[0]->material->texMaps);
+ midCol.setTexMap(BtnMid[0]->material->texMaps);
+ rightCol.setTexMap(BtnRight[0]->material->texMaps);
+
+ for (int i = 1; i < 6; i++) {
+ leftCol.applyAlso(BtnLeft[i]->material->texMaps);
+ midCol.applyAlso(BtnMid[i]->material->texMaps);
+ rightCol.applyAlso(BtnRight[i]->material->texMaps);
+ }
+
layoutLoaded = true;
}
@@ -226,6 +264,7 @@ void dWMShop_c::beginState_ShowWait() {
layout.enableNonLoopAnim(SHOW_ALL);
visible = true;
+ loadInfo();
loadModels();
}
void dWMShop_c::executeState_ShowWait() {
@@ -301,12 +340,14 @@ void dWMShop_c::endState_Wait() { }
void dWMShop_c::beginState_HideWait() {
MapSoundPlayer(SoundRelatedClass, SE_SYS_DIALOGUE_OUT_AUTO, 1);
layout.enableNonLoopAnim(HIDE_ALL);
+ layout.enableNonLoopAnim(DEACTIVATE_BUTTON+selected);
}
void dWMShop_c::executeState_HideWait() {
if (!layout.isAnimOn(HIDE_ALL))
state.setState(&StateID_Hidden);
}
void dWMShop_c::endState_HideWait() {
+ deleteModels();
visible = false;
}
@@ -384,10 +425,29 @@ const dWMShop_c::ItemTypes dWMShop_c::Inventory[10][12] = {
void dWMShop_c::loadModels() {
lakituModel = new ShopModel_c;
lakituModel->setupLakitu(shopKind);
+ lakituModel->x = 240.0f;
+ lakituModel->y = 220.0f;
+
+ static const float itemPos[ITEM_COUNT][2] = {
+ {357.0f, 276.0f},
+ {450.0f, 276.0f},
+ {543.0f, 276.0f},
+ {636.0f, 276.0f},
+
+ {380.0f, 190.0f},
+ {462.0f, 190.0f},
+ {544.0f, 190.0f},
+
+ {363.0f, 104.0f},
+ {413.0f, 104.0f},
+ {463.0f, 104.0f},
+ {513.0f, 104.0f},
+ {563.0f, 104.0f},
+ };
itemModels = new ShopModel_c[ITEM_COUNT];
for (int i = 0; i < ITEM_COUNT; i++)
- itemModels[i].setupItem(0.0f, 0.0f, Inventory[shopKind][i]);
+ itemModels[i].setupItem(itemPos[i][0], itemPos[i][1], Inventory[shopKind][i]);
}
void dWMShop_c::deleteModels() {
if (lakituModel)
@@ -400,6 +460,39 @@ void dWMShop_c::deleteModels() {
}
+void dWMShop_c::loadInfo() {
+ SaveBlock *save = GetSaveFile()->GetBlock(-1);
+
+ leftCol.colourise(save->hudHintH, save->hudHintS, save->hudHintL);
+ midCol.colourise(save->hudHintH, save->hudHintS, save->hudHintL);
+ rightCol.colourise(save->hudHintH, save->hudHintS, save->hudHintL);
+
+ // find out the shop name
+ dLevelInfo_c::entry_s *shopNameEntry =
+ dLevelInfo_c::s_info.searchBySlot(shopKind, 98);
+
+ wchar_t shopName[100];
+ // TODO: refactor this a bit
+ const char *sourceName = dLevelInfo_c::s_info.getNameForLevel(shopNameEntry);
+ int charCount = 0;
+
+ while (*sourceName != 0 && charCount < 99) {
+ shopName[charCount] = *sourceName;
+ sourceName++;
+ charCount++;
+ }
+ shopName[charCount] = 0;
+
+ Title->SetString(shopName);
+ TitleShadow->SetString(shopName);
+
+ // load the coin count
+ int scCount = getStarCoinCount();
+ WriteNumberToTextBox(&scCount, CoinCount, false);
+ WriteNumberToTextBox(&scCount, CoinCountShadow, false);
+}
+
+
void dWMShop_c::buyItem(int item) {
static int itemDefs[6][3] = {
// Cost, Start Index, Count