Added texture pack switch menu and some QOL Changes

This commit is contained in:
KiritoDev 2021-05-14 00:14:54 -05:00
parent 810c7f7426
commit 9c654cfe04
21 changed files with 288 additions and 77 deletions

View File

@ -273,7 +273,7 @@ endif
SRC_DIRS += src/moon src/moon/texts src/moon/utils src/moon/network
# Moon64 SRC [View]
SRC_DIRS += src/moon/ui src/moon/ui/interfaces src/moon/ui/screens src/moon/ui/screens/options src/moon/ui/screens/options/categories src/moon/ui/utils src/moon/ui/widgets
SRC_DIRS += src/moon/ui src/moon/ui/interfaces src/moon/ui/screens src/moon/ui/screens/options src/moon/ui/screens/options/categories src/moon/ui/utils src/moon/ui/widgets src/moon/ui/screens/addons
# Moon64 SRC [IO]
SRC_DIRS += src/moon/io src/moon/io/modules

View File

14
src/moon/config/mooncfg.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef MoonCFG
#define MoonCFG
#include <vector>
#include <string>
namespace Moon {
extern std::vector<std::string> texturePacks;
void saveConfig();
void loadConfig();
}
#endif

View File

@ -14,7 +14,7 @@ map<string, AnimatedEntry*> textures;
long long getMilliseconds(){
struct timeval te;
gettimeofday(&te, NULL);
return te.tv_sec*1000LL + te.tv_usec/1000;
return te.tv_sec * 1000LL + te.tv_usec / 1000;
}
void AnimatedModifier::onInit(){
@ -23,10 +23,11 @@ void AnimatedModifier::onInit(){
string texName = string(*hookTexture);
if(textures.find(texName) != textures.end()){
AnimatedEntry* entry = textures[texName];
Frame *frame = entry->frames[entry->lastFrame];
if(getMilliseconds() >= entry->lastTime + entry->delay){
if(getMilliseconds() >= entry->lastTime + frame->delay){
int maxFrames = entry->frames.size() - 1;
bool reachMax = (entry->lastFrame < entry->frames.size() - 1);
bool reachMax = (entry->lastFrame < maxFrames);
if(entry->bounce){
if(entry->lastFrame >= maxFrames)
entry->lastBounce = true;
@ -36,9 +37,10 @@ void AnimatedModifier::onInit(){
entry->lastFrame += entry->bounce ? entry->lastBounce ? -1 : 1 : (reachMax ? 1 : -entry->lastFrame);
entry->lastTime = getMilliseconds();
frame = entry->frames[entry->lastFrame];
}
(*hookTexture) = const_cast<char*>(entry->frames[entry->lastFrame].c_str());
(*hookTexture) = const_cast<char*>(frame->path.c_str());
}
return false;
}});
@ -46,14 +48,19 @@ void AnimatedModifier::onInit(){
void AnimatedModifier::onLoad(std::string texture, json data){
if(textures.find(texture) == textures.end()){
cout << data.contains("frames") << " " << data.contains("delay") << " " << data.contains("bounce") << endl;
if(!(data.contains("frames") && data.contains("delay") && data.contains("bounce"))) return;
cout << "Found animated entry: " << texture << " with " << data["frames"].size() << " length" << endl;
textures[texture] = new AnimatedEntry({
.frames = data["frames"],
.delay = data["delay"],
.bounce = data["bounce"]
});
AnimatedEntry *entry = new AnimatedEntry();
entry->advancedMode = data.contains("advancedMode") ? (bool) data["advancedMode"] : false;
entry->bounce = data["bounce"];
for(auto &frame : data["frames"]){
if(!entry->advancedMode)
entry->frames.push_back( new Frame({.delay = data["delay"], .path = frame}));
else
entry->frames.push_back( new Frame({.delay = frame["delay"], .path = frame["path"]}));
}
textures[texture] = entry;
}
}

View File

@ -6,10 +6,15 @@
#include <vector>
#include <string>
struct AnimatedEntry {
std::vector<std::string> frames;
struct Frame {
long delay;
std::string path;
};
struct AnimatedEntry {
std::vector<Frame*> frames;
bool bounce;
bool advancedMode;
int lastFrame;
bool lastBounce;

View File

@ -134,7 +134,7 @@ float GetStickValue(MoonButtons button, bool absolute){
}
float GetScreenWidth(bool u4_3){
return GFX_DIMENSIONS_ASPECT_RATIO > 1 || u4_3 ? SCREEN_WIDTH + abs(GFX_DIMENSIONS_FROM_LEFT_EDGE(0)) * 2 : SCREEN_WIDTH;
return GFX_DIMENSIONS_ASPECT_RATIO > 1 || !u4_3 ? SCREEN_WIDTH + abs(GFX_DIMENSIONS_FROM_LEFT_EDGE(0)) * 2 : SCREEN_WIDTH;
}
float GetScreenHeight() {

View File

@ -2,6 +2,7 @@
#include <iostream>
#include "interfaces/moon-screen.h"
#include "screens/options/main-view.h"
#include "screens/addons/addons-view.h"
extern "C" {
#include "game/game_init.h"
@ -20,8 +21,10 @@ void MoonUpdateStatus();
void MoonInitUI() {
if(screens.empty())
if(screens.empty()){
screens.push_back(new MoonOptMain());
screens.push_back(new MoonAddonsScreen());
}
screens[currentScreen]->Mount();
screens[currentScreen]->Init();
@ -51,6 +54,7 @@ void MoonChangeUI(int index){
void MoonHandleToggle(){
if(gPlayer1Controller->buttonPressed & toggle){
currentScreen = 0;
isOpen = !isOpen;
if(isOpen) isRunning = false;
}

View File

@ -0,0 +1,187 @@
#include "addons-view.h"
#include <iostream>
#include "moon/ui/utils/moon-draw-utils.h"
#include "moon/ui/moon-ui-manager.h"
#include "moon/mod-engine/engine.h"
#include "moon/mod-engine/textures/mod-texture.h"
#include <cstring>
using namespace std;
extern "C" {
#include "sm64.h"
#include "gfx_dimensions.h"
#include "pc/configfile.h"
}
BitModule* currentPack;
vector<BitModule*> texturePackList;
int currentSubItem = 0;
int focusFlag;
int focusRange = 80;
float focusAnim = focusRange / 2;
enum ItemButtons{
UP,
DOWN,
TOGGLE
};
void MoonAddonsScreen::Init(){
texturePackList.clear();
this->scrollIndex = 0;
currentPack = NULL;
copy(Moon::addons.begin(), Moon::addons.end(), back_inserter(texturePackList));
reverse(texturePackList.begin(), texturePackList.end());
}
void MoonAddonsScreen::Mount(){
}
bool dispatched;
void rebuildTextureCache(){
vector<int> order;
for(auto &addon : texturePackList){
vector<BitModule*>::iterator itr = find(Moon::addons.begin(), Moon::addons.end(), addon);
order.push_back(distance(Moon::addons.begin(), itr));
}
reverse(order.begin(), order.end());
MoonInternal::buildTextureCache(order);
}
void MoonAddonsScreen::Update(){
float yStick = GetStickValue(MoonButtons::U_STICK, false);
if(yStick > 0) {
if(dispatched) return;
if(currentPack != NULL){
if(currentSubItem > 0)
currentSubItem--;
else
currentSubItem = 2;
dispatched = true;
return;
}
if(this->scrollIndex > 0)
this->scrollIndex--;
else
this->scrollIndex = texturePackList.size() - 1;
dispatched = true;
}
if(yStick < 0) {
if(dispatched) return;
if(currentPack != NULL){
if(currentSubItem < 2)
currentSubItem++;
else
currentSubItem = 0;
dispatched = true;
return;
}
if(this->scrollIndex < texturePackList.size() - 1)
this->scrollIndex++;
else
this->scrollIndex = 0;
dispatched = true;
}
if(!yStick)
dispatched = false;
if(IsBtnPressed(MoonButtons::A_BTN)) {
if(currentPack != NULL){
switch(currentSubItem){
case ItemButtons::UP:
if(this->scrollIndex > 0){
std::swap(texturePackList[this->scrollIndex], texturePackList[this->scrollIndex - 1]);
currentPack = texturePackList[this->scrollIndex--];
rebuildTextureCache();
}
break;
case ItemButtons::DOWN:
if(this->scrollIndex < texturePackList.size() - 1){
std::swap(texturePackList[this->scrollIndex], texturePackList[this->scrollIndex + 1]);
currentPack = texturePackList[this->scrollIndex++];
rebuildTextureCache();
}
break;
case ItemButtons::TOGGLE:
break;
}
return;
}
currentPack = texturePackList[this->scrollIndex];
currentSubItem = 0;
}
if(IsBtnPressed(MoonButtons::B_BTN)) {
if(currentPack != NULL){
currentPack = NULL;
return;
}
MoonChangeUI(0);
}
MoonScreen::Update();
}
char *strdup(const char *src_str) noexcept {
char *new_str = new char[std::strlen(src_str) + 1];
std::strcpy(new_str, src_str);
return new_str;
}
void MoonAddonsScreen::Draw(){
string curTitle = "Texture packs";
float step = 1.5;
if(focusAnim >= focusRange)
focusFlag = 1;
else if (focusAnim <= focusRange / 2)
focusFlag = 0;
focusAnim += step * (focusFlag ? -1 : 1);
int boxWidth = SCREEN_WIDTH - 50;
int boxHeight = GetScreenHeight() * 0.8;
float txtWidth = MoonGetTextWidth(curTitle, 1.0, true);
MoonDrawRectangle(0, 0, GetScreenWidth(false), GetScreenHeight(), {0, 0, 0, 100}, false);
MoonDrawColoredText(SCREEN_WIDTH / 2 - txtWidth / 2, 10, curTitle, 1.0, {255, 255, 255, 255}, true, true);
MoonDrawRectangle(25, 35, boxWidth, boxHeight, {0, 0, 0, 100}, true);
Color focusColor = {255, 255, 255, 40 + focusAnim};
int i = 0;
for(auto &addon : texturePackList){
bool selected = i == this->scrollIndex && currentPack != NULL;
int itemWidth = boxWidth - (selected ? 15 : 0);
MoonDrawRectangle(35, 45 + (i * 35), itemWidth - 20, 31, i == this->scrollIndex && !selected ? focusColor : (Color){0, 0, 0, 100}, true);
string iconPath = "mod-icons://"+addon->name;
MoonDrawTexture(35, 45 + (i * 35), 30, 30, strdup(iconPath.c_str()));
MoonDrawText(70, 45 + (i * 35) + 3, addon->name, 0.8, {255, 255, 255, 255}, true, true);
MoonDrawText(70, 45 + (i * 35) + 16, addon->description, 0.8, {255, 255, 255, 255}, true, true);
string rawVer = to_string(addon->version);
string version = "v"+rawVer.substr(0, rawVer.find(".")+2);
MoonDrawText(itemWidth + 13 - MoonGetTextWidth(version, 0.5, false), 45 + (i * 35) + 2, version, 0.5, {255, 255, 255, 255}, true, true);
MoonDrawText(itemWidth + 13 - MoonGetTextWidth(addon->author, 0.5, false), 45 + (i * 35) + 22, addon->author, 0.5, {255, 255, 255, 255}, true, true);
if(selected){
MoonDrawRectangle(itemWidth + 16, 45 + (i * 35), 13, 9.3, currentSubItem == ItemButtons::UP ? focusColor : (Color){0, 0, 0, 100}, true);
MoonDrawTexture (itemWidth + 18, 45 + (i * 35), 8, 8, "textures/special/up.rgba16");
MoonDrawRectangle(itemWidth + 16, 45 + (i * 35) + 10.9, 13, 9.3, currentSubItem == ItemButtons::DOWN ? focusColor : (Color){0, 0, 0, 100}, true);
MoonDrawTexture (itemWidth + 18, 46 + (i * 35) + 10.9, 8, 8, "textures/special/down.rgba16");
MoonDrawRectangle(itemWidth + 16, 45 + (i * 35) + 21.7, 13, 9.3, currentSubItem == ItemButtons::TOGGLE ? focusColor : (Color){0, 0, 0, 100}, true);
MoonDrawTexture (itemWidth + 18, 46 + (i * 35) + 21.7, 8, 8, "textures/special/remove.rgba16");
}
i++;
}
MoonScreen::Draw();
}

View File

@ -0,0 +1,14 @@
#ifndef MoonScreenAddons
#define MoonScreenAddons
#include "moon/ui/interfaces/moon-screen.h"
class MoonAddonsScreen : public MoonScreen {
public:
void Init();
void Update();
void Draw();
void Mount();
};
#endif

View File

@ -2,6 +2,7 @@
#include "moon/texts/moon-loader.h"
#include "moon/ui/widgets/mw-value.h"
#include "moon/ui/moon-ui-manager.h"
using namespace std;
@ -28,5 +29,8 @@ MGameCategory::MGameCategory() : MoonCategory("TEXT_OPT_GAME"){
#else
exitY = 91;
#endif
this->catOptions.push_back(new MWValue(22, exitY, "TEXT_EXIT_GAME", { .btn = game_exit}, true));
this->catOptions.push_back(new MWValue(22, exitY, "Texture Packs", { .btn = [](){
MoonChangeUI(1);
}}, false));
this->catOptions.push_back(new MWValue(22, exitY + 17, "TEXT_EXIT_GAME", { .btn = game_exit}, true));
}

View File

@ -1,29 +0,0 @@
#include "mtextures.h"
#include "moon/texts/moon-loader.h"
#include "moon/ui/widgets/mw-value.h"
#include "moon/mod-engine/engine.h"
#include "moon/mod-engine/textures/mod-texture.h"
#include <algorithm>
using namespace std;
extern "C" {
#include "pc/configfile.h"
}
std::vector<int> order;
MWValue *tmpButton;
MTexturesCategory::MTexturesCategory() : MoonCategory("Textures"){
this->titleKey = false;
for(int i = 0; i < Moon::addons.size(); i++) order.push_back(i);
this->catOptions.push_back(tmpButton = new MWValue(22, 57, "Randomize packs", {.btn = [](){
tmpButton->title = "Randomize on progress";
std::random_shuffle ( order.begin(), order.end() );
MoonInternal::buildTextureCache(order);
tmpButton->title = "Randomize packs";
}}, false));
}

View File

@ -1,13 +0,0 @@
#ifndef MoonTexturesCategory
#define MoonTexturesCategory
#include "mcategory.h"
#include <vector>
#include <string>
class MTexturesCategory : public MoonCategory {
public:
MTexturesCategory();
};
#endif

View File

@ -13,7 +13,6 @@
#ifdef BETTERCAMERA
#include "moon/ui/screens/options/categories/mcamera.h"
#endif
#include "moon/ui/screens/options/categories/mtextures.h"
#include "moon/io/moon-io.h"
#include "moon/io/modules/mouse-io.h"
@ -49,13 +48,16 @@ void MoonOptMain::Mount(){
categories.push_back(new MVideoCategory());
categories.push_back(new MAudioCategory());
categories.push_back(new MCheatsCategory());
categories.push_back(new MTexturesCategory());
// categories.push_back(new MTexturesCategory());
this->setCategory(categoryIndex);
MoonScreen::Mount();
}
void MoonOptMain::Update(){
if(this->selected == NULL) {
if(IsBtnPressed(MoonButtons::B_BTN)){
isOpen = false;
}
float xStick = GetStickValue(MoonButtons::L_STICK, false);
if(xStick < 0) {
if(cswStickExecuted) return;

View File

@ -25,7 +25,7 @@ void MoonDrawColoredText(float x, float y, std::string text, float scale, struct
gSPDisplayList(gDisplayListHead++, dl_rgba16_text_begin);
std::transform(text.begin(), text.end(), text.begin(), ::toupper);
if(dropShadow){
if(dropShadow){
moon_draw_colored_text(x, y + 1, getTranslatedText(text.c_str()), scale, {10, 10, 10, 255});
}
gDPSetEnvColor(gDisplayListHead++, color.r, color.g, color.b, color.a);
@ -38,3 +38,17 @@ void MoonDrawColoredText(float x, float y, std::string text, float scale, struct
void MoonDrawRectangle(float x, float y, float w, float h, struct Color c, bool u4_3){
moon_draw_rectangle(x, y, w, h, c, u4_3);
}
void MoonDrawTexture(float x, float y, float w, float h, char* texture){
gSPDisplayList(gDisplayListHead++, dl_hud_img_begin);
gDPSetTile(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_32b, 0, 0, G_TX_LOADTILE, 0, G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOLOD);
gDPTileSync(gDisplayListHead++);
gDPSetTile(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_32b, 2, 0, G_TX_RENDERTILE, 0, G_TX_NOMIRROR, 3, G_TX_NOLOD, G_TX_NOMIRROR, 3, G_TX_NOLOD);
gDPSetTileSize(gDisplayListHead++, G_TX_RENDERTILE, 0, 0, (int)w << G_TEXTURE_IMAGE_FRAC, (int)h << G_TEXTURE_IMAGE_FRAC);
gDPPipeSync(gDisplayListHead++);
gDPSetTextureImage(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_32b, 1, texture);
gDPLoadSync(gDisplayListHead++);
gDPLoadBlock(gDisplayListHead++, G_TX_LOADTILE, 0, 0, w * h - 1, CALC_DXT(w, G_IM_SIZ_32b_BYTES));
gSPTextureRectangle(gDisplayListHead++, (int) x << 2, (int) y << 2, (int)(x + w) << 2, (int)(y + h) << 2, G_TX_RENDERTILE, 0, 0, 4 << 10, 1 << 10);
gSPDisplayList(gDisplayListHead++, dl_hud_img_end);
}

View File

@ -12,9 +12,11 @@ extern "C" {
#include "game/geo_misc.h"
#include "text/txtconv.h"
}
float MoonGetTextWidth (std::string text, float scale, bool colored);
void MoonDrawText (float x, float y, std::string text, float scale, struct Color color, bool dropShadow, bool u4_3);
void MoonDrawColoredText(float x, float y, std::string text, float scale, struct Color color, bool dropShadow, bool u4_3);
void MoonDrawTexture (float x, float y, float w, float h, char* texture);
float MoonGetTextWidth (std::string text, float scale, bool colored);
void MoonDrawRectangle (float x, float y, float w, float h, struct Color c, bool u4_3);
void MoonDrawColoredText(float x, float y, std::string text, float scale, struct Color color, bool dropShadow, bool u4_3);
#endif

View File

@ -6,7 +6,7 @@
#include "config.h"
#include "game/geo_misc.h"
f32 moon_get_text_width(u8* text, float scale, u8 colored) {
f32 moon_get_text_width(u8* text, float scale, u8 colored) {
f32 size = 0;
s32 strPos = 0;
@ -14,18 +14,18 @@ f32 moon_get_text_width(u8* text, float scale, u8 colored) {
if(colored)
size += (text[strPos] == GLOBAL_CHAR_SPACE ? 8.0 : 12.0) * scale;
else
size += (f32)(gDialogCharWidths[text[strPos]]) * scale;
size += (f32)(gDialogCharWidths[text[strPos]]) * scale;
strPos++;
}
return size;
}
void moon_draw_colored_text(f32 x, f32 y, const u8 *str, float scale, struct Color c) {
void moon_draw_colored_text(f32 x, f32 y, const u8 *str, float scale, struct Color c) {
void **hudLUT2 = segmented_to_virtual(main_hud_lut);
u32 xStride = round(12 * scale);
s32 strPos = 0;
s32 w = round(16 * scale);
s32 w = round(16 * scale);
gDPSetEnvColor(gDisplayListHead++, c.r, c.g, c.b, c.a);
while (str[strPos] != GLOBAR_CHAR_TERMINATOR) {
@ -48,7 +48,7 @@ void moon_draw_text(f32 x, f32 y, const u8 *str, float scale) {
y -= 16 * scale;
Mtx *_Matrix = (Mtx *) alloc_display_list(sizeof(Mtx));
if (!_Matrix) return;
if (!_Matrix) return;
guScale(_Matrix, scale, scale, 1.f);
create_dl_translation_matrix(MENU_MTX_PUSH, x, y, 0.0f);
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(_Matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
@ -97,7 +97,7 @@ void moon_draw_text(f32 x, f32 y, const u8 *str, float scale) {
strPos++;
}
create_dl_scale_matrix(MENU_MTX_NOPUSH, 1.0f, 1.0f, 1.0f);
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
}
@ -116,7 +116,7 @@ Vtx *make_rect_verts(float w, float h) {
}
void moon_draw_texture(s32 x, s32 y, u32 w, u32 h, u8 *texture) {
gSPDisplayList(gDisplayListHead++, dl_hud_img_begin);
gSPDisplayList(gDisplayListHead++, dl_hud_img_begin);
gDPSetTile(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_32b, 0, 0, G_TX_LOADTILE, 0, G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR, G_TX_NOMASK, G_TX_NOLOD);
gDPTileSync(gDisplayListHead++);
gDPSetTile(gDisplayListHead++, G_IM_FMT_RGBA, G_IM_SIZ_32b, 2, 0, G_TX_RENDERTILE, 0, G_TX_NOMIRROR, 3, G_TX_NOLOD, G_TX_NOMIRROR, 3, G_TX_NOLOD);
@ -140,17 +140,17 @@ void moon_draw_rectangle(f32 x, f32 y, f32 w, f32 h, struct Color c, u8 u4_3) {
}
create_dl_translation_matrix(MENU_MTX_PUSH, x, y, 0);
guScale(_Matrix, 1, 1, 1);
guScale(_Matrix, 1, 1, 1);
Vtx *vertices = make_rect_verts(w, h);
gSPMatrix(gDisplayListHead++, VIRTUAL_TO_PHYSICAL(_Matrix), G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
gDPSetEnvColor(gDisplayListHead++, c.r, c.g, c.b, c.a);
gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING)
gDPSetCombineMode(gDisplayListHead++, G_CC_FADE, G_CC_FADE);
gDPSetRenderMode(gDisplayListHead++, G_RM_XLU_SURF, G_RM_XLU_SURF2);
gSPVertex(gDisplayListHead++, vertices, 4, 0);
gSP2Triangles(gDisplayListHead++, 0, 1, 2, 0x0, 0, 2, 3, 0x0);
gSP2Triangles(gDisplayListHead++, 0, 1, 2, 0x0, 0, 2, 3, 0x0);
gSPPopMatrix(gDisplayListHead++, G_MTX_MODELVIEW);
gDPSetEnvColor(gDisplayListHead++, 255, 255, 255, 255);

View File

@ -4,10 +4,10 @@
#include "types.h"
struct Color {
u8 r;
u8 g;
u8 b;
u8 a;
int r;
int g;
int b;
int a;
};
f32 moon_get_text_width(u8* text, float scale, u8 colored);

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB