Jump to content

Awesomium Integration


Rick
 Share

Recommended Posts

https://db.tt/TefSRu0H

 

There was another topic about this recently so I thought I'd share what I had when we were working on the Dead Anyway game as it may help others in the future.

 

Awesomium is a library that let's you use html/css/javascript for your game UI. http://www.awesomium.com/

 

This example provides a system where you can call javascript functions from lua and lua functions from javascript (some C++ code acts as the middle man but it's generic and you won't have to touch it) in a generic fashion. All you have to do is define the functions and their parameters and then call a SendMessage() function passing in the string value of the function to call in the other language and a csv string of the arguments.

 

 

So if I wanted Lua to call a Javascript function I'd define my Javascript function in my html page:

 

// called when the craft button is clicked on the html page
$("#craft").click(function(){
app.sendMessage("Craft", "rope, 2")
});

 

 

Then on the Lua side you just define the Craft function:

 

function Craft(item, qty)
end

 

 

If I wanted to go the other way, I'd make the call from Lua:

 

SendUIMessage("Craft", 'Axe, 1')

 

and on the javascript side I'd define the function:

 

function Craft(item, qty){
}

 

 

This only has mouse input integration. I haven't figured out keyboard integration yet.

 

 

If you want to play around with the example the html page is in the UI folder and you can define your lua functions that get called from javascript in the Scripts/UICallbacks.lua file. You can alter the html file however you want and the lua files however you want to see the results. Shouldn't be any need to alter the C++ VS project.

 

If you want to make changes to the VS project then download Awesomium and you should be good to go. A variable for the path gets created for you and that's what's used in the VS projects for the include and lib path so it should just work once you download it and install it.

  • Upvote 1
Link to comment
Share on other sites

find a way to send keystrokes! :)

 

i'm using something like:

 

WebKeyboardEvent keyEvent;
char chr;

for (int i=1; i<256; i++){
   char chr=i;

   keyEvent.type = WebKeyboardEvent::kTypeKeyDown;
keyEvent.native_key_code = chr;
webView->InjectKeyboardEvent(keyEvent);
keyEvent.type = WebKeyboardEvent::kTypeChar;
keyEvent.text[0] = chr;
webView->InjectKeyboardEvent(keyEvent);
keyEvent.type = Awesomium::WebKeyboardEvent::kTypeKeyUp;
keyEvent.native_key_code = chr;
webView->InjectKeyboardEvent(keyEvent);
}

 

with this code, there are no A/a upper/lower

so some key mapping will be necessary :(

Paren el mundo!, me quiero bajar.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...