testmodules/uitest: Test very simple but correct UI usage
This commit is contained in:
parent
b3a151e8a9
commit
19a1da6033
39
test/testmodules/uitest/client_lua/init.lua
Normal file
39
test/testmodules/uitest/client_lua/init.lua
Normal file
@ -0,0 +1,39 @@
|
||||
-- Buildat: uitest/client_lua/init.lua
|
||||
-- http://www.apache.org/licenses/LICENSE-2.0
|
||||
-- Copyright 2014 Perttu Ahola <celeron55@gmail.com>
|
||||
local log = buildat.Logger("uitest")
|
||||
local magic = require("buildat/extension/urho3d")
|
||||
local uistack = require("buildat/extension/uistack")
|
||||
log:info("uitest/init.lua loaded")
|
||||
|
||||
local ui_stack = uistack.main
|
||||
|
||||
function show_stuff()
|
||||
local root = ui_stack:push({desc="uitest root"})
|
||||
root.defaultStyle = magic.cache:GetResource("XMLFile", "__menu/res/main_style.xml")
|
||||
|
||||
local window = root:CreateChild("Window")
|
||||
window:SetStyleAuto()
|
||||
window:SetName("window")
|
||||
window:SetLayout(magic.LM_VERTICAL, 10, magic.IntRect(10, 10, 10, 10))
|
||||
window:SetAlignment(magic.HA_LEFT, magic.VA_CENTER)
|
||||
|
||||
local message_text = window:CreateChild("Text")
|
||||
message_text:SetName("message_text")
|
||||
message_text:SetStyleAuto()
|
||||
message_text.text = "Stuff"
|
||||
message_text:SetTextAlignment(magic.HA_CENTER)
|
||||
end
|
||||
|
||||
show_stuff()
|
||||
|
||||
function handle_keydown(event_type, event_data)
|
||||
local key = event_data:GetInt("Key")
|
||||
if key == magic.KEY_ESC then
|
||||
log:info("KEY_ESC pressed")
|
||||
buildat.disconnect()
|
||||
end
|
||||
end
|
||||
magic.SubscribeToEvent("KeyDown", "handle_keydown")
|
||||
|
||||
-- vim: set noet ts=4 sw=4:
|
70
test/testmodules/uitest/uitest.cpp
Normal file
70
test/testmodules/uitest/uitest.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
#include "core/log.h"
|
||||
#include "interface/module.h"
|
||||
#include "interface/server.h"
|
||||
#include "interface/event.h"
|
||||
#include "network/api.h"
|
||||
#include "client_file/api.h"
|
||||
|
||||
using interface::Event;
|
||||
|
||||
namespace uitest {
|
||||
|
||||
struct Module: public interface::Module
|
||||
{
|
||||
interface::Server *m_server;
|
||||
|
||||
Module(interface::Server *server):
|
||||
interface::Module("uitest"),
|
||||
m_server(server)
|
||||
{
|
||||
log_v(MODULE, "uitest construct");
|
||||
}
|
||||
|
||||
~Module()
|
||||
{
|
||||
log_v(MODULE, "uitest destruct");
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
log_v(MODULE, "uitest init");
|
||||
m_server->sub_event(this, Event::t("core:start"));
|
||||
m_server->sub_event(this, Event::t("network:new_client"));
|
||||
m_server->sub_event(this, Event::t("client_file:files_transmitted"));
|
||||
}
|
||||
|
||||
void event(const Event::Type &type, const Event::Private *p)
|
||||
{
|
||||
EVENT_VOIDN("core:start", on_start)
|
||||
EVENT_TYPEN("network:new_client", on_new_client, network::NewClient)
|
||||
EVENT_TYPEN("client_file:files_transmitted", on_files_transmitted,
|
||||
client_file::FilesTransmitted)
|
||||
}
|
||||
|
||||
void on_start()
|
||||
{
|
||||
}
|
||||
|
||||
void on_new_client(const network::NewClient &new_client)
|
||||
{
|
||||
log_i(MODULE, "uitest::on_new_client: id=%zu", new_client.info.id);
|
||||
}
|
||||
|
||||
void on_files_transmitted(const client_file::FilesTransmitted &event)
|
||||
{
|
||||
log_v(MODULE, "on_files_transmitted(): recipient=%zu", event.recipient);
|
||||
|
||||
network::access(m_server, [&](network::Interface * inetwork){
|
||||
inetwork->send(event.recipient, "core:run_script",
|
||||
"buildat.run_script_file(\"uitest/init.lua\")");
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
EXPORT void* createModule_uitest(interface::Server *server){
|
||||
return (void*)(new Module(server));
|
||||
}
|
||||
}
|
||||
}
|
||||
// vim: set noet ts=4 sw=4:
|
Loading…
x
Reference in New Issue
Block a user