Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions sdlms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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})
Expand Down
128 changes: 128 additions & 0 deletions sdlms/Components/C_Cursor.cpp
Original file line number Diff line number Diff line change
@@ -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<Wz>().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<State>(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<AnimatedSprite>()->set_animate(true);
}

void C_Cursor::stop_animate()
{
get_component<AnimatedSprite>()->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<String>())
{
auto t = val->get_component<Transform>();
auto rtr = val->get_component<RelativeTransform>();
world->destroy_component(t, false);
world->destroy_component(rtr, false);
delete t;
delete rtr;
delete val;
}

for (auto &[key, val] : get_entity<NameTag>())
{
auto t = val->get_component<Transform>();
auto rtr = val->get_component<RelativeTransform>();
world->destroy_component(t, false);
world->destroy_component(rtr, false);
delete t;
delete rtr;
delete val;
}

auto t = get_component<Transform>();
world->destroy_component(t, false);
delete t;

auto nor = get_component<Normal>();
if (nor != nullptr)
{
world->destroy_component(nor, false);
delete nor;
}

auto ran = get_component<RandomInput>();
if (ran != nullptr)
{
world->destroy_component(ran, false);
delete ran;
}

auto ltr = get_component<LimitTransform>();
if (ltr != nullptr)
{
world->destroy_component(ltr, false);
delete ltr;
} */
}
49 changes: 49 additions & 0 deletions sdlms/Components/C_Cursor.h
Original file line number Diff line number Diff line change
@@ -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<std::u16string, std::u16string> str_map;
State act = State::IDLE;
std::unordered_map<State, AnimatedSprite*> aspr_map;
std::unordered_map<std::u16string, AnimatedSprite*> aspr_map1;
//State state = State::IDLE;
};
Empty file.
27 changes: 27 additions & 0 deletions sdlms/Core/EntityBuilder/EB_Cursor.h
Original file line number Diff line number Diff line change
@@ -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;
}
};
4 changes: 2 additions & 2 deletions sdlms/Resource/Wz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
}
48 changes: 48 additions & 0 deletions sdlms/Systems/S_Cursor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "S_Cursor.h"
#include <ranges>
#include <algorithm>
#include <SDL2/SDL.h>
#include "Components/C_Cursor.h"
#include "Core/Input.h"

void S_Cursor::run(World &world)
{
if (world.components_exist_of_type<C_Cursor>())
{
for (auto &[index, pla] : world.get_components<C_Cursor>())
{
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<Transform>());
}
}
}

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));
}
27 changes: 27 additions & 0 deletions sdlms/Systems/S_Cursor.h
Original file line number Diff line number Diff line change
@@ -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 <ranges>
#include <algorithm>
#include <SDL2/SDL.h>
#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);
};
22 changes: 22 additions & 0 deletions sdlms/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,6 +25,17 @@
#include <emscripten.h>
#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;

Expand Down Expand Up @@ -56,6 +68,7 @@ int main(int argc, char *argv[])
#else
Wz *wz = new Wz("./Data/");
FreeType::init("./Data/");

#endif
world.add_resource(wz);

Expand All @@ -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(); // 玩家控制的角色
Expand All @@ -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();
Expand Down