VERSIÓ 1.3.15
- [NEW] mouse.dblclick() - [FIX] de vegades no pillava be la rodeta del ratolí - [NEW] sys.dir() torna el contingut del directori primer les carpetes, i tot ordenat alfabèticament - [WIP] Treballant en ferramentes
This commit is contained in:
40
lua.cpp
40
lua.cpp
@@ -4,6 +4,9 @@
|
||||
#include "jfile.h"
|
||||
#include "log.h"
|
||||
#include <filesystem>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
extern "C" {
|
||||
@@ -723,23 +726,38 @@ extern "C" {
|
||||
std::string path = "./data";
|
||||
if (lua_gettop(L) > 0) path = luaL_checkstring(L, 1);
|
||||
|
||||
lua_newtable(L);
|
||||
int i=1;
|
||||
|
||||
// Collect entries
|
||||
std::vector<fs::directory_entry> entries;
|
||||
for (const auto& entry : fs::directory_iterator(path)) {
|
||||
lua_newtable(L); // create subtable for this entry
|
||||
entries.push_back(entry);
|
||||
}
|
||||
|
||||
// name field
|
||||
lua_pushstring(L, entry.path().u8string().c_str());
|
||||
// Sort: directories first, then files; both alphabetically
|
||||
std::sort(entries.begin(), entries.end(),
|
||||
[](const fs::directory_entry& a, const fs::directory_entry& b) {
|
||||
bool adir = a.is_directory();
|
||||
bool bdir = b.is_directory();
|
||||
if (adir != bdir) return adir > bdir; // directories before files
|
||||
return a.path().filename().string() < b.path().filename().string();
|
||||
});
|
||||
|
||||
// Build Lua table
|
||||
lua_newtable(L);
|
||||
int i = 1;
|
||||
for (const auto& entry : entries) {
|
||||
lua_newtable(L);
|
||||
|
||||
// name field (canonical absolute path)
|
||||
lua_pushstring(L, fs::canonical(entry.path()).u8string().c_str());
|
||||
lua_setfield(L, -2, "name");
|
||||
|
||||
// dir field (true if directory, false otherwise)
|
||||
// dir field
|
||||
lua_pushboolean(L, entry.is_directory());
|
||||
lua_setfield(L, -2, "dir");
|
||||
|
||||
// insert subtable into main table at index i
|
||||
lua_rawseti(L, -2, i++);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -864,6 +882,11 @@ extern "C" {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_mouse_dblclick(lua_State *L) {
|
||||
lua_pushboolean(L, doubleclick());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int cpp_mouse_discard(lua_State *L) {
|
||||
mdiscard();
|
||||
return 0;
|
||||
@@ -1047,6 +1070,7 @@ void push_lua_funcs() {
|
||||
lua_pushcfunction(L,cpp_mouse_wheel); lua_setfield(L, -2, "wheel");
|
||||
lua_pushcfunction(L,cpp_mouse_down); lua_setfield(L, -2, "down");
|
||||
lua_pushcfunction(L,cpp_mouse_press); lua_setfield(L, -2, "press");
|
||||
lua_pushcfunction(L,cpp_mouse_dblclick); lua_setfield(L, -2, "dblclick");
|
||||
lua_pushcfunction(L,cpp_mouse_discard); lua_setfield(L, -2, "discard");
|
||||
|
||||
lua_pushinteger(L, 1); lua_setfield(L, -2, "LEFT");
|
||||
|
||||
16
mini.cpp
16
mini.cpp
@@ -112,6 +112,7 @@ Uint8 key_just_pressed = 0;
|
||||
int mouse_x, mouse_y, mouse_wheel;
|
||||
Uint32 mouse_buttons;
|
||||
uint8_t mouse_just_pressed = 0;
|
||||
bool double_click = false;
|
||||
bool mouse_discard = false;
|
||||
|
||||
SDL_Gamepad *gamepad = NULL;
|
||||
@@ -479,8 +480,9 @@ int main(int argc,char*argv[]){
|
||||
key_just_pressed = 0;
|
||||
pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID;
|
||||
mouse_just_pressed = 0;
|
||||
mouse_wheel = 0;
|
||||
double_click = false;
|
||||
while(!should_exit) {
|
||||
mouse_wheel = 0;
|
||||
if (update_mode==UPDATE_WAIT) SDL_WaitEvent(NULL);
|
||||
else if (update_mode==UPDATE_TIMEOUT) SDL_WaitEventTimeout(NULL, timeout);
|
||||
while(SDL_PollEvent(&mini_eve)) {
|
||||
@@ -522,7 +524,11 @@ int main(int argc,char*argv[]){
|
||||
if (mouse_discard)
|
||||
mouse_discard = false;
|
||||
else
|
||||
mouse_just_pressed = mini_eve.button.button;
|
||||
if (mini_eve.button.clicks==2 && mini_eve.button.button==SDL_BUTTON_LEFT) {
|
||||
double_click = true;
|
||||
} else {
|
||||
mouse_just_pressed = mini_eve.button.button;
|
||||
}
|
||||
}
|
||||
if (mini_eve.type == SDL_EVENT_MOUSE_WHEEL) {
|
||||
mouse_wheel = mini_eve.wheel.y;
|
||||
@@ -558,6 +564,8 @@ int main(int argc,char*argv[]){
|
||||
if (beats>0)beats--;
|
||||
key_just_pressed = 0;
|
||||
mouse_just_pressed = 0;
|
||||
double_click = false;
|
||||
mouse_wheel = 0;
|
||||
pad_just_pressed = SDL_GAMEPAD_BUTTON_INVALID;
|
||||
}
|
||||
SDL_SetRenderTarget(mini_ren, mini_shadertex);
|
||||
@@ -1313,6 +1321,10 @@ bool mbtnp(uint8_t i) {
|
||||
return mouse_just_pressed == i;
|
||||
}
|
||||
|
||||
bool doubleclick() {
|
||||
return double_click;
|
||||
}
|
||||
|
||||
void mdiscard() {
|
||||
mouse_discard = true;
|
||||
}
|
||||
|
||||
1
mini.h
1
mini.h
@@ -225,6 +225,7 @@ int mousey();
|
||||
int mwheel();
|
||||
bool mbtn(uint8_t i);
|
||||
bool mbtnp(uint8_t i);
|
||||
bool doubleclick();
|
||||
void mdiscard();
|
||||
|
||||
float time();
|
||||
|
||||
5
tools/fonted/data/game.ini
Normal file
5
tools/fonted/data/game.ini
Normal file
@@ -0,0 +1,5 @@
|
||||
title=NEW MINI PROJECT
|
||||
config=newminiproject
|
||||
width=320
|
||||
height=240
|
||||
zoom=2
|
||||
138
tools/fonted/data/main.lua
Normal file
138
tools/fonted/data/main.lua
Normal file
@@ -0,0 +1,138 @@
|
||||
function loadDir(path)
|
||||
files = sys.dir(path)
|
||||
if #files > 0 then
|
||||
dir = files[1].name:match("(.+)/[^/]+$")
|
||||
else
|
||||
dir = path
|
||||
end
|
||||
table.insert(files, 1, { dir=true, name=".." })
|
||||
selected = 0
|
||||
offset = 0
|
||||
lift_height=-1
|
||||
lift_top=0
|
||||
if #files>23 then
|
||||
lift_height=23*161/#files
|
||||
end
|
||||
end
|
||||
|
||||
function goBack()
|
||||
dir = dir:match("(.+)/[^/]+$")
|
||||
loadDir(dir)
|
||||
end
|
||||
|
||||
function mini.init()
|
||||
surf.cls(0)
|
||||
folder = surf.new(5,4)
|
||||
surf.target(folder)
|
||||
for i=0,4 do for j=0,3 do surf.pixel(i,j,0) end end
|
||||
for i=2,4 do surf.pixel(i,0,255) end
|
||||
surf.target(0)
|
||||
loadDir(".")
|
||||
end
|
||||
|
||||
function mini.update()
|
||||
|
||||
local mx,my=mouse.pos()
|
||||
|
||||
view.origin(0,0)
|
||||
for i=0,15 do
|
||||
draw.rectf(i*8, 0, 8, 8, i)
|
||||
end
|
||||
pal.trans(255)
|
||||
view.origin(20, 20)
|
||||
draw.rrectf(0,0,280,200,3,15)
|
||||
draw.rrectf(4,4,272,9,2,12)
|
||||
draw.rrectf(4,17,272,163,2,12)
|
||||
if lift_height>0 then draw.rrectf(271,18+lift_top,4,lift_height,2,14) end
|
||||
|
||||
draw.rrectf(192,185,40,11,2,9)
|
||||
draw.rrectf(192,184,40,11,2,10)
|
||||
draw.text("OK",209,187,9)
|
||||
|
||||
draw.rrectf(236,185,40,11,2,1)
|
||||
draw.rrectf(236,184,40,11,2,2)
|
||||
draw.text("CANCEL",245,187,1)
|
||||
|
||||
local y = 19
|
||||
draw.text(dir, 6, 6, 0)
|
||||
|
||||
surf.source(folder)
|
||||
|
||||
-- if mx>4 and mx<268 and my>=y-1 and my<y+6 then
|
||||
-- draw.rectf(4,y-1,272,7,13)
|
||||
-- if mouse.dblclick() then
|
||||
-- goBack();
|
||||
-- end
|
||||
-- end
|
||||
-- draw.surf(0,0,5,4,7,y+1,5,4)
|
||||
-- pal.subpal(0,3)
|
||||
-- draw.surf(0,0,5,4,6,y,5,4)
|
||||
-- pal.subpal(0)
|
||||
-- draw.text("..", 13, y, 0) y=y+7
|
||||
local count = 0
|
||||
for k,file in ipairs(files) do
|
||||
local filename = file.name:match("([^/]+)$")
|
||||
if count < offset then goto continue end
|
||||
--if v:match("%.gif$") then
|
||||
if mx>4 and mx<268 and my>=y-1 and my<y+6 then
|
||||
draw.rectf(4,y-1,272,7,13)
|
||||
if mouse.dblclick() then
|
||||
if file.dir then
|
||||
if k==1 then
|
||||
goBack()
|
||||
else
|
||||
loadDir(dir.."/"..filename)
|
||||
end
|
||||
else
|
||||
--selected = k
|
||||
end
|
||||
elseif mouse.press(mouse.LEFT) then
|
||||
selected = k
|
||||
end
|
||||
end
|
||||
|
||||
if selected == k then
|
||||
draw.rectf(4,y-1,272,7,10)
|
||||
end
|
||||
|
||||
if file.dir then
|
||||
draw.surf(0,0,5,4,7,y+1,5,4)
|
||||
pal.subpal(0,3)
|
||||
draw.surf(0,0,5,4,6,y,5,4)
|
||||
pal.subpal(0)
|
||||
draw.text(filename, 13, y, 0)
|
||||
else
|
||||
draw.text(filename, 6, y, 0)
|
||||
end
|
||||
y=y+7
|
||||
::continue::
|
||||
count=count+1
|
||||
if count-offset>=23 then break end
|
||||
end
|
||||
|
||||
if key.press(key.RETURN) and selected~=-1 then
|
||||
if files[selected].dir then
|
||||
local filename = files[selected].name:match("([^/]+)$")
|
||||
loadDir(dir.."/"..filename)
|
||||
else
|
||||
-- do nothing for now
|
||||
end
|
||||
elseif key.press(key.DOWN) and selected<#files then
|
||||
selected=selected+1
|
||||
elseif key.press(key.UP) then
|
||||
if selected>1 then
|
||||
selected=selected-1
|
||||
else
|
||||
selected = 1
|
||||
end
|
||||
end
|
||||
|
||||
local scroll = -mouse.wheel()
|
||||
if scroll~=0 then
|
||||
offset=offset+scroll
|
||||
if offset<0 then offset=0 end
|
||||
if offset+23 > #files then offset = #files-23 end
|
||||
lift_top=offset*161/#files
|
||||
end
|
||||
|
||||
end
|
||||
BIN
tools/fonted/data/subatomic.gif
Normal file
BIN
tools/fonted/data/subatomic.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 540 B |
@@ -518,6 +518,10 @@ function mouse.down(btn) end
|
||||
---Returns whether the specified mouse button has just been pressed
|
||||
function mouse.press(btn) end
|
||||
|
||||
---@return boolean
|
||||
---Returns whether the user performed a double click
|
||||
function mouse.dblclick() end
|
||||
|
||||
---Ignores current down button, effectively not raising the next "press" event
|
||||
function mouse.discard() end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user