diff --git a/sdlms/CMakeLists.txt b/sdlms/CMakeLists.txt index 7df26103..df76cb2c 100644 --- a/sdlms/CMakeLists.txt +++ b/sdlms/CMakeLists.txt @@ -1,6 +1,10 @@ +cmake_minimum_required(VERSION 3.19.2) +project(sdlMS) -set(FFMPEG_INCLUDE "E:\\mygame\\Maple\\sdlMS2\\FFMPEG\\include") -set(FFMPEG_LIB "E:\\mygame\\Maple\\sdlMS2\\FFMPEG\\lib") +set(CMAKE_CXX_STANDARD 20) + +set(FFMPEG_INCLUDE "C:/FFMPEG/include") +set(FFMPEG_LIB "C:/FFMPEG/lib") include_directories( ${CMAKE_CURRENT_SOURCE_DIR} @@ -21,7 +25,7 @@ link_directories( ${FFMPEG_LIB} ) -file(GLOB SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/**/*.cpp) +file(GLOB_RECURSE SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) if(WIN32) add_executable(sdlMS ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ${SOURCE_FILES}) diff --git a/sdlms/Components/C_Cursor.cpp b/sdlms/Components/C_Cursor.cpp new file mode 100644 index 00000000..0c335c51 --- /dev/null +++ b/sdlms/Components/C_Cursor.cpp @@ -0,0 +1,128 @@ +#include "C_Cursor.h" + +#include "String.h" + +#include "Components/Sprite.h" +#include "Components/Transform.h" +#include "Components/RelativeTransform.h" +#include "Components/RandomInput.h" +#include "Components/LimitTransform.h" +#include "Components/Line.h" +#include "Components/Physic/Normal.h" +#include "Resource/Wz.h" + +C_Cursor::C_Cursor(wz::Node *node, int id, int rx0, int rx1, World *world) +{ + +} + +// 测试 +C_Cursor::C_Cursor(World *world) +{ + auto node_cursor = world->get_resource().UI->get_root()->find_from_path(u"Basic.img/Cursor"); + + for (auto &[name, val] : node_cursor->get_children()) + { + if (name != u"info") + { + auto aspr = new AnimatedSprite(val[0]); + auto id = std::stoi(std::string{name.begin(), name.end()}); + aspr_map[static_cast(id)] = aspr; + world->add_component(aspr); + } + } + + act = State::IDLE; + + /* add_component(aspr_map[state]); + + Transform *tr = new Transform(); + add_component(tr); + world->add_component(tr, 3000000); */ +} + +/* void C_Cursor::switch_act(State s) +{ + if (s != state) + { + if (aspr_map.contains(s)) + //if (aspr_map1.contains("")) + { + auto aspr = aspr_map[s]; + aspr->set_anim_index(0); + aspr->set_anim_time(0); + state = s; + add_component(aspr); + } + } +} + +void C_Cursor::start_animate() +{ + get_component()->set_animate(true); +} + +void C_Cursor::stop_animate() +{ + get_component()->set_animate(false); +} +*/ + +C_Cursor::~C_Cursor() +{ + /* auto world = World::get_world(); + + for (auto &[key, val] : aspr_map) + { + auto aspr = val; + world->destroy_component(aspr, false); + delete aspr; + } + + for (auto &[key, val] : get_entity()) + { + auto t = val->get_component(); + auto rtr = val->get_component(); + world->destroy_component(t, false); + world->destroy_component(rtr, false); + delete t; + delete rtr; + delete val; + } + + for (auto &[key, val] : get_entity()) + { + auto t = val->get_component(); + auto rtr = val->get_component(); + world->destroy_component(t, false); + world->destroy_component(rtr, false); + delete t; + delete rtr; + delete val; + } + + auto t = get_component(); + world->destroy_component(t, false); + delete t; + + auto nor = get_component(); + if (nor != nullptr) + { + world->destroy_component(nor, false); + delete nor; + } + + auto ran = get_component(); + if (ran != nullptr) + { + world->destroy_component(ran, false); + delete ran; + } + + auto ltr = get_component(); + if (ltr != nullptr) + { + world->destroy_component(ltr, false); + delete ltr; + } */ +} diff --git a/sdlms/Components/C_Cursor.h b/sdlms/Components/C_Cursor.h new file mode 100644 index 00000000..2e8eec9b --- /dev/null +++ b/sdlms/Components/C_Cursor.h @@ -0,0 +1,49 @@ +#pragma once +#include "Component.h" +#include "wz/Property.hpp" +#include "Core/World.h" +#include "Components/AnimatedSprite.h" + +class C_Cursor : public Component +{ + public: +enum State + { + IDLE, + CANCLICK, + GAME, + HOUSE, + CANCLICK2, + CANGRAB, + GIFT, + VSCROLL, + HSCROLL, + VSCROLLIDLE, + HSCROLLIDLE, + GRABBING, + CLICKING, + RCLICK, + LEAF = 18, + CHATBARVDRAG = 67, + CHATBARHDRAG, + CHATBARBLTRDRAG, + CHATBARMOVE = 72, + CHATBARBRTLDRAG, + LENGTH + }; + + C_Cursor(wz::Node *node, int id, int rx0, int rx1, World *world); + C_Cursor(World *world); + ~C_Cursor(); + + void switch_act(State s); + void stop_animate(); + void start_animate(); + +public: + std::unordered_map str_map; + State act = State::IDLE; + std::unordered_map aspr_map; + std::unordered_map aspr_map1; + //State state = State::IDLE; +}; \ No newline at end of file diff --git a/sdlms/Core/EntityBuilder/EB_Cursor.cpp b/sdlms/Core/EntityBuilder/EB_Cursor.cpp new file mode 100644 index 00000000..e69de29b diff --git a/sdlms/Core/EntityBuilder/EB_Cursor.h b/sdlms/Core/EntityBuilder/EB_Cursor.h new file mode 100644 index 00000000..2215da7e --- /dev/null +++ b/sdlms/Core/EntityBuilder/EB_Cursor.h @@ -0,0 +1,27 @@ +#pragma once + +#include "wz/Property.hpp" +#include "Core/World.h" +#include "Components/AnimatedSprite.h" +#include "Components/C_Cursor.h" +#include "Components/Transform.h" + +class EB_Cursor +{ +public: + static Entity* BuildEntity(World *world) + { + Entity *entity = new Entity(); + + C_Cursor *c_Cursor = new C_Cursor(world); + Transform *c_T = new Transform(0,0,0,true); + + entity->add_component(c_Cursor->aspr_map[c_Cursor->act]); + entity->add_component(c_Cursor); + entity->add_component(c_T); + + world->add_component(c_T, 3000000); + world->add_component(c_Cursor); + return entity; + } +}; \ No newline at end of file diff --git a/sdlms/Resource/Wz.cpp b/sdlms/Resource/Wz.cpp index 93b35762..b160e7e6 100644 --- a/sdlms/Resource/Wz.cpp +++ b/sdlms/Resource/Wz.cpp @@ -26,7 +26,7 @@ Wz::Wz(const std::string &filename_prefix) Sound = (new wz::File(iv, (std::string(filename_prefix) + std::string("Sound.wz")).c_str())); String = (new wz::File(iv, (std::string(filename_prefix) + std::string("String.wz")).c_str())); // TamingMob = (new wz::File(iv, (std::string(filename_prefix) + std::string("TamingMob.wz")).c_str())); - // UI = (new wz::File(iv, (std::string(filename_prefix) + std::string("UI.wz")).c_str())); + UI = (new wz::File(iv, (std::string(filename_prefix) + std::string("UI.wz")).c_str())); // Base->parse(); Character->parse(u"Character"); @@ -44,5 +44,5 @@ Wz::Wz(const std::string &filename_prefix) Sound->parse(u"Sound"); String->parse(u"String"); // TamingMob->parse(); - // UI->parse(u"UI"); + UI->parse(u"UI"); } \ No newline at end of file diff --git a/sdlms/Systems/S_Cursor.cpp b/sdlms/Systems/S_Cursor.cpp new file mode 100644 index 00000000..e37b8372 --- /dev/null +++ b/sdlms/Systems/S_Cursor.cpp @@ -0,0 +1,48 @@ +#include "S_Cursor.h" +#include +#include +#include +#include "Components/C_Cursor.h" +#include "Core/Input.h" + +void S_Cursor::run(World &world) +{ + if (world.components_exist_of_type()) + { + for (auto &[index, pla] : world.get_components()) + { + if (Input::is_mouse_button_pressed(Input::MouseButton::ButtonLeft)) + { + switch_act(pla, C_Cursor::State::CLICKING); + } + else if (Input::is_mouse_button_released(Input::MouseButton::ButtonLeft)) + { + switch_act(pla, C_Cursor::State::IDLE); + } + + update_Transform(pla->get_owner_component()); + } + } +} + +void S_Cursor::switch_act(C_Cursor *cCursor, C_Cursor::State action) +{ + if (action != cCursor->act) + { + // if (cCursor->aspr_map.contains(action)) + { + auto aspr = cCursor->aspr_map[action]; + aspr->set_anim_index(0); + aspr->set_anim_time(0); + cCursor->act = action; + cCursor->get_owner()->add_component(aspr); + } + } +} + +void S_Cursor::update_Transform(Transform *t) +{ + int x, y; + Uint32 mouse_state = SDL_GetMouseState(&x, &y); + t->set_position(SDL_FPoint(x, y)); +} \ No newline at end of file diff --git a/sdlms/Systems/S_Cursor.h b/sdlms/Systems/S_Cursor.h new file mode 100644 index 00000000..b3e05aaa --- /dev/null +++ b/sdlms/Systems/S_Cursor.h @@ -0,0 +1,27 @@ +#pragma once +#include "Systems/System.h" +#include "Components/AnimatedSprite.h" +#include "Components/Transform.h" +#include "Components/HVMove.h" +#include "Components/Avatar.h" + +#include "Entities/Portal.h" + +#include "S_Cursor.h" +#include +#include +#include +#include "Components/C_Cursor.h" +#include "Core/Input.h" + +class S_Cursor : public System +{ +public: + void run(World &world) override; + +private: + bool update_animated_sprite(AnimatedSprite *aspr, int delta_time, World &world); + void update_avatar(Avatar *hvm, int delta_time, World &world); + void switch_act(C_Cursor* cCursor, C_Cursor::State action); + void update_Transform(Transform* cCursor); +}; diff --git a/sdlms/main.cpp b/sdlms/main.cpp index 38dec5da..f717bc7e 100644 --- a/sdlms/main.cpp +++ b/sdlms/main.cpp @@ -9,6 +9,7 @@ #include "Systems/InputSystem.h" #include "Systems/SpriteSystem.h" #include "Systems/TransformSystem.h" +#include "Systems/S_Cursor.h" #include "Components/Sound.h" #include "Components/Camera.h" #include "Components/Player.h" @@ -24,6 +25,17 @@ #include #endif +#ifdef __ANDROID__ +#include "SDL_main.h" +#endif + +#include "Net/Session.h" +#include "IO/UI.h" +#include "Timer.h" +#include "Constants.h" +#include "Configuration.h" +#include "Core/EntityBuilder/EB_Cursor.h" + int width = 800; int height = 600; @@ -56,6 +68,7 @@ int main(int argc, char *argv[]) #else Wz *wz = new Wz("./Data/"); FreeType::init("./Data/"); + #endif world.add_resource(wz); @@ -76,6 +89,7 @@ int main(int argc, char *argv[]) world.add_system(new TransformSystem()); world.add_system(new RenderSystem()); + world.add_system(new S_Cursor()); Camera *camera = new Camera(0, 0, width, height); Player *pla = new Player(); // 玩家控制的角色 @@ -91,6 +105,14 @@ int main(int argc, char *argv[]) world.add_component(nor); world.add_component(pla); } +#ifndef __ANDROID__ + + Entity* cursor = EB_Cursor::BuildEntity(&world); + world.add_entity(cursor); + + SDL_ShowCursor(SDL_DISABLE); +#endif + // { // Mob *mob = new Mob(&world, {0, 0}); // Normal *nor = new Normal();